File: grib_dump.sh

package info (click to toggle)
eccodes 2.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 154,404 kB
  • sloc: cpp: 162,953; ansic: 26,308; sh: 21,742; f90: 6,854; perl: 6,361; python: 5,172; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 283; xml: 183; awk: 66
file content (200 lines) | stat: -rwxr-xr-x 5,536 bytes parent folder | download | duplicates (2)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/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

REDIRECT=/dev/null

label="grib_dump_test"
temp=temp.$label.txt

if [ $HAVE_MEMFS -eq 1 ]; then
    unset ECCODES_DEFINITION_PATH
    unset ECCODES_SAMPLES_PATH
fi

files="
constant_field.grib1
lfpw.grib1
missing_field.grib1
reduced_gaussian_lsm.grib1
reduced_gaussian_model_level.grib1
reduced_gaussian_pressure_level.grib1
reduced_gaussian_pressure_level_constant.grib1
reduced_gaussian_sub_area.grib1
reduced_gaussian_surface.grib1
reduced_latlon_surface.grib1
reduced_latlon_surface_constant.grib1
reference_ensemble_mean.grib1
reference_stdev.grib1
regular_gaussian_model_level.grib1
regular_gaussian_pressure_level.grib1
regular_gaussian_pressure_level_constant.grib1
regular_gaussian_surface.grib1
regular_latlon_surface.grib1
regular_latlon_surface_constant.grib1
second_ord_rbr.grib1
small_ensemble.grib1
spectral_complex.grib1
spherical_model_level.grib1
spherical_pressure_level.grib1
constant_field.grib2
gfs.c255.grib2
jpeg.grib2
missing.grib2
multi.grib2
multi_created.grib2
reduced_gaussian_model_level.grib2
reduced_gaussian_pressure_level.grib2
reduced_gaussian_pressure_level_constant.grib2
reduced_gaussian_sub_area.grib2
reduced_gaussian_surface.grib2
reduced_gaussian_surface_jpeg.grib2
reduced_latlon_surface.grib2
reduced_latlon_surface_constant.grib2
regular_gaussian_model_level.grib2
regular_gaussian_pressure_level.grib2
regular_gaussian_pressure_level_constant.grib2
regular_gaussian_surface.grib2
regular_latlon_surface.grib2
regular_latlon_surface_constant.grib2
sample.grib2
spherical_model_level.grib2
spherical_pressure_level.grib2
test_uuid.grib2
tigge_af_ecmwf.grib2
tigge_cf_ecmwf.grib2
v.grib2
"

for file in $files; do
   if [ -f ${data_dir}/$file ]; then
      ${tools_dir}/grib_dump -O ${data_dir}/$file 2> $REDIRECT > $REDIRECT
   fi
done


# Test for dumping a section
# ---------------------------
if [ $HAVE_JPEG -eq 0 ]; then
    # No JPEG decoding enabled so dumping section 7 will issue errors
    # but dumping non-data sections should work
    file=${data_dir}/jpeg.grib2
    ${tools_dir}/grib_dump -O -p section_3,section_4 $file > $temp 2>&1
    set +e
    # Look for the word ERROR in output. We should not find any
    grep -q 'ERROR ' $temp
    if [ $? -eq 0 ]; then
        echo "grib_dump on $file: found string ERROR in grib_dump output!"
        cat $temp
        exit 1
    fi
    set -e
fi

# Use -s option
file=$data_dir/sample.grib2
${tools_dir}/grib_dump -s year=1909 $file > $temp 2>&1
grep -q "dataDate = 19090206" $temp

# Skip handle
file=$data_dir/sample.grib2
${tools_dir}/grib_dump -w count=4 $file > $temp 2>&1

file=$data_dir/sample.grib2
ECCODES_DEBUG=1 ${tools_dir}/grib_dump $file > $temp 2>&1

# Check the right number of sections are listed in the dump
# ---------------------------------------------------------
file=$data_dir/sample.grib2
${tools_dir}/grib_dump -O $file > $temp
count=$(grep -c SECTION_ $temp)
[ $count -eq 8 ]

file=$data_dir/test_uuid.grib2
${tools_dir}/grib_dump -wcount=1 -O $file > $temp
count=$(grep -c SECTION_ $temp)
[ $count -eq 7 ]

file=$data_dir/regular_gaussian_model_level.grib1
${tools_dir}/grib_dump -O $file > $temp
count=$(grep -c SECTION_ $temp)
[ $count -eq 4 ]

file=$data_dir/missing_field.grib1
${tools_dir}/grib_dump -O $file > $temp
count=$(grep -c SECTION_ $temp)
[ $count -eq 5 ]

# Repeated key numberOfSection
file=$data_dir/sample.grib2
${tools_dir}/grib_dump -O $file > $temp
grep -q "numberOfSection = 1" $temp
grep -q "numberOfSection = 3" $temp
grep -q "numberOfSection = 4" $temp
grep -q "numberOfSection = 5" $temp
grep -q "numberOfSection = 7" $temp


# Dump long array
# ----------------
input=$data_dir/lfpw.grib1
${tools_dir}/grib_dump -w count=1 -p SPD $input


# ECC-1749: grib_dump: No gap between offsets and key name
#-----------------------------------------------------------
file=$data_dir/sst_globus0083.grib
${tools_dir}/grib_dump -O $file > $temp 2>&1
grep -q "12-10227752 codedValues" $temp

# Code tables and code flags
#-----------------------------------------------------------
file=$data_dir/sample.grib2
${tools_dir}/grib_dump -Ot $file > $temp 2>&1
fgrep -q "codetable (int) typeOfFirstFixedSurface = 103 [Specified height level above ground (m)  (grib2/tables/4/4.5.table) ]" $temp
fgrep -q "codeflag (int) resolutionAndComponentFlags = 48 [00110000 (grib2/tables/4/3.3.table) ]" $temp
fgrep -q "codeflag (int) scanningMode = 0 [00000000 (grib2/tables/4/3.4.table) ]" $temp

# Error conditions
#-----------------------------------------------------------
file=$data_dir/sample.grib2
${tools_dir}/grib_dump -p nonexist $file > $temp 2>&1
grep -q "Key/value not found" $temp

# Invalid options
set +e
${tools_dir}/grib_dump -jOD $file > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]


# Unreadable message
#-----------------------------------------------------------
tempOut=temp.$label.out
echo GRIB > $temp

set +e
${tools_dir}/grib_dump $temp > $tempOut 2>&1
status=$?
set -e
grep -q "unreadable message" $tempOut

set +e
${tools_dir}/grib_dump -j $temp > $tempOut 2>&1
status=$?
set -e
grep -q "unreadable message" $tempOut

rm -f $tempOut

# Clean up
rm -f $temp