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.
|
2014-08-28 09:03:16 +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
|
2023-03-18 16:00:11 +00:00
|
|
|
|
2024-07-12 08:51:12 +00:00
|
|
|
if [ $HAVE_GEOGRAPHY -eq 0 ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-03-18 16:00:11 +00:00
|
|
|
label="grib_iterator_test"
|
2023-07-19 15:58:28 +00:00
|
|
|
tempText=temp.$label.txt
|
|
|
|
tempGrib=temp.$label.grib
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
files="reduced_latlon_surface.grib1 \
|
|
|
|
reduced_gaussian_pressure_level.grib1 \
|
|
|
|
regular_gaussian_pressure_level.grib1 \
|
|
|
|
reduced_gaussian_sub_area.grib1 \
|
|
|
|
regular_latlon_surface.grib1 \
|
|
|
|
reduced_latlon_surface.grib2 \
|
|
|
|
reduced_gaussian_pressure_level.grib2 \
|
|
|
|
regular_gaussian_pressure_level.grib2 \
|
|
|
|
reduced_gaussian_sub_area.grib2 \
|
|
|
|
regular_latlon_surface.grib2"
|
|
|
|
|
2020-07-05 21:40:57 +00:00
|
|
|
for f in $files; do
|
2024-01-05 16:05:59 +00:00
|
|
|
file=${data_dir}/$f
|
|
|
|
# Must exclude the first line of grib_get_data which is "Latitude Longitude Value"
|
|
|
|
iterator_count=`${tools_dir}/grib_get_data -m 9999:missing -f -p centre -F "%g" -w count=1 $file | grep -v Lat |wc -l `
|
|
|
|
numberOfPoints=`${tools_dir}/grib_get -w count=1 -p numberOfPoints $file`
|
|
|
|
[ $numberOfPoints = ${iterator_count} ]
|
2013-03-25 12:04:10 +00:00
|
|
|
done
|
|
|
|
|
2023-07-19 15:58:28 +00:00
|
|
|
|
2021-02-03 17:25:51 +00:00
|
|
|
# ECC-822: Increase lat/lon decimals using default grib_get_data
|
2023-07-19 15:58:28 +00:00
|
|
|
${tools_dir}/grib_get_data -L%12.6f%11.5f ${data_dir}/regular_latlon_surface.grib2 > $tempText
|
|
|
|
|
|
|
|
${tools_dir}/grib_get_data -p shortName,level ${data_dir}/regular_latlon_surface.grib2 > $tempText
|
|
|
|
grep -q "Latitude Longitude Value shortName level" $tempText
|
2021-02-03 17:25:51 +00:00
|
|
|
|
2021-08-23 15:38:53 +00:00
|
|
|
|
2022-06-27 10:47:10 +00:00
|
|
|
# Run on a spectral field - should just print out its values
|
2023-07-19 15:58:28 +00:00
|
|
|
${tools_dir}/grib_get_data "$samp_dir/sh_ml_grib2.tmpl" > $tempText
|
|
|
|
|
|
|
|
|
2024-03-05 13:51:14 +00:00
|
|
|
# ECC-1781: Reduced Gaussian grid with rotation
|
|
|
|
# ---------------------------------------------
|
|
|
|
${tools_dir}/grib_get_data $samp_dir/reduced_rotated_gg_pl_320_grib1.tmpl > $tempText
|
|
|
|
${tools_dir}/grib_get_data $samp_dir/reduced_rotated_gg_pl_320_grib2.tmpl > $tempText
|
2024-03-06 10:01:00 +00:00
|
|
|
ECCODES_DEBUG=-1 ${tools_dir}/grib_get_data ${data_dir}/reduced_gaussian_sub_area.grib2 > $tempText 2>&1
|
|
|
|
grep -q "sub-area num points=53564" $tempText
|
2024-03-05 13:51:14 +00:00
|
|
|
|
|
|
|
|
2023-07-19 15:58:28 +00:00
|
|
|
# ECC-1642: badly encoded regular grids
|
|
|
|
# -------------------------------------
|
|
|
|
${tools_dir}/grib_set -s Ni=33 $samp_dir/GRIB2.tmpl $tempGrib
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_get_data $tempGrib > $tempText 2>&1
|
|
|
|
status=$?
|
2024-01-03 17:35:09 +00:00
|
|
|
set -e
|
2023-07-19 15:58:28 +00:00
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Grid description is wrong or inconsistent" $tempText
|
|
|
|
|
|
|
|
|
|
|
|
${tools_dir}/grib_set -s Ni=MISSING $samp_dir/GRIB2.tmpl $tempGrib
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_get_data $tempGrib > $tempText 2>&1
|
|
|
|
status=$?
|
2024-01-03 17:35:09 +00:00
|
|
|
set -e
|
2023-07-19 15:58:28 +00:00
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Grid description is wrong or inconsistent" $tempText
|
2022-06-27 10:47:10 +00:00
|
|
|
|
|
|
|
|
2024-01-03 17:35:09 +00:00
|
|
|
set +e
|
2023-08-26 12:52:06 +00:00
|
|
|
${tools_dir}/grib_ls -s Ni=missing -j -p latLonValues $data_dir/sample.grib2 > $tempText 2>&1
|
2024-01-03 17:35:09 +00:00
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
2024-10-22 09:04:41 +00:00
|
|
|
cat $tempText
|
2023-08-26 12:52:06 +00:00
|
|
|
grep -q "Key Ni cannot be 'missing' for a regular grid" $tempText
|
|
|
|
grep -q "latlonvalues: Unable to create iterator" $tempText
|
|
|
|
|
|
|
|
|
2024-01-03 17:35:09 +00:00
|
|
|
# -w option
|
2024-01-20 14:50:49 +00:00
|
|
|
input=$data_dir/tigge_cf_ecmwf.grib2
|
|
|
|
${tools_dir}/grib_get_data -w count=11 $input > $tempText
|
2024-01-03 17:35:09 +00:00
|
|
|
|
2024-01-20 14:50:49 +00:00
|
|
|
# Skip missing
|
|
|
|
input=$data_dir/simple_bitmap.grib
|
|
|
|
grib_check_key_equals $input bitmapPresent 1
|
|
|
|
${tools_dir}/grib_get_data $input > $tempText
|
|
|
|
|
|
|
|
# Print a double key
|
|
|
|
input=$data_dir/simple_bitmap.grib
|
|
|
|
${tools_dir}/grib_get_data -p referenceValue $input > $tempText
|
|
|
|
|
|
|
|
# Print a key with missing value
|
|
|
|
input=$data_dir/sample.grib2
|
|
|
|
${tools_dir}/grib_get_data -p scaleFactorOfEarthMajorAxis $input > $tempText
|
2024-01-03 17:35:09 +00:00
|
|
|
|
|
|
|
# ------------------------
|
|
|
|
# Bad key
|
|
|
|
# ------------------------
|
2024-01-20 14:50:49 +00:00
|
|
|
input=$data_dir/sample.grib2
|
|
|
|
${tools_dir}/grib_get_data -f -p nonexistingkey $input > $tempText
|
2024-01-03 17:35:09 +00:00
|
|
|
grep -q "not found" $tempText
|
|
|
|
|
|
|
|
|
2024-01-20 14:50:49 +00:00
|
|
|
# ------------------------
|
|
|
|
# Bad options
|
|
|
|
# ------------------------
|
|
|
|
input=$data_dir/sample.grib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_get_data -Lxxx $input > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Invalid lats/lons format option" $tempText
|
|
|
|
|
|
|
|
|
2024-01-03 17:35:09 +00:00
|
|
|
# ------------------------
|
|
|
|
# Unreadable message
|
|
|
|
# ------------------------
|
|
|
|
echo GRIB > $tempGrib
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_get_data $tempGrib > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
cat $tempText
|
|
|
|
grep -q "unreadable message" $tempText
|
|
|
|
|
2024-01-05 16:05:59 +00:00
|
|
|
# Legacy Gaussian sub-area (produced by old ProdGen)
|
|
|
|
# See ECC-906:
|
|
|
|
# grib_get_data not working correctly with old-style sub-areas of reduced grids
|
2024-01-20 14:50:49 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
2024-01-05 16:05:59 +00:00
|
|
|
input=$data_dir/reduced_gaussian_sub_area.legacy.grib1
|
2024-01-05 16:54:42 +00:00
|
|
|
if [ -f "$input" ]; then
|
|
|
|
${tools_dir}/grib_get_data $input > $tempText
|
|
|
|
grib_check_key_equals $input legacyGaussSubarea 1
|
|
|
|
|
|
|
|
ECCODES_DEBUG=-1 ${tools_dir}/grib_ls -p numberOfDataPoints $input > $tempText 2>&1
|
|
|
|
grep -q "LEGACY MODE activated. Count.=253982. changed to num values.=254139" $tempText
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Iterate with DEBUG on
|
|
|
|
input=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
|
|
|
|
ECCODES_DEBUG=1 ${tools_dir}/grib_get_data $input > $tempText 2>&1
|
|
|
|
grep "global num points=6114" $tempText
|
2024-01-03 17:35:09 +00:00
|
|
|
|
2024-08-26 15:00:43 +00:00
|
|
|
# Bad -s
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_get_data -s blah=999 $data_dir/sample.grib2 > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Key/value not found" $tempText
|
|
|
|
|
|
|
|
# Bad -p
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_get_data -f -p values $data_dir/sample.grib2 > $tempText 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Passed array is too small" $tempText
|
|
|
|
|
2024-01-03 17:35:09 +00:00
|
|
|
|
2022-06-27 10:47:10 +00:00
|
|
|
# Clean up
|
2023-07-19 15:58:28 +00:00
|
|
|
rm -f $tempText $tempGrib
|