Newer
Older
function concatStructTSG( hMainFig, tsg_old )
%
% Concatenate some elements of a TSG structure. Mainly :
% - TSG data members (DAYD, DATE, LATX, LONX, SSPS, SSJT, SSTP)
% - Discrete data (_EXT) members (DAYD, DATE, LATX, LONX, SSPS, SSTP)
%
% Right now, do not concatenate :
% - Calibration coefficent
% - '_HIST'
% - preference
%
% If the concatenanted TSG structures have identical dates, the double
% are supressed.
%
% This function is called by TEST_READ_V2.m
% concatNumTsg - At the end of this file
% concatInt8Tsg - At the end of this file
% supTsgDouble - At the end of this file
% supTsgExtDouble - At the end of this file
% Input
% hMainFig .... Handle to the main application
% tsg_old ..... TSG struct array, the first loaded in tsgqc. The data will
% be concatenated in this variable
%
% The tsg structure array to concatenate has been initialised in
% TEST_READ_V2 and saved in the application data variable 'tsg_data'.
%
%
% Retrieve the new tsg struct that we want to concatenate
% -------------------------------------------------------
tsg_new = getappdata( hMainFig, 'tsg_data' );
% iOrder is used to sort the members of the strcture
% DAYD is not concatenated right now because the function concatNumTsg uses
% the variable DAYD to konw the size of the arrays.
% ----------------------------------------------------------------------
% Concatenate the arrays
% ----------------------
tsg_old.DATE = [tsg_old.DATE; tsg_new.DATE];
tsg_old.DATE = tsg_old.DATE(iOrder,:);
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'LATX');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'LONX');
tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, 'POSITION_QC');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SPDC');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'PRES');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'FLOW');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'CNDC');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'CNDC_STD');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'CNDC_CAL');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'CNDC_FREQ');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSJT');
tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, 'SSJT_QC');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSJT_STD');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSJT_CAL');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSJT_FREQ');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSJT_ADJUSTED');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSJT_ADJUSTED_ERROR');
tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, 'SSJT_ADJUSTED_QC');
% % concatStrTsg( iOrder, tsg_old, tsg_new, 'SSJT_ADJUSTED_HIST');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSPS');
tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, 'SSPS_QC');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSPS_STD');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSPS_CAL');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSPS_ADJUSTED');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSPS_ADJUSTED_ERROR');
tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, 'SSPS_ADJUSTED_QC');
% % concatStrTsg( iOrder, tsg_old, tsg_new, 'SSPS_ADJUSTED_HIST');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSTP');
tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, 'SSTP_QC');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSTP_CAL');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSTP_FREQ');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSTP_ADJUSTED');
tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, 'SSTP_ADJUSTED_ERROR');
tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, 'SSTP_ADJUSTED_QC');
% % concatStrTsg( iOrder, tsg_old, tsg_new, 'SSTP_ADJUSTED_HIST');
% Discrete samples
% ----------------
tsg_old.DAYD_EXT = [tsg_old.DAYD_EXT; tsg_new.DAYD_EXT];
tsg_old.DATE_EXT = [tsg_old.DATE_EXT; tsg_new.DATE_EXT];
tsg_old.LATX_EXT = [tsg_old.LATX_EXT; tsg_new.LATX_EXT];
tsg_old.LONX_EXT = [tsg_old.LONX_EXT; tsg_new.LONX_EXT];
tsg_old.SSPS_EXT = [tsg_old.SSPS_EXT; tsg_new.SSPS_EXT];
tsg_old.SSPS_EXT_BOTTLE = strvcat(tsg_old.SSPS_EXT_BOTTLE, tsg_new.SSPS_EXT_BOTTLE);
tsg_old.SSPS_EXT_QC = [tsg_old.SSPS_EXT_QC; tsg_new.SSPS_EXT_QC];
tsg_old.SSPS_EXT_TYPE = strvcat(tsg_old.SSPS_EXT_TYPE, tsg_new.SSPS_EXT_TYPE);
tsg_old.SSPS_EXT_ANALDATE = strvcat(tsg_old.SSPS_EXT_ANALDATE,tsg_new.SSPS_EXT_ANALDATE);
tsg_old.SSTP_EXT = [tsg_old.SSTP_EXT; tsg_new.SSTP_EXT];
tsg_old.SSTP_EXT_QC = [tsg_old.SSTP_EXT_QC; tsg_new.SSTP_EXT_QC];
tsg_old.SSTP_EXT_TYPE = strvcat(tsg_old.SSTP_EXT_TYPE, tsg_new.SSTP_EXT_TYPE);
if ~isempty(tsg_old.DAYD_EXT)
[tsg_old.DAYD_EXT, iOrder] = sort(tsg_old.DAYD_EXT);
tsg_old.DATE_EXT = tsg_old.DATE_EXT(iOrder,:);
tsg_old.LATX_EXT = tsg_old.LATX_EXT(iOrder);
tsg_old.LONX_EXT = tsg_old.LONX_EXT(iOrder);
tsg_old.SSPS_EXT = tsg_old.SSPS_EXT(iOrder);
tsg_old.SSPS_EXT_QC = tsg_old.SSPS_EXT_QC(iOrder);
tsg_old.SSPS_EXT_BOTTLE = tsg_old.SSPS_EXT_BOTTLE(iOrder,:);
tsg_old.SSPS_EXT_TYPE = tsg_old.SSPS_EXT_TYPE(iOrder,:);
tsg_old.SSPS_EXT_ANALDATE = tsg_old.SSPS_EXT_ANALDATE(iOrder,:);
tsg_old.SSTP_EXT = tsg_old.SSTP_EXT(iOrder);
tsg_old.SSTP_EXT_QC = tsg_old.SSTP_EXT_QC(iOrder);
tsg_old.SSTP_EXT_TYPE = tsg_old.SSTP_EXT_TYPE(iOrder,:);
% Suppress Double. Compare the dates
% ----------------------------------
tsg_old = supTsgExtDouble(tsg_old);
setappdata( hMainFig, 'tsg_data', tsg_old );
%% *************************************************************************
function tsg_old = concatNumTsg( iOrder, tsg_old, tsg_new, Para)
%
% Concatenate 2 numeric arrays
%
% Input
% iOrder - Indicies to organise the array in time ascending order
% tsg_old - First TSG structure
% tsg_new - TSG structure that we want to concatenate
% Para - Member of the structures to concatenate
%
% Output
% If tsg_new.Para and tsg_old.Para are empty nothing is done
% ----------------------------------------------------------
if isempty(tsg_new.(Para)) && isempty(tsg_old.(Para))
% If only tsg_new.PARA is empty, fill it with NaN. The dimension of the
% final array must must be equal to the sum of the dimension of tsg.DAYD
% and tsg_old.DAYD
% ----------------------------------------------------------------------
elseif isempty(tsg_new.(Para))
tsg_new.(Para) = NaN * ones( size( tsg_new.DAYD ) );
% See preceding comment
% ---------------------
elseif isempty(tsg_old.(Para))
tsg_old.(Para) = NaN * ones( size( tsg_old.DAYD ) );
end
% Re-order the struct array
% -------------------------
%% *************************************************************************
function tsg_old = concatInt8Tsg( iOrder, NO_CONTROL, tsg_old, tsg_new, Para)
%
% Concatenate 2 numeric int8 arrays
%
% Input
% iOrder - Indicies to organise the array in time ascending order
% NO_CONTROL - Value for no control quality code
% tsg_old - First TSG structure
% tsg_new - Second TSG structure
% Para - Member of the structures to concatenate
%
% Output
% If tsg_new.Para and tsg_old.Para are empty nothing is done
% ----------------------------------------------------------
if isempty(tsg_new.(Para)) && isempty(tsg_old.(Para))
% If only tsg.PARA is empty, fill it with NO_CONTROL. The dimension of the
% concatenate array must must be equal to the sum of the dimension of
% tsg.DAYD and tsg_old.DAYD
% --------------------------------------------------------------------
elseif isempty(tsg_new.(Para))
tsg_new.(Para) = int8(NO_CONTROL) * int8(ones( size( tsg_new.DAYD )));
% See preceding comment
% ---------------------
elseif isempty(tsg_old.(Para))
tsg_old.(Para) = int8(NO_CONTROL) * int8(ones( size( tsg_old.DAYD )));
end
% Re-order the struct array
% -------------------------
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
%%
function tsg = supTsgDouble( tsg)
%
% Suppress measurements made at the same date
% The comparison cannot be made using tsg.DAYD :
% This cannot be done using the Matlab Serial Date format as there can be
% some loss of precision.. Especially when a floating number was written in
% a file.
%
% I use tsg.DATE. Could be simplify by comparing string rather than
% converting DATE with datenum
%
% ------------------------------------------------------------------------
% Convert string array DATE in numerical array
% --------------------------------------------
date = str2num(tsg.DATE);
% Compare adjacent element in an array
% ------------------------------------
date_diff = find( diff( date ) == 0 );
if ~isempty( date_diff )
tsg.DAYD(date_diff) = [];
tsg.DATE(date_diff,:) = [];
tsg.LATX(date_diff) = [];
tsg.LONX(date_diff) = [];
tsg.POSITION_QC(date_diff) = [];
if ~isempty(tsg.SPDC); tsg.SPDC(date_diff) = []; end
if ~isempty(tsg.PRES); tsg.PRES(date_diff) = []; end
if ~isempty(tsg.FLOW); tsg.FLOW(date_diff) = []; end
if ~isempty(tsg.CNDC); tsg.CNDC(date_diff) = []; end
if ~isempty(tsg.CNDC_STD); tsg.CNDC_STD(date_diff) = []; end
if ~isempty(tsg.CNDC_CAL); tsg.CNDC_CAL(date_diff) = []; end
if ~isempty(tsg.CNDC_FREQ); tsg.CNDC_FREQ(date_diff) = []; end
if ~isempty(tsg.SSJT); tsg.SSJT(date_diff) = []; end
if ~isempty(tsg.SSJT_QC); tsg.SSJT_QC(date_diff) = []; end
if ~isempty(tsg.SSJT_STD); tsg.SSJT_STD(date_diff) = []; end
if ~isempty(tsg.SSJT_CAL); tsg.SSJT_CAL(date_diff) = []; end
if ~isempty(tsg.SSJT_FREQ); tsg.SSJT_FREQ(date_diff) = []; end
if ~isempty(tsg.SSJT_ADJUSTED); tsg.SSJT_ADJUSTED(date_diff) = []; end
if ~isempty(tsg.SSJT_ADJUSTED_ERROR); tsg.SSJT_ADJUSTED_ERROR(date_diff) = []; end
if ~isempty(tsg.SSJT_ADJUSTED_QC); tsg.SSJT_ADJUSTED_QC(date_diff) = []; end
% if ~isempty(tsg.SSJT_ADJUSTED_HIST(date_diff,:) = []; end
if ~isempty(tsg.SSPS); tsg.SSPS(date_diff) = []; end
if ~isempty(tsg.SSPS_QC); tsg.SSPS_QC(date_diff) = []; end
if ~isempty(tsg.SSPS_STD); tsg.SSPS_STD(date_diff) = []; end
if ~isempty(tsg.SSPS_CAL); tsg.SSPS_CAL(date_diff) = []; end
if ~isempty(tsg.SSPS_ADJUSTED); tsg.SSPS_ADJUSTED(date_diff) = []; end
if ~isempty(tsg.SSPS_ADJUSTED_ERROR); tsg.SSPS_ADJUSTED_ERROR(date_diff) = []; end
if ~isempty(tsg.SSPS_ADJUSTED_QC); tsg.SSPS_ADJUSTED_QC(date_diff) = []; end
% if ~isempty(tsg.SSPS_ADJUSTED_HIST(date_diff,:) = []; end
if ~isempty(tsg.SSTP); tsg.SSTP(date_diff) = []; end
if ~isempty(tsg.SSTP_QC); tsg.SSTP_QC(date_diff) = []; end
if ~isempty(tsg.SSTP_CAL); tsg.SSTP_CAL(date_diff) = []; end
if ~isempty(tsg.SSTP_FREQ); tsg.SSTP_FREQ(date_diff) = []; end
if ~isempty(tsg.SSTP_ADJUSTED); tsg.SSTP_ADJUSTED(date_diff) = []; end
if ~isempty(tsg.SSTP_ADJUSTED_ERROR); tsg.SSTP_ADJUSTED_ERROR(date_diff) = []; end
if ~isempty(tsg.SSTP_ADJUSTED_QC); tsg.SSTP_ADJUSTED_QC(date_diff) = []; end
% if ~isempty(tsg.SSTP_ADJUSTED_HIST);tsg.SSTP_ADJUSTED_HIST(date_diff,:) = []; end
end
end
%%
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
% Test : suppress measurements made at the same date
% The comparison cannot be made using tsg.DAYD_EXT.
% This cannot be done using the Matlab Serial Date format as there can be
% some loss of precision.
%
% I use tsg.DATE_EXT
% ------------------------------------------------------------------------
if ~isempty( tsg.DATE_EXT )
% Convert string array DATE in numerical array
% --------------------------------------------
date = str2num(tsg.DATE_EXT);
% Compare adjacent element in an array
% ---------------------------------------------
date_diff = find( diff( date ) == 0 );
if ~isempty( date_diff )
tsg.DAYD_EXT(date_diff) = [];
tsg.DATE_EXT(date_diff,:) = [];
tsg.LATX_EXT(date_diff) = [];
tsg.LONX_EXT(date_diff) = [];
tsg.SSPS_EXT(date_diff) = [];
tsg.SSPS_EXT_QC(date_diff) = [];
tsg.SSPS_EXT_BOTTLE(date_diff,:) = [];
tsg.SSPS_EXT_TYPE(date_diff,:) = [];
tsg.SSPS_EXT_ANALDATE(date_diff,:)= [];
tsg.SSTP_EXT(date_diff) = [];
tsg.SSTP_EXT_QC(date_diff) = [];
tsg.SSTP_EXT_TYPE(date_diff,:) = [];
end
end
end