From 6d5ce5562f39c01d2ca1906b3ef2be062805ec2b Mon Sep 17 00:00:00 2001 From: Jacques Grelet <jacques.grelet@ird.fr> Date: Wed, 16 Jan 2008 16:55:50 +0000 Subject: [PATCH] add comments if no data for <var>_WS and <var>_EXT, dimension DAYD_WS or DAYD_EXT are not defined --- tsg_io/writeTSGDataNetCDF.m | 79 +++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/tsg_io/writeTSGDataNetCDF.m b/tsg_io/writeTSGDataNetCDF.m index 4d048e4..a6940e9 100644 --- a/tsg_io/writeTSGDataNetCDF.m +++ b/tsg_io/writeTSGDataNetCDF.m @@ -13,7 +13,9 @@ function [error] = writeTSGDataNetCDF( hTsgGUI, filename) % % The data are store using setappdata - Variable name : 'tsg_data' % -% Caution : replace the fill-value with NaN +% Actually, with DAYD, DAYD_WS and DAT_EXT dimensions defined: 61 variables +% DAYD, DAYD_WS dimensions defined: 57 variables +% DAYD only dimension defined: 53 variables % % $Id$ @@ -52,8 +54,8 @@ tsg = getappdata( hTsgGUI, 'tsg_data'); nca = tsg_nc('tsg_ncattr.csv'); nca_keys = keys(nca); -% Get GF3 variables list codes from class tsg_nc with file 'tsg_ncvar.csv' -% ----------------------------------------------------------------------- +% Get variables list codes from class tsg_nc with file 'tsg_ncvar.csv' +% -------------------------------------------------------------------- ncv = tsg_nc('tsg_ncvar.csv'); ncv_keys = keys(ncv); ncv_fieldNames = get_fieldnames(ncv); @@ -68,10 +70,31 @@ fprintf('...writing %s : ', filename); % Variable dimensions % ------------------- nc('DAYD') = numel(tsg.DAYD); -nc('DAYD_WS') = numel(tsg.DAYD_WS); % number of water samples -nc('DAYD_EXT') = numel(tsg.DAYD_EXT); % number of external SSPS or SSTP comparison -nc('NCOEF_CAL') = 5; % number of calibration coefficients -nc('NCOEF_LIN') = 2; % number of linearisation coefficients + +% if dimension is empty (no data), don't create, because create empty +% dimension quive it unlimited dimension, but you can only have one +% unlimited dimension in a file +% -------------------------------------------------------------------- + +% number of water samples +% ----------------------- +if ~isempty(tsg.DAYD_WS) + nc('DAYD_WS') = numel(tsg.DAYD_WS); +end + +% number of external SSPS or SSTP comparison +% ------------------------------------------ +if ~isempty(tsg.DAYD_EXT) + nc('DAYD_EXT') = numel(tsg.DAYD_EXT); +end + +% number of calibration coefficients +% ---------------------------------- +nc('NCOEF_CAL') = 5; + +% number of linearisation coefficients +% ------------------------------------ +nc('NCOEF_LIN') = 2; % Fixed dimensions % ---------------- @@ -99,8 +122,8 @@ for i=1:numel(ncv_keys) dimension = get(ncv, variable, ncv_fieldNames{1}); nctype = get(ncv, variable, ncv_fieldNames{2}); - % define dimension, value must be a cell - % -------------------------------------- + % create variable dimension, value must be a cell + % ----------------------------------------------- switch nctype case 'double' nc{variable} = ncdouble(dimension); @@ -118,13 +141,19 @@ for i=1:numel(ncv_keys) nc{variable} = ncfloat(dimension); end - % jump dimension and nctype field - % ------------------------------- + % create variable attribute, jump dimension and nctype fields + % ----------------------------------------------------------- for j=3:numel(ncv_fieldNames) fieldName = ncv_fieldNames{j}; value = get(ncv, variable, fieldName); + % if field is empy, it's not a attribute for this netcdf variable + % --------------------------------------------------------------- if ~isempty(value) + + % only two type for variable attribute: char or float, could be + % modified in the futur ... + % ------------------------------------------------------------- if ischar(value) nc{variable}.(fieldName) = ncchar(value); else @@ -158,30 +187,22 @@ end % Write measurements (variables) % ------------------------------- for i=1:numel(ncv_keys) - + % get netcdf variable name % ------------------------ variable = ncv_keys{i}; - + % display waitbar % --------------- waitbar( i/numel(ncv_keys), wb, ['writing ' variable ' variable']); - - % DATE as two dimension - % don't work under windows - % nc{variable}(:) = tsg.(variable); - %if strmatch('DATE', variable) - % nc{variable}(:,:) = tsg.(variable); - %else - % other one dimension - % under Linux, when you write an with empty matrix to an unlimited - % variable dimension, nc was corrupted to double object - % works well on windows - if ~isempty(tsg.(variable)) - %nc{variable}(1:length(tsg.(variable))) = tsg.(variable); - nc{variable}(:) = tsg.(variable); - end - %end + + % don't write value if empty data, netcdf use FillValue_ attribute + % in case of unlimited dimension, for example only, use: + % nc{variable}(1:length(tsg.(variable))) = tsg.(variable); + % ---------------------------------------------------------------- + if ~isempty(tsg.(variable)) + nc{variable}(:) = tsg.(variable); + end end % Close waitbar -- GitLab