Skip to content

Commit

Permalink
Add large file test for getgb2i2() (#647)
Browse files Browse the repository at this point in the history
* changed default index version back to 1

* adding getgb2i2()

* adding getgb2i2()

* fixed dox

* more testing

* more testing

* more testing

* more testing

* adding large file test

* more test development

* testing last message
  • Loading branch information
edwardhartnett authored Mar 20, 2024
1 parent abfe0fc commit e327d2e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ if(FTP_TEST_FILES)
if(FTP_LARGE_TEST_FILES)
create_test(test_fv3 ${kind})
create_test(test_create_index_fv3 ${kind})
create_test(test_files_fv3 ${kind})
endif()
if(FTP_EXTRA_TEST_FILES)
create_test(test_create_index_gfsprs ${kind})
Expand Down
81 changes: 81 additions & 0 deletions tests/test_files_fv3.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
! This is a test program for NCEPLIBS-g2.
!
! This program tests reading the very large FV3 GRIB2 file, using
! getgb2i2().
!
! Ed Hartnett 3/20/24
program test_files_fv3
use grib_mod
implicit none

integer :: lugb = 10
integer :: jdisc = -1, jpdtn = -1, jgdtn = -1, jskp = 0
integer, dimension(200) :: jids, jpdt, jgdt
logical :: unpack = .true.
type(gribfield) :: gfld
integer :: expected_idsect(13) = (/ 7, 0, 2, 1, 1, 2022, 6, 21, 0, 0, 0, 0, 1 /)
integer :: expected_igdtmpl(22) = (/ 6, 0, 0, 0, 0, 0, 0, 4881, 2961, 0, 0, -37000000, &
299000000, 48, 37000000, 61000000, 25000, 25000, 64, -35000000, 247000000, 0 /)
integer :: expected_ipdtmpl(15) = (/ 3, 0, 2, 0, 134, 0, 0, 1, 0, 1, 0, 0, 255, 0, 0 /)
integer :: expected_idrtmpl(18) = (/ 1216637952, 0, 3, 17, 0, 1, 0, 0, 0, 560759, 0, &
5, 1, 1, 63, 6, 2, 3 /)
integer :: i, idxver, iret, k

print *, 'Testing reading GRIB2 file fv3lam.t00z.prslev.f000.grib2...'

idxver = 2
! Open the file.
call baopenr(lugb, 'data/fv3lam.t00z.prslev.f000.grib2', iret)
if (iret .ne. 0) stop 2

! Find the last message in the file.
jids = -9999
jpdt = -9999
jgdt = -9999
jskp = 1080 ! skip to the last message
call getgb2i2(lugb, 0, jskp, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
unpack, idxver, k, gfld, iret)
if (iret .ne. 0) stop 3
! Make sure we found message 1081 in the file.
if (k .ne. 1081) stop 4
if (gfld%version .ne. 2 .or. gfld%discipline .ne. 10 .or. gfld%idsectlen .ne. 13 .or. &
gfld%locallen .ne. 0 .or. gfld%ifldnum .ne. 1 .or. gfld%griddef .ne. 0 .or. &
gfld%ngrdpts .ne. 14452641 .or. gfld%numoct_opt .ne. 0 .or. gfld%interp_opt .ne. 0 .or. &
gfld%num_opt .ne. 0 .or. gfld%igdtnum .ne. 1 .or. gfld%ipdtnum .ne. 0 .or. &
gfld%ipdtlen .ne. 15 .or. gfld%ndpts .ne. 8793914 .or. gfld%idrtnum .ne. 3 .or. &
gfld%idrtlen .ne. 18 .or. gfld%unpacked .neqv. .false. .or. gfld%expanded .neqv. .true. .or. &
gfld%ibmap .ne. 0) stop 10
do i = 1, 13
if (gfld%idsect(i) .ne. expected_idsect(i)) stop 20
end do
do i = 1, 22
if (gfld%igdtmpl(i) .ne. expected_igdtmpl(i)) stop 30
end do
do i = 1, 15
if (gfld%ipdtmpl(i) .ne. expected_ipdtmpl(i)) then
print *, 'got gfld%ipdtmpl', gfld%ipdtmpl
print *, 'expected ', expected_ipdtmpl
stop 40
endif
end do
do i = 1, 18
if (gfld%idrtmpl(i) .ne. expected_idrtmpl(i)) stop 50
end do
! do i = 1, 100
! print *, gfld%fld(1)
! end do

! Close the file.
call baclose(lugb, iret)
if (iret .ne. 0) stop 200

! Free memory.
call gf_free(gfld)

! Free internal library memory.
call gf_finalize(iret)
if (iret .ne. 0) stop 5

print *, 'OK!'
print *, 'SUCCESS!'
end program test_files_fv3

0 comments on commit e327d2e

Please sign in to comment.