From 71ff6824dc9db99e2d4cb5a592a8fed746966f36 Mon Sep 17 00:00:00 2001
From: Yves Gouriou <yves.gouriou@ird.fr>
Date: Fri, 8 Jan 2010 14:04:35 +0000
Subject: [PATCH] Creation d'un menu QCauto qui permet d'appliquer des tests
 automatiques. Les limites de ces test sont entres dans le menu Preference

---
 tsg_util/automaticQC.m     |  44 -----
 tsg_util/maxSSPSQC.m       |  49 ++++++
 tsg_util/maxSSTPQC.m       |  49 ++++++
 tsg_util/minFlowQC.m       |  49 ++++++
 tsg_util/minPressQC.m      |  49 ++++++
 tsg_util/minSSPSQC.m       |  49 ++++++
 tsg_util/minSSTPQC.m       |  49 ++++++
 tsg_util/preferencesForm.m | 349 +++++++++++++++++++++++++++----------
 tsg_util/tsg_preferences.m |  19 +-
 tsgqc.m                    |  89 +++++++++-
 10 files changed, 654 insertions(+), 141 deletions(-)
 create mode 100644 tsg_util/maxSSPSQC.m
 create mode 100644 tsg_util/maxSSTPQC.m
 create mode 100644 tsg_util/minFlowQC.m
 create mode 100644 tsg_util/minPressQC.m
 create mode 100644 tsg_util/minSSPSQC.m
 create mode 100644 tsg_util/minSSTPQC.m

diff --git a/tsg_util/automaticQC.m b/tsg_util/automaticQC.m
index 09a0cd2..19e5053 100644
--- a/tsg_util/automaticQC.m
+++ b/tsg_util/automaticQC.m
@@ -95,50 +95,6 @@ if ~isempty( ind )
   tsg.SSTP_QC(ind) = MISSING_VALUE;
 end
 
