Skip to content

Commit

Permalink
improved test
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed May 16, 2024
1 parent 57abb00 commit d4f7d80
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 52 deletions.
6 changes: 6 additions & 0 deletions tests/g2_test_util.F90
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,22 @@ subroutine g2_gbytec1(in, siout, iskip, nbits)
integer, intent(inout) :: siout
integer, intent(in) :: iskip, nbits
end subroutine g2_gbytec1
end interface
interface
subroutine g2_gbytec(in, iout, iskip, nbits)
character*1, intent(in) :: in(*)
integer, intent(inout) :: iout(*)
integer, intent(in) :: iskip, nbits
end subroutine g2_gbytec
end interface
interface
subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n)
character*1, intent(in) :: in(*)
integer, intent(out) :: iout(*)
integer, intent(in) :: iskip, nbits, nskip, n
end subroutine g2_gbytesc
end interface
interface
subroutine g2_gbytec8(in, iout, iskip, nbits)
character*1, intent(in) :: in(*)
integer (kind = 8), intent(inout) :: iout(*)
Expand Down
161 changes: 109 additions & 52 deletions tests/test_getg2i2r.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,64 @@ program test_getg2ir2
integer (kind = 8) :: msk1, msk2
integer :: mnum
integer :: nlen, nnum, nmess, iret
integer :: idxver, i
integer :: idxver, i, j

integer :: index_rec_len
integer (kind = 8) :: b2s_message, b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
integer (kind = 8) :: total_bytes
integer :: grib_version, discipline, field_number
integer :: SEC1_LEN
parameter (SEC1_LEN = 21)
integer :: GDS_LEN
parameter (GDS_LEN = 72)
integer :: PDS_LEN
parameter (PDS_LEN = 34)
integer :: DRS_LEN
parameter (DRS_LEN = 23)
integer :: BMS_LEN
parameter (BMS_LEN = 6)
integer :: lengds, lenpds, lendrs
character :: sec1(SEC1_LEN), gds(GDS_LEN), pds(PDS_LEN), drs(DRS_LEN), bms(BMS_LEN)
character :: expected_sec1(SEC1_LEN) = (/ char(0), char(0), char(0), char(21), char(1), char(0), &
char(7), char(0), char(0), char(2), char(1), &
char(1), char(7), char(229), char(11), char(30), char(0), char(0), char(0), char(0), char(1)/)
character :: expected_gds(GDS_LEN) = (/ char(0), char(0), char(0), char(72), char(3), char(0), char(0), &
char(0), char(142), char(39), char(0), char(0), char(0), char(0), char(6), char(0), char(0), &
char(0), char(0), char(0), char(0), char(0), char(0), char(0), char(0), char(0), char(0), char(0), &
char(0), char(0), char(0), char(0), char(0), char(241), char(0), char(0), char(0), char(151), &
char(0), char(0), char(0), char(0), char(0), char(0), char(0), char(0), char(2), char(250), &
char(240), char(128), char(12), char(132), char(88), char(128), char(48), char(1), char(125), &
char(120), char(64), char(14), char(230), char(178), char(128), char(0), char(2), char(139), &
char(11), char(0), char(2), char(139), char(11), char(0) /)
character :: expected_pds(PDS_LEN) = (/ char(0), char(0), char(0), char(34), char(4), char(0), char(0), &
char(0), char(0), char(2), char(1), char(2), char(0), char(11), char(0), char(0), char(0), char(1), &
char(0), char(0), char(0), char(0), char(1), char(0), char(0), char(0), char(0), char(1), char(255), &
char(0), char(0), char(0), char(0), char(0) /)
character :: expected_drs(DRS_LEN) = (/ char(0), char(0), char(0), char(23), char(5), char(0), char(0), &
char(43), char(33), char(0), char(40), char(65), char(32), char(0), char(0), char(0), char(0), char(0), &
char(2), char(11), char(0), char(0), char(255) /)
character :: expected_bms(BMS_LEN) = (/ char(0), char(0), char(17), char(203), char(6), char(0) /)

interface
subroutine read_index(cbuf, idxver, index_rec_len, b2s_message, b2s_lus, b2s_gds, b2s_pds, b2s_drs, &
b2s_bms, b2s_data, total_bytes, grib_version, discipline, field_number, sec1, lengds, gds, lenpds, pds, &
lendrs, drs, bms, iret)
character(len=1), pointer, dimension(:), intent(in) :: cbuf(:)
integer, intent(in) :: idxver
integer, intent(out) :: index_rec_len
integer (kind = 8), intent(out) :: b2s_message, b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
integer (kind = 8), intent(out) :: total_bytes
integer, intent(out) :: grib_version, discipline, field_number
character, intent(out) :: sec1(21)
integer, intent(inout) :: lengds
character, intent(out) :: gds(:)
integer, intent(inout) :: lenpds
character, intent(out) :: pds(:)
integer, intent(inout) :: lendrs
character, intent(out) :: drs(:)
character, intent(out) :: bms(:)
integer, intent(out) :: iret
end subroutine read_index
subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, nlen, nnum, nmess, iret)
integer, intent(in) :: lugb
integer (kind = 8), intent(in) :: msk1, msk2
Expand All @@ -25,9 +80,6 @@ subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, nlen, nnum, nmess, ire
end subroutine getg2i2r
end interface

integer :: index_rec_len, b2s_message, b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
integer :: total_bytes, grib_version, discipline, field_number, inc

print *, 'Testing the getg2ir2() subroutine - expect and ignore error messages during test...'

