Skip to content

Commit 9553f0e

Browse files
committed
Cleanup debug output and modify start/count element range checks.
1 parent 6540394 commit 9553f0e

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/physics/utils/pio_reader.F90

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ subroutine get_netcdf_var_int_1d(this, varname, var, errmsg, errcode, start, cou
326326
if (do_subset) then
327327
!If subsetting is requested, then read only the specified
328328
!subset of the variable:
329-
write(*,*) 'var size:', size(var), alloc_dims(:)
330-
write(*,*) 'start/count:', start(:), count(:)
331329
errcode = pio_get_var(pio_file_handle, var_id, start, count, var(:))
332330
else
333331
!Otherwise, read the entire variable:
@@ -2258,12 +2256,12 @@ subroutine var_subset_check(varname, var_ndims, dim_sizes, do_subset, alloc_dims
22582256

22592257
!Check that start indices are within bounds:
22602258
do i = 1, file_var_dim_num
2261-
if ((start(i) < 0) .or. (start(i) >= dim_sizes(i))) then
2259+
if ((start(i) < 1) .or. (start(i) > dim_sizes(i))) then
22622260
errcode = bad_subset_range_err
22632261
write(errmsg, '(a,i0,3a,i0,a,i0,a)') &
22642262
"Element ", i, " of 'start' for variable '", &
2265-
trim(varname), "' is out of bounds. Expected 0 to ", &
2266-
dim_sizes(i)-1, " but got ", start(i), "."
2263+
trim(varname), "' is out of bounds. Expected 1 to ", &
2264+
dim_sizes(i), " but got ", start(i), "."
22672265
return
22682266
end if
22692267
end do
@@ -2274,20 +2272,20 @@ subroutine var_subset_check(varname, var_ndims, dim_sizes, do_subset, alloc_dims
22742272
!start + count is within bounds
22752273
!for each dimension:
22762274
do i = 1, file_var_dim_num
2277-
if (count(i) < 0) then
2275+
if ((count(i) < 1) .or. (count(i) > dim_sizes(i))) then
22782276
errcode = bad_subset_range_err
22792277
write(errmsg, '(a,i0,3a,i0,a,i0,a)') &
22802278
"Element ", i, " of 'count' for variable '", &
22812279
trim(varname), "' is out of bounds. Expected 1 to ", &
22822280
dim_sizes(i), " but got ", count(i), "."
22832281
return
2284-
else if (start(i) + count(i) > dim_sizes(i)) then
2285-
errcode = bad_subset_range_err
2286-
write(errmsg, '(a,i0,3a,i0,a,i0,a)') &
2287-
"Element ", i, " of 'start' + 'count' for variable '", &
2288-
trim(varname), "' is out of bounds. Expected 1 to ", &
2289-
dim_sizes(i), " but got ", start(i) + count(i), "."
2290-
return
2282+
! else if (start(i) + count(i) > dim_sizes(i)) then
2283+
! errcode = bad_subset_range_err
2284+
! write(errmsg, '(a,i0,3a,i0,a,i0,a)') &
2285+
! "Element ", i, " of 'start' + 'count' for variable '", &
2286+
! trim(varname), "' is out of bounds. Expected 1 to ", &
2287+
! dim_sizes(i), " but got ", start(i) + count(i), "."
2288+
! return
22912289
end if
22922290
end do
22932291

test/unit/fortran/src/pio_reader/test_pio_reader.pf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,14 +1618,14 @@ subroutine test_pio_reader_bad_count_element_range()
16181618
call reader%open_file(fname, errmsg, errcode)
16191619

16201620
! Attempt to read variable with negative start element:
1621-
call reader%get_var("pressure", pressure, errmsg, errcode, start=(/0/), count=(/-6/))
1621+
call reader%get_var("pressure", pressure, errmsg, errcode, start=(/1/), count=(/-6/))
16221622

16231623
! Check that the correct error was raised:
16241624
@assertNotEqual(0, errcode)
16251625
@assertEqual(expected_err_msg_neg, trim(errmsg))
16261626

16271627
! Next attempt to read variable with too-large start element:
1628-
call reader%get_var("pressure", pressure, errmsg, errcode, start=(/1/), count=(/59/))
1628+
call reader%get_var("pressure", pressure, errmsg, errcode, start=(/1/), count=(/60/))
16291629

16301630
! Check that the correct error was raised:
16311631
@assertNotEqual(0, errcode)

0 commit comments

Comments
 (0)