Newer
Older
function [] = tsg_mergesample( hTsgGUI )
Yves Gouriou
committed
%
% function [sample] = dev_mergesample( bucketNETCDF, bucketASCII)
%
% Merge the 2 types of 'bucket' records, if they exists
%
% Input
% bucketNETCDF ........ Struct. bucket data included in the TSG NetCDF file
% bucketASCII ......... Struct. bucket data store in an ASCII file
%
% Ouptut
% sample .............. Struct. gathering all bucket measurements
%
% Get bucket data in ASCII or NETCDF format. If the data does not exist
% getappdata return an empty matrix
% ---------------------------------------------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');
Yves Gouriou
committed
% Create a structure with an NaN
% No other solution as I can't add a structure to an empty one
% ------------------------------------------------------------
sample = struct('DAYD',NaN , 'LATX',NaN , 'LONX',NaN , ...
'SSPS',NaN , 'SSPS_QC',NaN , 'SSPS_DIF',NaN ,...
'SSPS_SMOOTH',NaN , 'SSPS_TYPE', NaN);
Yves Gouriou
committed
% Fill the structure sample with the bucket data.
Yves Gouriou
committed
% This measurements are of TYPE 1
% ------------------------------------------------
if ~isempty(tsg.SSPS_WS)
sample.DAYD = [sample.DAYD; tsg.DAYD_WS];
sample.LATX = [sample.LATX; tsg.LATX_WS];
sample.LONX = [sample.LONX; tsg.LONX_WS];
sample.SSPS = [sample.SSPS; tsg.SSPS_WS];
sample.SSPS_QC = [sample.SSPS_QC; tsg.SSPS_WS_QC];
sample.SSPS_DIF = [sample.SSPS_DIF; zeros(size(sample.DAYD))];
sample.SSPS_SMOOTH = [sample.SSPS_SMOOTH; zeros(size(sample.DAYD))];
sample.SSPS_TYPE = [sample.SSPS_TYPE; ones(size(sample.DAYD))];
Yves Gouriou
committed
end
% Fill the structure sample with the external sample
% This measurements are of TYPE EXT
% --------------------------------------------------
if ~isempty(tsg.SSPS_EXT)
sample.DAYD = [sample.DAYD; tsg.DAYD_EXT];
sample.LATX = [sample.LATX; tsg.LATX_EXT];
sample.LONX = [sample.LONX; tsg.LONX_EXT];
sample.SSPS = [sample.SSPS; tsg.SSPS_EXT];
sample.SSPS_QC = [sample.SSPS_QC; tsg.SSPS_EXT_QC];
sample.SSPS_DIF = [sample.SSPS_DIF; zeros(size(tsg.DAYD_EXT))];
sample.SSPS_SMOOTH = [sample.SSPS_SMOOTH; zeros(size(tsg.DAYD_EXT))];
sample.SSPS_TYPE = [sample.SSPS_TYPE; tsg.SSPS_EXT_TYPE];
Yves Gouriou
committed
end
% Eliminate the first element if NaN
% ----------------------------------
if isnan(sample.DAYD(1))
sample.DAYD(1) = [];
sample.LATX(1) = [];
sample.LONX(1) = [];
sample.SSPS(1) = [];
sample.SSPS_QC(1) = [];
sample.SSPS_DIF(1) = [];
sample.SSPS_SMOOTH(1) = [];
sample.SSPS_TYPE(1) = [];
end
Yves Gouriou
committed
% Sort the struct sample - increasing time.
% -----------------------------------------
if ~isempty(sample)
[sample.DAYD, iOrder] = sort(sample.DAYD);
sample.LATX = sample.LATX(iOrder);
sample.LONX = sample.LONX(iOrder);
sample.SSPS = sample.SSPS(iOrder);
sample.SSPS_QC = sample.SSPS_QC(iOrder);
sample.SSPS_DIF = sample.SSPS_DIF(iOrder);
sample.SSPS_SMOOTH = sample.SSPS_SMOOTH(iOrder);
sample.SSPS_TYPE = sample.SSPS_TYPE(iOrder);
Yves Gouriou
committed
end
% Update application data sample
% ------------------------------
setappdata( hTsgGUI, 'sample', sample );