-
-% ************************** TEST 3 ***********************************
-%
-% Get BAD code value
-% ------------------
-badCode = tsg.qc.hash.BAD.code;
-
-% Set salinity QC to BAD for SSS > 50
-% -----------------------------------
-ind = find(tsg.SSPS > 50);
-if ~isempty( ind )
-  tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
-end
-
-% 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 salinity QC to BAD for FLOW < 0.1
-% -------------------------------------
-if isfield( tsg, 'FLOW' )
-  ind = find(tsg.FLOW < 1);
-  if ~isempty( ind )
-    tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
-  end
-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 SSTP < -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 );
diff --git a/tsg_util/maxSSPSQC.m b/tsg_util/maxSSPSQC.m
new file mode 100644
index 0000000..bec0927
--- /dev/null
+++ b/tsg_util/maxSSPSQC.m
@@ -0,0 +1,49 @@
+function maxSSPSQC(hMainFig)
+%
+% This function is called after option/preferences menu has been activated
+% and flag salinity data where SSPS > max as BAD if test is on
+%
+% Input
+% -----
+% hMainFig ............ Handle to the main user interface
+%
+
+% Get the data from the application GUI
+% -------------------------------------
+tsg = getappdata( hMainFig, 'tsg_data');
+
+% Get BAD code value
+% ----------------------
+badCode = tsg.qc.hash.BAD.code;
+
+ssps_max = tsg.preference.ssps_max_string;
+
+% If necessary replace a comma by a point
+% ---------------------------------------
+ssps_max = regexprep(ssps_max, ',', '.');
+
+% If bias not a numeric, str2double return a NaN
+% ----------------------------------------------
+ssps_max = str2double( ssps_max );
+
+if isnumeric( ssps_max ) && ~isnan( ssps_max )
+
+  % Set salinity QC to BAD for ssps < ssps_max
+  % -----------------------------------------------------
+  ind = find(tsg.SSPS > ssps_max);
+  if ~isempty( ind )
+    tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
+  end
+
+  % Save tsg structure
+  % ------------------
+  setappdata( hMainFig, 'tsg_data', tsg);
+  
+else
+  
+  msgbox('Enter a numeric value in the REFERENCE menu', 'ssps QC',...
+         'error', 'modal');
+
+end
+
+end
diff --git a/tsg_util/maxSSTPQC.m b/tsg_util/maxSSTPQC.m
new file mode 100644
index 0000000..55a7c1e
--- /dev/null
+++ b/tsg_util/maxSSTPQC.m
@@ -0,0 +1,49 @@
+function maxSSTPQC(hMainFig)
+%
+% This function is called after option/preferences menu has been activated
+% and flag salinity data where SSTP > max as BAD if test is on
+%
+% Input
+% -----
+% hMainFig ............ Handle to the main user interface
+%
+
+% Get the data from the application GUI
+% -------------------------------------
+tsg = getappdata( hMainFig, 'tsg_data');
+
+% Get BAD code value
+% ----------------------
+badCode = tsg.qc.hash.BAD.code;
+
+sstp_max = tsg.preference.sstp_max_string;
+
+% If necessary replace a comma by a point
+% ---------------------------------------
+sstp_max = regexprep(sstp_max, ',', '.');
+
+% If bias not a numeric, str2double return a NaN
+% ----------------------------------------------
+sstp_max = str2double( sstp_max );
+
+if isnumeric( sstp_max ) && ~isnan( sstp_max )
+
+  % Set salinity QC to BAD for ssps < ssps_max
+  % -----------------------------------------------------
+  ind = find(tsg.SSTP > sstp_max);
+  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
diff --git a/tsg_util/minFlowQC.m b/tsg_util/minFlowQC.m
new file mode 100644
index 0000000..f42d88a
--- /dev/null
+++ b/tsg_util/minFlowQC.m
@@ -0,0 +1,49 @@
+function minFlowQC(hMainFig)
+%
+% This function is called after option/preferences menu has been activated
+% and flag salinity data where FLOW < min as BAD if test is on
+%
+% Input
+% -----
+% hMainFig ............ Handle to the main user interface
+%
+
+% Get the data from the application GUI
+% -------------------------------------
+tsg = getappdata( hMainFig, 'tsg_data');
+
+% Get BAD code value
+% ----------------------
+badCode = tsg.qc.hash.BAD.code;
+
+flow_min = tsg.preference.flow_min_string;
+
+% If necessary replace a comma by a point
+% ---------------------------------------
+flow_min = regexprep(flow_min, ',', '.');
+
+% If bias not a numeric, str2double return a NaN
+% ----------------------------------------------
+flow_min = str2double( flow_min );
+
+if isnumeric( flow_min ) && ~isnan( flow_min )
+
+  % Set salinity QC to BAD for flow < flow_min
+  % -----------------------------------------------------
+  ind = find(tsg.FLOW < flow_min);
+  if ~isempty( ind )
+    tsg.SSPS_QC(ind) = castByteQC( badCode, ind );
+  end
+
+  % Save tsg structure
+  % ------------------
+  setappdata( hMainFig, 'tsg_data', tsg);
+  
+else
+  
+  msgbox('Enter a numeric value in the REFERENCE menu', 'Flow QC',...
+         'error', 'modal');
+
+end
+
+end
diff --git a/tsg_util/minPressQC.m b/tsg_util/minPressQC.m
new file mode 100644
index 0000000..a3df1f3
--- /dev/null
+++ b/tsg_util/minPressQC.m
@@ -0,0 +1,49 @@
+function minPressQC(hMainFig)
+%
+% This function is called after option/preferences menu has been activated
+% and flag salinity data where PRESS < min as BAD if test is on
+%
+% Input
+% -----
+% hMainFig ............ Handle to the main user interface
+%
+
+% Get the data from the application GUI
+% -------------------------------------
+tsg = getappdata( hMainFig, 'tsg_data');
+
+% Get BAD code value
+% ----------------------
+badCode = tsg.qc.hash.BAD.code;
+
+press_min = tsg.preference.press_min_string;
+
+% If necessary replace a comma by a point
+% ---------------------------------------
+press_min = regexprep(press_min, ',', '.');
+
+% If bias not a numeric, str2double return a NaN
+% ----------------------------------------------
+press_min = str2double( press_min );
+
+if isnumeric( press_min ) && ~isnan( press_min )
+
+  % Set salinity QC to BAD for flow < flow_min
+  % -----------------------------------------------------
+  ind = find(tsg.PRESS < press_min);
+  if ~isempty( ind )
+    tsg.PRESS_QC(ind) = castByteQC( badCode, ind );
+  end
+
+  % Save tsg structure
+  % ------------------
+  setappdata( hMainFig, 'tsg_data', tsg);
+  
+else
+  
+  msgbox('Enter a numeric value in the REFERENCE menu', 'Press QC',...
+         'error', 'modal');
+
+end
+
+end
diff --git a/tsg_util/minSSPSQC.m b/tsg_util/minSSPSQC.m
new file mode 100644
index 0000000..a6b2de2
--- /dev/null
+++ b/tsg_util/minSSPSQC.m
@@ -0,0 +1,49 @@
+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
+%
+
+% 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 sstp < ssps_min
+  % -----------------------------------------------------
+  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
diff --git a/tsg_util/minSSTPQC.m b/tsg_util/minSSTPQC.m
new file mode 100644
index 0000000..77ea3f4
--- /dev/null
+++ b/tsg_util/minSSTPQC.m
@@ -0,0 +1,49 @@
+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
+%
+
+% 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
diff --git a/tsg_util/preferencesForm.m b/tsg_util/preferencesForm.m
index 7332bdf..92a7021 100644
--- a/tsg_util/preferencesForm.m
+++ b/tsg_util/preferencesForm.m
@@ -16,10 +16,6 @@ error = -1;
 % -------------------------------------
 tsg = getappdata(hTsgGUI, 'tsg_data');
 
