Skip to content
Snippets Groups Projects
updateTsgStruct.m 4.06 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

% Compute ship velocity from positions if sog not available
% Must be done first as we use getappdata and setappdata within
% the function
% ---------------------------------------------------------
shipVelocity( hMainFig );

jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed
% Get the data from the application GUI
% -------------------------------------
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');

% Suppress longitude discontinuity at -180 or 180 crossing 
% --------------------------------------------------------
dlon=circshift(tsg.LONX,-1)-tsg.LONX;
dlon=dlon(1:end-1);
tsg.indcross=find(abs(dlon)>350);
if ~isempty(tsg.indcross)
    tsg.loncross=sign(dlon(tsg.indcross))*360;
    for i=1:length(tsg.indcross)
        tsg.LONX(tsg.indcross(i)+1:end)=tsg.LONX(tsg.indcross(i)+1:end)-tsg.loncross(i);
    end
end

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);
if max(tsg.LONX)>(min(tsg.LONX)+360)
    tsg.WEST_LONX  = -180;
    tsg.EAST_LONX  = 180;
else
    tsg.WEST_LONX  = mod(min(tsg.LONX)+180,360)-180;
    tsg.EAST_LONX  = mod(max(tsg.LONX)+180,360)-180;
end
jacques.grelet_ird.fr's avatar
jacques.grelet_ird.fr committed

% 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)];

% Variables must exists
% ---------------------
Yves Gouriou's avatar
Yves Gouriou committed
for i = 1: nPARA
Yves Gouriou's avatar
Yves Gouriou committed
  para1 =  PARA(i,:);
  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

% Empty variables filled with NaN
% -------------------------------
names = fieldnames( tsg );
for i = 1: length(names)
  para = char( names(i) );
  if ~isstruct(tsg.(para)) && ~isempty(tsg.(para)) && ~iscell(tsg.(para))
    A = tsg.(para);
    ind = find( isnan( A ) == 0 );
    if isempty( ind )
      tsg.(para) = [];
    end
Yves Gouriou's avatar
Yves Gouriou committed
  end
% initialise empty coefficients variables with type defined with preference
% -------------------------------------------------------------------------
coeff_type = {{'DATE','A','B','C','D','F0',''},{'DATE','A','B','C','D','M','CPCOR'},...
  {'DATE','A','B','C','D','F0',''}; ...
  {'DATE','G','H','I','J','F0',''},{'DATE','G','H','I','J','CTCOR','CPCOR'},...
  {'DATE','G','H','I','J','F0',''}};
lin_type = {'offset','slope'};
lin_val  = [0,1];

var = {'SSJT_CALCOEF', 'CNDC_CALCOEF', 'SSTP_CALCOEF'};

pref = tsg.preference.coeff_type_value;

for i = 1:numel(var)
  if isempty(tsg.(var{i}))
    for j = 1:tsg.dim.CALCOEF
      tsg.(var{i})(j) = NaN;
      tsg.([var{i} '_CONV']) = ...
        [tsg.([var{i} '_CONV']); padding(coeff_type{pref,i}{j}, tsg.dim.COEF_CONV_SIZE)];
    end
Yves Gouriou's avatar
Yves Gouriou committed
end

var ={'SSJT_LINCOEF', 'CNDC_LINCOEF', 'SSTP_LINCOEF'};

for i = 1:numel(var)
  if isempty(tsg.(var{i}))
    for j = 1:tsg.dim.LINCOEF
      tsg.(var{i})(j) = lin_val(j);
      tsg.([var{i} '_CONV']) = ...
        [tsg.([var{i} '_CONV']); padding(lin_type{j}, tsg.dim.COEF_CONV_SIZE)];
    end
Yves Gouriou's avatar
Yves Gouriou committed
end
% Initialise  'variables_LINCOEF'
% in tsg_initialisation now
% -------------------------------
% 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
% ------------------
setappdata( hMainFig, 'tsg_data', tsg);