Skip to content
Snippets Groups Projects
Commit e83869f8 authored by Yves Gouriou's avatar Yves Gouriou
Browse files

Mise en place d'un fichier de log

parent 479581bb
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,10 @@ if fid ~= -1
tsg.SSPS_WS_QC = tsg.SSPS_WS_QC(iOrder);
end
% Keep the name of the file for the log file
% ------------------------------------------
tsg.report.wsfile = filename;
% Save the data in the application GUI
% ------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg );
......
function [error] = readCoriolisData( hTsgGUI, filename)
function [error] = readCoriolisData( hMainFig, filename)
% Format :
% 1,6 Date du profil ARGO : YYYY-MM-DD HH:MI:SS
......@@ -33,7 +33,7 @@ if fid ~= -1
% Get the tsg structure from application GUI
% ------------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
tsg = getappdata( hMainFig, 'tsg_data');
% Read the file
% -------------
......@@ -107,9 +107,14 @@ if fid ~= -1
tsg.SSPS_EXT_TYPE = tsg.SSPS_EXT_TYPE(iOrder,:);
tsg.SSTP_EXT_TYPE = tsg.SSTP_EXT_TYPE(iOrder,:);
end
% Keep the name of the file for the log file
% ------------------------------------------
tsg.report.extfile = filename;
% Save the data in the application GUI
% ------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg );
setappdata( hMainFig, 'tsg_data', tsg );
% Clear the Workspace
% -------------------
......
function [error] = readTsgDataLabview( hTsgGUI, filename )
function [error] = readTsgDataLabview( hMainFig, filename )
%
% Fonction de lecture des fichiers TSG issus du programme
% d'acquisition LabView XXX
......@@ -6,7 +6,7 @@ function [error] = readTsgDataLabview( hTsgGUI, filename )
% [error] = rdtsglabview( Fichier )
%
% Input
% hTsgGUI ............ Handel to the main user interface
% hMainFig ............ Handel to the main user interface
% filename ........... Data filename
%
% Output
......@@ -33,7 +33,7 @@ function [error] = readTsgDataLabview( hTsgGUI, filename )
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
tsg = getappdata( hMainFig, 'tsg_data');
% Display read file info on console
% ---------------------------------
......@@ -69,7 +69,7 @@ if fid ~= -1
% Nombre de lignes du fichier
% ---------------------------
nblig = length(sst);
nbrecords = length(sst);
% decode tsg raw data
% -------------------
......@@ -110,12 +110,12 @@ if fid ~= -1
% initialize and set <data>_FREQ to NaN
% -------------------------------------
tsg.SSJT_FREQ = nan(nblig,1);
tsg.CNDC_FREQ = nan(nblig,1);
tsg.SSJT_FREQ = nan(nbrecords,1);
tsg.CNDC_FREQ = nan(nbrecords,1);
% loop on all TsgRaw data
% -----------------------
for i=1:nblig
for i=1:nbrecords
% remove leading and trailing white space when string contain NaN
% ---------------------------------------------------------------
......@@ -139,7 +139,7 @@ if fid ~= -1
% -------------------------------------------
noNaN = find( strcmp( date, 'NaN') == 0 & strcmp( time, 'NaN') == 0 );
if~isempty( noNaN )
if ~isempty( noNaN )
% Every variable are put in a structure
% -------------------------------------
......@@ -183,17 +183,22 @@ if fid ~= -1
fileparts(filename);
tsg.file.type = 'LABVIEW';
% Save the data in the application GUI
% ------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg );
% Clear the Workspace
% -------------------
clear date time lat lon sst sss cond condRaw sog cog
end
% Perform somme automatic tests
% -----------------------------
automaticQC( hMainFig )
% Keep somme information for the log file
% ---------------------------------------
tsg.report.tsgfile = filename;
tsg.report.nodate = nbrecords - length(noNaN);
if ~isempty( noNaN )
% Save the data in the application GUI
% ------------------------------------
setappdata( hMainFig, 'tsg_data', tsg );
% Close the file
% --------------
......
function [error] = readTsgDataNetCDF( hTsgGUI, filename)
function [error] = readTsgDataNetCDF( hMainFig, filename)
% Function to read the TSG data. Should be a NetCDF file
% GOSUD data format TSG V1.4
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
% hMainFig ............ Handel to the main user interface
% filename ........... Data filename
%
% Output
......@@ -21,7 +21,7 @@ function [error] = readTsgDataNetCDF( hTsgGUI, filename)
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
tsg = getappdata( hMainFig, 'tsg_data');
% Display read file info on console
% ---------------------------------
......@@ -106,10 +106,17 @@ for i=1:length(variables)
end
end
% Perform somme automatic tests
% -----------------------------
automaticQC( hMainFig )
% Keep somme information for the log file
% ---------------------------------------
tsg.report.tsgfile = filename;
% Save the data in the application GUI
% ------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg );
setappdata( hMainFig, 'tsg_data', tsg );
% Close the file
% --------------
......
function [error] = readTsgDataTxt( hTsgGUI, filename)
function [error] = readTsgDataTxt( hMainFig, filename)
% Function to read the TSG data. Should be a NetCDF file
%
% Input
% -----
% hTsgGUI ............ Handle to the main user interface
% hMainFig ............ Handle to the main user interface
% filename ........... Data filename
%
% Output
......@@ -18,7 +18,7 @@ function [error] = readTsgDataTxt( hTsgGUI, filename)
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
tsg = getappdata( hMainFig, 'tsg_data');
% Display read file info on console
% ---------------------------------
......@@ -48,8 +48,8 @@ tsgData = fscanf(fid, '%d/%d/%d %d:%d:%d %f %f %f %f %d %f %f', [13 Inf])';
% Every variable are put in a structure
% -------------------------------------
tsg.DAYD = datenum(tsgData(:,3), tsgData(:,2),tsgData(:,1), ...
tsgData(:,4),tsgData(:,5),tsgData(:,6));
tsg.DAYD = datenum(tsgData(:,3), tsgData(:,2),tsgData(:,1), ...
tsgData(:,4),tsgData(:,5),tsgData(:,6));
% save original date
% ------------------
......@@ -73,12 +73,20 @@ tsg.file.type = 'ASCII';
% Save the data in the application GUI
% ------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg );
setappdata( hMainFig, 'tsg_data', tsg );
% Clear the Workspace
% -------------------
clear tsgdata
% Perform somme automatic tests
% -----------------------------
automaticQC( hMainFig );
% Keep somme information for the log file
% ---------------------------------------
tsg.report.tsgfile = filename;
% Close the file
% --------------
fclose( fid );
......
function [error] = readTsgDataXML( hTsgGUI, filename)
function [error] = readTsgDataXML( hMainFig, filename)
% Function to read the TSG data XML file
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
% hMainFig ............ Handel to the main user interface
% filename ........... Data filename
%
% Output
......@@ -18,7 +18,7 @@ function [error] = readTsgDataXML( hTsgGUI, filename)
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
tsg = getappdata( hMainFig, 'tsg_data');
% Display read file info on console
% ---------------------------------
......@@ -173,7 +173,7 @@ end
%
% % Save the data in the application GUI
% % ------------------------------------
% setappdata( hTsgGUI, 'tsg_data', tsg );
% setappdata( hMainFig, 'tsg_data', tsg );
% Clear the Workspace
% -------------------
......@@ -182,7 +182,15 @@ end
% Close the file
% --------------
fclose( fid );
% Perform somme automatic tests
% -----------------------------
automaticQC( hMainFig )
% Keep somme information for the log file
% ---------------------------------------
tsg.report.tsgfile = filename;
% Display time to read file on console
% ------------------------------------
t = toc; fprintf('...done (%6.2f sec).\n\n',t);
......
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
......@@ -16,6 +16,8 @@ function [] = automaticQC( hMainFig )
% --------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
MISSING_VALUE = get(tsg.qc.hash, 'MISSING_VALUE', 'code');
% ************************** TEST 1 ***********************************
%
% Detect records with date and time at NaN.
......@@ -28,9 +30,13 @@ tsg = getappdata( hMainFig, 'tsg_data');
% Delete the records with inversion
%
% Find negative differences between successive dates
difDate = diff( tsg.DAYD );
ind = find( difDate < 0 ) + 1;
nbBadDate = 0;
difDate = diff( tsg.DAYD );
ind = find( difDate < 0 ) + 1;
while ~isempty( ind )
nbBadDate = nbBadDate + length( nbBadDate );
if ~isempty( tsg.DAYD ); tsg.DAYD(ind) = []; end;
if ~isempty( tsg.DATE ); tsg.DATE(ind, :) = []; end;
if ~isempty( tsg.LATX ); tsg.LATX(ind) = []; end;
......@@ -48,8 +54,27 @@ while ~isempty( ind )
difDate = diff( tsg.DAYD );
ind = find( difDate < 0 ) + 1;
end
% Keep the number of data not in increasing date
% ----------------------------------------------
tsg.report.sortdate = nbBadDate;
% NO_VALUE code
% -------------
ind = find( isnan(tsg.SSPS) == 1);
if ~isempty( ind )
tsg.SSPS_QC(ind) = MISSING_VALUE;
end
ind = find( isnan(tsg.SSJT) == 1);
if ~isempty( ind )
tsg.SSJT_QC(ind) = MISSING_VALUE;
end
ind = find( isnan(tsg.SSTP) == 1);
if ~isempty( ind )
tsg.SSTP_QC(ind) = MISSING_VALUE;
end
% ************************** TEST 3 ***********************************
%
......@@ -71,6 +96,20 @@ if ~isempty( ind )
tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
end
% Set salinity QC to BAD for SSTP > 40
% -----------------------------------
ind = find(tsg.SSTP > 40);
if ~isempty( ind )
tsg.SSTP_QC(ind) = castByteQC( badCode, ind );
end
% Set salinity QC to BAD for STP < -3
% -----------------------------------
ind = find(tsg.SSTP < -3);
if ~isempty( ind )
tsg.SSTP_QC(ind) = castByteQC( badCode, ind );
end
% Save the data in the application GUI
% ------------------------------------
setappdata( hMainFig, 'tsg_data', tsg );
......
......@@ -90,20 +90,20 @@ end
% Plot SSPS, with no code, on axe3
% --------------------------------
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD, tsg.([PARA '_ADJUSTED']), [],...
[PARA '_ADJUSTED'],'r','none','*',1);
[PARA '_ADJUSTED'],'r','none','*',2);
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD, tsg.(PARA),...
[],PARA,'k','none','*',1);
[],PARA,'k','none','*',2);
% Plot TSG_ADJUSTED + ERROR on axe 3
% -----------------------------------
if iERR ~= 0
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD(iVC(iERR)),...
tsg.([PARA '_ADJUSTED'])(iVC(iERR)) + tsg.([PARA '_ADJUSTED_ERROR'])(iVC(iERR)),...
[], [PARA '_ADJUSTED'],'g','none','*',1);
[], [PARA '_ADJUSTED'],'g','none','*',2);
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD(iVC(iERR)),...
tsg.([PARA '_ADJUSTED'])(iVC(iERR)) - tsg.([PARA '_ADJUSTED_ERROR'])(iVC(iERR)),...
[], [PARA '_ADJUSTED'],'g','none','*',1);
[], [PARA '_ADJUSTED'],'g','none','*',2);
end
end
......@@ -20,13 +20,13 @@ switch nPlot
if ~isempty( tsg.LATX ) && ~isempty( tsg.SSPS)
ind = find( isnan(tsg.LATX) == 1 | isnan(tsg.LONX) == 1);
if ~isempty( tsg.ssps_smooth )
if ~isempty( ind )
plot_Tsg( hMainFig, hPlotAxes, 1, tsg.DAYD(ind), tsg.SSPS(ind), [],...
'SSPS_NOPOS','b','none','*',2);
end
ind = find( isnan(tsg.LATX) == 0 | isnan(tsg.LONX) == 0);
if ~isempty( tsg.SSPS )
if ~isempty( ind )
plot_Tsg( hMainFig, hPlotAxes, 1, tsg.DAYD(ind), tsg.SSPS(ind), [],...
'SSPS','k','none','*',2);
end
......
......@@ -58,10 +58,19 @@ tsg.file.type = [];
% -------------------------------------------------------------------------
%% Smooth TSG time serie fields
% -------------------------------------------------------------------------
tsg.ssps_smooth = [];
tsg.ssps_smooth.nval = [];
tsg.SSTP_smooth = [];
tsg.SSTP_smooth.nval = [];
% tsg.ssps_smooth = [];
% tsg.ssps_smooth.nval = [];
% tsg.SSTP_smooth = [];
% tsg.SSTP_smooth.nval = [];
% -------------------------------------------------------------------------
%% Variable used for the report
% -------------------------------------------------------------------------
tsg.report.tsgfile = ''; % Name of the TSG file
tsg.report.wsfile = ''; % Name of the Water sample file
tsg.report.extfile = ''; % Name of the External sample file
tsg.report.nodate = 0; % Records eliminated because they have no date
tsg.report.sortdate = 0; % Records eliminated because date is not increasing
% -------------------------------------------------------------------------
%% Structure used to merge WS and EXT sample
......
......@@ -365,6 +365,16 @@ hHeaderPushtool = uipushtool(... % Open headerForm button
'Enable', 'off',...
'ClickedCallback', @HeaderMenuCallback);
hReportPushtool = uipushtool(... % Open Report saving button
'Parent',hToolbar,...
'TooltipString','Save a report',...
'CData',iconRead(...
[DEFAULT_PATH_FILE 'tsg_icon' filesep 'reporticon.mat']),...
'HandleVisibility','on', ...
'Tag','PUSHTOOL_REPORT',...
'Enable', 'off',...
'ClickedCallback', @ReportMenuCallback);
%% Dynamic text area
% -----------------------------------------------------------------------
% Dynamic text area that displays the loaded filename, date, position and
......@@ -1083,10 +1093,6 @@ end
tsg_initialisation(hMainFig);
errTsg = readTsgDataLabview( hMainFig, fullFileName );
if errTsg > 0 % Reading is OK
automaticQC( hMainFig );
end
case 5 % Read bucket file *.btl
if ~isempty( tsg.SSPS )
errSpl = readBucketData( hMainFig, fullFileName );
......@@ -2598,6 +2604,18 @@ end
end
%% ReportMenuCallback
% -------------------------------------------------------------------
% Callback function run when the Report tool bar item is selected
% -------------------------------------------------------------------
function ReportMenuCallback(hObject, eventdata)
% call report function
% --------------------
saveReport(hMainFig);
end
%% SaveMenuCallback
% -------------------------------------------------------------------
% Callback function run when the Save menu item is selected
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment