Skip to content

Commit 7264649

Browse files
Adding tests with netcdf (#130)
* 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 * updated some file names * temporarily adding flags to developer workflow to view test coverage * forgot to install libaec in last commit * more tests * Update run_wgrib2_netcdf4_tests.sh * adding more tests * removed recent test - wasn't working * fixed comments * more tests --------- Co-authored-by: Edward Hartnett <38856240+edwardhartnett@users.noreply.github.com>
1 parent ef98afb commit 7264649

File tree

8 files changed

+272938
-25
lines changed

8 files changed

+272938
-25
lines changed

.github/workflows/developer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: |
2929
sudo apt-get update
3030
sudo apt-get install libnetcdf-dev libnetcdff-dev netcdf-bin pkg-config
31-
sudo apt-get install libpng-dev autotools-dev autoconf gcovr
31+
sudo apt-get install libpng-dev autotools-dev libaec-dev autoconf gcovr
3232
3333
- name: cache-jasper
3434
id: cache-jasper
@@ -105,7 +105,7 @@ jobs:
105105
export CFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
106106
export FCFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
107107
export FFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
108-
cmake .. -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data
108+
cmake .. -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data -DUSE_NETCDF4=ON -DUSE_AEC=ON
109109
make VERBOSE=1
110110
ctest --verbose --output-on-failure --rerun-failed
111111
gcovr --root .. -v --html-details --exclude ../tests --exclude CMakeFiles --print-summary -o test-coverage.html &> /dev/null

tests/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ copy_test_data(gdaswave.t00z.wcoast.0p16.f000.grib2)
9292
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2.inv)
9393
copy_test_data(ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt)
9494
copy_test_data(ref_simple_packing.grib2)
95-
copy_test_data(ref_WW3_Regional_US_West_Coast_20220718_0000.grib2.inv)
96-
copy_test_data(tmp_int.grb)
9795
copy_test_data(gdas.t12z.pgrb2.1p00.anl.75r.grib2)
9896
copy_test_data(ref_wind.gdas.t12z.pgrb2.1p00.anl.75r.grib2.inv)
9997
copy_test_data(ref_uv.gdas.t12z.pgrb2.1p00.anl.75r.grib2.inv)
@@ -114,6 +112,9 @@ shell_test(run_wgrib2_rpn_tests)
114112

115113
if (USE_NETCDF4)
116114
shell_test(run_wgrib2_netcdf4_tests)
115+
copy_test_data(ref_ncdump4.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt)
116+
copy_test_data(ref_tablenc.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt)
117+
copy_test_data(nctab.table)
117118
endif()
118119
if (USE_NETCDF3)
119120
shell_test(run_wgrib2_netcdf3_tests)

tests/data/nctab.table

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$nlev 5
2+
$levs 0.1 0.07 0.04 0.02 0.01
3+
$grads 1
4+
UGRD:*:u
5+
VGRD:*:v
6+
TMP:*:temp
7+
HGT:*:hgtprs
8+
RH:*:rh

tests/data/ref_ncdump4.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt

Lines changed: 272829 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
netcdf tablenc {
2+
dimensions:
3+
latitude = 181 ;
4+
longitude = 360 ;
5+
time = UNLIMITED ; // (1 currently)
6+
plevel = 5 ;
7+
variables:
8+
double latitude(latitude) ;
9+
latitude:units = "degrees_north" ;
10+
latitude:long_name = "latitude" ;
11+
double longitude(longitude) ;
12+
longitude:units = "degrees_east" ;
13+
longitude:long_name = "longitude" ;
14+
double time(time) ;
15+
time:units = "seconds since 1970-01-01 00:00:00.0 0:00" ;
16+
time:long_name = "verification time generated by wgrib2 function verftime()" ;
17+
time:reference_time = 1714132800. ;
18+
time:reference_time_type = 1 ;
19+
time:reference_date = "2024.04.26 12:00:00 UTC" ;
20+
time:reference_time_description = "analyses, reference date is fixed" ;
21+
time:time_step_setting = "auto" ;
22+
time:time_step = 0. ;
23+
float plevel(plevel) ;
24+
plevel:lev_type = 100 ;
25+
plevel:units = "mb" ;
26+
plevel:long_name = "pressure level" ;
27+
plevel:_FillValue = 9.999e+20f ;
28+
float hgtprs(time, plevel, latitude, longitude) ;
29+
hgtprs:_FillValue = 9.999e+20f ;
30+
hgtprs:short_name = "hgtprs" ;
31+
hgtprs:long_name = "Geopotential Height" ;
32+
hgtprs:level = "pressure level" ;
33+
hgtprs:units = "m" ;
34+
float temp(time, plevel, latitude, longitude) ;
35+
temp:_FillValue = 9.999e+20f ;
36+
temp:short_name = "temp" ;
37+
temp:long_name = "Temperature" ;
38+
temp:level = "pressure level" ;
39+
temp:units = "K" ;
40+
float rh(time, plevel, latitude, longitude) ;
41+
rh:_FillValue = 9.999e+20f ;
42+
rh:short_name = "rh" ;
43+
rh:long_name = "Relative Humidity" ;
44+
rh:level = "pressure level" ;
45+
rh:units = "percent" ;
46+
float u(time, plevel, latitude, longitude) ;
47+
u:_FillValue = 9.999e+20f ;
48+
u:short_name = "u" ;
49+
u:long_name = "U-Component of Wind" ;
50+
u:level = "pressure level" ;
51+
u:units = "m/s" ;
52+
float v(time, plevel, latitude, longitude) ;
53+
v:_FillValue = 9.999e+20f ;
54+
v:short_name = "v" ;
55+
v:long_name = "V-Component of Wind" ;
56+
v:level = "pressure level" ;
57+
v:units = "m/s" ;
58+
59+
// global attributes:
60+
:Conventions = "COARDS" ;
61+
:History = "created by wgrib2" ;
62+
:GRIB2_grid_template = 0 ;
63+
}

