Skip to content
Snippets Groups Projects
automaticQC.m 3.46 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 > 50
Yves Gouriou's avatar
Yves Gouriou committed
%
% 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');

% Get tsg fieldnames
% ------------------
tsgNames     = fieldnames(tsg);
nbFieldNames = length( tsgNames );

% Get the size of the times series array
% --------------------------------------
tsgLength = length( tsg.DAYD );

% get MISSING_VALUE from tsg.qc.hash
% -----------------------------------
MISSING_VALUE = tsg.qc.hash.MISSING_VALUE.code;
Yves Gouriou's avatar
Yves Gouriou committed
% ************************** 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
nbBadDate = 0;
difDate   = diff( tsg.DAYD );
ind       = find( difDate < 0 );
Yves Gouriou's avatar
Yves Gouriou committed
while ~isempty( ind )
  % if DAYD is of length N, DIFF is of length N-1
  % Need to add one to the indices
  % ---------------------------------------------
  ind = ind + 1;
  % Store the number of bad date
  % -----------------------------
  nbBadDate = nbBadDate + length( ind );
  
  % Delete bad records
  % ------------------
  for i = 1 : nbFieldNames
    
    para = char( tsgNames{i} );
    
    % Find array of length DAYD in the TSG structure
    % ----------------------------------------------
    if length( tsg.(para) ) == tsgLength
      tsg.(para)(ind,:) = [];
  % Tsg length has been modified
  % ----------------------------
  tsgLength = tsgLength - length( ind );
  
Yves Gouriou's avatar
Yves Gouriou committed
  difDate = diff( tsg.DAYD );
  ind     = find( difDate < 0 );
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;
Yves Gouriou's avatar
Yves Gouriou committed
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

Yves Gouriou's avatar
Yves Gouriou committed

% ************************** TEST 3 ***********************************
%
Yves Gouriou's avatar
Yves Gouriou committed
% Get BAD code value
% ------------------
% Set salinity QC to BAD for SSS > 50
Yves Gouriou's avatar
Yves Gouriou committed
% -----------------------------------
ind = find(tsg.SSPS > 50);
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
% Set temperature QC to BAD for SSTP > 40
% ---------------------------------------
ind = find(tsg.SSTP > 40);
if ~isempty( ind )
  tsg.SSTP_QC(ind) = castByteQC( badCode, ind );
end

% Set temperature QC to BAD for STP < -3
% --------------------------------------
ind = find(tsg.SSTP < -3);
if ~isempty( ind )
  tsg.SSTP_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 );