-% disable ship speed test 
-% -----------------------
-tsg.preference.ship_speed_test=1;
-
 % set default uicontrol size
 % --------------------------
 height = 0.03;
@@ -48,6 +44,21 @@ hPreferencesFig = figure(...
   'Position',get(hTsgGUI,'Position'), ...
   'Color', get(0, 'DefaultUIControlBackgroundColor'));
 
+% display Climatology TITLE
+% -------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize, 'FontWeight', 'bold',...
+  'HorizontalAlignment', 'Left', ...
+  'Position',[left, bottom, 2*length, height],'String', 'Climatology');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
 % display climatology text
 % -------------------------
 uicontrol(...
@@ -112,31 +123,142 @@ if bottom < .1
   left = left + inc_x;
 end
 
-% display ship speed test text
-% ----------------------------
+% display conventions field if exist
+% ----------------------------------
+% uicontrol(...
+%   'Parent', hPreferencesFig, ...
+%   'Units', 'normalized', ...
+%   'Style', 'text', ...
+%   'Fontsize', tsg.fontSize-2, ...
+%   'HorizontalAlignment', 'left', ...
+%   'Position', [left + 2*length, bottom, length, height], ...
+%   'String', char(s.conventions));
+
+% display Calibration TITLE
+% --------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize, 'FontWeight', 'bold',...
+  'HorizontalAlignment', 'Left', ...
+  'Position',[left, bottom, 2*length, height], 'String', 'Calibration coefficient');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
+% display coefficient type text
+% -----------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, ...
+  'HorizontalAlignment', 'left', 'Position',[left, bottom, length, height], ...
+  'TooltipString', 'select coefficients type', ...
+  'String', 'Coefficients type');
+
+% display coefficient type uicontrol
+% ----------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'BackgroundColor', 'w', 'Style', 'popupmenu', 'Fontsize', tsg.fontSize-2, ...
+  'HorizontalAlignment', 'right', ...
+  'Position', [left + length, bottom, length, height], ...
+  'String', tsg.preference.coeff_type_string , ...
+  'Value', tsg.preference.coeff_type_value , ...
+  'Tag', 'PREFERENCES_COEFF_TYPE');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
+% display Figure TITLE
+% --------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize, 'FontWeight', 'bold',...
+  'HorizontalAlignment', 'Left', ...
+  'Position',[left, bottom, 2*length, height], 'String', 'Figure');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
+% display connected line uicontrol
+% --------------------------------
+
+% display connected line text
+% -------------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
   'Units', 'normalized', ...
   'Style', 'Text', ...