tests/data/tmp_int.grb

-95.6 KB
Binary file not shown.

tests/run_wgrib2_netcdf3_tests.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
#!/bin/sh
2-
# This checks the use of AEC compression, only available if USE_NETCDF4 is turned on in CMake.
2+
# This checks the use of netcdf, only available if USE_NETCDF4 is turned on in CMake.
33
#
44
# Alyson Stahl, 4/22/24
55

66
set -e
77
set -x
88

9+
echo "*** Testing converting from grib to netcdf to grib"
910
# make template
10-
../wgrib2/wgrib2 data/tmp_int.grb -rpn 0 -grib_out junk.template
11+
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -rpn 0 -grib_out junk_netcdf.template
1112

1213
# make netcdf file
13-
../wgrib2/wgrib2 data/tmp_int.grb -nc3 -netcdf junk.nc
14+
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -nc3 -netcdf junk_netcdf.nc
1415

1516
# convert netcdf to grb
16-
../wgrib2/wgrib2 junk.template -import_netcdf junk.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk.grb
17+
../wgrib2/wgrib2 junk_netcdf.template -import_netcdf junk_netcdf.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk_netcdf.grb
1718

18-
n=`../wgrib2/wgrib2 data/tmp_int.grb -var -lev -rpn "sto_1" -import_grib junk.grb -rpn "rcl_1:print_rms" | \
19+
n=`../wgrib2/wgrib2 data/ref_simple_packing.grib2 -var -lev -rpn "sto_1" -import_grib junk_netcdf.grb -rpn "rcl_1:print_rms" | \
1920
grep -v ":rpn=0:" | wc -l`
2021

21-
rm junk.grb junk.nc junk.template
22-
if [ "$n" -eq 1 ] ; then
23-
echo "success"
24-
exit 0
25-
else
22+
rm junk_netcdf.grb junk_netcdf.nc junk_netcdf.template
23+
if [ "$n" -ne 1 ] ; then
2624
exit 1
2725
fi
2826

27+
echo "*** SUCCESS!"
28+
exit 0

tests/run_wgrib2_netcdf4_tests.sh

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
#!/bin/sh
2-
# This checks the use of AEC compression, only available if USE_NETCDF4 is turned on in CMake.
2+
# This checks the use of netcdf, only available if USE_NETCDF4 is turned on in CMake.
33
#
44
# Alyson Stahl, 4/22/24
55

66
set -e
7-
set -x
87

8+
echo "*** Testing converting from grib to netcdf to grib"
99
# make template
10-
../wgrib2/wgrib2 data/tmp_int.grb -rpn 0 -grib_out junk.template
10+
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -rpn 0 -grib_out junk_netcdf.template
1111

1212
# make netcdf file
13-
../wgrib2/wgrib2 data/tmp_int.grb -nc4 -netcdf junk.nc
13+
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -nc4 -netcdf junk_netcdf.nc
1414

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

18-
n=`../wgrib2/wgrib2 data/tmp_int.grb -var -lev -rpn "sto_1" -import_grib junk.grb -rpn "rcl_1:print_rms" | \
18+
n=`../wgrib2/wgrib2 data/ref_simple_packing.grib2 -var -lev -rpn "sto_1" -import_grib junk_netcdf.grb -rpn "rcl_1:print_rms" | \
1919
grep -v ":rpn=0:" | wc -l`
2020

21-
rm junk.grb junk.nc junk.template
22-
if [ "$n" -eq 1 ] ; then
23-
echo "success"
24-
exit 0
25-
else
21+
rm junk_netcdf.grb junk_netcdf.nc junk_netcdf.template
22+
if [ "$n" -ne 1 ] ; then
2623
exit 1
2724
fi
2825

26+
echo "*** Testing converting from grib to netcdf with variables stored in 3D structure"
27+
../wgrib2/wgrib2 data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -nc_nlev 7 -netcdf junk_netcdf.nc -match ":(UGRD|VGRD|HGT|TMP):"
28+
ncdump -v HGT,TMP,UGRD,VGRD junk_netcdf.nc > netcdf.txt
29+
touch netcdf.txt
30+
diff -w data/ref_ncdump4.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt netcdf.txt
31+
32+
33+
echo "*** Testing converting from grib to netcdf using table"
34+
../wgrib2/wgrib2 data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -match ":(UGRD|VGRD|TMP|HGT|RH):" -nc_table data/nctab.table -netcdf tablenc.nc
35+
ncdump -h tablenc.nc > tablenc.txt
36+
touch tablenc.txt
37+
diff -w tablenc.txt data/ref_tablenc.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt
38+
39+
echo "*** SUCCESS!"
40+
exit 0

0 commit comments

Comments
 (0)