[Dart-dev] DART/branches Revision: 11023

dart at ucar.edu dart at ucar.edu
Tue Feb 7 13:24:58 MST 2017


thoar at ucar.edu
2017-02-07 13:24:57 -0700 (Tue, 07 Feb 2017)
171
Partway to flexible support for time variables with calendars that may
differ from the calendar being used in DART.
Currently only works when calendars are 'no calendar'




Modified: DART/branches/rma_single_file/io/dart_time_io_mod.f90
===================================================================
--- DART/branches/rma_single_file/io/dart_time_io_mod.f90	2017-02-07 20:21:01 UTC (rev 11022)
+++ DART/branches/rma_single_file/io/dart_time_io_mod.f90	2017-02-07 20:24:57 UTC (rev 11023)
@@ -12,10 +12,12 @@
 !>@todo should this go in state_vector_io_mod or io_filename_mod?
 !> @{
 
-use types_mod,        only : r8, i8
-use time_manager_mod, only : time_type, set_time, get_time, print_time
-use utilities_mod,    only : nc_check
+use types_mod,        only : r8, digits12
+use time_manager_mod, only : time_type, set_time, get_time, print_time, &
+                             set_calendar_type, set_date
 
+use utilities_mod,    only : nc_check, E_MSG, E_ERR, error_handler
+
 use typeSizes
 use netcdf
 
@@ -24,47 +26,127 @@
 
 public :: read_model_time, write_model_time
 
+! version controlled file description for error handling, do not edit
+character(len=256), parameter :: source   = &
+   "$URL$"
+character(len=32 ), parameter :: revision = "$Revision$"
+character(len=128), parameter :: revdate  = "$Date$"
+
+character(len=512) :: string1, string2, string3
+
 contains
 
 
 !--------------------------------------------------------------------
-!> read the dart time from the input file
+!> Make a stab at reading the time from the input file
 
 
 function read_model_time(filename)
 
 character(len=*), intent(in) :: filename
-type(time_type) :: read_model_time
+type(time_type)              :: read_model_time
 
-integer :: ncid, ntimes, TimeVarID, TimeDimID
-integer :: seconds, days
-real(r8), allocatable :: model_time(:)
+integer :: ncid, ios, numdims, xtype, VarID, TimeDimID
+integer :: ntimes, seconds, days
+integer :: year, month, day, hour, minute, second
+type(time_type) :: base_time
 
-! open netcdf file
+real(digits12), allocatable :: model_time(:)
+
+integer, dimension(NF90_MAX_VAR_DIMS) :: dimIDs
+character(len=NF90_MAX_NAME)          :: varname,dimname
+character(len=256) :: calendar
+character(len=256) :: unitstring
+
 call nc_check( nf90_open(filename, NF90_NOWRITE, ncid), &
                'read_model_time',  'opening : "'//trim(filename)//'"')
 
+ios = nf90_inq_varid(ncid, "time", VarID)
+if (ios /= NF90_NOERR) then
+   write(string1,*)'Expecting to be able to read the model time from a "time" variable'
+   write(string2,*)'in "'//trim(filename)//'"'
+   write(string3,*)'You may need to supply a model-specific "read_model_time()" to read the time.'
+   call error_handler(E_ERR,'read_model_time', string1, &
+              source, revision, revdate, text2=string2, text3=string3)
+endif
 
-! grab time from file
-call nc_check( nf90_inq_varid(ncid, "time", TimeVarID), &
-               'read_model_time', 'inq_varid time' )
+ios = nf90_inquire_variable(ncid, VarID, xtype=xtype, dimids=dimIDs, ndims=numdims)
+call nc_check(ios, 'read_model_time', 'inquire_variable "time" from "'//trim(filename)//'"')
 
-call nc_check(nf90_inq_dimid(ncid, "time", TimeDimID), &
-               'read_model_time', 'inq_varid time "'//trim(filename)//'"')
+if (numdims > 1) then
+   write(string1,*)'Expecting the "time" variable to be a single dimension.'
+   write(string2,*)'in "'//trim(filename)//'"'
+   write(string3,*)'You may need to supply a model-specific "read_model_time()" to read the time.'
+   call error_handler(E_ERR,'read_model_time', string1, &
+              source, revision, revdate, text2=string2, text3=string3)
+endif
 
-call nc_check( nf90_inquire_dimension(ncid, TimeDimID, len=ntimes), &
-               'read_model_time', 'inq_variable ntimes' )
+! Since the time variable is known to have only 1 dimension, we know TimeDimID is the first one.
+TimeDimID = dimids(1)
 
+ios = nf90_inquire_dimension(ncid, TimeDimID, len=ntimes)
+call nc_check(ios, 'read_model_time', 'inquire_dimension for ntimes "'//trim(filename) )
+
 allocate( model_time(ntimes) )
-call nc_check( nf90_get_var(ncid, TimeVarID, model_time), &
-               'read_model_time','get_var time' )


More information about the Dart-dev mailing list