eccodes/tests/grib_ls_json.sh

65 lines
1.8 KiB
Bash
Raw Normal View History

2019-08-28 14:42:36 +00:00
#!/bin/sh
# Copyright 2005-2019 ECMWF.
#
# 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.
#
. ./include.sh
tempLog=temp.grib_ls_json.log
2019-08-28 14:42:36 +00:00
rm -f $tempLog
cd ${data_dir}
# Test a MISSING key
# --------------------
input=sample.grib2
${tools_dir}/grib_ls -j -p scaledValueOfEarthMajorAxis $input > $tempLog
grep -q '"scaledValueOfEarthMajorAxis": "MISSING"' $tempLog
2019-08-28 14:42:36 +00:00
# Test decoding a given key as string and integer
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
grep -q '"levelType": "pl"' $tempLog
grep -q '"levelType": 100' $tempLog
# Test decoding floating point key with format
# ---------------------------------------------
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
# Check JSON validity
# --------------------
# 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
grib_files=`cat ${data_dir}/grib_data_files.txt`
for file in ${grib_files}
do
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
# Clean up
rm -f $tempLog