[Dart-dev] DART/branches Revision: 12477

dart at ucar.edu dart at ucar.edu
Mon Apr 2 09:21:44 MDT 2018


nancy at ucar.edu
2018-04-02 09:21:44 -0600 (Mon, 02 Apr 2018)
155
add support for creating an unlimited dim, and for
4d arrays (wrf has these although they are 3d spatial
arrays plus time where time is always length 1).




Modified: DART/branches/nsc_updates/assimilation_code/modules/utilities/netcdf_utilities_mod.f90
===================================================================
--- DART/branches/nsc_updates/assimilation_code/modules/utilities/netcdf_utilities_mod.f90	2018-04-02 15:20:25 UTC (rev 12476)
+++ DART/branches/nsc_updates/assimilation_code/modules/utilities/netcdf_utilities_mod.f90	2018-04-02 15:21:44 UTC (rev 12477)
@@ -37,6 +37,7 @@
           nc_add_attribute_to_variable,   &
           nc_get_attribute_from_variable, &
           nc_define_dimension,            &
+          nc_define_unlimited_dimension,  &
           nc_define_integer_variable,     &
           nc_define_real_variable,        &
           nc_define_double_variable,      &
@@ -115,6 +116,8 @@
    module procedure nc_put_real_2d
    module procedure nc_put_int_3d
    module procedure nc_put_real_3d
+   module procedure nc_put_int_4d
+   module procedure nc_put_real_4d
 end interface
 
 interface nc_get_variable
@@ -129,6 +132,8 @@
    module procedure nc_get_short_3d
    module procedure nc_get_int_3d
    module procedure nc_get_real_3d
+   module procedure nc_get_int_4d
+   module procedure nc_get_real_4d
 end interface
 
 interface nc_get_variable_size
@@ -603,7 +608,24 @@
 end subroutine nc_define_dimension
 
 !--------------------------------------------------------------------
+
+subroutine nc_define_unlimited_dimension(ncid, dimname, context, filename)
+
+integer,          intent(in) :: ncid
+character(len=*), intent(in) :: dimname
+character(len=*), intent(in), optional :: context
+character(len=*), intent(in), optional :: filename
+
+character(len=*), parameter :: routine = 'nc_define_unlimited_dimension'
+integer :: ret, dimid
+
+ret = nf90_def_dim(ncid, dimname, NF90_UNLIMITED, dimid)
+call nc_check(ret, routine, 'define unlimited_dimension '//trim(dimname), context, filename, ncid)
+
+end subroutine nc_define_unlimited_dimension
+
 !--------------------------------------------------------------------
+!--------------------------------------------------------------------
 ! defining variables section
 
 !> unfortunately, the scalar versions of these routines cannot be
@@ -659,36 +681,20 @@
 character(len=*), intent(in), optional :: filename
 
 character(len=*), parameter :: routine = 'nc_define_var_int_Nd'
-integer :: ret, dimid1, dimid2, dimid3, varid
+integer :: i, ret, ndims, varid, dimids(NF90_MAX_VAR_DIMS)
 
-if (size(dimnames) >= 1) then
-   ret = nf90_inq_dimid(ncid, dimnames(1), dimid1)
-   call nc_check(ret, routine, 'inquire dimension id for dim '//trim(dimnames(1)), context, filename, ncid)
-endif
-
-if (size(dimnames) >= 2) then
-   ret = nf90_inq_dimid(ncid, dimnames(2), dimid2)
-   call nc_check(ret, routine, 'inquire dimension id for dim '//trim(dimnames(2)), context, filename, ncid)
-endif
-
-if (size(dimnames) >= 3) then
-   ret = nf90_inq_dimid(ncid, dimnames(3), dimid3)
-   call nc_check(ret, routine, 'inquire dimension id for dim '//trim(dimnames(3)), context, filename, ncid)
-endif
-
-if (size(dimnames) >= 4) then
-   call error_handler(E_ERR, routine, 'only 1d, 2d and 3d integer variables supported', &
+ndims = size(dimnames)
+if (ndims > 4) then
+   call error_handler(E_ERR, routine, 'only 1d, 2d, 3d and 4d integer variables supported', &
                       source, revision, revdate, text2='variable '//trim(varname))
 endif
 
-if (size(dimnames) == 1) then
-   ret = nf90_def_var(ncid, varname, nf90_int, dimid1, varid=varid)
-else if (size(dimnames) == 2) then
-   ret = nf90_def_var(ncid, varname, nf90_int, dimids=(/ dimid1, dimid2 /), varid=varid)
-else if (size(dimnames) == 3) then
-   ret = nf90_def_var(ncid, varname, nf90_int, dimids=(/ dimid1, dimid2, dimid3 /), varid=varid)
-endif
+do i=1, ndims
+   ret = nf90_inq_dimid(ncid, dimnames(i), dimids(i))
+   call nc_check(ret, routine, 'inquire dimension id for dim '//trim(dimnames(i)), context, filename, ncid)
+enddo
 
+ret = nf90_def_var(ncid, varname, nf90_int, dimids(1:ndims), varid=varid)
 call nc_check(ret, routine, 'define integer variable '//trim(varname), context, filename, ncid)
 
 end subroutine nc_define_var_int_Nd


More information about the Dart-dev mailing list