function [] = automaticQC( hTsgGUI )
%
% function [] = automaticQC( hTsgGUI )
%
% Automatic controlon TSG time series
%
% Test for :
% No date or time
% SSS < 0 and SSS > 40
%

% Get application data : TSG structure
% --------------------------------------
tsg  = getappdata( hTsgGUI, 'tsg_data');

% Detect records with date and time at NaN
% ----------------------------------------
indNaN = find( isnan(tsg.DAYD) == 1 );

% Get BAD code value
% ------------------
badCode = get(tsg.qc.hash, 'BAD', 'code');

% Set salinity QC to BAD for SSS > 40
% -----------------------------------
ind = find(tsg.SSPS > 40);
%tsg.SSPS_QC(ind)    = badCode * ones(size(ind),1);
if ~isempty( ind )
  tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
end

% Set salinity QC to BAD for SSS < 0
% -----------------------------------
ind = find(tsg.SSPS < 0);
%tsg.SSPS_QC(ind)    = badCode*ones(size(ind),1);
if ~isempty( ind )
  tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
end

% Save the data in the application GUI
% ------------------------------------
setappdata( hTsgGUI, 'tsg_data', tsg );

end