From 3e2c0c858ba0188e04860e2481b687aead9c618e Mon Sep 17 00:00:00 2001
From: Yves Gouriou <yves.gouriou@ird.fr>
Date: Wed, 12 Mar 2008 11:25:23 +0000
Subject: [PATCH] =?UTF-8?q?D=C3=A9veloppement=20module=20d'interpolation?=
 =?UTF-8?q?=20des=20positions?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 tsg_util/automaticQC.m        |  2 +-
 tsg_util/interpPosLinear.m    | 49 ++++++++++++++++++-----------
 tsg_util/plot_Interpolation.m | 14 ++++++---
 tsgqc_GUI.m                   | 59 ++++++++++++++++++++++++++++++++---
 4 files changed, 94 insertions(+), 30 deletions(-)

diff --git a/tsg_util/automaticQC.m b/tsg_util/automaticQC.m
index aba6307..98716b9 100644
--- a/tsg_util/automaticQC.m
+++ b/tsg_util/automaticQC.m
@@ -32,7 +32,7 @@ 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;
+  if ~isempty( tsg.DATE );      tsg.DATE(ind, :)      = []; end;
   if ~isempty( tsg.LATX );      tsg.LATX(ind)      = []; end;
   if ~isempty( tsg.LONX );      tsg.LONX(ind)      = []; end;
   if ~isempty( tsg.SSPS );      tsg.SSPS(ind)      = []; end;
diff --git a/tsg_util/interpPosLinear.m b/tsg_util/interpPosLinear.m
index 0fe231d..dab63ff 100644
--- a/tsg_util/interpPosLinear.m
+++ b/tsg_util/interpPosLinear.m
@@ -15,38 +15,49 @@ function [error] = interpPosLinear( hMainFig, dateMin, dateMax )
 
 % Get application data
 % --------------------
-tsg    = getappdata( hMainFig, 'tsg_data');
+tsg = getappdata( hMainFig, 'tsg_data');
 
-% Get INTERPOLATED_VALUE code
-% ---------------------------
+% Get NO_CONTROL and INTERPOLATED_VALUE codes
+% -------------------------------------------
 NO_CONTROL         = get(tsg.qc.hash, 'NO_CONTROL', 'code');
 INTERPOLATED_VALUE = get(tsg.qc.hash, 'INTERPOLATED_VALUE', 'code');
 
 error = 1;
 if dateMax > dateMin
 
-  % find the closest point
-  % ----------------------
-  ind = find( tsg.DAYD >= dateMin && tsg.DAYD <= dateMax );
+  % Indices of the records to interpolate
+  % -------------------------------------
+  iRec = find( tsg.DAYD >= dateMin & tsg.DAYD <= dateMax );
 
-  if ~isempty( ind )
+  if ~isempty( iRec )
     
-    % Look for records with no position
-    % ---------------------------------
-    ind2 = find( isnan(tsg.LATX(ind)) == 1 );
-    Y = interp1( tsg.DAYD(ind), tsg.LATX(ind), tsg.DAYD(ind(ind2)) );
-    tsg.LATX(ind(ind2)) = Y;
+    % Look for records with Good Position
+    % -----------------------------------
+    iGP = find( isnan(tsg.LATX(iRec)) == 0 );
     
-    Y = interp1( tsg.DAYD(ind), tsg.LONX(ind), tsg.DAYD(ind(ind2)) );
-    tsg.LONX(ind(ind2)) = Y;
+    % Look for records with No Position
+    % -----------------------------------
+    iNP = find( isnan(tsg.LATX(iRec)) == 1 );
     
