From 548e3a6f03c2d3d44b24884ba5e4b7a61054d623 Mon Sep 17 00:00:00 2001
From: Yves Gouriou <yves.gouriou@ird.fr>
Date: Thu, 10 Apr 2008 19:16:24 +0000
Subject: [PATCH] =?UTF-8?q?Cr=C3=A9e=20une=20fonction=20ind=C3=A9pendante?=
 =?UTF-8?q?=20pour=20le=20calcul=20de=20la=20vitesse=20du=20navire?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 tsg_util/shipVelocity.m    | 27 +++++++++++++++++++++++++
 tsg_util/updateTsgStruct.m | 41 +++++++++++++++++++-------------------
 2 files changed, 48 insertions(+), 20 deletions(-)
 create mode 100644 tsg_util/shipVelocity.m

diff --git a/tsg_util/shipVelocity.m b/tsg_util/shipVelocity.m
new file mode 100644
index 0000000..bc759c3
--- /dev/null
+++ b/tsg_util/shipVelocity.m
@@ -0,0 +1,27 @@
+function shipVelocity( hMainFig )
+%
+% Compute the ship velocity
+%
+
+% Get the data from the application GUI
+% -------------------------------------
+tsg = getappdata( hMainFig, 'tsg_data');
+
+% Compute ship velocity from positions if sog not available
+% ---------------------------------------------------------
+if isempty(tsg.SPDC)
+  range    = m_lldist(tsg.LONX,tsg.LATX);
+  ind      = size(tsg.DAYD);
+  tsg.SPDC = zeros(size(ind));
+
+  for i=1:length(tsg.DAYD)-1
+    tsg.SPDC(i) = range(i) / ((tsg.DAYD(i+1)-tsg.DAYD(i)) * 24 * 1.854);
+  end
+  tsg.SPDC = [tsg.SPDC';0];
+end
+
+% Save tsg structure
+% ------------------
+setappdata( hMainFig, 'tsg_data', tsg);
+
+end
diff --git a/tsg_util/updateTsgStruct.m b/tsg_util/updateTsgStruct.m
index bd5261e..34500d5 100644
--- a/tsg_util/updateTsgStruct.m
+++ b/tsg_util/updateTsgStruct.m
@@ -9,6 +9,13 @@ function updateTsgStruct(hMainFig)
 %
 % $Id$
 
+
+% Compute ship velocity from positions if sog not available
+% Must be done first as we use getappdata and setappdata within
+% the function
+% ---------------------------------------------------------
+shipVelocity( hMainFig );
+
 % Get the data from the application GUI
 % -------------------------------------
 tsg = getappdata( hMainFig, 'tsg_data');
@@ -16,6 +23,10 @@ tsg = getappdata( hMainFig, 'tsg_data');
 nPARA = 2;
 PARA  = ['SSPS'; 'SSJT'];
 
+% Get NO_CONTROL and INTERPOLATED_VALUE codes
+% -------------------------------------------
+NO_CONTROL = get(tsg.qc.hash, 'NO_CONTROL', 'code');
+
 % get min and max values for position and set to globals attributes
 % -----------------------------------------------------------------
 tsg.SOUTH_LATX = min(tsg.LATX);
@@ -30,28 +41,17 @@ tsg.DATE_START = [date(1:8) date(10:15)];
 date           = datestr(max(tsg.DAYD),30);
 tsg.DATE_END   = [date(1:8) date(10:15)];
 
-% Compute ship velocity from positions if sog not available
-% ---------------------------------------------------------
-if isempty(tsg.SPDC)
-  range    = m_lldist(tsg.LONX,tsg.LATX);
-  ind      = size(tsg.DAYD);
-  tsg.SPDC = zeros(size(ind));
-  
-  for i=1:length(tsg.DAYD)-1
-    tsg.SPDC(i) = range(i) / ((tsg.DAYD(i+1)-tsg.DAYD(i)) * 24 * 1.854);
-  end
-  tsg.SPDC = [tsg.SPDC';0];
-end
-
-% Varaibles must exists
+% Variables must exists
 % ---------------------
 for i = 1: nPARA
 
   para1 =  PARA(i,:);
-  if isempty( tsg.(para1) )
-    msgbox(['You must initialise the tsg.' PARA(i,:) ' variable'],...
-      'function ''updateTsgStruct''', ....
-      'warn', 'modal');
+  if ~isempty( tsg.(para1) ) && isempty( tsg.([para1 '_QC']) )
+
+    % If QC variables are emptied, fill them with NO_CONTROL code value
+    % -----------------------------------------------------------------
+    tsg.([para1 '_QC']) = castByteQC( NO_CONTROL, tsg.DAYD );
+
   end
 end
 
@@ -84,7 +84,8 @@ if isempty(tsg.SSTP_LINCOEF)
   tsg.SSTP_LINCOEF(2) = 0;
 end
 
-% Save tsg structure 
+% Save tsg structure
 % ------------------
 setappdata( hMainFig, 'tsg_data', tsg);
- 
\ No newline at end of file
+
+end
-- 
GitLab