Skip to content

Commit

Permalink
added USE_G2C_API option (#791)
Browse files Browse the repository at this point in the history
* added USE_G2C_API option

* added option USE_G2C_API to spack package file

* added option USE_G2C_API to spack package file

* dealing with option USE_G2C_API

* dealing with option USE_G2C_API

* dealing with option USE_G2C_API

* dealing with option USE_G2C_API

* added USE_G2C_API to developer CI workflow
  • Loading branch information
edwardhartnett authored Dec 31, 2024
1 parent c6541b7 commit 6efb630
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"),
]

Expand Down
7 changes: 6 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 6efb630

Please sign in to comment.