-    if isempty( tsg.POSITION_QC )
-      tsg.POSITION = NO_CONTROL * ones( size(tsg.DAYD) );
+    if ~isempty( iNP ) && ~isempty( iGP )
+
+      Y = interp1(tsg.DAYD(iRec(iGP)), tsg.LATX(iRec(iGP)), tsg.DAYD(iRec) );
+      
+      tsg.LATX(iRec(iNP)) = Y(iRec(iNP) - iRec(1) + 1);
+
+      Y = interp1(tsg.DAYD(iRec(iGP)), tsg.LONX(iRec(iGP)), tsg.DAYD(iRec) );
+      
+      tsg.LONX(iRec(iNP)) = Y(iRec(iNP) - iRec(1) + 1);
+
+      if isempty( tsg.POSITION_QC )
+        tsg.POSITION_QC = castByteQC( NO_CONTROL, tsg.DAYD );
+      end
+
+      tsg.POSITION_QC(iRec(iNP)) = INTERPOLATED_VALUE;
+      
     end
-    
-    tsg.POSITION_QC(ind(ind2)) = INTERPOLATED_VALUE;
 
-  end 
+  end
   
   % Update tsg application data
   % ---------------------------
diff --git a/tsg_util/plot_Interpolation.m b/tsg_util/plot_Interpolation.m
index 9c6a26c..af8e917 100644
--- a/tsg_util/plot_Interpolation.m
+++ b/tsg_util/plot_Interpolation.m
@@ -22,7 +22,7 @@ switch nPlot
       ind = find( isnan(tsg.LATX) == 1 | isnan(tsg.LONX) == 1);
       if ~isempty( tsg.ssps_smooth )
         plot_Tsg( hMainFig, hPlotAxes, 1, tsg.DAYD(ind), tsg.SSPS(ind), [],...
-          'SSPS_NOPOS','r','none','*',2);
+          'SSPS_NOPOS','b','none','*',2);
       end
 
       ind = find( isnan(tsg.LATX) == 0 | isnan(tsg.LONX) == 0);
@@ -42,8 +42,10 @@ switch nPlot
     end
     if ~isempty(tsg.POSITION_QC)
       ind = find( tsg.POSITION_QC == INTERPOLATED_VALUE );
-      plot_Tsg( hMainFig, hPlotAxes, 2, tsg.DAYD(ind), tsg.LATX(ind),[],...
-                'LATX_INTERP','r','none','*',2);
+      if ~isempty( ind )
+        plot_Tsg( hMainFig, hPlotAxes, 2, tsg.DAYD(ind), tsg.LATX(ind),[],...
+                 'LATX_INTERP','r','none','*',2);
+      end
     end
     
   % ---------------------------------------------------------------------
@@ -55,8 +57,10 @@ switch nPlot
     end
     if ~isempty(tsg.POSITION_QC)
       ind = find( tsg.POSITION_QC == INTERPOLATED_VALUE );
-      plot_Tsg( hMainFig, hPlotAxes, 2, tsg.DAYD(ind), tsg.LONX(ind),[],...
-                'LONX_INTERP','r','none','*',2);
+      if ~isempty( ind )
+        plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD(ind), tsg.LONX(ind),[],...
+                  'LONX_INTERP','r','none','*',2);
+      end
     end
 
 end