-  'Fontsize', tsg.fontSize-1, ...
-  'HorizontalAlignment', 'left', ...
+  'Fontsize', tsg.fontSize-1, 'HorizontalAlignment', 'left', ...
   'Position',[left, bottom, length, height], ...
-  'TooltipString', 'enable/disable ship speed test', ...
-  'String', 'Ship Speed Test');
+  'TooltipString', 'select plot with connected line', ...
+  'String', 'Plot with connectd line');
 
-% display ship speed test uicontrol
-% ---------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', 'BackgroundColor', 'w', ...
+  'Style', 'popupmenu', 'Fontsize', tsg.fontSize-2, ...
+  'HorizontalAlignment', 'right', ...
+  'Position', [left + length, bottom, length, height], ...
+  'String', tsg.preference.plot_connected_string , ...
+  'Value', tsg.preference.plot_connected_value , ...
+  'Tag', 'PREFERENCES_PLOT_CONNECTED_LINE');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
+% display map resolution text
+% -----------------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
   'Units', 'normalized', ...
-  'BackgroundColor', 'w', ...
-  'Style', 'popupmenu', ...
-  'Fontsize', tsg.fontSize-2, ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, ...
+  'HorizontalAlignment', 'left', 'Position',[left, bottom, length, height], ...
+  'TooltipString', 'select map resolution', ...
+  'String', 'Map Resolution');
+
+% display map resolution uicontrol
+% --------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'BackgroundColor', 'w', 'Style', 'popupmenu',   'Fontsize', tsg.fontSize-2, ...
   'HorizontalAlignment', 'right', ...
   'Position', [left + length, bottom, length, height], ...
-  'String', tsg.preference.ship_speed_test_string, ...
-  'Value', tsg.preference.ship_speed_test, ...
-  'Tag', 'PREFERENCES_SHIP_SPEED_TEST');
+  'String', tsg.preference.map_resolution_string, ...
+  'Value', tsg.preference.map_resolution, ...
+  'Tag', 'PREFERENCES_MAP_RESOLUTION');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
+% display QC Automatic Test TITLE
+% --------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize, 'FontWeight', 'bold',...
+  'HorizontalAlignment', 'Left', ...
+  'Position',[left, bottom, 2*length, height], ...
+  'String', 'Min/Max values for automatic QC');
 
 bottom = bottom - inc_y - height;
 if bottom < .1
@@ -154,7 +276,7 @@ uicontrol(...
   'HorizontalAlignment', 'left', ...
   'Position',[left, bottom, length, height], ...
   'TooltipString', 'select ship speed min (knots)', ...
-  'String', 'Ship Speed Min');
+  'String', 'Ship Speed Min (knots)');
 
 % display ship speed min uicontrol
 % --------------------------------
@@ -166,9 +288,8 @@ uicontrol(...
   'Fontsize', tsg.fontSize-2, ...
   'HorizontalAlignment', 'right', ...
   'Position', [left + length, bottom, length, height], ...
-  'String', tsg.preference.ship_speed_min_string, ...
-  'Value', tsg.preference.ship_speed_min, ...
-  'Tag', 'PREFERENCES_SHIP_SPEED_MIN');
+  'String', tsg.preference.ship_speed_min_string, ... 
+  'Value', tsg.preference.ship_speed_min, 'Tag', 'PREFERENCES_SHIP_SPEED_MIN');
 
 bottom = bottom - inc_y - height;
 if bottom < .1
@@ -176,43 +297,49 @@ if bottom < .1
   left = left + inc_x;
 end
 
-% display connected line text
-% -------------------------
+% display FLOW min text
+% ----------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
   'Units', 'normalized', ...
-  'Style', 'Text', ...
-  'Fontsize', tsg.fontSize-1, ...
-  'HorizontalAlignment', 'left', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, 'HorizontalAlignment', 'left', ...
   'Position',[left, bottom, length, height], ...
-  'TooltipString', 'select plot with connected line', ...
-  'String', 'Plot with connectd line');
+  'TooltipString', 'Select min Flow (liter/min)', 'String', 'Flow Min (l/minute)');
 
