Skip to content

Commit

Permalink
adding large file testing (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett authored Jul 18, 2023
1 parent 007847b commit a05a1b4
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 20 deletions.
40 changes: 21 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ set(lib_name ${PROJECT_NAME})

include(GNUInstallDirs)

# Handle user build options.
option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF)
option(FTP_TEST_FILES "Fetch and test with files on FTP site." OFF)
option(FTP_LARGE_TEST_FILES "Fetch and test with very large files on FTP site." OFF)
option(FTP_EXTRA_TEST_FILES "Test with files not yet available via FTP." OFF)
option(LOGGING "Turn on internal logging messages. Only useful to g2 developers." OFF)
option(BUILD_4 "Build libg2_4.a" ON)
option(BUILD_D "Build libg2_d.a" ON)
option(BUILD_WITH_W3EMC "Build with NCEPLIBS-w3emc, enabling some GRIB1 functionality" ON)

# Developers can use this option to specify a local directory which
# holds the test files. They will be copied instead of fetching the
# files via FTP.
SET(TEST_FILE_DIR "." CACHE STRING "Check this directory for test files before using FTP.")
message(STATUS "Finding test data files in directory ${TEST_FILE_DIR}.")

# Set pre-processor symbol if logging is desired.
if(LOGGING)
add_definitions(-DLOGGING)
endif()

# Handle build type.
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
message(STATUS "Setting build type to 'Release' as none was specified.")
Expand Down Expand Up @@ -39,25 +60,6 @@ if(${CMAKE_Fortran_COMPILER_ID} MATCHES "^(GNU)$" AND ${CMAKE_Fortran_COMPILER_V
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()

# Handle user build options.
option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF)
option(FTP_TEST_FILES "Fetch and test with files on FTP site." OFF)
option(LOGGING "Turn on internal logging messages. Only useful to g2 developers." OFF)
option(BUILD_4 "Build libg2_4.a" ON)
option(BUILD_D "Build libg2_d.a" ON)
option(BUILD_WITH_W3EMC "Build with NCEPLIBS-w3emc, enabling some GRIB1 functionality" ON)

# Developers can use this option to specify a local directory which
# holds the test files. They will be copied instead of fetching the
# files via FTP.
SET(TEST_FILE_DIR "." CACHE STRING "Check this directory for test files before using FTP.")
message(STATUS "Finding test data files in directory ${TEST_FILE_DIR}.")

# Set pre-processor symbol if logging is desired.
if(LOGGING)
add_definitions(-DLOGGING)
endif()

# There was a bug in jasper for the intel compiler that was fixed in
# 2.0.25.
find_package(Jasper 2.0.25 REQUIRED)
Expand Down
13 changes: 12 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@ if(FTP_TEST_FILES)
set(FILE_GEGFS_F144 "gegfs.t00z.pgrb2a.0p50.f144")
set(FILE_GEGFS_MEF144 "gegfs.t00z.pgrb2a.0p50_mef144")
set(FILE_GEP19_F144 "gep19.t00z.pgrb2a.0p50.f144")
if(FTP_EXTRA_TEST_FILES)
if(FTP_LARGE_TEST_FILES)
set(FILE_FV3_ATM "fv3lam.t00z.prslev.f000.grib2")
endif()
endif()

# Get each of the test data files.
foreach(THE_FILE IN LISTS WW3_WEST_FILE FILE_GEP19_BCF144 FILE_GEAVG FILE_GEC00
FILE_GEGFS_F144 FILE_GEGFS_MEF144 FILE_GEP19_F144 )
FILE_GEGFS_F144 FILE_GEGFS_MEF144 FILE_GEP19_F144 FILE_FV3_ATM)
PULL_DATA(${G2_FTP_URL} ${THE_FILE})
endforeach()

Expand All @@ -102,6 +107,12 @@ if(FTP_TEST_FILES)
if (BUILD_WITH_W3EMC)
create_test(test_getgb2_mem ${kind})
endif()
# This test depends on a very large file downloaded from FTP.
if(FTP_EXTRA_TEST_FILES)
if(FTP_LARGE_TEST_FILES)
create_test(test_fv3 ${kind})
endif()
endif()
endforeach()
endif()

Expand Down
72 changes: 72 additions & 0 deletions tests/test_fv3.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
! This is a test program for NCEPLIBS-g2.
!
! This program tests reading a very large FV3 GRIB2 file, only
! downloaded if both the FTP_TEST_FILES and the FTP_LARGE_TEST_FILES
! are set to ON at build time.
!
! Ed Hartnett 7/17/23
program test_fv3
use grib_mod
implicit none

! THese are the test files we will use.
character(*) :: TEST_FILE
parameter (TEST_FILE = 'data/fv3lam.t00z.prslev.f000.grib2')
integer :: NUM_MSG
parameter (NUM_MSG = 555)
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 :: i, start
integer :: lskip, lgrib
integer :: iret

print *, 'Testing reading GRIB2 file ', TEST_FILE
print *, 'trying getgb2()...'

! Open the file.
call baopenr(lugb, TEST_FILE, iret)
if (iret .ne. 0) stop 2

! Learn about the file.
jids = -9999
jpdt = -9999
jgdt = -9999
call getgb2(lugb, 0, jskp, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
unpack, jskp, gfld, iret)
if (iret .ne. 0) stop 3

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

! Free memory.
call gf_free(gfld)
call gf_finalize(iret)
if (iret .ne. 0) stop 5

print *, 'OK!'
print *, 'trying skgb()...'

! Open the file.
call baopenr(lugb, TEST_FILE, iret)
if (iret .ne. 0) stop 2

! Loop through the file, checking location of each message.
start = 0
do i = 1, NUM_MSG
call skgb(lugb, start, 10000, lskip, lgrib)
print *, i, lskip, lgrib
! if (lskip .ne. expected_lskip(i) .or. lgrib .ne. expected_lgrib(i)) stop 101
start = start + lgrib
end do

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

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

0 comments on commit a05a1b4

Please sign in to comment.