From 9363da6570c42f2a34fa551196117c7b52c48e63 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 18 Dec 2019 17:16:33 +0000 Subject: [PATCH] ECC-1041: grib_to_netcdf gives unexpected parameter names --- tests/grib_to_netcdf.sh | 55 +++++++++++++++++++++++++++-------------- tools/grib_to_netcdf.c | 3 ++- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/tests/grib_to_netcdf.sh b/tests/grib_to_netcdf.sh index bb5fd53a0..617ac9f75 100755 --- a/tests/grib_to_netcdf.sh +++ b/tests/grib_to_netcdf.sh @@ -8,14 +8,36 @@ # virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. . ./include.sh -#set -x # Disable if autotools being used src_config=${src_dir}/config.h if [ -f ${src_config} ]; then - exit 0 + exit 0 fi +label="grib_to_netcdf_test" +tempGrib=temp.${label}.grib +tempNetcdf=temp.${label}.nc +tempText=temp.${label}.txt + +# Do we have ncdump? +NC_DUMPER="" +if command -v "ncdump" >/dev/null 2>&1; then + NC_DUMPER="ncdump" +fi + +# ECC-1041: One parameter with different expvers +# This has 5 messages, all 'tp'. Change the first message to have a different expver +input=${data_dir}/tp_ecmwf.grib +${tools_dir}/grib_set -w stepRange=12 -s experimentVersionNumber=0005 $input $tempGrib +${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib +if test "x$NC_DUMPER" != "x"; then + $NC_DUMPER -h $tempNetcdf > $tempText + grep -q "short tp_0005" $tempText + grep -q "short tp_0001" $tempText +fi + + grib_files="\ regular_latlon_surface.grib2 \ regular_latlon_surface.grib1 \ @@ -26,26 +48,23 @@ grib_files="\ ncf_types="NC_SHORT NC_INT NC_FLOAT NC_DOUBLE" -tmp_netcdf=tmp.ncf - # Go thru all the specified GRIB files and convert them to NetCDF -for dt in $ncf_types -do - for f in $grib_files - do - rm -f $tmp_netcdf - [ -f ${data_dir}/$f ] - ${tools_dir}/grib_to_netcdf -D $dt -o $tmp_netcdf ${data_dir}/$f >/dev/null - ${tools_dir}/grib_to_netcdf -T -o $tmp_netcdf ${data_dir}/$f >/dev/null - done +for dt in $ncf_types; do + for f in $grib_files; do + rm -f $tempNetcdf + [ -f ${data_dir}/$f ] + ${tools_dir}/grib_to_netcdf -D $dt -o $tempNetcdf ${data_dir}/$f >/dev/null + ${tools_dir}/grib_to_netcdf -T -o $tempNetcdf ${data_dir}/$f >/dev/null + done done # Try creating different kinds; netcdf3 classic and large # TODO: enable tests for netcdf4 formats too input=${data_dir}/regular_latlon_surface.grib2 -${tools_dir}/grib_to_netcdf -k 1 -o $tmp_netcdf $input >/dev/null -${tools_dir}/grib_to_netcdf -k 2 -o $tmp_netcdf $input >/dev/null -#${tools_dir}/grib_to_netcdf -k 3 -o $tmp_netcdf $input >/dev/null -#${tools_dir}/grib_to_netcdf -k 4 -o $tmp_netcdf $input >/dev/null +${tools_dir}/grib_to_netcdf -k 1 -o $tempNetcdf $input >/dev/null +${tools_dir}/grib_to_netcdf -k 2 -o $tempNetcdf $input >/dev/null +#${tools_dir}/grib_to_netcdf -k 3 -o $tempNetcdf $input >/dev/null +#${tools_dir}/grib_to_netcdf -k 4 -o $tempNetcdf $input >/dev/null -rm -f $tmp_netcdf + +rm -f $tempNetcdf $tempGrib $tempText diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index 176c18782..88c9f7a3f 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -3573,7 +3573,8 @@ static void find_nc_attributes(const request *subset_r, const request *user_r, n if(!isalpha(att->name[0])) { char buf[1048]; - sprintf(buf,"p%s",att->name); + const char *val = get_value(subset_r, "param", 0); + sprintf(buf,"%s_%s", (val ? val : "p"), att->name); strcpy(att->name,buf); } }