[Dart-dev] DART/branches Revision: 12079

dart at ucar.edu dart at ucar.edu
Thu Nov 9 11:54:24 MST 2017


hendric at ucar.edu
2017-11-09 11:54:24 -0700 (Thu, 09 Nov 2017)
50
using all nc calls from netcdf_utilities_mod.f90




Modified: DART/branches/recam/models/cam-fv/model_mod.f90
===================================================================
--- DART/branches/recam/models/cam-fv/model_mod.f90	2017-11-09 18:48:44 UTC (rev 12078)
+++ DART/branches/recam/models/cam-fv/model_mod.f90	2017-11-09 18:54:24 UTC (rev 12079)
@@ -25,11 +25,14 @@
 use  ensemble_manager_mod
 use distributed_state_mod
 use   state_structure_mod
-use  netcdf_utilities_mod,  only : nc_check, nc_get_variable, nc_get_variable_size, &
-                                   nc_add_attribute_to_variable, nc_define_real_variable, &
-                                   nc_add_global_creation_time, nc_add_global_attribute, &
-                                   nc_define_dimension, nc_put_variable, nc_sync, nc_enddef, &
-                                   nc_redef
+use  netcdf_utilities_mod,  only : nc_get_variable, nc_get_variable_size, &
+                                   nc_add_attribute_to_variable, &
+                                   nc_define_real_variable, &
+                                   nc_add_global_creation_time, &
+                                   nc_add_global_attribute, &
+                                   nc_define_dimension, nc_put_variable, &
+                                   nc_sync, nc_enddef, nc_redef, nc_open, &
+                                   nc_close, nc_variable_exists
 use       location_io_mod
 use        quad_utils_mod
 use     default_model_mod,  only : adv_1step, init_time, init_conditions, &
@@ -1224,27 +1227,40 @@
 integer,         intent(in) :: ncid
 type(time_type), intent(in) :: model_time
 
-integer :: year, month, day, hour, minute, second
+integer :: iyear, imonth, iday, ihour, iminute, isecond
 integer :: cam_date, cam_tod
+integer :: ios, VarID
 
+character(len=*), parameter :: routine = 'write_model_time'
+
 if ( .not. module_initialized ) call static_init_model
 
-call get_date(model_time, year, month, day, hour, minute, second)
+call get_date(model_time, iyear, imonth, iday, ihour, iminute, isecond)
 
-cam_date = year*10000 + month*100 + day
-cam_tod  = hour*3600  + minute*60 + second
+cam_date = iyear*10000 + imonth*100 + iday
+cam_tod  = ihour*3600  + iminute*60 + isecond
 
-! begin define mode
-call nc_check(nf90_Redef(ncid),"redef")
+! if the file doesn't already have a "date" variable, so we make one
+if (.not. nc_variable_exists(ncid, "date")) then
+   call error_handler(E_MSG, routine,'"date" variable not found in file ', &
+                      source, revision, revdate, text2='creating one')
 
-call nc_check( nf90_put_att(ncid, NF90_GLOBAL, 'date', cam_date), &
-                       'write_model_time', 'put_att date')
+   call nc_redef(ncid)
+   call nc_put_variable(ncid, 'date', cam_date, routine)
+   call nc_enddef(ncid)
+endif
 
-call nc_check( nf90_put_att(ncid, NF90_GLOBAL, 'datesec', cam_tod), &
-                       'write_model_time', 'put_att datesec')
+! if the file doesn't already have a "datesec" variable, so we make one
+if (.not. nc_variable_exists(ncid, "datesec")) then
 
-call nc_check( nf90_Enddef(ncid),"write_model_time", "Enddef" )
+   call error_handler(E_MSG, routine,'"datesec" variable not found in file ', &
+                      source, revision, revdate, text2='creating one')
 
+   call nc_redef(ncid)
+   call nc_put_variable(ncid, 'datesec', cam_tod,  routine)
+   call nc_enddef(ncid)
+endif
+
 end subroutine write_model_time
 
 !--------------------------------------------------------------------
@@ -1261,18 +1277,19 @@
 
 integer :: ncid
 integer :: timesize
-integer :: datefull, datesec
+integer :: cam_date, cam_tod
 integer :: iyear, imonth, iday, ihour, imin, isec, rem
 
+character(len=*), parameter :: routine = 'read_model_time'
+
 if ( .not. module_initialized ) call static_init_model
 
 if ( .not. file_exist(filename) ) then
    write(string1,*) trim(filename), ' does not exist.'
-   call error_handler(E_ERR,'read_model_time',string1,source,revision,revdate)
+   call error_handler(E_ERR,routine,string1,source,revision,revdate)
 endif
 
-call nc_check( nf90_open(trim(filename), NF90_NOWRITE, ncid), &
-                  'read_model_time', 'open '//trim(filename))
+ncid = nc_open_readonly(filename, routine)
 
 ! CAM initial files have two variables of length 
 ! 'time' (the unlimited dimension): date, datesec
@@ -1286,18 +1303,17 @@


More information about the Dart-dev mailing list