File: grib_ls_json.sh

package info (click to toggle)
eccodes 2.46.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 154,956 kB
  • sloc: cpp: 163,970; ansic: 26,310; sh: 22,006; f90: 6,854; perl: 6,361; python: 5,352; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 279; xml: 183; awk: 66
file content (139 lines) | stat: -rwxr-xr-x 4,102 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
# (C) Copyright 2005- 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.ctest.sh

tempLog=temp.grib_ls_json.log
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
# 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 ..."

cd ${data_dir}

# 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 "ERROR: grib_ls: JSON output should not have contained 'not_found'"
  exit 1
fi


# 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

# Test a MISSING key
# ----------------------------------------------------
input=sample.grib2
${tools_dir}/grib_ls -j -p scaledValueOfEarthMajorAxis $input > $tempLog
grep -q '"scaledValueOfEarthMajorAxis": "MISSING"' $tempLog


# Test decoding a given key as string and integer
# ----------------------------------------------------
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


# Check output from all our downloaded GRIBs
# ----------------------------------------------------
grib_files=`cat ${data_dir}/grib_data_files.txt`
for file in ${grib_files}; do
  if [ "$file" = "bad.grib" ]; then continue; fi
  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

# 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

# ECC-2089: The 'geography' namespace should not include 'bitmapPresent' and 'bitmap'
input=${data_dir}/missing_field.grib1
grib_check_key_equals $input bitmapPresent 1
${tools_dir}/grib_ls -j -n geography $input > $tempLog
set +e
grep bitmap $tempLog
status=$?
set -e
[ $status -ne 0 ]


# ECC-2210: grib_ls with '-j' and empty output
rm -f $tempLog
input=sample.grib2
${tools_dir}/grib_ls -j -w level=42 $input > $tempLog
if test "x$JSON_CHECK" != "x"; then
  json_xs -t none < $tempLog
fi
cat > $tempRef <<EOF
{ "messages" : [
]}
EOF
diff $tempRef $tempLog


# Clean up
rm -f $tempLog $tempOut $tempRef