-% display connected line uicontrol
-% --------------------------------
+% display FLOW min uicontrol
+% -------------------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
-  'Units', 'normalized', ...
-  'BackgroundColor', 'w', ...
-  'Style', 'popupmenu', ...
-  'Fontsize', tsg.fontSize-2, ...
+  'Units', 'normalized', 'Style', 'Edit', ...
+  'Fontsize', tsg.fontSize-2, 'BackgroundColor', 'w', ...
   'HorizontalAlignment', 'right', ...
   'Position', [left + length, bottom, length, height], ...
-  'String', tsg.preference.plot_connected_string , ...
-  'Value', tsg.preference.plot_connected_value , ...
-  'Tag', 'PREFERENCES_PLOT_CONNECTED_LINE');
+  'String', tsg.preference.flow_min_string, 'Tag', 'PREFERENCES_FLOW_MIN');
 
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
 
-% display conventions field if exist
-% ----------------------------------
-% uicontrol(...
-%   'Parent', hPreferencesFig, ...
-%   'Units', 'normalized', ...
-%   'Style', 'text', ...
-%   'Fontsize', tsg.fontSize-2, ...
-%   'HorizontalAlignment', 'left', ...
-%   'Position', [left + 2*length, bottom, length, height], ...
-%   'String', char(s.conventions));
+% display PRESS min text
+% ----------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, 'HorizontalAlignment', 'left', ...
+  'Position',[left, bottom, length, height], ...
+  'TooltipString', 'Select min pressure pump', 'String', 'Pressure Min (l/minute)');
+
+% display PRESS min uicontrol
+% -------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', 'Style', 'Edit', ...
+  'Fontsize', tsg.fontSize-2, 'BackgroundColor', 'w', ...
+  'HorizontalAlignment', 'right', ...
+  'Position', [left + length, bottom, length, height], ...
+  'String', tsg.preference.press_min_string, 'Tag', 'PREFERENCES_PRESS_MIN');
 
 bottom = bottom - inc_y - height;
 if bottom < .1
@@ -220,31 +347,49 @@ if bottom < .1
   left = left + inc_x;
 end
 
-% display coefficient type text
-% -----------------------------
+% display SSPS min text
+% ----------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
   'Units', 'normalized', ...
-  'Style', 'Text', ...
-  'Fontsize', tsg.fontSize-1, ...
-  'HorizontalAlignment', 'left', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, 'HorizontalAlignment', 'left', ...
   'Position',[left, bottom, length, height], ...
-  'TooltipString', 'select coefficients type', ...
-  'String', 'Coefficients type');
+  'TooltipString', 'Select min SSPS', 'String', 'SSPS min');
 
-% display coefficient type uicontrol
-% ----------------------------------
+% display SSPS min uicontrol
+% -------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', 'Style', 'Edit', ...
+  'Fontsize', tsg.fontSize-2, 'BackgroundColor', 'w', ...
+  'HorizontalAlignment', 'right', ...
+  'Position', [left + length, bottom, length, height], ...
+  'String', tsg.preference.ssps_min_string, 'Tag', 'PREFERENCES_SSPS_MIN');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
+% display SSPS max text
+% ----------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
   'Units', 'normalized', ...
-  'BackgroundColor', 'w', ...
-  'Style', 'popupmenu', ...
-  'Fontsize', tsg.fontSize-2, ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, 'HorizontalAlignment', 'left', ...
+  'Position',[left, bottom, length, height], ...
+  'TooltipString', 'Select max SSPS', 'String', 'SSPS max');
+
+% display SSPS max uicontrol
+% -------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', 'Style', 'Edit', ...
+  'Fontsize', tsg.fontSize-2, 'BackgroundColor', 'w', ...
   'HorizontalAlignment', 'right', ...
   'Position', [left + length, bottom, length, height], ...
-  'String', tsg.preference.coeff_type_string , ...
-  'Value', tsg.preference.coeff_type_value , ...
-  'Tag', 'PREFERENCES_COEFF_TYPE');
+  'String', tsg.preference.ssps_max_string, 'Tag', 'PREFERENCES_SSPS_MAX');
 
 bottom = bottom - inc_y - height;
 if bottom < .1
@@ -252,31 +397,49 @@ if bottom < .1
   left = left + inc_x;
 end
 