diff --git a/tsgqc_GUI.m b/tsgqc_GUI.m
index 9ac9358..d223e76 100644
--- a/tsgqc_GUI.m
+++ b/tsgqc_GUI.m
@@ -885,13 +885,13 @@ hpInterpPos = uipanel( ...
   'Title', 'Lat-Lon interpolation', ...
   'FontSize', tsg.fontSize-1, 'Fontweight', 'bold', ...
   'Visible', 'off', ...
-  'Units', 'normalized','Position', [.0, .85, .15, .11]);
+  'Units', 'normalized','Position', [.0, .75, .15, .21]);
 hrbInterpLinear = uicontrol( ...
   'Style','pushbutton', 'Parent',hpInterpPos, ...
   'String','Linear interpolation',...
   'FontSize',tsg.fontSize-1,...
   'Tag', 'TAG_PUSH_INTERP_LINEAR', ...
-  'Units', 'normalized','pos',[.05 .6 .9 .3], ...
+  'Units', 'normalized','pos',[.05 .65 .9 .25], ...
   'HandleVisibility','callback', ...
   'Callback', @InterpPosLinearCallback);
 hrbInterpOther = uicontrol( ...
@@ -899,9 +899,17 @@ hrbInterpOther = uicontrol( ...
   'String','Other method',...
   'FontSize',tsg.fontSize-1,...
   'Tag', 'TAG_PUSH_INTERP_OTHER', ...
-  'Units', 'normalized','pos',[.05 .1 .9 .3], ...
+  'Units', 'normalized','pos',[.05 .35 .9 .25], ...
   'HandleVisibility','callback', ...
   'Callback', @InterpPosOtherCallback);
+hrbInterpCancel = uicontrol( ...
+  'Style','pushbutton', 'Parent',hpInterpPos, ...
+  'String','Cancel interpolation',...
+  'FontSize',tsg.fontSize-1,...
+  'Tag', 'TAG_PUSH_INTERP_CANCEL', ...
+  'Units', 'normalized','pos',[.05 .05 .9 .25], ...
+  'HandleVisibility','callback', ...
+  'Callback', @InterpPosCancelCallback);
 
 
 %% test if user preference autoload field is checked (on)
@@ -1120,8 +1128,7 @@ end
   % Callback function run when 
   %
   function Inter_OnMenuCallback( hObject, eventdata)
-      
-  
+
     % Activate or desactivate uipanels
     % --------------------------------
     set( hpCalCoef,            'Visible', 'off' );
@@ -1174,6 +1181,10 @@ end
     plot_Validation( hMainFig, hPlotAxes, 2 );
     plot_Validation( hMainFig, hPlotAxes, 3 );
     
+    % Set the pointer
+    % ---------------
+    set( hMainFig, 'Pointer', 'arrow');
+
   end
 
 %% InterpLinearCallback ...............................Interpolation Linear
@@ -1218,6 +1229,40 @@ end
             'modal' );
   end
 
+%% InterpPosCancelCallback ..........................Cancel Interpolation
+  %----------------------------------------------------------------------
+  function InterpPosCancelCallback(hObject, eventdata)
+    % Callback function run when
+    
+    % Get tsg application data
+    % ------------------------
+    tsg = getappdata( hMainFig, 'tsg_data' );
+    
+    % Get NO_CONTROL and INTERPOLATED_VALUE codes
+    % -------------------------------------------
+    NO_CONTROL         = get(tsg.qc.hash, 'NO_CONTROL', 'code');
+    INTERPOLATED_VALUE = get(tsg.qc.hash, 'INTERPOLATED_VALUE', 'code');
+
+    if ~isempty( tsg.POSITION_QC )
+      iINTERP = find(  tsg.POSITION_QC == INTERPOLATED_VALUE);
+      tsg.LATX( iINTERP ) = NaN * ones( size( iINTERP), 1 );
+      tsg.LONX( iINTERP ) = NaN * ones( size( iINTERP), 1 );
+      tsg.POSITION_QC = [];
+    end
+    
+    % Save tsg application data
+    % --------------------------
+    setappdata( hMainFig, 'tsg_data', tsg );
+    
+    % Refresh plots
+    % -------------
+    plot_Interpolation( hMainFig, hPlotAxes, 1 );
+    plot_Interpolation( hMainFig, hPlotAxes, 2 );
+    plot_Interpolation( hMainFig, hPlotAxes, 3 );
+
+  end
+
+
 %% Cal_OnMenuCallback ..................................... Calibration
   %----------------------------------------------------------------------
   % Callback function run when 
@@ -2040,6 +2085,10 @@ end
       plot_Validation( hMainFig, hPlotAxes, 2 );
       plot_Validation( hMainFig, hPlotAxes, 3 );
     end
+    
+    % Set the pointer
+    % ---------------
+    set( hMainFig, 'Pointer', 'arrow');
 
   end
 
-- 
GitLab