Skip to content

Commit

Permalink
Tests for bitmaps (#768)
Browse files Browse the repository at this point in the history
* bitmap test file

* add test file

* copy test data

* Update test_bitmap.F90

* Update test_bitmap.F90

* debug memcheck

* Update test_bitmap.F90

* debug test coverage

* debug workflows

* fix test coverage

* debug failing workflows

* Update test_bitmap.F90

* debugging

* Update test_bitmap.F90

* debugging memory errors

* undo last change

* debug

* Update test_bitmap.F90

* debug

* Update test_bitmap.F90

* remove comments

* Update test_bitmap.F90

* Update test_bitmap.F90

* Update test_bitmap.F90

* change to getidx2 to get cbuf

* Update test_bitmap.F90

* debug pngunpack

* debug

* Update test_bitmap.F90

* debug

* Update test_bitmap.F90

* Update test_bitmap.F90

* debug

* typo

* Update test_bitmap.F90

* Update test_bitmap.F90

* add new test file

* file name

* swap file

* checking result

* Update test_bitmap.F90

* checking more values

* Update test_bitmap.F90
  • Loading branch information
AlysonStahl-NOAA authored Dec 15, 2024
1 parent 18074e3 commit e357ffc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
cd g2
mkdir build
cd build
cmake -DBUILD_UTILS=OFF -DUSE_AEC=ON -DFTP_LARGE_TEST_FILES=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-bacio;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-w3emc;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DCMAKE_Fortran_FLAGS="-g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0 -Wall -fno-omit-frame-pointer -fsanitize=address" -DCMAKE_C_FLAGS="-g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0 -Wall -fno-omit-frame-pointer -fsanitize=address" -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data -DCMAKE_BUILD_TYPE=Debug ..
cmake -DBUILD_UTILS=OFF -DUSE_AEC=ON -DFTP_LARGE_TEST_FILES=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-bacio;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-w3emc;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DCMAKE_Fortran_FLAGS="-g -O0 -Wall -fno-omit-frame-pointer -fsanitize=address" -DCMAKE_C_FLAGS="-g -O0 -Wall -fno-omit-frame-pointer -fsanitize=address" -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data -DCMAKE_BUILD_TYPE=Debug ..
make -j2 VERBOSE=1
ctest --verbose --output-on-failure --rerun-failed
Expand All @@ -79,7 +79,7 @@ jobs:
mkdir build
doxygen --version
cd build
cmake -DBUILD_UTILS=ON -DG2C_COMPARE=OFF -DUSE_AEC=ON -DFTP_LARGE_TEST_FILES=ON -DENABLE_DOCS=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-bacio;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-w3emc;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data ..
cmake -DBUILD_UTILS=ON -DUSE_AEC=ON -DFTP_LARGE_TEST_FILES=ON -DENABLE_DOCS=ON -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/jasper;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-bacio;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-w3emc;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-ip;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-g2c" -DCMAKE_Fortran_FLAGS="-g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0" -DCMAKE_C_FLAGS="-g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0" -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data ..
make -j2 VERBOSE=1
ctest --verbose --output-on-failure --rerun-failed
gcovr --root .. -v --html-details --exclude ../tests --exclude CMakeFiles --print-summary -o test-coverage.html &> /dev/null
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grb2index2)
copy_test_data(g1.grib2)
copy_test_data(gdaswave.t00z.wcoast.0p16.f000.grib2)
copy_test_data(ref_test_jpcpack_4_output.txt)
copy_test_data(ref_jpeg_bitmap.grib2)

# Build a _4 and _d version of each test and link them to the _4 and
# _d builds of the library, for 4-byte real, and 8-byte real.
Expand Down Expand Up @@ -208,6 +209,7 @@ foreach(kind ${kinds})
create_test(test_gettemplates ${kind})
create_test(test_addfield ${kind})
create_test(test_gf_unpack2 ${kind})
create_test(test_bitmap ${kind})