-% display map resolution text
-% -----------------------------
+% display SSTP min text
+% ----------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
   'Units', 'normalized', ...
-  'Style', 'Text', ...
-  'Fontsize', tsg.fontSize-1, ...
-  'HorizontalAlignment', 'left', ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, 'HorizontalAlignment', 'left', ...
   'Position',[left, bottom, length, height], ...
-  'TooltipString', 'select map resolution', ...
-  'String', 'Map Resolution');
+  'TooltipString', 'Select min SSTP', 'String', 'SSTP min (°C)');
 
-% display map resolution uicontrol
-% --------------------------------
+% display SSTP min uicontrol
+% -------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', 'Style', 'Edit', ...
+  'Fontsize', tsg.fontSize-2, 'BackgroundColor', 'w', ...
+  'HorizontalAlignment', 'right', ...
+  'Position', [left + length, bottom, length, height], ...
+  'String', tsg.preference.sstp_min_string, 'Tag', 'PREFERENCES_SSTP_MIN');
+
+bottom = bottom - inc_y - height;
+if bottom < .1
+  bottom = 0.95;
+  left = left + inc_x;
+end
+
+% display SSTP max text
+% ----------------------
 uicontrol(...
   'Parent', hPreferencesFig, ...
   'Units', 'normalized', ...
-  'BackgroundColor', 'w', ...
-  'Style', 'popupmenu', ...
-  'Fontsize', tsg.fontSize-2, ...
+  'Style', 'Text', 'Fontsize', tsg.fontSize-1, 'HorizontalAlignment', 'left', ...
+  'Position',[left, bottom, length, height], ...
+  'TooltipString', 'Select max SSTP', 'String', 'SSTP max (°C)');
+
+% display SSTP max uicontrol
+% -------------------------------
+uicontrol(...
+  'Parent', hPreferencesFig, ...
+  'Units', 'normalized', 'Style', 'Edit', ...
+  'Fontsize', tsg.fontSize-2, 'BackgroundColor', 'w', ...
   'HorizontalAlignment', 'right', ...
   'Position', [left + length, bottom, length, height], ...
-  'String', tsg.preference.map_resolution_string, ...
-  'Value', tsg.preference.map_resolution, ...
-  'Tag', 'PREFERENCES_MAP_RESOLUTION');
+  'String', tsg.preference.sstp_max_string, 'Tag', 'PREFERENCES_SSTP_MAX');
 
 bottom = bottom - inc_y - height;
 if bottom < .1
@@ -344,17 +507,29 @@ uiwait(hPreferencesFig);
       get(prefs.PREFERENCES_LEVITUS_VALUE, 'value');
     tsg.preference.levitus_depth_value = ...
       get(prefs.PREFERENCES_LEVITUS_DEPTH, 'value');
-    tsg.preference.ship_speed_test = ...
-      get(prefs.PREFERENCES_SHIP_SPEED_TEST, 'value');
-    tsg.preference.ship_speed_min = ...
-      get(prefs.PREFERENCES_SHIP_SPEED_MIN, 'value');
-    tsg.preference.plot_connected_value = ...
-      get(prefs.PREFERENCES_PLOT_CONNECTED_LINE, 'value');
     tsg.preference.coeff_type_value = ...
       get(prefs.PREFERENCES_COEFF_TYPE, 'value');
+    % Figure
+    tsg.preference.plot_connected_value = ...
+      get(prefs.PREFERENCES_PLOT_CONNECTED_LINE, 'value');
     tsg.preference.map_resolution = ...
       get(prefs.PREFERENCES_MAP_RESOLUTION, 'value');
- 
+    % QC Tests
+    tsg.preference.flow_min_string = ...
+      get(prefs.PREFERENCES_FLOW_MIN, 'string');
+    tsg.preference.press_min_string = ...
+      get(prefs.PREFERENCES_PRESS_MIN, 'string');
+    tsg.preference.ship_speed_min = ...
+      get(prefs.PREFERENCES_SHIP_SPEED_MIN, 'value');
+    tsg.preference.ssps_min_string = ...
+      get(prefs.PREFERENCES_SSPS_MIN, 'string');
+    tsg.preference.ssps_max_string = ...
+      get(prefs.PREFERENCES_SSPS_MAX, 'string');
+    tsg.preference.sstp_min_string = ...
+      get(prefs.PREFERENCES_SSTP_MIN, 'string');
+    tsg.preference.sstp_max_string = ...
+      get(prefs.PREFERENCES_SSTP_MAX, 'string');
+    
     % Save tsg structure
     % ------------------
     setappdata(hTsgGUI, 'tsg_data', tsg);
