Newer
Older
%
% 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 );
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');

jacques.grelet_ird.fr
committed
PARA = {'SSPS', 'SSJT', 'SSTP'};
% Get NO_CONTROL and INTERPOLATED_VALUE codes

jacques.grelet_ird.fr
committed
% a modifier !!!!!!!!!!!!!
% -------------------------------------------

jacques.grelet_ird.fr
committed
s = tsg.qc.hash.NO_CONTROL;
NO_CONTROL = s.code;
gael.alory_legos.obs-mip.fr
committed
% shift to [-180 180] longitude by default
% ----------------------------------------

jacques.grelet_ird.fr
committed
tsg.LONX = mod(tsg.LONX + 180, 360) - 180;
gael.alory_legos.obs-mip.fr
committed
% Suppress longitude discontinuity at -180 or 180 crossing
% --------------------------------------------------------
deflon = find(isfinite(tsg.LONX));
dlon = diff(tsg.LONX(deflon));

jacques.grelet_ird.fr
committed
tsg.indcross = find(abs(dlon) > 180);
if ~isempty(tsg.indcross)

jacques.grelet_ird.fr
committed
tsg.loncross = sign(dlon(tsg.indcross)) * 360;
tsg.indcross = deflon(tsg.indcross);
for i=1:length(tsg.indcross)

jacques.grelet_ird.fr
committed
tsg.LONX(tsg.indcross(i)+1:end) = ...
tsg.LONX(tsg.indcross(i)+1:end) - tsg.loncross(i);
end
end
tsg.lonplus = 0;

jacques.grelet_ird.fr
committed
tsg.lonmod = 0;
% get min and max values for position and set to globals attributes
% -----------------------------------------------------------------
tsg.SOUTH_LATX = min(tsg.LATX);
tsg.NORTH_LATX = max(tsg.LATX);

jacques.grelet_ird.fr
committed
if (max(tsg.LONX)-min(tsg.LONX)) > 360
tsg.WEST_LONX = -180;
tsg.EAST_LONX = 180;
else

jacques.grelet_ird.fr
committed
tsg.WEST_LONX = mod(min(tsg.LONX)+180, 360) - 180;
tsg.EAST_LONX = mod(max(tsg.LONX)+180, 360) - 180;
end
% get date start and end value and set to globals attributes

jacques.grelet_ird.fr
committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
% by default db-oceano use this format yyyymmddHHMMSS
% ----------------------------------------------------------
tsg.DATE_START = datestr(min(tsg.DAYD), tsg.preference.date_format_attribute);
tsg.DATE_END = datestr(max(tsg.DAYD), tsg.preference.date_format_attribute);
% if date is in standard format, change, if not, user need to update
% inside headerform
% ------------------------------------------------------------------
if size(tsg.DATE, 2) == 14
tsg.DATE_CREATION = datestr(datenum(tsg.DATE_CREATION, ...
'yyyyddmmHHMMSS'), tsg.preference.date_format_attribute);
end
if size(tsg.DATE, 2) == 14
tsg.DATE_UPDATE = datestr(datenum(tsg.DATE_UPDATE, ...
'yyyyddmmHHMMSS'), tsg.preference.date_format_attribute);
end
% update tsg.xxx_DATE_xxx with new or ISO8601 format if necessary
% conventions for variables are saved in tsg.conventions structure
% see updateTsgStruct.m
% ----------------------------------------------------------------
if ~isempty(tsg.REFERENCE_DATE_TIME) && ~isempty(tsg.conventions)
tsg.REFERENCE_DATE_TIME = datestr(datenum(tsg.REFERENCE_DATE_TIME,...
tsg.conventions.REFERENCE_DATE_TIME), tsg.preference.date_format_variable);
end
if ~isempty(tsg.DATE) && ~isempty(tsg.conventions)
tsg.DATE = datestr(datenum(tsg.DATE, ...
tsg.conventions.DATE), tsg.preference.date_format_variable);
end
if ~isempty(tsg.DATE_EXT) && ~isempty(tsg.conventions)
tsg.DATE_EXT = datestr(datenum(tsg.DATE_EXT, ...
tsg.conventions.DATE_EXT), tsg.preference.date_format_variable);
end
if ~isempty(tsg.SSPS_EXT_ANALDATE) && ~isempty(tsg.conventions)
tsg.SSPS_EXT_ANALDATE = datestr(datenum(tsg.DATE_EXT, ...
tsg.conventions.SSPS_EXT_ANALDATE), tsg.preference.date_format_variable);
end
% Variables must exists

