Newer
Older

jacques.grelet_ird.fr
committed
function readTsgIniLabview(hMainFig, fid)
% readTsgIniLabview(hMainFig, filename)
% read TSG labview acquisition .ini file
%
% Input
% -----
% hMainFig ............ Handle to the main user interface
% fid ............ file descriptor on the .ini file opened
%
% Output
% ------
% none ............. tsg struct is saved with setappdata
%
% $Id$
% Get the tsg struct from the application GUI
% -------------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');

jacques.grelet_ird.fr
committed
% Get an instance of dynaload objetc from file 'tsgqc_netcdf.csv'
% -----------------------------------------------------------------
nc = dynaload('tsgqc_netcdf.csv');
% Get attributes & variables list from dynaload instance
% ------------------------------------------------------
nca_keys = keys(nc.ATTRIBUTES);
ncv_keys = keys(nc.VARIABLES);

jacques.grelet_ird.fr
committed
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
% read first line
% -------------
inputText = textscan(fid, '%s', 1, 'delimiter', '\n');
% test the end-of-file
% --------------------
while ~feof(fid)
% use string instead cell
% -----------------------
str = inputText{1}{1};
% Iterate from each element from object nca and additional variables
% ------------------------------------------------------------------
for ii = nca_keys
% get key, use char because i is cell
% -----------------------------------
clef = char(ii);
% construct regex with pair cle=value
% and extract value
% ------------------------------------
regex = strcat('^\s*', clef, '\s*=\s*(\w.+)$');
match = regexp( str, regex, 'tokens');
% build tsg struct
% ----------------
if ~isempty(match)
%if isnan(str2double(match{1}{1}))
tsg.(clef) = match{1}{1};
%else
% tsg.(clef) = sprintf('%f',str2double(match{1}{1}));
%end
continue
end
end
% Iterate from each element from object nca and additional variables
% ------------------------------------------------------------------
for ii = ncv_keys
% get key, use char because i is cell
% -----------------------------------
clef = char(ii);
% construct regex with pair cle=value and extract value
% simple variables are : SSPS_DEPH=8.00000000E+0
% coeff variables are : SSJT_CALCOEF_G=4,23058298E-3 or
% CNDC_LINCOEF_OFFSET=0.00000000E+0
% ------------------------------------
if ~isempty(strfind(clef, 'COEF'))
regex = strcat('^\s*', clef, '_(\w+)?\s*=\s*(.*)$');
match = regexp( str, regex, 'tokens');
elseif ~isempty(strfind(clef, 'DEPH'))
regex = strcat('^\s*', clef, '\s*=\s*(.*)$');
%regex = strcat('^\s*\w*_DEPH_?\w*\s*=\s*(\w.+)$');
match = regexp( str, regex, 'tokens');
else
match = [];
end
% build tsg struct
% ----------------
if ~isempty(match)
% variable SSPS_DEPH return one match, SSJT_CALCOEF_G two
% -------------------------------------------------------
switch size(match{1},2)
% in case of calibration coefficients, have key/value pair
% --------------------------------------------------------
case 2
% get key
% --------
k = match{1}{1};
% convert date in julian day when key is 'DATE', else to double
% -------------------------------------------------------------
if strcmpi(k, 'DATE')
v = datenumToJulian(datenum(match{1}{2}, 'dd/mm/yyyy'));
else
v = str2double(match{1}{2});
end
% add key to _CONV array, with length of STRING8
% ----------------------------------------------
tsg.([clef '_CONV']) = [tsg.([clef '_CONV']); padding(k, 8)];
% add value to coefficients array
% -------------------------------
tsg.(clef) = [tsg.(clef); v];
% for debbuging only
% ------------------
%fprintf('%s: %s -> %f\n', clef, k, v);
case 1
% add value to variable array
% ---------------------------
tsg.(clef) = str2double(match{1}{1});
% for debbuging only
% ------------------
%fprintf('%s: %f\n', clef, tsg.(clef));
end
% quit for loop
% -------------
continue
end % end of match
end % end ncv_keys
% read next line
% --------------
inputText = textscan(fid, '%s', 1, 'delimiter', '\n');
end % end of while loop
% Save the data in the application GUI
% ------------------------------------
setappdata( hMainFig, 'tsg_data', tsg );
% close .ini file
% ---------------
fclose(fid);