@@ -363,10 +538,6 @@ uiwait(hPreferencesFig);
     % ------------------------------
     updateTsgStructWithCalCoeff(hTsgGUI);
 
-    % apply ship speed QC
-    % -------------------
-    minSpeedQC(hTsgGUI);
-
     % close windows (replace call to uiresume(hHeaderFig))
     % ----------------------------------------------------
     close(hPreferencesFig);
diff --git a/tsg_util/tsg_preferences.m b/tsg_util/tsg_preferences.m
index 61c320a..c8b65be 100644
--- a/tsg_util/tsg_preferences.m
+++ b/tsg_util/tsg_preferences.m
@@ -131,20 +131,27 @@ end
     preference.version               = VERSION;
     preference.char_version          = CHAR_VERSION;
     preference.autoload              = 'off';
+    % Climatology
     preference.levitus_version       = {'WOA01','WOA05'};
     preference.levitus_value         = 2;  % WOA05
     preference.levitus_depth_string  = {'0','10'};
     preference.levitus_depth_value   = 1;
-    preference.ship_speed_test_string= {'none','automatic'};
-    preference.ship_speed_test       = 1; % no test on ship speed
-    preference.ship_speed_min_string = {'1','3','5'};
-    preference.ship_speed_min        = 1;
-    preference.plot_connected_string = {'none', '-', '--', ':', '-.'};
-    preference.plot_connected_value  = 1;  % 0, line not connected
     preference.coeff_type_string     = {'use A-D', 'use G-J'};
     preference.coeff_type_value      = 2;
+    % Plot
     preference.map_resolution_string = {'low','medium','high'};
     preference.map_resolution        = 1;
+    preference.plot_connected_string = {'none', '-', '--', ':', '-.'};
+    preference.plot_connected_value  = 1;  % 0, line not connected
+    % QC test
+    preference.flow_min_string       = {'1'};
+    preference.press_min_string      = {'1'};
+    preference.ship_speed_min_string = {'1','3','5'};
+    preference.ship_speed_min        = 1;
+    preference.ssps_min_string       = {'0'};
+    preference.ssps_max_string       = {'50'};
+    preference.sstp_min_string       = {'-3'};
+    preference.sstp_max_string       = {'40'};
 
     % save preference struct to 'prefdir.mat' file
     % ---------------------------------------------
diff --git a/tsgqc.m b/tsgqc.m
index f84ff99..df9af84 100644
--- a/tsgqc.m
+++ b/tsgqc.m
@@ -36,8 +36,8 @@ global NETCDF_FORMAT_VERSION
 % version number, may be used to initialize some files when it change
 % 0.90x -> 1.0RCx
 % -------------------------------------------------------------------
-VERSION = 1.01;  % -> 1.01
-CHAR_VERSION = '1.01';
+VERSION = 1.02;  % -> 1.02
+CHAR_VERSION = '1.02';
 
 % netcdf file version, see DATA FORMAT TSG document:
 % CORTSG_format_gosud_1.5.doc
@@ -267,6 +267,35 @@ uimenu(hOptionMenu,'Label','Preferences',...
   'Enable', 'on',...
   'Callback', {@PreferencesMenuCallback});
 
