Skip to content

Commit dc9e869

Browse files
committed
test add read variable slice test
1 parent 5aa9124 commit dc9e869

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/tests/test_io.f90

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ program test_netcdf
2626
subroutine test_real_int(path)
2727

2828
character(*), intent(in) :: path
29-
type(netcdf_file) :: ncf
29+
type(netcdf_file) :: hf
3030

3131
integer :: i1(4), ierr
32-
real(real32) :: nan, r1(4), r2(4,4)
32+
real(real32) :: nan, r1(4), r2(4,4), B(6,6)
3333
integer(int32), dimension(4,4) :: i2, i2t
3434
integer(int64), dimension(4,4) :: i2t64
3535
real(real32), allocatable :: rr2(:,:)
@@ -53,45 +53,49 @@ subroutine test_real_int(path)
5353

5454
r2 = i2
5555

56-
call ncf%initialize(path // '/io_test.nc', ierr, status='replace', action='rw', comp_lvl=1)
56+
call hf%initialize(path // '/io_test.nc', ierr, status='replace', action='rw', comp_lvl=1)
5757
if(ierr/=0) error stop 'initialize'
5858

59-
call ncf%write('nan', nan, ierr)
59+
call hf%write('nan', nan, ierr)
6060
if(ierr/=0) error stop 'write 0-D: real32 NaN'
6161

62-
call ncf%write('real32-2d', r2, ierr, ['x', 'y'])
62+
call hf%write('real32-2d', r2, ierr, ['x', 'y'])
6363
if(ierr/=0) error stop 'write 2-D: real32'
6464

65-
call ncf%write('real64-2d', real(r2, real64), ierr)
65+
call hf%write('real64-2d', real(r2, real64), ierr)
6666
if(ierr/=0) error stop 'write 2-D: real64'
6767

68-
call ncf%write('int32-2d', i2, ierr, ['x', 'y'])
68+
call hf%write('int32-2d', i2, ierr, ['x', 'y'])
6969
if(ierr/=0) error stop 'write 2-D: int32'
7070

71-
call ncf%write('int64-2d', int(i2, int64), ierr)
71+
call hf%write('int64-2d', int(i2, int64), ierr)
7272
if(ierr/=0) error stop 'write 2-D: int64'
7373

74-
call ncf%finalize(ierr)
74+
call hf%finalize(ierr)
7575
if (ierr /= 0) error stop 'write finalize'
7676

7777
!-----------------
7878

79-
call ncf%initialize(path // '/io_test.nc', ierr,status='old',action='r')
79+
call hf%initialize(path // '/io_test.nc', ierr,status='old',action='r')
8080

81-
call ncf%read('int32-2d',i2t, ierr)
81+
call hf%read('int32-2d',i2t, ierr)
8282
if (.not.all(i2==i2t)) error stop 'read 2-D: int32 does not match write'
8383

84-
call ncf%read('int64-2d',i2t64, ierr)
84+
call hf%read('int64-2d',i2t64, ierr)
8585
if (.not.all(i2==i2t64)) error stop 'read 2-D: int64 does not match write'
8686

87-
call ncf%shape('real32-2d', dimnames, dims, ierr)
87+
call hf%shape('real32-2d', dimnames, dims, ierr)
8888
allocate(rr2(dims(1), dims(2)))
89-
call ncf%read('real32-2d',rr2, ierr)
89+
call hf%read('real32-2d',rr2, ierr)
9090
if (.not.all(r2 == rr2)) error stop 'real 2-D: read does not match write'
9191

92-
call ncf%read('nan',nant, ierr)
93-
if (.not.ieee_is_nan(nant)) error stop 'failed storing or reading NaN'
94-
call ncf%finalize(ierr)
92+
! check read into a variable slice
93+
call hf%read('real32-2d', B(2:5,3:6), ierr)
94+
if(.not.all(B(2:5,3:6) == r2)) error stop 'real 2D: reading into variable slice'
95+
96+
call hf%read('nan',nant, ierr)
97+
if (.not.ieee_is_nan(nant)) error stop 'failed storing or reading NaN'
98+
call hf%finalize(ierr)
9599
if (ierr /= 0) error stop 'read finalize'
96100

97101
end subroutine test_real_int

0 commit comments

Comments
 (0)