diff --git a/tsg_io/readTsgDataNetCDF.m b/tsg_io/readTsgDataNetCDF.m index 4df8f6c62ae703c21e0713fc59c4a3b7215508bd..4aaf3e6f8737cbd9a44ac8e0f3e3b97c3b44382a 100644 --- a/tsg_io/readTsgDataNetCDF.m +++ b/tsg_io/readTsgDataNetCDF.m @@ -109,7 +109,7 @@ close(nc); % Display time to read file on console % ------------------------------------ -t = toc; fprintf('...done (%6.2f sec).\n\n',t); +t = toc; fprintf('...done (%5.2f sec).\n\n',t); % Everything OK % ------------- diff --git a/tsg_io/writeTSGDataNetCDF.m b/tsg_io/writeTSGDataNetCDF.m index 65607ff2c4431cdfa06ad857b6cc61fa31770633..4d048e4b97762c534707fce548ff2b022b41b6d1 100644 --- a/tsg_io/writeTSGDataNetCDF.m +++ b/tsg_io/writeTSGDataNetCDF.m @@ -54,7 +54,7 @@ nca_keys = keys(nca); % Get GF3 variables list codes from class tsg_nc with file 'tsg_ncvar.csv' % ----------------------------------------------------------------------- -ncv = tsg_nc('tsg_test.csv'); +ncv = tsg_nc('tsg_ncvar.csv'); ncv_keys = keys(ncv); ncv_fieldNames = get_fieldnames(ncv); @@ -95,20 +95,36 @@ end % Create NetCDF variables and attributes % -------------------------------------- for i=1:numel(ncv_keys) - for j=1:numel(ncv_fieldNames) - variable = ncv_keys{i}; + variable = ncv_keys{i}; + dimension = get(ncv, variable, ncv_fieldNames{1}); + nctype = get(ncv, variable, ncv_fieldNames{2}); + + % define dimension, value must be a cell + % -------------------------------------- + switch nctype + case 'double' + nc{variable} = ncdouble(dimension); + case 'float' + nc{variable} = ncfloat(dimension); + case 'int' + nc{variable} = ncint(dimension); + case 'short' + nc{variable} = ncshort(dimension); + case 'byte' + nc{variable} = ncbyte(dimension); + case 'char' + nc{variable} = ncchar(dimension); + otherwise + nc{variable} = ncfloat(dimension); + end + + % jump dimension and nctype field + % ------------------------------- + for j=3:numel(ncv_fieldNames) fieldName = ncv_fieldNames{j}; value = get(ncv, variable, fieldName); - % define dimension - % ---------------- - if strcmp(fieldName,'dimension') - s = ['nc{''' variable '''} = {''' value '''}']; - eval(s); - - % define variable attributes - % -------------------------- - elseif ~isempty(value) + if ~isempty(value) if ischar(value) nc{variable}.(fieldName) = ncchar(value); else @@ -154,9 +170,9 @@ for i=1:numel(ncv_keys) % DATE as two dimension % don't work under windows % nc{variable}(:) = tsg.(variable); - if strmatch('DATE', variable) - nc{variable}(:,:) = tsg.(variable); - else + %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 @@ -165,7 +181,7 @@ for i=1:numel(ncv_keys) %nc{variable}(1:length(tsg.(variable))) = tsg.(variable); nc{variable}(:) = tsg.(variable); end - end + %end end % Close waitbar