From b9a560fe51256cba0251cfb233848b88a7d8faef Mon Sep 17 00:00:00 2001 From: David A Minton Date: Tue, 6 Sep 2022 16:55:53 -0400 Subject: [PATCH] Improved handling of string dimension array. bin.nc files saved by the xarray system will make string arrays with dimension string32. Rename those back to str in that case --- src/netcdf/netcdf.f90 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 56e20a018..6e102d969 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -382,6 +382,7 @@ module subroutine netcdf_open(self, param, readonly) logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only ! Internals integer(I4B) :: mode + character(len=NF90_MAX_NAME) :: str_dim_name mode = NF90_WRITE if (present(readonly)) then @@ -392,7 +393,9 @@ module subroutine netcdf_open(self, param, readonly) call check( nf90_inq_dimid(self%ncid, TIME_DIMNAME, self%time_dimid) ) call check( nf90_inq_dimid(self%ncid, ID_DIMNAME, self%id_dimid) ) - call check( nf90_inq_dimid(self%ncid, STR_DIMNAME, self%str_dimid) ) + call check( nf90_inquire_dimension(self%ncid, max(self%time_dimid,self%id_dimid)+1, name=str_dim_name) ) + call check( nf90_inq_dimid(self%ncid, str_dim_name, self%str_dimid) ) + if (str_dim_name /= "str") call check( nf90_rename_dim(self%ncid, str_dim_name, STR_DIMNAME) ) call check( nf90_inq_varid(self%ncid, TIME_DIMNAME, self%time_varid)) call check( nf90_inq_varid(self%ncid, ID_DIMNAME, self%id_varid)) @@ -496,7 +499,7 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) ! Return integer(I4B) :: ierr !! Error code: returns 0 if the read is successful ! Internals - integer(I4B) :: dim, i, j, tslot, idmax, npl_check, ntp_check + integer(I4B) :: dim, i, j, tslot, idmax, npl_check, ntp_check, t_max, str_max real(DP), dimension(:), allocatable :: rtemp integer(I4B), dimension(:), allocatable :: itemp logical, dimension(:), allocatable :: validmask, tpmask, plmask @@ -517,6 +520,8 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) allocate(validmask(idmax)) allocate(tpmask(idmax)) allocate(plmask(idmax)) + call check( nf90_inquire_dimension(iu%ncid, iu%time_dimid, len=t_max) ) + call check( nf90_inquire_dimension(iu%ncid, iu%str_dimid, len=str_max) ) ! First filter out only the id slots that contain valid bodies if (param%in_form == XV) then