[Dart-dev] DART/branches Revision: 11508
dart at ucar.edu
dart at ucar.edu
Tue Apr 18 20:55:40 MDT 2017
thoar at ucar.edu
2017-04-18 20:55:39 -0600 (Tue, 18 Apr 2017)
337
This will read time variables with units of 'days',
'days since YYYY-MM-DD HH:MM:SS' and
'seconds since YYYY-MM-DD HH:MM:SS'
and convert them to the matlab 'datenum' format.
To view the date as a date ... use datestr() on the result.
The low-order models simply use units of 'days' with no
reference year - necessitating the change.
Modified: DART/branches/rma_output_files/diagnostics/matlab/private/nc_read_time.m
===================================================================
--- DART/branches/rma_output_files/diagnostics/matlab/private/nc_read_time.m 2017-04-18 23:53:31 UTC (rev 11507)
+++ DART/branches/rma_output_files/diagnostics/matlab/private/nc_read_time.m 2017-04-19 02:55:39 UTC (rev 11508)
@@ -3,7 +3,7 @@
% attribute. At present, the calendar is ignored.
% Returns the time compatible with matlab's 'datenum' base.
%
-% cdate = nc_read_time('example.nc','time');
+% cdate = nc_read_time('true_state.nc','time');
%% DART software - Copyright UCAR. This open source software is provided
% by UCAR, "as is", without charge, subject to all terms of use at
@@ -11,18 +11,23 @@
%
% DART $Id$
-dates = [];
-timeorigin = 0;
-
+dates = [];
times = ncread(fname,varid);
timeunits = nc_read_att(fname,varid,'units');
+
if (~ isempty(timeunits))
- timebase = sscanf(timeunits,'%*s%*s%d%*c%d%*c%d'); % YYYY MM DD
- if (timebase(1) > 0000)
+ if strcmp(timeunits,'days')
+ dates = times;
+ elseif strncmp(timeunits,'days since',numel('days since'))
+ timebase = sscanf(timeunits,'%*s%*s%d%*c%d%*c%d'); % YYYY MM DD
timeorigin = datenum(timebase(1),timebase(2),timebase(3));
+ dates = times + timeorigin;
+ elseif strncmp(timeunits,'seconds since',numel('seconds since'))
+ timebase = sscanf(timeunits,'%*s%*s%d%*c%d%*c%d'); % YYYY MM DD
+ timeorigin = datenum(timebase(1),timebase(2),timebase(3));
+ dates = times ./ 86400.0 + timeorigin;
end
end
-dates = times + timeorigin;
% <next few lines under version control, do not edit>
% $URL$
More information about the Dart-dev
mailing list