From 8e09b8cb0c39f28b99732fa865063c3b2b21bcad Mon Sep 17 00:00:00 2001 From: AlysonStahl-NOAA <166434581+AlysonStahl-NOAA@users.noreply.github.com> Date: Tue, 16 Apr 2024 10:19:37 -0600 Subject: [PATCH] Added file options for AEC and an additional unit test (#117) * Added Ed and Wesley's changes for AEC compression * Update Linux_options.yml * Update CMakeLists.txt * Added a unit test * Reverted a few changes in wgrib2/CMakeLists.txt * added new test data to tests\CMakeLists.txt * Renamed test data files and added tests to workflow --- .github/workflows/Linux_options.yml | 14 ++++++++- .github/workflows/developer.yml | 8 +++++ CMakeLists.txt | 9 ++++-- cmake/Findlibaec.cmake | 31 +++++++++++++++++++ tests/CMakeLists.txt | 1 + ...s_gdaswave.t00z.wcoast.0p16.f000.grib2.txt | 19 ++++++++++++ tests/run_wgrib2_tests.sh | 5 +++ wgrib2/CMakeLists.txt | 5 +++ 8 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 cmake/Findlibaec.cmake create mode 100644 tests/data/ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt diff --git a/.github/workflows/Linux_options.yml b/.github/workflows/Linux_options.yml index 9611cc2f..debbad55 100644 --- a/.github/workflows/Linux_options.yml +++ b/.github/workflows/Linux_options.yml @@ -30,6 +30,9 @@ jobs: - { options: "-DUSE_IPOLATES=1" } + - { + options: "-DUSE_AEC=ON" + } steps: @@ -37,9 +40,17 @@ jobs: run: | sudo apt-get update sudo apt-get install libnetcdf-dev libnetcdff-dev netcdf-bin pkg-config - sudo apt-get install libpng-dev autotools-dev autoconf + sudo apt-get install libpng-dev autotools-dev autoconf libaec-dev + + - name: cache-jasper + id: cache-jasper + uses: actions/cache@v3 + with: + path: ~/jasper + key: jasper-${{ runner.os }}-1.900.1 - name: checkout-jasper + if: steps.cache-jasper.outputs.cache-hit != 'true' uses: actions/checkout@v2 with: repository: jasper-software/jasper @@ -123,3 +134,4 @@ jobs: cd b cmake ${{ matrix.config.options }} -DCMAKE_PREFIX_PATH="~/sp;~/ip;~/ip2" .. make VERBOSE=1 + ctest --verbose --output-on-failure --rerun-failed diff --git a/.github/workflows/developer.yml b/.github/workflows/developer.yml index 0ea81f62..852a5f79 100644 --- a/.github/workflows/developer.yml +++ b/.github/workflows/developer.yml @@ -30,7 +30,15 @@ jobs: sudo apt-get install libnetcdf-dev libnetcdff-dev netcdf-bin pkg-config sudo apt-get install libpng-dev autotools-dev autoconf gcovr + - name: cache-jasper + id: cache-jasper + uses: actions/cache@v3 + with: + path: ~/jasper + key: jasper-${{ runner.os }}-1.900.1 + - name: checkout-jasper + if: steps.cache-jasper.outputs.cache-hit != 'true' uses: actions/checkout@v4 with: repository: jasper-software/jasper diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fb56d3c..109fc881 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,8 +127,13 @@ if(USE_PNG) find_package(PNG REQUIRED) endif() -# write config.h. This is used internally by wgrib2 code and is not -# installed. +# Find required packages to use AEC +message(STATUS "Checking of the user wants to use AEC...") +if(USE_AEC) + find_package(libaec 1.0.6 REQUIRED) +endif() + +# write config.h message(STATUS "Writing config.h...") FILE(WRITE "wgrib2/config.h" "/* config.h generated by cmake */\n") FILE(APPEND "wgrib2/config.h" "#ifndef _CONFIG_H\n") diff --git a/cmake/Findlibaec.cmake b/cmake/Findlibaec.cmake new file mode 100644 index 00000000..bde72aa4 --- /dev/null +++ b/cmake/Findlibaec.cmake @@ -0,0 +1,31 @@ +# +# Find libaec +# +# LIBAEC_FOUND - if false, do not try to use libaec +# LIBAEC_INCLUDE_DIRS - the libaec include directories +# LIBAEC_LIBRARIES - the libraries to link against to use libaec +# +# This file is part of NCEPLIBS-g2c. Distributed under the LGPL v3.0. + +find_package(PkgConfig QUIET) +pkg_check_modules(LIBAEC_PKGCONF QUIET libaec aec) +set(LIBAEC_VERSION ${LIBAEC_PKGCONF_VERSION}) + +find_path(LIBAEC_INCLUDE_DIRS + NAMES libaec.h + HINTS ${LIBAEC_PKGCONF_INCLUDEDIR} ${LIBAEC_PKGCONF_INCLUDE_DIRS} +) + +find_library(LIBAEC_LIBRARIES + NAMES libaec aec + HINTS ${LIBAEC_PKGCONF_LIBDIR} ${LIBAEC_PKGCONF_LIBRARY_DIRS} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(libaec + FOUND_VAR LIBAEC_FOUND + REQUIRED_VARS LIBAEC_LIBRARIES LIBAEC_INCLUDE_DIRS + VERSION_VAR LIBAEC_VERSION +) + +mark_as_advanced(LIBAEC_INCLUDE_DIRS LIBAEC_LIBRARIES) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cdf0d3af..85ee89f3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,6 +25,7 @@ endfunction() # Copy test data file into buiild directory for testing. copy_test_data(gdaswave.t00z.wcoast.0p16.f000.grib2) copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2.inv) +copy_test_data(ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt) # Run these shell tests. shell_test(run_wgrib2_tests) diff --git a/tests/data/ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt b/tests/data/ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt new file mode 100644 index 00000000..a3dae41a --- /dev/null +++ b/tests/data/ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt @@ -0,0 +1,19 @@ +1:0:npts=36391 +2:15254:npts=36391 +3:37897:npts=36391 +4:53794:npts=36391 +5:69064:npts=36391 +6:79482:npts=36391 +7:91308:npts=36391 +8:108541:npts=36391 +9:116716:npts=36391 +10:128832:npts=36391 +11:140848:npts=36391 +12:151732:npts=36391 +13:161021:npts=36391 +14:173676:npts=36391 +15:189425:npts=36391 +16:205285:npts=36391 +17:218263:npts=36391 +18:237035:npts=36391 +19:259223:npts=36391 diff --git a/tests/run_wgrib2_tests.sh b/tests/run_wgrib2_tests.sh index 7848825d..39e8385d 100644 --- a/tests/run_wgrib2_tests.sh +++ b/tests/run_wgrib2_tests.sh @@ -19,5 +19,10 @@ ls -l ../wgrib2 cat tmp.txt cmp tmp.txt data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2.inv +# Returns number of grid points in grid +../wgrib2/wgrib2 data/gdaswave.t00z.wcoast.0p16.f000.grib2 -npts > npts.txt +cat npts.txt +cmp npts.txt data/ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt + echo "*** SUCCESS!" exit 0 diff --git a/wgrib2/CMakeLists.txt b/wgrib2/CMakeLists.txt index e0508874..84ab9ea0 100644 --- a/wgrib2/CMakeLists.txt +++ b/wgrib2/CMakeLists.txt @@ -138,6 +138,11 @@ target_link_libraries(obj_lib PUBLIC gctpc -lm) # Link to gctpc directly because oobject libraries do not link transitively target_link_libraries(wgrib2_exe PRIVATE gctpc) + +if(${USE_AEC} STREQUAL ON) + target_link_libraries(wgrib2_exe PRIVATE aec) +endif() + target_link_libraries(wgrib2_exe PRIVATE obj_lib) if(BUILD_LIB)