Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for bitmaps #768

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_png_bitmap.png)

# 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_png_bitmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions tests/test_bitmap.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
! 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_png_bitmap.png')
character(*) :: BITMAP_FILE_INDEX
parameter(BITMAP_FILE_INDEX = 'test_bitmap_index.grb2index')

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

character(len=1), pointer, dimension(:) :: cbuf(:)
integer :: idxver, myidxver, nlen, nnum, ifldnum, iret
type(gribfield) :: gfld

interface
subroutine getg2i2(lugi, cbuf, idxver, nlen, nnum, iret)
integer, intent(in) :: lugi
character(len=1), pointer, dimension(:) :: cbuf
integer, intent(out) :: idxver, nlen, nnum, iret
end subroutine getg2i2
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 3

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

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

call baclose(lugb, iret)
if (iret .ne. 0) stop 6

! Read the index file.
call getg2i2(lugi, cbuf, myidxver, nlen, nnum, iret)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check for more than just success? For example, you should know what myindexver, nlen, and nnum you will get back here. Check them too.

if (iret .ne. 0) stop 7

call baclose(lugi, iret)
if (iret .ne. 0) stop 8

ifldnum = 6
call gf_getfld(cbuf, nlen, ifldnum, .true., .true., gfld, iret)
if (iret .ne. 0) stop 9

! Free resources.
call gf_free(gfld)

print *, 'SUCCESS!'
end program test_bitmap
Loading