Skip to content
Snippets Groups Projects
updateTsgStruct.m 2.32 KiB
Newer Older
function updateTsgStruct(hMainFig)
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%
% This function is called after reading data and update tsg structure
% with common values
%
% Input
% -----
% hMainFig ............ Handel to the main user interface
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
%
% $Id$

% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
Yves Gouriou's avatar
Yves Gouriou committed
nPARA = 3;
PARA  = ['SSPS'; 'SSJT'; 'SSPS'];

jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% get min and max values for position and set to globals attributes
% -----------------------------------------------------------------
tsg.SOUTH_LATX = min(tsg.LATX);
tsg.NORTH_LATX = max(tsg.LATX);
tsg.WEST_LONX  = min(tsg.LONX);
tsg.EAST_LONX  = max(tsg.LONX);

% get date start and end value and set to globals attributes
% -----------------------------------------------------------------
date           = datestr(min(tsg.DAYD),30);
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
tsg.DATE_START = [date(1:8) date(10:15)];
date           = datestr(max(tsg.DAYD),30);
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
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);
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
  tsg.SPDC = zeros(size(ind));
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
  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

% Initialise ADJUSTED variables if empty
% --------------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
for i = 1: nPARA
Yves Gouriou's avatar
Yves Gouriou committed
  para1 =  PARA(i,:);
  para2 = [PARA(i,:) '_QC'];
  para3 = [PARA(i,:) '_ADJUSTED'];
  para4 = [PARA(i,:) '_ADJUSTED_QC'];
  para5 = [PARA(i,:) '_ADJUSTED_ERROR'];
Yves Gouriou's avatar
Yves Gouriou committed
  if isempty( tsg.(para3) ) && ~isempty( tsg.(para1) )
    tsg.(para3) = tsg.(para1);
    tsg.(para4) = tsg.(para2);
    tsg.(para5) = NaN * ones( size( tsg.(para1) ));
Yves Gouriou's avatar
Yves Gouriou committed
  elseif isempty( tsg.(para1) )
Yves Gouriou's avatar
Yves Gouriou committed
    msgbox(['You must initialise the tsg.' PARA(i) ' variable'],...
            'function ''updateTsgStruct''', ....
            'warn', 'modal');
  end
% Initialise  'variables_LINCOEF'
% -------------------------------
Yves Gouriou's avatar
Yves Gouriou committed
if isempty(tsg.SSJT_LINCOEF)
  tsg.SSJT_LINCOEF(1) = 1;
  tsg.SSJT_LINCOEF(2) = 0;
end
if isempty(tsg.CNDC_LINCOEF)
  tsg.CNDC_LINCOEF(1) = 1;
  tsg.CNDC_LINCOEF(2) = 0;
end
if isempty(tsg.SSTP_LINCOEF)
  tsg.SSTP_LINCOEF(1) = 1;
  tsg.SSTP_LINCOEF(2) = 0;
end
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% Save tsg structure 
% ------------------
setappdata( hMainFig, 'tsg_data', tsg);