2013-03-25 12:04:10 +00:00
|
|
|
#!/bin/sh
|
2020-01-28 14:32:34 +00:00
|
|
|
# (C) Copyright 2005- ECMWF.
|
2013-03-25 12:04:10 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the terms of the Apache Licence Version 2.0
|
|
|
|
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
2020-01-07 10:20:34 +00:00
|
|
|
#
|
2013-03-25 12:04:10 +00:00
|
|
|
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
|
|
|
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
|
|
|
|
2022-04-03 22:02:48 +00:00
|
|
|
. ./include.ctest.sh
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-07 10:20:34 +00:00
|
|
|
if [ $ECCODES_ON_WINDOWS -eq 1 ]; then
|
|
|
|
# m2-bash messes with the system path.
|
|
|
|
# %CONDA_PREFIX%\Library\usr\bin is converted to /usr/bin.
|
|
|
|
# %CONDA_PREFIX%\Library\bin is converted to /bin.
|
|
|
|
# However the contents of /bin and /usr/bin are identical.
|
|
|
|
# They both point to %CONDA_PREFIX%\Library\usr\bin!
|
|
|
|
# This means we're unable to access important dlls (like netcdf.dll) which live in
|
|
|
|
# %CONDA_PREFIX%\Library\bin.
|
|
|
|
# It is not obvious why this behaviour exists.
|
|
|
|
# We add this directory back to the path manually.
|
|
|
|
export PATH=$PATH:$CONDA_PREFIX/Library/bin
|
|
|
|
fi
|
|
|
|
|
2019-12-18 17:16:33 +00:00
|
|
|
label="grib_to_netcdf_test"
|
|
|
|
tempGrib=temp.${label}.grib
|
|
|
|
tempNetcdf=temp.${label}.nc
|
|
|
|
tempText=temp.${label}.txt
|
2023-01-22 14:52:09 +00:00
|
|
|
tempDir=temp.${label}.dir
|
2019-12-18 17:16:33 +00:00
|
|
|
|
2021-08-14 20:11:13 +00:00
|
|
|
have_netcdf4=0
|
|
|
|
|
2019-12-18 17:16:33 +00:00
|
|
|
# Do we have ncdump?
|
|
|
|
NC_DUMPER=""
|
|
|
|
if command -v "ncdump" >/dev/null 2>&1; then
|
|
|
|
NC_DUMPER="ncdump"
|
|
|
|
fi
|
|
|
|
|
2023-10-10 17:31:23 +00:00
|
|
|
|
2023-10-10 20:46:57 +00:00
|
|
|
echo "Test 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
|
2021-08-14 20:11:13 +00:00
|
|
|
fi
|
|
|
|
|
2023-10-10 20:46:57 +00:00
|
|
|
echo "Test HDF5 decoding ..."
|
|
|
|
# ---------------------------
|
|
|
|
# Note: this is only available in NetCDF-4. So need to check if the command worked with -k3
|
|
|
|
input=${data_dir}/sample.grib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_to_netcdf -k3 -o $tempNetcdf $input 2>/dev/null
|
|
|
|
stat=$?
|
|
|
|
set -e
|
|
|
|
if [ $stat -eq 0 ]; then
|
|
|
|
have_netcdf4=1
|
|
|
|
${tools_dir}/grib_dump -TA -O $tempNetcdf
|
|
|
|
res=`${tools_dir}/grib_get -TA -p identifier $tempNetcdf`
|
|
|
|
[ "$res" = "HDF5" ]
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2013-10-01 09:19:35 +00:00
|
|
|
grib_files="\
|
2018-05-22 16:51:28 +00:00
|
|
|
regular_latlon_surface.grib2 \
|
|
|
|
regular_latlon_surface.grib1 \
|
|
|
|
regular_gaussian_model_level.grib1 \
|
|
|
|
regular_gaussian_pressure_level.grib2 \
|
|
|
|
regular_gaussian_surface.grib1 \
|
|
|
|
missing.grib2"
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2022-02-05 20:40:45 +00:00
|
|
|
ncf_types="NC_INT NC_FLOAT NC_DOUBLE"
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
# Go thru all the specified GRIB files and convert them to NetCDF
|
2019-12-18 17:16:33 +00:00
|
|
|
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
|
2013-03-25 12:04:10 +00:00
|
|
|
done
|
2015-01-07 11:48:17 +00:00
|
|
|
|
2021-08-15 21:15:30 +00:00
|
|
|
echo "Test creating different kinds ..."
|
2021-01-05 16:39:48 +00:00
|
|
|
# ------------------------------------------------------------------
|
2015-01-07 11:48:17 +00:00
|
|
|
input=${data_dir}/regular_latlon_surface.grib2
|
2019-12-18 17:16:33 +00:00
|
|
|
${tools_dir}/grib_to_netcdf -k 1 -o $tempNetcdf $input >/dev/null
|
|
|
|
${tools_dir}/grib_to_netcdf -k 2 -o $tempNetcdf $input >/dev/null
|
2021-08-14 20:11:13 +00:00
|
|
|
if [ $have_netcdf4 -eq 1 ]; then
|
|
|
|
${tools_dir}/grib_to_netcdf -k 3 -o $tempNetcdf $input >/dev/null
|
|
|
|
${tools_dir}/grib_to_netcdf -k 4 -o $tempNetcdf $input >/dev/null
|
|
|
|
fi
|
2019-12-18 17:16:33 +00:00
|
|
|
|
2021-08-15 21:15:30 +00:00
|
|
|
echo "Test shuffle and deflate ..."
|
|
|
|
# ---------------------------------
|
2021-08-15 21:20:50 +00:00
|
|
|
if [ $have_netcdf4 -eq 1 ]; then
|
|
|
|
input=${data_dir}/sst_globus0083.grib
|
|
|
|
${tools_dir}/grib_to_netcdf -s -d9 -k4 -o $tempNetcdf $input
|
|
|
|
fi
|
2021-08-15 21:15:30 +00:00
|
|
|
|
2021-01-05 16:39:48 +00:00
|
|
|
echo "Test ECC-1060 ..."
|
|
|
|
# ----------------------
|
2020-01-20 13:50:14 +00:00
|
|
|
sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
${tools_dir}/grib_set -s productDefinitionTemplateNumber=30 $sample2 $tempGrib
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib
|
|
|
|
${tools_dir}/grib_set -s productDefinitionTemplateNumber=31 $sample2 $tempGrib
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib
|
|
|
|
|
2024-05-18 16:25:22 +00:00
|
|
|
ECCODES_DEBUG=-1 ${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib
|
|
|
|
|
|
|
|
|
|
|
|
# The -u option
|
|
|
|
input=${data_dir}/sample.grib2
|
|
|
|
${tools_dir}/grib_to_netcdf -u time -o $tempNetcdf $input
|
|
|
|
|
|
|
|
|
2021-01-05 16:39:48 +00:00
|
|
|
echo "Test different resolutions ..."
|
|
|
|
# ------------------------------------
|
|
|
|
# This should fail as messages have different resolutions
|
|
|
|
tempGrib2=temp.${label}.2.grib
|
|
|
|
${tools_dir}/grib_set -s Ni=17,Nj=32,step=12 $ECCODES_SAMPLES_PATH/regular_ll_pl_grib2.tmpl $tempGrib
|
|
|
|
cat $ECCODES_SAMPLES_PATH/regular_ll_pl_grib2.tmpl $tempGrib > $tempGrib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib2 2>$tempText
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status = 1 ]
|
|
|
|
grep -q "GRIB message 2 has different resolution" $tempText
|
|
|
|
|
|
|
|
rm -f $tempGrib2
|
2015-01-07 11:48:17 +00:00
|
|
|
|
2023-01-22 14:52:09 +00:00
|
|
|
echo "Test directory traversal ..."
|
|
|
|
# ------------------------------------
|
|
|
|
rm -f $tempNetcdf
|
|
|
|
mkdir -p $tempDir/subdir
|
|
|
|
cp ${data_dir}/regular_latlon_surface.grib2 $tempDir/subdir
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempDir > $tempText
|
|
|
|
[ -f "$tempNetcdf" ]
|
|
|
|
grep -q "Processing input file .*/subdir/regular_latlon_surface.grib2" $tempText
|
|
|
|
rm -rf $tempDir
|
|
|
|
|
2023-07-27 12:15:48 +00:00
|
|
|
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
|
|
|
|
|
2024-03-08 12:21:39 +00:00
|
|
|
|
|
|
|
echo "Not a regular grid ..."
|
|
|
|
# --------------------------
|
2023-10-30 16:35:13 +00:00
|
|
|
input=${data_dir}/reduced_gaussian_pressure_level.grib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $input > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "not on a regular lat/lon grid or on a regular Gaussian grid" $tempText
|
|
|
|
|
|
|
|
|
2024-03-08 12:21:39 +00:00
|
|
|
# ECC-1783: No error message when input file has invalid fields
|
|
|
|
input=$data_dir/bad.grib
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $input > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Wrong message length" $tempText
|
|
|
|
|
|
|
|
|
2024-05-18 16:25:22 +00:00
|
|
|
# Non-GRIB input
|
|
|
|
input=$data_dir/bufr/aaen_55.bufr
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $input > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Input does not contain any field" $tempText
|
|
|
|
|
|
|
|
|
|
|
|
# Bad reference date
|
|
|
|
input=$data_dir/sample.grib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_to_netcdf -Rxxx -o $tempNetcdf $input > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Invalid reference date" $tempText
|
|
|
|
|
|
|
|
|
2024-03-08 12:21:39 +00:00
|
|
|
# Validity time check
|
2023-07-27 12:15:48 +00:00
|
|
|
export GRIB_TO_NETCDF_CHECKVALIDTIME=0
|
|
|
|
${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib
|
|
|
|
[ -f "$tempNetcdf" ]
|
|
|
|
unset GRIB_TO_NETCDF_CHECKVALIDTIME
|
|
|
|
|
|
|
|
|
2020-01-20 13:50:14 +00:00
|
|
|
# Clean up
|
2019-12-18 17:16:33 +00:00
|
|
|
rm -f $tempNetcdf $tempGrib $tempText
|