Skip to content
Snippets Groups Projects
automaticQC.m 2.44 KiB
Newer Older
Yves Gouriou's avatar
Yves Gouriou committed
function [] = automaticQC( hMainFig )
Yves Gouriou's avatar
Yves Gouriou committed
%
% function [] = automaticQC( hTsgGUI )
%
% Automatic controlon TSG time series
%
% Test for :
Yves Gouriou's avatar
Yves Gouriou committed
% 1 -  
% 2 -  Increasing date
% 3 -  SSS < 0 and SSS > 40
%
% TODO : Create a log file with the results of these tests
Yves Gouriou's avatar
Yves Gouriou committed
%

% Get application data : TSG structure
% --------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
tsg  = getappdata( hMainFig, 'tsg_data');

% ************************** TEST 1 ***********************************
%
% Detect records with date and time at NaN.
% This is done in the reading function
Yves Gouriou's avatar
Yves Gouriou committed
% ************************** TEST 2 ***********************************
%
% Test if the records are correctly sorted : increasing date
% Delete the records with inversion
% 
% Find negative differences between successive dates
difDate = diff( tsg.DAYD );
ind = find( difDate < 0 ) + 1;
while ~isempty( ind )
  if ~isempty( tsg.DAYD );      tsg.DAYD(ind)      = []; end;
  if ~isempty( tsg.DATE );      tsg.DATE(ind, :)      = []; end;
Yves Gouriou's avatar
Yves Gouriou committed
  if ~isempty( tsg.LATX );      tsg.LATX(ind)      = []; end;
  if ~isempty( tsg.LONX );      tsg.LONX(ind)      = []; end;
  if ~isempty( tsg.SSPS );      tsg.SSPS(ind)      = []; end;
  if ~isempty( tsg.SSPS_QC );   tsg.SSPS_QC(ind)   = []; end;
  if ~isempty( tsg.SSJT );      tsg.SSJT(ind)      = []; end;
  if ~isempty( tsg.SSJT_QC );   tsg.SSJT_QC(ind)   = []; end;
  if ~isempty( tsg.SSTP );      tsg.SSTP(ind)      = []; end;
  if ~isempty( tsg.SSTP_QC );   tsg.SSTP_QC(ind)   = []; end;
  if ~isempty( tsg.CNDC );      tsg.CNDC(ind)      = []; end;
  if ~isempty( tsg.SPDC );      tsg.SPDC(ind)      = []; end;
  if ~isempty( tsg.CNDC_FREQ ); tsg.CNDC_FREQ(ind) = []; end;
  if ~isempty( tsg.SSJT_FREQ ); tsg.SSJT_FREQ(ind) = []; end;

  difDate = diff( tsg.DAYD );
  ind = find( difDate < 0 ) + 1;

end

% ************************** TEST 3 ***********************************
%
Yves Gouriou's avatar
Yves Gouriou committed
% Get BAD code value
% ------------------
badCode = get(tsg.qc.hash, 'BAD', 'code');

% Set salinity QC to BAD for SSS > 40
% -----------------------------------
ind = find(tsg.SSPS > 40);
if ~isempty( ind )
  tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
end
Yves Gouriou's avatar
Yves Gouriou committed

% Set salinity QC to BAD for SSS < 0
% -----------------------------------
ind = find(tsg.SSPS < 0);
if ~isempty( ind )
  tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
end
Yves Gouriou's avatar
Yves Gouriou committed

% Save the data in the application GUI
% ------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
setappdata( hMainFig, 'tsg_data', tsg );