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

moved test data to subdirectory "data", allow user to specify local data directory to find FTP files, added some test files for future testing #181

Merged
merged 8 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is the main CMake file for NCEPLIBS-grib_util.
#
# Mark Potts, Kyle Gerheiser
# Mark Potts, Kyle Gerheiser, Ed Hartnett
cmake_minimum_required(VERSION 3.15)

file(STRINGS "VERSION" pVersion)
Expand All @@ -11,6 +11,7 @@ project(gributil VERSION ${pVersion} LANGUAGES C Fortran)
option(OPENMP "use OpenMP threading" OFF)
option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF)
option(FTP_TEST_FILES "Fetch and test with files on FTP site." OFF)
SET(TEST_FILE_DIR "." CACHE STRING "Check this directory for test files before using FTP.")

if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
message(STATUS "Setting build type to 'Release' as none was specified.")
Expand Down
4 changes: 2 additions & 2 deletions src/degrib2/degrib2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ program degrib2
integer :: maxlocal, n, ncgb, numfields, numlocal
real :: fldmax, fldmin, sum
parameter(msk1 = 32000, msk2 = 4000)
CHARACTER(len = 1), allocatable, dimension(:) :: cgrib
character(len = 1), allocatable, dimension(:) :: cgrib
integer :: listsec0(3)
integer :: listsec1(13)
character(len = 250) :: gfile1
character(len = 8) :: pabbrev
character(len = 30) :: labbrev
character(len = 90) :: tabbrev
INTEGER(4) NARG, IARGC, temparg
integer(4) narg, iargc, temparg
integer :: currlen = 0, numpts = 0
logical :: unpack, expand
type(gribfield) :: gfld
Expand Down
31 changes: 23 additions & 8 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,36 @@ endfunction()

# Copy each necessary test data file to the binary build directory.
function(gu_copy_test_data name)
file(COPY "${CMAKE_SOURCE_DIR}/tests/${name}"
DESTINATION ${CMAKE_BINARY_DIR}/tests
file(COPY "${CMAKE_SOURCE_DIR}/tests/data/${name}"
DESTINATION ${CMAKE_BINARY_DIR}/tests/data
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endfunction()

# Some test files are large and are kept on the NOAA EMC FTP
# site. This function is used to download such test data. It takes two
# arguments, the URL and the file to be downloaded.
function(PULL_DATA THE_URL THE_FILE)
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${THE_FILE}")
# If the TEST_FILE_DIR was specified, look for our test data files
# there before FTPing them. Developers can keep all test files on
# their machines, and save the time of downloading them every time.
if(NOT ${TEST_FILE_DIR} STREQUAL ".")
if (EXISTS ${TEST_FILE_DIR}/${THE_FILE})
message(STATUS "Copying file ${TEST_FILE_DIR}/${THE_FILE} to test data directory.")
FILE(COPY ${TEST_FILE_DIR}/${THE_FILE}
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
endif()
endif()
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}")
message(STATUS "Downloading file ${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}.")
file(DOWNLOAD
${THE_URL}/${THE_FILE}
${CMAKE_CURRENT_BINARY_DIR}/${THE_FILE}
${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}
SHOW_PROGRESS
STATUS status
INACTIVITY_TIMEOUT 30
)
)
list(GET status 0 status_num)
if(NOT status_num EQUAL 0 OR NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${THE_FILE}")
if(NOT status_num EQUAL 0 OR NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}")
message(FATAL_ERROR "Could not download ${THE_FILE}")
endif()
endif()
Expand Down Expand Up @@ -65,11 +76,14 @@ if(FTP_TEST_FILES)
set(G2_FTP_URL "https://ftp.emc.ncep.noaa.gov/static_files/public/NCEPLIBS-g2")
set(WW3_WEST_FILE "WW3_Regional_US_West_Coast_20220718_0000.grib2")
set(WW3_EAST_FILE "WW3_Regional_US_East_Coast_20220717_0600.grib2")

set(GDAS_FILE "gdas.t12z.pgrb2.1p00.anl.grib2")
set(BLEND_FILE "blend.t19z.core.f001.co.grib2")
set(CMC_FILE "cmc_geavg.t12z.pgrb2a.0p50.f000")

# Get the files from the FTP site.
# Not using the East Coast file yet.
# foreach(THE_FILE IN LISTS WW3_WEST_FILE WW3_EAST_FILE)
foreach(THE_FILE IN LISTS WW3_WEST_FILE)
foreach(THE_FILE IN LISTS WW3_WEST_FILE GDAS_FILE BLEND_FILE CMC_FILE)
PULL_DATA(${G2_FTP_URL} ${THE_FILE})
endforeach()

Expand All @@ -80,4 +94,5 @@ if(FTP_TEST_FILES)

# Run these shell tests which use the FTP files.
gu_test(run_ftp_tests)
gu_test(run_all_ftp_tests)
endif()
Loading