From 265b4fc49b0b53465ef2558f2d26b7ef6f2b8826 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 27 Jul 2023 13:15:48 +0100 Subject: [PATCH] Tools: grib_to_netcdf test for GRIB_TO_NETCDF_CHECKVALIDTIME --- src/latlon.req | 1 - src/spectral.req | 1 - tests/grib_to_netcdf.sh | 19 +++++++++++++++++++ tools/grib_to_netcdf.cc | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) delete mode 100644 src/latlon.req delete mode 100644 src/spectral.req diff --git a/src/latlon.req b/src/latlon.req deleted file mode 100644 index bf3968bfa..000000000 --- a/src/latlon.req +++ /dev/null @@ -1 +0,0 @@ -ret,padding=0,level=500,grid=2/2,area=2/0/0/2,target=latlon.grib diff --git a/src/spectral.req b/src/spectral.req deleted file mode 100644 index 982ce8868..000000000 --- a/src/spectral.req +++ /dev/null @@ -1 +0,0 @@ -ret,padding=0,level=500,resol=21,target=spectral.grib diff --git a/tests/grib_to_netcdf.sh b/tests/grib_to_netcdf.sh index 5c1f13d35..9e2151b7c 100755 --- a/tests/grib_to_netcdf.sh +++ b/tests/grib_to_netcdf.sh @@ -135,5 +135,24 @@ ${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempDir > $tempText grep -q "Processing input file .*/subdir/regular_latlon_surface.grib2" $tempText rm -rf $tempDir +echo "Enable/Disable Checks ..." +# --------------------------------- +rm -f $tempNetcdf +input=${data_dir}/regular_latlon_surface.grib2 +cat $input $input > $tempGrib +# By default checks are enabled. So this should fail +set +e +${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Wrong number of fields" $tempText + +export GRIB_TO_NETCDF_CHECKVALIDTIME=0 +${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib +[ -f "$tempNetcdf" ] +unset GRIB_TO_NETCDF_CHECKVALIDTIME + + # Clean up rm -f $tempNetcdf $tempGrib $tempText diff --git a/tools/grib_to_netcdf.cc b/tools/grib_to_netcdf.cc index a4c95f5ed..fec300970 100644 --- a/tools/grib_to_netcdf.cc +++ b/tools/grib_to_netcdf.cc @@ -2107,8 +2107,12 @@ static void get_nc_options(const request* user_r) setup.history = history ? grib_context_strdup(ctx, (history)) : NULL; setup.unlimited = unlimited ? grib_context_strdup(ctx, ((unlimited))) : NULL; + setup.checkvalidtime = true; checkvalidtime_env = getenv("GRIB_TO_NETCDF_CHECKVALIDTIME"); - setup.checkvalidtime = checkvalidtime_env ? atol(checkvalidtime_env) : 1; + if (checkvalidtime_env) { + const long v = atol(checkvalidtime_env); + if (v == 0) setup.checkvalidtime = false; + } setup.mars_description = empty_request("MARS"); }