2019-08-28 14:42:36 +00:00
|
|
|
#!/bin/sh
|
2020-01-28 14:32:34 +00:00
|
|
|
# (C) Copyright 2005- ECMWF.
|
2019-08-28 14:42:36 +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.
|
|
|
|
#
|
|
|
|
# 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
|
2019-08-28 14:42:36 +00:00
|
|
|
|
2019-08-28 15:44:07 +00:00
|
|
|
tempLog=temp.grib_ls_json.log
|
2019-08-29 11:13:41 +00:00
|
|
|
tempOut=temp.grib_ls_json.txt
|
|
|
|
tempRef=temp.grib_ls_json.ref
|
|
|
|
rm -f $tempLog $tempOut $tempRef
|
|
|
|
|
|
|
|
# Decide if we have the JSON verifier commandline utility
|
|
|
|
JSON_VERIF="json_xs"
|
|
|
|
JSON_CHECK=""
|
|
|
|
if command -v $JSON_VERIF >/dev/null 2>&1; then
|
|
|
|
JSON_CHECK=$JSON_VERIF
|
|
|
|
fi
|
2020-06-01 16:00:13 +00:00
|
|
|
# ECC-1119: Check the json_xs command actually works!
|
|
|
|
set +e
|
|
|
|
echo '[]' | json_xs > /dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then JSON_CHECK=""; fi
|
|
|
|
set -e
|
|
|
|
echo "Using $JSON_CHECK ..."
|
2019-08-28 14:42:36 +00:00
|
|
|
|
|
|
|
cd ${data_dir}
|
|
|
|
|
2019-08-28 17:00:32 +00:00
|
|
|
# Check there is no "not_found" for a mixed GRIB file
|
|
|
|
# ----------------------------------------------------
|
|
|
|
input=mixed.grib
|
|
|
|
# Normally dataType will not exist for the kwbc messages so we should
|
|
|
|
# get several 'not_found' strings
|
|
|
|
${tools_dir}/grib_ls $input > $tempLog
|
|
|
|
grep -q 'not_found' $tempLog
|
|
|
|
|
|
|
|
# With the JSON option grib_ls will not use the first message's keys
|
|
|
|
# so there should not be any instances of 'not_found'
|
|
|
|
${tools_dir}/grib_ls -j $input > $tempLog
|
|
|
|
if grep -q 'not_found' $tempLog; then
|
|
|
|
echo "grib_ls: JSON output should not have contained 'not_found'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-08-29 11:13:41 +00:00
|
|
|
|
|
|
|
# Test ordering
|
|
|
|
# ----------------------------------------------------
|
|
|
|
input=high_level_api.grib2
|
|
|
|
${tools_dir}/grib_ls -j -B'step:i desc' $input > $tempLog
|
|
|
|
|
|
|
|
if test "x$JSON_CHECK" != "x"; then
|
|
|
|
json_xs -t none < $tempLog
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep stepRange $tempLog > $tempOut
|
|
|
|
cat > $tempRef <<EOF
|
|
|
|
"stepRange": 24,
|
|
|
|
"stepRange": 18,
|
|
|
|
"stepRange": 12,
|
|
|
|
"stepRange": 6,
|
|
|
|
"stepRange": 0,
|
|
|
|
EOF
|
|
|
|
diff $tempRef $tempOut
|
|
|
|
|
2019-08-28 14:42:36 +00:00
|
|
|
# Test a MISSING key
|
2019-08-29 11:13:41 +00:00
|
|
|
# ----------------------------------------------------
|
2019-08-28 14:42:36 +00:00
|
|
|
input=sample.grib2
|
|
|
|
${tools_dir}/grib_ls -j -p scaledValueOfEarthMajorAxis $input > $tempLog
|
2019-08-28 15:44:07 +00:00
|
|
|
grep -q '"scaledValueOfEarthMajorAxis": "MISSING"' $tempLog
|
2019-08-28 14:42:36 +00:00
|
|
|
|
|
|
|
|
2019-08-28 15:44:07 +00:00
|
|
|
# Test decoding a given key as string and integer
|
2019-08-29 11:13:41 +00:00
|
|
|
# ----------------------------------------------------
|
2019-08-28 14:42:36 +00:00
|
|
|
input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
|
|
|
${tools_dir}/grib_ls -j -p levelType,levelType:i $input > $tempLog
|
2019-08-28 15:44:07 +00:00
|
|
|
grep -q '"levelType": "pl"' $tempLog
|
|
|
|
grep -q '"levelType": 100' $tempLog
|
|
|
|
|
|
|
|
|
|
|
|
# Test decoding floating point key with format
|
2019-08-29 11:13:41 +00:00
|
|
|
# ----------------------------------------------------
|
2019-08-28 15:44:07 +00:00
|
|
|
input=$ECCODES_SAMPLES_PATH/reduced_gg_pl_128_grib2.tmpl
|
|
|
|
${tools_dir}/grib_ls -j -p latitudeOfLastGridPointInDegrees $input > $tempLog
|
|
|
|
grep -q '"latitudeOfLastGridPointInDegrees": -89.4628' $tempLog
|
|
|
|
|
|
|
|
${tools_dir}/grib_ls -F%.3f -j -p latitudeOfLastGridPointInDegrees $input > $tempLog
|
|
|
|
grep -q '"latitudeOfLastGridPointInDegrees": -89.463' $tempLog
|
2019-08-28 14:42:36 +00:00
|
|
|
|
|
|
|
|
2019-08-29 11:13:41 +00:00
|
|
|
# Check output from all our downloaded GRIBs
|
|
|
|
# ----------------------------------------------------
|
2019-08-28 14:42:36 +00:00
|
|
|
grib_files=`cat ${data_dir}/grib_data_files.txt`
|
2020-03-03 17:28:56 +00:00
|
|
|
for file in ${grib_files}; do
|
|
|
|
if [ "$file" = "bad.grib" ]; then continue; fi
|
2019-08-28 14:42:36 +00:00
|
|
|
input=${data_dir}/$file
|
|
|
|
${tools_dir}/grib_ls -j $input > $tempLog
|
|
|
|
if test "x$JSON_CHECK" != "x"; then
|
|
|
|
json_xs -t none < $tempLog
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-05-17 15:05:10 +00:00
|
|
|
# ECC-1243: listing the geography namespace
|
|
|
|
# -----------------------------------------
|
|
|
|
${tools_dir}/grib_ls -j -n geography ${data_dir}/reduced_latlon_surface.grib2 > $tempLog
|
|
|
|
if test "x$JSON_CHECK" != "x"; then
|
|
|
|
json_xs -t none < $tempLog
|
|
|
|
fi
|
|
|
|
|
2019-08-28 14:42:36 +00:00
|
|
|
|
|
|
|
# Clean up
|
2019-08-29 11:13:41 +00:00
|
|
|
rm -f $tempLog $tempOut $tempRef
|