Newer
Older
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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
function error = saveReport( hMainFig )
%
% Input
% -----
% hMainFig ............ Handel to the main user interface
%
% Output
% ------
% error .............. 1: OK ; -1 : an error occured
error = -1;
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
nPara = 3;
PARA = ['SSPS'; 'SSJT'; 'SSTP'];
% Get NO_CONTROL and INTERPOLATED_VALUE codes
% -------------------------------------------
MISSING_VALUE = get(tsg.qc.hash, 'MISSING_VALUE', 'code');
NO_CONTROL = get(tsg.qc.hash, 'NO_CONTROL', 'code');
GOOD = get(tsg.qc.hash, 'GOOD', 'code');
PROBABLY_GOOD = get(tsg.qc.hash, 'PROBABLY_GOOD', 'code');
BAD = get(tsg.qc.hash, 'BAD', 'code');
PROBABLY_BAD = get(tsg.qc.hash, 'PROBABLY_BAD', 'code');
VALUE_CHANGED = get(tsg.qc.hash, 'VALUE_CHANGED', 'code');
HARBOUR = get(tsg.qc.hash, 'HARBOUR', 'code');
INTERPOLATED_VALUE = get(tsg.qc.hash, 'INTERPOLATED_VALUE', 'code');
% Get the prefix of the TSG filename
% Delete the path
% ----------------------------------
[token, remain] = strtok(tsg.report.tsgfile, filesep);
while ~isempty( remain )
[token, remain] = strtok(remain, filesep);
end
[token, remain] = strtok(token, '.');
% Open the dialog box to choose the Directory and name of the file
% ----------------------------------------------------------------
[FileName, PathName, FilterIndex] = ...
uiputfile('*.log','Save the log file', [token '.log'] );
if FileName ~= 0
% Open the file
% -------------
fid = fopen( [PathName FileName], 'w' );
if fid ~= -1
% Write the date and time when the file is saved
% ----------------------------------------------
fprintf( fid, '\t\t\t\t TSGQC REPORT \n');
fprintf( fid, '\t\t\t %s \n\n', datestr( fix(clock), 0));
% Write the name of the files used during the session
% ---------------------------------------------------
fprintf( fid, 'TSG file : %s\n\n', tsg.report.tsgfile);
if ~isempty( tsg.report.wsfile )
fprintf( fid, 'Water sample file : %s\n\n', tsg.report.wsfile);
else
fprintf( fid, 'No water sample file used during this session\n\n');
end
if ~isempty( tsg.report.wsfile )
fprintf( fid, 'External file : %s\n\n', tsg.report.extfile);
else
fprintf( fid, 'No external sample file used during this session\n\n');
end
% Position interpolation
% ----------------------
ind = find( tsg.POSITION_QC == INTERPOLATED_VALUE );
fprintf( fid, '%d records have interpolated position\n\n', length( ind ));
% No date
% -------
fprintf( fid, ...
'%d records have been deleted because they have no date\n\n',...
tsg.report.nodate);
% Records deleted because date is not increasing
% -------------------------------------------------
fprintf( fid, ...
'%d records deleted because its date is not increasing\n\n',...
tsg.report.nodate);
% Records calibrated ?
% --------------------
for ipar = 1 : nPara
para = PARA(ipar,:);
fprintf( fid, '\n****************** %s PARAMETER **************\n\n', para);
noNaN = find( isnan( tsg.([para '_CAL']) == 0));
if ~isempty( tsg.(para) )
% --------------------
% Test for calibration
% --------------------
if ~isempty( tsg.([para '_CAL'])) & isempty( noNaN )
fprintf( fid, 'Time series calibrated\n');
fprintf( fid, '\t\tUsed oefficients: \n' );
% Peculiar case. No calibration coefficient for SSPS but for
% conductivity
% ----------------------------------------------------------
para_old = '';
if strcmp( para, 'SSPS' )
para_old = para;
para = 'CNDC';
end
fprintf( fid, '\t\tSlope : %f\n', tsg.([para '_LINCOEF'])(1));
fprintf( fid, '\t\tOffset : %f\n\n', tsg.([para '_LINCOEF'])(2));
if ~isempty( para_old )
para= para_old;
end
else
fprintf( fid, 'Time series not calibrated \n\n' );
end % if ~isempty( tsg.([para '_CAL'])) & isempty( noNaN )
% ---------------
% Validation code
% ---------------
% get list of keys from hashtable tsg.qc.hash, defined inside
% tsg_initialisation.m
% -----------------------------------------------------------
qc_list = get(tsg.qc.hash);
% iterate (loop) on each key store inside hastable
% ------------------------------------------------
for i=1:numel(qc_list)
% get key and some values in hashtable
% ------------------------------------
key = qc_list{i};
code = get(tsg.qc.hash, key, 'code');
% find number of sample flag with this QC code
% --------------------------------------------
ind = find(tsg.([para '_QC']) == code);
fprintf( fid, '%07d %s code \n', length( ind ), key );
end
% --------------------------------------------
% Number of record corrected versus calibrated
% --------------------------------------------
% ind = find( tsg.([para '_QC']) == VALUE_CHANGED );
% if ~isempty( ind )
% ind = find( tsg.([para '_ADJUSTED_ERROR']) );
% if ~isempty( ind )
% printf( fid, '%d records have been adjusted\n\n', length( ind ));
% end
% end
% ----------------------
% Number of Water sample
% ----------------------
% -------------------------------
% Number of External Water sample
% -------------------------------
else
fprintf( fid, 'no time series \n\n' );
end % ~isempty( tsg.para )
end % for ipar
else
error = -1;
end % if fid
end % if FileName