Skip to content

Commit

Permalink
Merge pull request #403 from NCAR/bug-fix_read_state
Browse files Browse the repository at this point in the history
bug-fix: add a check for unlimited dimension in read_variables
  • Loading branch information
hkershaw-brown authored Oct 13, 2022
2 parents 27f57a1 + 8a51181 commit ba00b2c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ individual files.

The changes are now listed with the most recent at the top.

**October 13 2022 :: Bug-fix for read variables. Tag v10.5.3**

- Per-file check for unlimited dimension before variable read. Netcdf
dimension counts adjusted accordingly. Fixes problems when reading from
DART created netcdf files, for example, from fill_inflation_restart
- Bug-fix for verbose printing of state_structure info

**October 10 2022 :: Bug-fix for obs_converter builds. Tag v10.5.2**

- Bug fix for converter builds using the template model_mod.f90
Expand Down
21 changes: 15 additions & 6 deletions assimilation_code/modules/io/direct_netcdf_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -855,24 +855,31 @@ subroutine read_variables(ncfile_in, var_block, start_var, end_var, domain)
num_dims = get_io_num_dims(domain, i)
allocate(counts(num_dims))
allocate(slice_start(num_dims))
counts(:) = 1

slice_start(:) = 1 ! default to read all dimensions start at 1

if (has_unlimited_dim(domain)) then

slice_start(:) = 1 ! default to read all dimensions start at 1
counts(num_dims) = 1 ! one slice of unlimited dimesion
counts(1:num_dims-1) = get_dim_lengths(domain, i) ! the state

! read latest time slice - hack to get started with tiegcm
! not sure if it will always be the last time slice
ret = nf90_inquire(ncfile_in, unlimitedDimID=unlim_dimID)
call nc_check(ret, 'read_variables: nf90_inquire', 'unlimitedDimID')
ret = nf90_inquire_dimension(ncfile_in, unlim_dimID, len=slice_start(num_dims))
call nc_check(ret, 'read_variables: nf90_inquiredimension', 'unlimitedDim length')

if (unlim_dimID /= -1) then ! unlimited dimension exists
ret = nf90_inquire_dimension(ncfile_in, unlim_dimID, len=slice_start(num_dims))
call nc_check(ret, 'read_variables: nf90_inquire_dimension', 'unlimitedDim length')
if (slice_start(num_dims) == 0) slice_start(num_dims) = 1 ! newly created file
else ! file does not have an unlimited dimension because it was created by DART
slice_start(num_dims) = 1
endif

else

slice_start(:) = 1 ! default to read all dimensions start at 1
counts(:) = get_dim_lengths(domain, i) ! the state
counts(1:get_num_dims(domain,i)) = get_dim_lengths(domain, i) ! the state
endif

ret = nf90_inq_varid(ncfile_in, get_variable_name(domain, i), var_id)
Expand Down Expand Up @@ -1579,6 +1586,7 @@ subroutine write_variables(ncid, var_block, start_var, end_var, domain, &
allocate(counts(num_dims))
allocate(slice_start(num_dims))
slice_start(:) = 1 ! default to read all dimensions starting at 1
counts(:) = 1

if (has_unlimited_dim(domain)) then

Expand All @@ -1599,9 +1607,10 @@ subroutine write_variables(ncid, var_block, start_var, end_var, domain, &

else

counts(:) = get_dim_lengths(domain, i)
counts(1:get_num_dims(domain, i)) = get_dim_lengths(domain, i)
endif


!>@todo FIXME, the first variable in the second domain is not found when using coamps_nest.
ret = nf90_inq_varid(ncid, trim(get_variable_name(domain, i)), var_id)
call nc_check(ret, 'write_variables:', 'nf90_inq_varid "'//trim(get_variable_name(domain,i))//'"')
Expand Down
3 changes: 2 additions & 1 deletion assimilation_code/modules/io/state_structure_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,7 @@ subroutine state_structure_info(dom_id)

200 format(4x,i2,', length = ',I8,', name = "',A,'"')
201 format(4x,i2,': ',2x,' length = ',I8,', name = "',A,'"')
202 format(4x,i2,': ',2x,' ID = ',I8,', length = ',I8,', name = "',A,'"')

! report on each variable in this domain

Expand Down Expand Up @@ -1848,7 +1849,7 @@ subroutine state_structure_info(dom_id)
array_lengths(1:num_dims) = get_io_dim_lengths(dom_id,ivar)
do jdim = 1, num_dims
dim_name = get_dim_name(dom_id, ivar, jdim)
write(*,200) jdim, array_ids(jdim), array_lengths(jdim), trim(dim_name)
write(*,202) jdim, array_ids(jdim), array_lengths(jdim), trim(dim_name)
enddo

if ( state%domain(dom_id)%info_file /= 'NULL' ) then
Expand Down
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
author = 'Data Assimilation Research Section'

# The full version, including alpha/beta/rc tags
release = '10.5.2'
release = '10.5.3'
master_doc = 'README'

# -- General configuration ---------------------------------------------------
Expand Down

0 comments on commit ba00b2c

Please sign in to comment.