function minSSTPQC(hMainFig)
%
% This function is called after option/preferences menu has been activated
% and flag salinity data where SSTP < min as BAD if test is on
%
% Input
% -----
% hMainFig ............ Handle to the main user interface
%
% $Id$

% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');

% Get BAD code value
% ----------------------
badCode = tsg.qc.hash.BAD.code;

sstp_min = tsg.preference.sstp_min_string;

% If necessary replace a comma by a point
% ---------------------------------------
sstp_min = regexprep(sstp_min, ',', '.');

% If bias not a numeric, str2double return a NaN
% ----------------------------------------------
sstp_min = str2double( sstp_min );

if isnumeric( sstp_min ) && ~isnan( sstp_min )

  % Set salinity QC to BAD for ssps < ssps_max
  % -----------------------------------------------------
  ind = find(tsg.SSTP < sstp_min);
  if ~isempty( ind )
    tsg.SSTP_QC(ind) = castByteQC( badCode, ind );
  end

  % Save tsg structure
  % ------------------
  setappdata( hMainFig, 'tsg_data', tsg);
  
else
  
  msgbox('Enter a numeric value in the REFERENCE menu', 'sstp QC',...
         'error', 'modal');

end

end