! Open a real GRIB2 file.
Expand Down Expand Up @@ -55,55 +107,60 @@ end subroutine getg2i2r
endif
endif

! Break out the index record into component values.
! if (idxver .eq. 1) then
! inc = 0
! call g2_gbytec(cbuf, index_rec_len, 0, 8 * 4)
! if (index_rec_len .ne. 200) stop 105
! print *, 'index_rec_len', index_rec_len
! call g2_gbytec(cbuf, b2s_message, 8 * 4, 8 * 4)
! if (b2s_message .ne. 202) stop 106
! call g2_gbytec(cbuf, b2s_lus, 8 * 8, 8 * 4)
! if (b2s_lus .ne. 0) stop 107
! call g2_gbytec(cbuf, b2s_gds, 8 * 12, 8 * 4)
! if (b2s_gds .ne. 37) stop 108
! else
! inc = 16
! call g2_gbytec(cbuf, index_rec_len, 0, 8 * 8)
! if (index_rec_len .ne. 200) then
! print *, 'index_rec_len', index_rec_len
! stop 110
! endif
! print *, 'index_rec_len', index_rec_len
! call g2_gbytec(cbuf, b2s_message, 8 * 8, 8 * 8)
! if (b2s_message .ne. 202) stop 111
! call g2_gbytec(cbuf, b2s_lus, 8 * 8, 8 * 8)
! if (b2s_lus .ne. 0) stop 112
! call g2_gbytec(cbuf, b2s_gds, 8 * 12, 8 * 8)
! if (b2s_gds .ne. 37) stop 113
! ! call g2_gbytec(cbuf, b2s_pds, 8 * 16, 8 * 8)
! ! if (b2s_pds .ne. 109) stop 114
! endif
! call g2_gbytec(cbuf, b2s_pds, 8 * 16, 8 * 4)
! if (b2s_pds .ne. 109) stop 200
! call g2_gbytec(cbuf, b2s_drs, inc + 8 * 20, 8 * 4)
! if (b2s_drs .ne. 143) stop 210
! call g2_gbytec(cbuf, b2s_bms, inc + 8 * 24, 8 * 4)
! if (b2s_bms .ne. 166) stop 220
! call g2_gbytec(cbuf, b2s_data, inc + 8 * 28, 8 * 4)
! if (b2s_data .ne. 4721) stop 230
! call g2_gbytec(cbuf, total_bytes, inc + 8 * 32, 8 * 8)
! if (total_bytes .ne. 11183) stop 240
! call g2_gbytec(cbuf, grib_version, inc + 8 * 40, 8 * 1)
! if (grib_version .ne. 2) stop 250
! call g2_gbytec(cbuf, discipline, inc + 8 * 41, 8 * 1)
! if (discipline .ne. 10) stop 260
! call g2_gbytec(cbuf, field_number, inc + 8 * 42, 8 * 2)
! if (field_number .ne. 1) stop 270
! print *, 'index_rec_len = ', index_rec_len, ' b2s_message = ', b2s_message
! print *, 'b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data: ', b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
! print *, 'total_bytes, grib_version, discipline, field_number: ', total_bytes, grib_version, discipline, field_number
! Break out the first index record into component values.
call read_index(cbuf, idxver, index_rec_len, b2s_message, b2s_lus, b2s_gds, b2s_pds, b2s_drs, &
b2s_bms, b2s_data, total_bytes, grib_version, discipline, field_number, sec1, lengds, gds, &
lenpds, pds, lendrs, drs, bms, iret)
if (iret .ne. 0) stop 21

print *, ' index_rec_len = ', index_rec_len, ' b2s_message = ', b2s_message
print *, ' b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data: ', b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
print *, ' total_bytes, grib_version, discipline, field_number: ', total_bytes, grib_version, discipline, field_number
print *, ' lengds, lenpds, lendrs', lengds, lenpds, lendrs

if (idxver .eq. 1) then
if (index_rec_len .ne. 200) stop 105
else
if (index_rec_len .ne. 212) then
print *, index_rec_len
stop 105
endif
endif
if (b2s_message .ne. 202) stop 106
if (b2s_lus .ne. 0) stop 107
if (b2s_gds .ne. 37) stop 108
if (b2s_pds .ne. 109) stop 109
if (b2s_drs .ne. 143) stop 110
if (b2s_bms .ne. 166) stop 111
if (b2s_data .ne. 4721) stop 112
if (total_bytes .ne. 11183) stop 113
if (grib_version .ne. 2) stop 114
if (discipline .ne. 10) stop 115
if (field_number .ne. 1) stop 116
do j = 1, SEC1_LEN
!print *, i, ichar(sec1(i))
if (sec1(i) .ne. expected_sec1(i)) stop 200
enddo
if (lengds .ne. GDS_LEN) stop 201
do j = 1, GDS_LEN
!print *, i, ichar(gds(i))
if (gds(i) .ne. expected_gds(i)) stop 201
enddo
if (lenpds .ne. PDS_LEN) stop 201
do j = 1, PDS_LEN
!print *, i, ichar(pds(i))
if (pds(i) .ne. expected_pds(i)) stop 210
enddo
if (lendrs .ne. DRS_LEN) stop 201
do j = 1, DRS_LEN
!print *, i, ichar(drs(i))
if (drs(i) .ne. expected_drs(i)) stop 210
enddo
do j = 1, BMS_LEN
!print *, i, ichar(bms(i))
if (bms(i) .ne. expected_bms(i)) stop 210
enddo

deallocate(cbuf)

call baclose(lugb, iret)
Expand Down

0 comments on commit d4f7d80

Please sign in to comment.