Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Improved handling of string dimension array. bin.nc files saved by th…
Browse files Browse the repository at this point in the history
…e xarray system will make string arrays with dimension string32. Rename those back to str in that case
  • Loading branch information
daminton committed Sep 6, 2022
1 parent 5dba7a1 commit b9a560f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/netcdf/netcdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b9a560f

Please sign in to comment.