Newer
Older
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');
% Open the dialog box to choose the Directory and name of the file
% ----------------------------------------------------------------
[FileName, PathName, FilterIndex] = ...
uiputfile('*.log','Save the log file', strcat(tsg.file.name, '.log') );
if FileName ~= 0
% Open the file
% -------------
fid = fopen( [PathName FileName], 'wt' );
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
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 their date are not increasing\n\n',...
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
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 )
% Number of records
% -----------------
nbRecords = length( tsg.DAYD );
fprintf( fid, 'Number of measurements : %d\n\n', nbRecords );
% ---------------
% 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 - %05.2f %% %s code \n', ...
length( ind ), length(ind)/nbRecords * 100 , key);
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
189
190
191
192
193
194
% --------------------------
% Number of record corrected
% --------------------------
ind = find( tsg.([para '_QC']) == VALUE_CHANGED );
if ~isempty( ind )
ind = find( tsg.([para '_ADJUSTED_ERROR']) );
if ~isempty( ind )
fprintf( fid, '\n %07d - %05.2f records have been adjusted\n\n',...
length( ind ), length(ind)/nbRecords * 100);
end
else
fprintf( fid, '\n No records have been adjusted\n\n');
end
% Number of Water sample
% no water sample for SSJT and SSTP
% ----------------------
if strcmp( para, 'SSPS')
if ~isempty( tsg.([para '_WS']) )
fprintf( fid, '%4d Water samples in the file\n\n', ...
length(tsg.([para '_WS'])));
else
fprintf( fid, 'No water sample\n\n');
end
end
% ------------------------------------
% Count water sample and external data
% No external data for SSJT
% ------------------------------------
para2 = para;
if strcmp( para, 'SSJT' )
para2 = 'SSTP';
end
% Number of External Water sample
% ---------------------------------
if ~isempty( tsg.([para2 '_EXT']) )
fprintf( fid, '%4d external samples in the file\n\n', ...
length(tsg.([para2 '_EXT'])));
else
fprintf( fid, 'No external sample\n\n');
end