[Dart-dev] DART/branches Revision: 11335

dart at ucar.edu dart at ucar.edu
Wed Mar 15 12:30:07 MDT 2017


thoar at ucar.edu
2017-03-15 12:30:06 -0600 (Wed, 15 Mar 2017)
230
Adding support for time variables that do not have a 'units'
attribute. Ensuring the suggested startup.m adds the right
directories if Matlab is invoked from within the DART_LAB/matlab
directory or any of the models directories.




Modified: DART/branches/rma_trunk/diagnostics/matlab/private/CheckModel.m
===================================================================
--- DART/branches/rma_trunk/diagnostics/matlab/private/CheckModel.m	2017-03-15 17:41:49 UTC (rev 11334)
+++ DART/branches/rma_trunk/diagnostics/matlab/private/CheckModel.m	2017-03-15 18:30:06 UTC (rev 11335)
@@ -19,19 +19,9 @@
 model      = ncreadatt(fname,'/','model');
 num_copies = dim_length(fname,'member'); % determine # of ensemble members
 [ens_size, ens_indices] = get_ensemble_indices(fname);
-times      = ncread(fname,'time');
-timeunits  = ncreadatt(fname,'time','units');
-timebase   = sscanf(timeunits,'%*s%*s%d%*c%d%*c%d'); % YYYY MM DD
-if (timebase(1) > 0000) 
-   timeorigin = datenum(timebase(1),timebase(2),timebase(3));
-else
-   timeorigin = 0;
-end
-dates      = times + timeorigin;
+dates      = nc_read_time(fname,'time');
 num_times  = length(dates);
 
-clear times timeunits timebase timeorigin
-
 if (isempty(model))
    error('%s has no ''model'' global attribute.',fname)
 end

Modified: DART/branches/rma_trunk/diagnostics/matlab/private/CheckModelCompatibility.m
===================================================================
--- DART/branches/rma_trunk/diagnostics/matlab/private/CheckModelCompatibility.m	2017-03-15 17:41:49 UTC (rev 11334)
+++ DART/branches/rma_trunk/diagnostics/matlab/private/CheckModelCompatibility.m	2017-03-15 18:30:06 UTC (rev 11335)
@@ -39,15 +39,7 @@
 
 tvars       = get_DARTvars(file1);
 tnum_times  = dim_length(file1,'time');
-times       = ncread( file1,'time');
-timeunits   = ncreadatt( file1,'time','units');
-timebase    = sscanf(timeunits,'%*s%*s%d%*c%d%*c%d'); % YYYY MM DD
-if (timebase(1) > 0000) 
-   timeorigin = datenum(timebase(1),timebase(2),timebase(3));
-else
-   timeorigin = 0;
-end
-ttimes      = times + timeorigin;
+ttimes      = nc_read_time(file1,'time');
 
 [tnum_vars,~] = ModelDimension(file1,tmodel);
 if ( tnum_vars <= 0 )
@@ -59,15 +51,7 @@
 
 dvars       = get_DARTvars(file2);
 dnum_times  = dim_length(file2,'time');
-times       = ncread( file2,'time');
-timeunits   = ncreadatt( file2,'time','units');
-timebase    = sscanf(timeunits,'%*s%*s%d%*c%d%*c%d'); % YYYY MM DD
-if (timebase(1) > 0000) 
-   timeorigin = datenum(timebase(1),timebase(2),timebase(3));
-else
-   timeorigin = 0;
-end
-dtimes      = times + timeorigin;
+dtimes      = nc_read_time(file2,'time');
 
 [dnum_vars,~] = ModelDimension(file2,dmodel);
 if ( dnum_vars <= 0 )

Added: DART/branches/rma_trunk/diagnostics/matlab/private/nc_read_time.m
===================================================================
--- DART/branches/rma_trunk/diagnostics/matlab/private/nc_read_time.m	                        (rev 0)
+++ DART/branches/rma_trunk/diagnostics/matlab/private/nc_read_time.m	2017-03-15 18:30:06 UTC (rev 11335)
@@ -0,0 +1,30 @@
+function dates = nc_read_time(fname,varid)
+%% Attempts to interpret the time variable based on any existing 'units'
+%  attribute. At present, the calendar is ignored.
+%  Returns the time compatible with matlab's 'datenum' base.
+%
+% cdate = nc_read_time('example.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
+% http://www.image.ucar.edu/DAReS/DART/DART_download
+%
+% DART $Id$
+
+dates = [];
+timeorigin = 0;
+
+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)
+        timeorigin = datenum(timebase(1),timebase(2),timebase(3));
+    end
+end
+dates      = times + timeorigin;
+
+% <next few lines under version control, do not edit>
+% $URL$
+% $Revision$
+% $Date$


More information about the Dart-dev mailing list