From a05a1b4e3b24e56283a7fb59d9f9fc5febda8ce3 Mon Sep 17 00:00:00 2001 From: Edward Hartnett <38856240+edwardhartnett@users.noreply.github.com> Date: Tue, 18 Jul 2023 05:42:42 -0600 Subject: [PATCH] adding large file testing (#492) --- CMakeLists.txt | 40 ++++++++++++------------ tests/CMakeLists.txt | 13 +++++++- tests/test_fv3.F90 | 72 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 tests/test_fv3.F90 diff --git a/CMakeLists.txt b/CMakeLists.txt index ad30745c..b02ee560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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.") @@ -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) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 29430bd4..da6acd40 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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() @@ -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() diff --git a/tests/test_fv3.F90 b/tests/test_fv3.F90 new file mode 100644 index 00000000..0e42f61a --- /dev/null +++ b/tests/test_fv3.F90 @@ -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