Skip to content

Commit

Permalink
added netcdf4 flag to Linux_options.yml (#121)
Browse files Browse the repository at this point in the history
* added netcdf4 flag to Linux_options.yml

* Update CMakeLists.txt

* Update Config.c

* Added tests for netcdf

* fixed potential source of error in developer workflow

* removed tarball

* restored netcdf tarball

---------

Co-authored-by: Edward Hartnett <[email protected]>
  • Loading branch information
AlysonStahl-NOAA and edwardhartnett authored May 9, 2024
1 parent e7f52f1 commit a928f5d
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/Linux_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- {
options: "-DUSE_AEC=ON"
}
- {
options: "-DUSE_NETCDF4=ON"
}

steps:

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ FILE(WRITE "wgrib2/config.h" "/* config.h generated by cmake */\n")
FILE(APPEND "wgrib2/config.h" "#ifndef _CONFIG_H\n")
FILE(APPEND "wgrib2/config.h" "#define _CONFIG_H\n")

FOREACH(var IN ITEMS USE_NETCDF3 USE_NETCDF4 USE_HDF5 USE_REGEX USE_TIGGE USE_MYSQL
FOREACH(var IN ITEMS USE_NETCDF3 USE_REGEX USE_TIGGE USE_MYSQL
USE_IPOLATES USE_UDF USE_OPENMP USE_PROJ4 USE_WMO_VALIDATION DISABLE_TIMEZONE
DISABLE_ALARM USE_NAMES USE_G2CLIB USE_PNG USE_JASPER USE_OPENJPEG MAKE_FTN_API USE_AEC BUILD_COMMENTS)

Expand Down
9 changes: 9 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,21 @@ copy_test_data(ref_wind.gdas.t12z.pgrb2.1p00.anl.75r.grib2.inv)
copy_test_data(ref_uv.gdas.t12z.pgrb2.1p00.anl.75r.grib2.inv)
copy_test_data(ref_grid.gdaswave.t00z.wcoast.0p16.f000.grib2.txt)


# Run these shell tests.
shell_test(run_wgrib2_tests)

if (USE_NETCDF4)
shell_test(run_wgrib2_netcdf4_tests)
endif()
if (USE_NETCDF3)
shell_test(run_wgrib2_netcdf3_tests)
endif()

if (USE_AEC)
shell_test(run_wgrib2_aec_tests)
endif()

if (FTP_TEST_FILES)
shell_test(run_wgrib2_ftp_tests)
endif()
28 changes: 28 additions & 0 deletions tests/run_wgrib2_netcdf3_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# This checks the use of AEC compression, only available if USE_NETCDF4 is turned on in CMake.
#
# Alyson Stahl, 4/22/24

set -e
set -x

# make template
../wgrib2/wgrib2 data/tmp_int.grb -rpn 0 -grib_out junk.template

# make netcdf file
../wgrib2/wgrib2 data/tmp_int.grb -nc3 -netcdf junk.nc

# convert netcdf to grb
../wgrib2/wgrib2 junk.template -import_netcdf junk.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk.grb

n=`../wgrib2/wgrib2 data/tmp_int.grb -var -lev -rpn "sto_1" -import_grib junk.grb -rpn "rcl_1:print_rms" | \
grep -v ":rpn=0:" | wc -l`

rm junk.grb junk.nc junk.template
if [ "$n" -eq 1 ] ; then
echo "success"
exit 0
else
exit 1
fi

28 changes: 28 additions & 0 deletions tests/run_wgrib2_netcdf4_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# This checks the use of AEC compression, only available if USE_NETCDF4 is turned on in CMake.
#
# Alyson Stahl, 4/22/24

set -e
set -x

# make template
../wgrib2/wgrib2 data/tmp_int.grb -rpn 0 -grib_out junk.template

# make netcdf file
../wgrib2/wgrib2 data/tmp_int.grb -nc4 -netcdf junk.nc

# convert netcdf to grb
../wgrib2/wgrib2 junk.template -import_netcdf junk.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk.grb

n=`../wgrib2/wgrib2 data/tmp_int.grb -var -lev -rpn "sto_1" -import_grib junk.grb -rpn "rcl_1:print_rms" | \
grep -v ":rpn=0:" | wc -l`

rm junk.grb junk.nc junk.template
if [ "$n" -eq 1 ] ; then
echo "success"
exit 0
else
exit 1
fi

8 changes: 4 additions & 4 deletions wgrib2/Config.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ int f_config(ARG0) {
#else
strcat(inv_out, "Netcdf package is not installed\n");
#endif
#if defined USE_NETCDF4
strcat(inv_out, "netcdf4: " USE_NETCDF4 "\n");
strcat(inv_out, "hdf5: " USE_HDF5 "\n");
#endif
//#if defined USE_NETCDF4
// strcat(inv_out, "netcdf4: " USE_NETCDF4 "\n");
// strcat(inv_out, "hdf5: " USE_HDF5 "\n");
//#endif
#ifdef USE_AEC
strcat(inv_out, USE_AEC " is installed\n" );
#endif
Expand Down

0 comments on commit a928f5d

Please sign in to comment.