# This test depends on gdt2gds(), which is not present if the GRIB1
# library is not also included in the build.
Expand Down
Binary file added tests/data/ref_jpeg_bitmap.grib2
Binary file not shown.
91 changes: 91 additions & 0 deletions tests/test_bitmap.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
! This is a test program for NCEPLIBS-g2.
!
! This program tests processing a GRIB2 file with bitmaps.
!
! Alyson Stahl 11/5/24
program test_bitmap
use bacio_module
use grib_mod
implicit none

character(*) :: BITMAP_FILE
parameter(BITMAP_FILE = 'data/ref_jpeg_bitmap.grib2')
character(*) :: BITMAP_FILE_INDEX
parameter(BITMAP_FILE_INDEX = 'test_bitmap_index.grb2index')

integer :: lugi, lugb
parameter(lugi = 31, lugb = 11)

integer :: idxver = 2, j = 0, jdisc = 0, jpdtn = 0, jgdtn = 0
integer :: iret, k, i
integer :: jids(13), jpdt(15), jgdt(19)
logical :: unpack = .true.
integer :: expected_idsect(13) = (/ 7, 0, 2, 1, 1, 2021, 11, 30, 0, 0, 0, 0, 1/)
integer :: expected_ipdtmpl(15) = (/ 2, 1, 2, 0, 11, 0, 0, 1, 0, 1, 0, 1, 255, 0, 0 /)
integer :: expected_igdtmpl(19) = (/ 6, 0, 0, 0, 0, 0, 0, 241, 151, 0, 0, 50000000, &
210000000, 48, 25000000, 250000000, 166667, 166667, 0/)
integer :: expected_idrtmpl(7) = (/ 1092616192, 0, 2, 11, 0, 0, 255 /)
type(gribfield) :: gfld

interface
subroutine g2_create_index(lugb, lugi, idxver, filename, iret)
integer, intent(in) :: lugb, lugi, idxver
character*(*) :: filename
integer, intent(out) :: iret
end subroutine g2_create_index
end interface

! Open GRIB2 file for reading.
call baopenr(lugb, BITMAP_FILE, iret)
if (iret .ne. 0) stop 2

! Open output file where index will be written.
call baopen(lugi, BITMAP_FILE_INDEX, iret)
if (iret .ne. 0) stop 3

call g2_create_index(lugb, lugi, idxver, BITMAP_FILE, iret)
if (iret .ne. 0) stop 4

jids = -9999
jpdt = -9999
jgdt = -9999
call getgb2i2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, &
jgdt, unpack, idxver, k, gfld, iret)
if (iret .ne. 0) stop 10
if (k .ne. 1) stop 11
if (gfld%version .ne. 2 .or. gfld%discipline .ne. 0 .or. gfld%idsectlen .ne. 13 .or. &
gfld%locallen .ne. 0 .or. gfld%ifldnum .ne. 1 .or. gfld%griddef .ne. 0 .or. &
gfld%ngrdpts .ne. 36391 .or. gfld%numoct_opt .ne. 0 .or. gfld%interp_opt .ne. 0 .or. &
gfld%num_opt .ne. 0 .or. gfld%igdtnum .ne. 0 .or. gfld%igdtlen .ne. 19 .or. &
gfld%ipdtnum .ne. 0 .or. gfld%ipdtlen .ne. 15 .or. gfld%ndpts .ne. 11041 .or. &
gfld%idrtnum .ne. 40 .or. gfld%idrtlen .ne. 7 .or. gfld%unpacked .neqv. .false. .or. &
gfld%expanded .neqv. .true. .or. gfld%ibmap .ne. 0) stop 12
do i = 1, 13
if (gfld%idsect(i) .ne. expected_idsect(i)) stop 13
end do
do i = 1, 19
if (gfld%igdtmpl(i) .ne. expected_igdtmpl(i)) stop 14
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 15
endif
end do
do i = 1, 7
if (gfld%idrtmpl(i) .ne. expected_idrtmpl(i)) stop 16
end do

call baclose(lugb, iret)
if (iret .ne. 0) stop 100
call baclose(lugi, iret)
if (iret .ne. 0) stop 101

! Free resources.
call gf_free(gfld)
call gf_finalize(iret)
if (iret .ne. 0) stop 102

print *, 'SUCCESS!'
end program test_bitmap

0 comments on commit e357ffc

Please sign in to comment.