[Dart-dev] DART/branches Revision: 12224

dart at ucar.edu dart at ucar.edu
Tue Dec 19 15:14:55 MST 2017


nancy at ucar.edu
2017-12-19 15:14:55 -0700 (Tue, 19 Dec 2017)
800
the NAG compiler pointed out that if you don't call
initialize_utilities() before calling register_module()
you get a recursive call to the init routine.  i changed
the code so anything used BY the init routine cannot be
called first - thus avoiding recursion.  i also removed
some unused code, changed some of the error handling so
it's clearer when you're writing an error message directly
to the stdout and when you're writing to a log file.

the netcdf_utilities_mod has changes that try to cache
the last N filenames, and match up the ncid values to the
name so the caller doesn't have to keep passing in the
filename just for error conditions.  if this works, this
should be migrated to the rma_trunk as well.

renamed a bunch of the interfaces to try to be more
helpful to a non-netcdf user.




Modified: DART/branches/recam/assimilation_code/modules/utilities/netcdf_utilities_mod.f90
===================================================================
--- DART/branches/recam/assimilation_code/modules/utilities/netcdf_utilities_mod.f90	2017-12-19 22:11:59 UTC (rev 12223)
+++ DART/branches/recam/assimilation_code/modules/utilities/netcdf_utilities_mod.f90	2017-12-19 22:14:55 UTC (rev 12224)
@@ -46,12 +46,13 @@
           nc_add_global_creation_time,    &
           nc_get_variable_num_dimensions, &
           nc_get_variable_size,           &
-          nc_open_readonly,               &
-          nc_open_readwrite,              &
-          nc_close,                       &
-          nc_redef,                       &
-          nc_enddef,                      &
-          nc_sync
+          nc_open_file_readonly,          &
+          nc_open_file_readwrite,         &
+          nc_create_file,                 &
+          nc_close_file,                  &
+          nc_begin_define_mode,           &
+          nc_end_define_mode,             &
+          nc_synchronize_file
 
 
 interface nc_add_global_attribute
@@ -122,6 +123,29 @@
 
 character(len=512) :: msgstring1, msgstring2, msgstring3
 
+!> make a derived type that is (ncid, filename) 
+!> store filename on file open, delete it on file close. cache the
+!> last N filenames - look them up on error and stop
+!> having to keep the filename around.
+
+!> NOTE!!
+!> this assumes that you are doing the open/read/write/close
+!> operations on the same task.  which i believe is true for all
+!> our current code.
+
+integer, parameter :: MAX_NCFILES = 10
+integer, parameter :: FH_EMPTY = -1
+
+type ncinfo_type
+  integer :: file_handle = FH_EMPTY
+  character(len=256) :: file_name = ''
+end type
+
+! for now hardcode max size.  could make it allocatable
+! and extend it if you need more open slots
+
+type(ncinfo_type) :: ncinfo(MAX_NCFILES)
+
 ! do we need one of these?
 !namelist /netcdf_utilities_nml/ 
 
@@ -131,7 +155,7 @@
 !> check return code from previous call. on error, print and stop.
 !> if you want to continue after an error don't use this call. 
 
-subroutine nc_check(istatus, subr_name, context, context2, filename)
+subroutine nc_check(istatus, subr_name, context, context2, filename, ncid)
 
 integer,          intent(in)           :: istatus
 character(len=*), intent(in)           :: subr_name
@@ -138,7 +162,9 @@
 character(len=*), intent(in), optional :: context
 character(len=*), intent(in), optional :: context2
 character(len=*), intent(in), optional :: filename
+integer,          intent(in), optional :: ncid
   
+character(len=256) :: saved_filename
 
 if (istatus == nf90_noerr) return
 
@@ -150,9 +176,17 @@
   msgstring1 = trim(context) // ': ' // trim(msgstring1)
 endif
 
+! you can give this routine a file handle and it will try
+! to extract the filename from it.
+if (.not. present(filename) .and. present(ncid)) then
+   call find_name_from_fh(ncid, saved_filename)
+else
+   saved_filename = filename
+endif
+
 ! this does not return 
 call error_handler(E_ERR, subr_name, msgstring1, source, revision, revdate, &
-                   text2=context2, text3=filename)
+                   text2=context2, text3=saved_filename)
   
 
 end subroutine nc_check
@@ -173,7 +207,7 @@
 integer :: ret
 
 ret = nf90_put_att(ncid, NF90_GLOBAL, attname, val)
-call nc_check(ret, routine, 'adding the global attribute: '//trim(attname), context, filename)
+call nc_check(ret, routine, 'adding the global attribute: '//trim(attname), context, filename, ncid)
 
 end subroutine nc_add_global_char_att
 


More information about the Dart-dev mailing list