jacques.grelet_ird.fr
committed
for para = PARA

jacques.grelet_ird.fr
committed
para = char(para);

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
if ~isempty( tsg.(para) ) && isempty( tsg.([para '_QC']) )
% If QC variables are emptied, fill them with NO_CONTROL code value
% -----------------------------------------------------------------

jacques.grelet_ird.fr
committed
tsg.([para '_QC']) = castByteQC( NO_CONTROL, tsg.DAYD );

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
if ~isempty( tsg.(para) ) && isempty( tsg.([para '_ADJUSTED_QC']) )

jacques.grelet_ird.fr
committed
% If QC variables are emptied, fill them with NO_CONTROL code value
% -----------------------------------------------------------------

jacques.grelet_ird.fr
committed
tsg.([para '_ADJUSTED_QC']) = castByteQC( NO_CONTROL, tsg.DAYD );

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% initialize POSITION_QC
% ----------------------
tsg.('POSITION_QC') = castByteQC( NO_CONTROL, tsg.DAYD );

jacques.grelet_ird.fr
committed
% Empty variables filled with NaN
% -------------------------------
names = fieldnames( tsg );
for i = 1: length(names)
para = char( names(i) );

jacques.grelet_ird.fr
committed
if ~isstruct(tsg.(para)) && ~isempty(tsg.(para)) && ~iscell(tsg.(para))
A = tsg.(para);
ind = find( isnan( A ) == 0 );
if isempty( ind )
tsg.(para) = [];
end
% Save tsg structure
% ------------------
setappdata( hMainFig, 'tsg_data', tsg);

jacques.grelet_ird.fr
committed
% reset calibration coefficients for this not comptatible version
% ---------------------------------------------------------------
if strcmp(tsg.FORMAT_VERSION, '1.4')
tsg.SSJT_CALCOEF = [];
tsg.CNDC_CALCOEF = [];
tsg.SSTP_CALCOEF = [];
tsg.SSJT_LINCOEF = [];
tsg.CNDC_LINCOEF = [];
tsg.SSTP_LINCOEF = [];
% Save tsg structure
% ------------------
setappdata( hMainFig, 'tsg_data', tsg);
end
% fill tsg calibration variables
% ------------------------------
updateTsgStructWithCalCoeff(hMainFig);
% Get the data from the application GUI
% -------------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
% Initialise 'variables_LINCOEF'
% in tsg_initialisation now
% -------------------------------
var ={'SSJT_LINCOEF', 'CNDC_LINCOEF', 'SSTP_LINCOEF'};
lin_type = {padding('SLOPE',tsg.dim.COEF_CONV_SIZE),...
padding('OFFSET',tsg.dim.COEF_CONV_SIZE)};
lin_val = [1,0];

jacques.grelet_ird.fr
committed
% loop over each variables
% ------------------------
for i = 1:numel(var)

jacques.grelet_ird.fr
committed
% check if var_LINCOEF not empty
% -----------------------------------

jacques.grelet_ird.fr
committed
if isempty(tsg.(var{i}))
for j = 1:tsg.dim.LINCOEF
tsg.(var{i})(j) = lin_val(j);

jacques.grelet_ird.fr
committed
end
% write LINCOEF_CONV's
% convert cell array of string to char array
% ------------------------------------------
tsg.([var{i} '_CONV']) = char(lin_type);

jacques.grelet_ird.fr
committed
end
setappdata( hMainFig, 'tsg_data', tsg);