diff --git a/.github/workflows/developer.yml b/.github/workflows/developer.yml index f607688a..67e3e047 100644 --- a/.github/workflows/developer.yml +++ b/.github/workflows/developer.yml @@ -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 -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 .. + cmake -DUSE_G2C_API=ON -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 @@ -79,7 +79,7 @@ jobs: mkdir build doxygen --version cd build - 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 .. + cmake -DUSE_G2C_API=ON -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index f7593b28..aae9d1df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(BUILD_WITH_W3EMC "Build with NCEPLIBS-w3emc, enabling some GRIB1 function option(BUILD_UTILS "Build grib utilities" ON) option(USE_AEC "Build with AEC (CCSDS) compression support" OFF) option(G2C_COMPARE "Enable copygb2 tests using g2c_compare" OFF) +option(USE_G2C_API "Enable new file-based API from NCEPLIBS-g2c" OFF) # Developers can use this option to specify a local directory which # holds the test files. They will be copied instead of fetching the @@ -73,7 +74,6 @@ 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) -find_package(g2c REQUIRED) find_package(PNG REQUIRED) find_package(bacio REQUIRED) if(bacio_VERSION LESS 2.5.0) @@ -90,8 +90,15 @@ if (BUILD_WITH_W3EMC) endif() # We need g2c if G2C_COMPARE is chosen. -if (G2C_COMPARE) - find_package(g2c 1.7.0 REQUIRED) +if (G2C_COMPARE OR USE_G2C_API) + find_package(g2c 2.1.0 REQUIRED) +else() + find_package(g2c REQUIRED) +endif() + +# Set a pre-processor symbol if we are using g2c API. +if (USE_G2C_API) + add_definitions(-DG2C_API) endif() # Figure whether user wants a _4, a _d, or both libraries. diff --git a/spack/package.py b/spack/package.py index 0b78d919..a4b78176 100644 --- a/spack/package.py +++ b/spack/package.py @@ -52,6 +52,12 @@ class G2(CMakePackage): description="Enable copygb2 tests using g2c_compare", when="@2.0.0:", ) + variant( + "use_g2c_api", + default=False, + description="Use new file-based API", + when="@2.0.0:", + ) depends_on("jasper@:2.0.32", when="@:3.4.7") depends_on("jasper") @@ -82,6 +88,7 @@ def cmake_args(self): self.define("BUILD_4", self.spec.satisfies("precision=4")), self.define("BUILD_D", self.spec.satisfies("precision=d")), self.define_from_variant("G2C_COMPARE", "g2c_compare"), + self.define_from_variant("USE_G2C_API", "use_g2c_api"), self.define_from_variant("BUILD_UTILS", "utils"), ] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12a0e0e0..fd60cc3e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,7 +9,12 @@ g2grids.F90 g2get.F90 g2getgb2.F90 g2index.F90 g2gf.F90 g2unpack.F90 g2create.F90 ${CMAKE_CURRENT_BINARY_DIR}/gribmod.F90 gridtemplates.F90 intmath.F90 g2jpc.F90 pack_gp.f params_ecmwf.F90 params.F90 pdstemplates.F90 g2png.F90 realloc.F90 reduce.f g2sim.F90 skgb.F90 -g2spec.F90 g2logging.F90 g2cf.F90 g2c_interface.F90) +g2spec.F90 g2logging.F90) + +# Add the G2C API code if required. +if (USE_G2C_API) + set(fortran_src ${fortran_src} g2cf.F90 g2c_interface.F90) +endif() # This function calls NCEPLIBS-w3emc. if (BUILD_WITH_W3EMC) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 91b16c8e..eecf0fdf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -171,7 +171,9 @@ 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. foreach(kind ${kinds}) - create_test(test_g2cf ${kind}) + if (USE_G2C_API) + create_test(test_g2cf ${kind}) + endif() create_test(test_misc ${kind}) create_test(test_g2 ${kind}) create_test(test_g1 ${kind})