[Dart-dev] DART/branches Revision: 12266

dart at ucar.edu dart at ucar.edu
Wed Jan 3 15:22:56 MST 2018


nancy at ucar.edu
2018-01-03 15:22:55 -0700 (Wed, 03 Jan 2018)
208
commit this version of the POP nc_write_model_atts()
so it can't be held hostage on cheyenne again.
this is to my development branch but after testing
and code review i think it could go onto the rma_trunk.




Modified: DART/branches/rma_updates_nancy/models/POP/model_mod.f90
===================================================================
--- DART/branches/rma_updates_nancy/models/POP/model_mod.f90	2018-01-03 21:30:00 UTC (rev 12265)
+++ DART/branches/rma_updates_nancy/models/POP/model_mod.f90	2018-01-03 22:22:55 UTC (rev 12266)
@@ -25,8 +25,12 @@
                              do_output, to_upper,                              &
                              find_namelist_in_file, check_namelist_read,       &
                              file_exist, find_textfile_dims, file_to_text
-use netcdf_utilities_mod, only : nc_add_global_attribute, nc_check, nc_sync, &
-                                 nc_add_global_creation_time, nc_redef, nc_enddef
+use netcdf_utilities_mod, only : nc_add_global_attribute, nc_check, nc_sync,        &
+                                 nc_add_global_creation_time, nc_redef, nc_enddef,  &
+                                 nc_add_attribute_to_variable, nc_define_dimension, & 
+                                 nc_define_real_variable, nc_define_integer_variable,   &
+                                 nc_put_variable
+
 use     obs_kind_mod, only : QTY_TEMPERATURE, QTY_SALINITY, QTY_DRY_LAND,      &
                              QTY_U_CURRENT_COMPONENT,QTY_V_CURRENT_COMPONENT,  &
                              QTY_SEA_SURFACE_HEIGHT, QTY_SEA_SURFACE_PRESSURE, &
@@ -1887,20 +1891,11 @@
 ! local variables 
 !----------------------------------------------------------------------
 
+character(len=*), parameter :: routine = 'nc_write_model_atts'
 integer     :: i
-character(len=256) :: filename
 
 if ( .not. module_initialized ) call static_init_model
 
-!--------------------------------------------------------------------
-! we only have a netcdf handle here so we do not know the filename
-! or the fortran unit number.  but construct a string with at least
-! the netcdf handle, so in case of error we can trace back to see
-! which netcdf file is involved.
-!--------------------------------------------------------------------
-
-write(filename,*) 'ncid', ncid
-
 !-------------------------------------------------------------------------------
 ! Write Global Attributes 
 !-------------------------------------------------------------------------------
@@ -1921,12 +1916,9 @@
 ! Define the new dimensions IDs
 !----------------------------------------------------------------------------
 
-call nc_check(nf90_def_dim(ncid, name='i', &
-       len = Nx, dimid = NlonDimID),'nc_write_model_atts', 'i def_dim '//trim(filename))
-call nc_check(nf90_def_dim(ncid, name='j', &
-       len = Ny, dimid = NlatDimID),'nc_write_model_atts', 'j def_dim '//trim(filename))
-call nc_check(nf90_def_dim(ncid, name='k', &
-       len = Nz, dimid =   NzDimID),'nc_write_model_atts', 'k def_dim '//trim(filename))
+call nc_define_dimension(ncid, 'i', Nx, routine)   ! Nlon
+call nc_define_dimension(ncid, 'j', Ny, routine)   ! Nlat
+call nc_define_dimension(ncid, 'k', Nz, routine)   ! Ndepth
 
 !----------------------------------------------------------------------------
 ! Create the Coordinate Variables and the Attributes
@@ -1934,115 +1926,75 @@
 !----------------------------------------------------------------------------
 
 ! U,V Grid Longitudes
-call nc_check(nf90_def_var(ncid,name='ULON', xtype=nf90_real, &
-              dimids=(/ NlonDimID, NlatDimID /), varid=ulonVarID),&
-              'nc_write_model_atts', 'ULON def_var '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulonVarID, 'long_name', 'longitudes of U,V grid'), &
-              'nc_write_model_atts', 'ULON long_name '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulonVarID, 'cartesian_axis', 'X'),  &
-              'nc_write_model_atts', 'ULON cartesian_axis '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulonVarID, 'units', 'degrees_east'), &
-              'nc_write_model_atts', 'ULON units '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulonVarID, 'valid_range', (/ 0.0_r8, 360.0_r8 /)), &
-              'nc_write_model_atts', 'ULON valid_range '//trim(filename))
+call nc_define_real_variable(ncid, 'ULON', (/ 'i', 'j' /), routine)
 
+call nc_add_attribute_to_variable(ncid, 'ULON', 'long_name', 'longitudes of U,V grid', routine)
+call nc_add_attribute_to_variable(ncid, 'ULON', 'cartesian_axis', 'X', routine)
+call nc_add_attribute_to_variable(ncid, 'ULON', 'units', 'degrees_east', routine)
+call nc_add_attribute_to_variable(ncid, 'ULON', 'valid_range', (/ 0.0_r8, 360.0_r8 /), routine)
+
 ! U,V Grid Latitudes
-call nc_check(nf90_def_var(ncid,name='ULAT', xtype=nf90_real, &
-              dimids=(/ NlonDimID, NlatDimID /), varid=ulatVarID),&
-              'nc_write_model_atts', 'ULAT def_var '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulatVarID, 'long_name', 'latitudes of U,V grid'), &
-              'nc_write_model_atts', 'ULAT long_name '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulatVarID, 'cartesian_axis', 'Y'),   &
-              'nc_write_model_atts', 'ULAT cartesian_axis '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulatVarID, 'units', 'degrees_north'),  &
-              'nc_write_model_atts', 'ULAT units '//trim(filename))
-call nc_check(nf90_put_att(ncid,  ulatVarID,'valid_range',(/ -90.0_r8, 90.0_r8 /)), &
-              'nc_write_model_atts', 'ULAT valid_range '//trim(filename))
+call nc_define_real_variable(ncid, 'ULAT', (/ 'i', 'j' /), routine)
 
+call nc_add_attribute_to_variable(ncid, 'ULAT', 'long_name', 'latitudes of U,V grid', routine)
+call nc_add_attribute_to_variable(ncid, 'ULAT', 'cartesian_axis', 'Y', routine)
+call nc_add_attribute_to_variable(ncid, 'ULAT', 'units', 'degrees_north', routine)
+call nc_add_attribute_to_variable(ncid, 'ULAT', 'valid_range', (/ -90.0_r8, 90.0_r8 /), routine)
 
 ! S,T,PSURF Grid Longitudes
-call nc_check(nf90_def_var(ncid,name='TLON', xtype=nf90_real, &
-              dimids=(/ NlonDimID, NlatDimID /), varid=tlonVarID),&


More information about the Dart-dev mailing list