@@ -93,7 +93,7 @@ module direct_netcdf_mod
9393 get_index_start, get_index_end , get_num_dims, &
9494 create_diagnostic_structure, &
9595 end_diagnostic_structure, &
96- has_unlimited_dim
96+ has_unlimited_dim, get_io_dim_ids
9797
9898use io_filenames_mod, only : get_restart_filename, inherit_copy_units, &
9999 stage_metadata_type, get_file_description, &
@@ -858,16 +858,17 @@ subroutine read_variables(ncfile_in, var_block, start_var, end_var, domain)
858858 counts(:) = 1
859859
860860 slice_start(:) = 1 ! default to read all dimensions start at 1
861-
862- if (has_unlimited_dim(domain)) then
861+
862+ ret = nf90_inquire(ncfile_in, unlimitedDimID= unlim_dimID)
863+ call nc_check(ret, ' read_variables: nf90_inquire' , ' unlimitedDimID' )
864+
865+ if (has_unlimited_dim(domain) .and. any (get_io_dim_ids(domain, i) == unlim_dimID )) then
863866
864867 counts(num_dims) = 1 ! one slice of unlimited dimesion
865- counts(1 :num_dims -1 ) = get_dim_lengths(domain, i) ! the state
868+ counts(1 :get_num_dims(domain, i) ) = get_dim_lengths(domain, i) ! the state
866869
867870 ! read latest time slice - hack to get started with tiegcm
868871 ! not sure if it will always be the last time slice
869- ret = nf90_inquire(ncfile_in, unlimitedDimID= unlim_dimID)
870- call nc_check(ret, ' read_variables: nf90_inquire' , ' unlimitedDimID' )
871872
872873 if (unlim_dimID /= - 1 ) then ! unlimited dimension exists
873874 ret = nf90_inquire_dimension(ncfile_in, unlim_dimID, len= slice_start(num_dims))
@@ -1588,15 +1589,17 @@ subroutine write_variables(ncid, var_block, start_var, end_var, domain, &
15881589 slice_start(:) = 1 ! default to read all dimensions starting at 1
15891590 counts(:) = 1
15901591
1591- if (has_unlimited_dim(domain)) then
1592+ ret = nf90_inquire(ncid, unlimitedDimID= unlim_dimID)
1593+ call nc_check(ret, ' read_variables: nf90_inquire' , ' unlimitedDimID' )
1594+
1595+ if (has_unlimited_dim(domain) .and. any (get_io_dim_ids(domain, i) == unlim_dimID )) then
15921596
15931597 counts(num_dims) = 1 ! one slice of unlimited dimesion
15941598 counts(1 :get_num_dims(domain, i)) = get_dim_lengths(domain, i)
15951599
15961600 ! write the latest time slice - HK hack to get started with tiegcm
15971601 ! not sure if it will always be the last time slice
1598- ret = nf90_inquire(ncid, unlimitedDimID= unlim_dimID)
1599- call nc_check(ret, ' write_variables: nf90_inquire' , ' unlimitedDimID' )
1602+
16001603 if (unlim_dimID /= - 1 ) then ! unlimited dimension exists
16011604 ret = nf90_inquire_dimension(ncid, unlim_dimID, len= slice_start(num_dims))
16021605 call nc_check(ret, ' write_variables: nf90_inquire dimension' , ' unlimitedDim length' )
0 commit comments