+%%  Menu QC automatic
+%   Dependent functions : preferenceForm.m; tsg_preference.m,
+%   @QCMenuCallback
+%   ----------------------------------------------------------
+hQCMenu = uimenu(...
+  'Parent', hMainFig, 'Enable', 'off', 'HandleVisibility', handleVisibility,...
+  'Label', 'QCauto');
+hFlowMenu = uimenu(...
+  'Parent', hQCMenu, 'Label','Flow', 'HandleVisibility', handleVisibility,...
+  'UserData', 'off','Enable', 'off','Callback', {@QCMenuCallback,'Flow'});
+hPressMenu = uimenu(...
+  'Parent', hQCMenu, 'Label','Press', 'HandleVisibility', handleVisibility,...
+  'UserData', 'off', 'Callback', {@QCMenuCallback,'Press'});
+hSpeedMenu = uimenu(...
+  'Parent', hQCMenu, 'Label','Ship Speed', 'HandleVisibility', handleVisibility,...
+  'UserData', 'off', 'Callback', {@QCMenuCallback,'Speed'});
+hSSPSminMenu = uimenu(...
+  'Parent', hQCMenu, 'Label','SSPS min', 'HandleVisibility', handleVisibility,...
+  'UserData', 'off', 'Callback', {@QCMenuCallback,'SSPSmin'});
+hSSPSmaxMenu = uimenu(...
+  'Parent', hQCMenu, 'Label','SSPS max', 'HandleVisibility', handleVisibility,...
+  'UserData', 'off', 'Callback', {@QCMenuCallback,'SSPSmax'});
+hSSTPminMenu = uimenu(...
+  'Parent', hQCMenu, 'Label','SSTP min', 'HandleVisibility', handleVisibility,...
+  'UserData', 'off', 'Callback', {@QCMenuCallback,'SSTPmin'});
+hSSTPmaxMenu = uimenu(...
+  'Parent', hQCMenu, 'Label','SSTP max', 'HandleVisibility', handleVisibility,...
+  'UserData', 'off', 'Callback', {@QCMenuCallback,'SSTPmax'});
+
 %%  Menu Help with F1 Help and About submenu
 % --------------------------------------------------------
 hOptionMenu = uimenu(hMainFig,'Label','Help');
@@ -1097,6 +1126,61 @@ hrbInterpCancel = uicontrol( ...
 
 %% *************************** CALLBACKS **********************************
 
+%% QCMenuCallback
+%----------------------------------------------------------------------
+% Callback function run when the Automatic QC menu item is selected
+%
+% Si vous modiifer ce CallBack verifier les modifications a apporter a
+% 1 - preferenceForm.m
+% 2 - tsg_preference.m
+%----------------------------------------------------------------------
+  function QCMenuCallback(hObject, eventdata, test)
+    
+    switch test
+      case 'Speed'
+        minSpeedQC(hMainFig)
+      case 'Flow'
+        minFlowQC(hMainFig)
+      case 'Press'
+        minPressQC(hMainFig)
+      case 'SSPSmin'
+        minSSPSQC(hMainFig)
+      case 'SSPSmax'
+        maxSSPSQC(hMainFig)
+      case 'SSTPmin'
+        minSSTPQC(hMainFig)
+      case 'SSTPmax'
+        maxSSTPQC(hMainFig)
+      otherwise
+        msgbox('QCMenuCallback : erreur', 'QCMenuCallback','error', 'modal');
+    end
+
+    % --------------------------
+    % refresh QC statistic panel
+    % --------------------------
+    display_QC( hMainFig );
+
+    % ------------------
+    % Refresh the plots
+    %-------------------
+    
+    % Get the parameter displayed on plot number 1 : figure at the top
+    % -----------------------------------------------------------------
+    PARA = getParaCorModule( hMainFig );
+
+    % Draw plot 1
+    % -----------
+    plot_Validation( hMainFig, hPlotAxes, 1, PARA{1} );
+
+    % Update the map if already displayed
+    % -----------------------------------
+    if strcmp( get(hMapFig,'visible'), 'on') == 1
+      erase_Line( hPlotAxes, 4 );
+      plot_map( hMainFig, hPlotAxes);
+    end
+
+  end
+
 %% OpenMenuCallback
 %----------------------------------------------------------------------
 % Callback function run when the Open menu item is selected
@@ -1238,6 +1322,7 @@ hrbInterpCancel = uicontrol( ...
         % ---------------------------
         set(hSaveMenu,   'Enable', 'on');
         set(hExportMenu, 'Enable', 'on');
+        set(hQCMenu, 'Enable', 'on');
 
         % update some fields in tsg structure and restore tsg
         % ---------------------------------------------------
-- 
GitLab