-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_header_information.m
84 lines (75 loc) · 2.71 KB
/
extract_header_information.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
%
% This file is part of pichim's controller tuning framework.
%
% This sofware is free. You can redistribute this software
% and/or modify this software under the terms of the GNU General
% Public License as published by the Free Software Foundation,
% either version 3 of the License, or (at your option) any later
% version.
%
% This software is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%
% See the GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public
% License along with this software.
%
% If not, see <http:%www.gnu.org/licenses/>.
%
%%
function [para, Nheader, ind] = extract_header_information(filePath) %#ok
fid = fopen(filePath);
tline = fgetl(fid);
para = [];
Nheader = 0;
do_read_para = false;
while ischar(tline)
Nheader = Nheader + 1;
% we start reading parameters at frameIntervalI
if ~isempty(regexp(tline, 'frameIntervalI', 'once'))
do_read_para = true;
end
% we stop reading parameters at loopIteration
if ~isempty(regexp(tline, 'loopIteration', 'once'))
break;
end
if do_read_para
idx = regexp(tline, '",');
para_name = tline(2:idx-1); %#ok
para_value = tline(idx+2:end);
if strcmp(para_value(1), '"')
try % 'magPID' '"40,,"'
eval(['para.(para_name) = [', para_value(2:end-1), '];']);
end
else
eval(['para.(para_name) = [', para_value, '];']);
end
end
tline = fgetl(fid);
end
fclose(fid);
%%
idx = regexp(tline, ',');
ind_cntr = 1;
% handle first element, should be 'loopIteration'
ind_name = tline(2:idx(1)-2); %#ok
eval(['ind.(ind_name) = [', num2str(ind_cntr), '];']);
% handle all elements between
for i = 1:length(idx)-1
ind_cntr = ind_cntr + 1;
ind_name = tline(idx(i)+2:idx(i+1)-2);
if strcmp(ind_name(1:4), 'eRPM')
eval(['ind.(ind_name(1:4))(str2double((ind_name(end-1))) + 1) = [', num2str(ind_cntr), '];']);
elseif strcmp(ind_name(end), ']')
eval(['ind.(ind_name(1:end-3))(str2double((ind_name(end-1))) + 1) = [', num2str(ind_cntr), '];']);
else
eval(['ind.(ind_name) = [', num2str(ind_cntr), '];']);
end
end
% handle last element, should be 'axisError[2]'
ind_cntr = ind_cntr + 1;
ind_name = tline(idx(end)+2:end-1); %#ok
eval(['ind.(ind_name(1:end-3))(str2double((ind_name(end-1))) + 1) = [', num2str(ind_cntr), '];']);
end