File: grib_set_fail.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 (210 lines) | stat: -rwxr-xr-x 6,240 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
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
201
202
203
204
205
206
207
208
209
210
#!/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

label="grib_set_fail_test"

outfile=${data_dir}/temp.$label.grib
temp=${data_dir}/temp.$label.out

infile=${data_dir}/regular_gaussian_surface.grib2


# Set without -s
# ----------------------------------------------------
set +e
${tools_dir}/grib_set -p levtype $infile $outfile > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "provide some keys to set" $temp

# Set with empty -s
# ----------------------------------------------------
set +e
${tools_dir}/grib_set -s '' $infile $outfile > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "provide some keys to set" $temp

# Out-of-bounds value
# ----------------------------------------------------
input=${data_dir}/reduced_gaussian_sub_area.grib2
set +e
${tools_dir}/grib_set -s perturbationNumber=1000 $input $outfile 2>$temp
status=$?
set -e
[ $status -ne 0 ]
grep -q "Trying to encode value of 1000 but the maximum allowable value is 255 (number of bits=8)" $temp

# Negative value for an unsigned key
# ----------------------------------------------------
input=${data_dir}/reduced_gaussian_sub_area.grib2
set +e
${tools_dir}/grib_set -s perturbationNumber=-1 $input $outfile 2>$temp
status=$?
set -e
[ $status -ne 0 ]
grep -q "Trying to encode a negative value of -1 for key of type unsigned" $temp

# Bad value for -d
# ----------------
input=${data_dir}/reduced_gaussian_sub_area.grib2
set +e
${tools_dir}/grib_set -d hello $input $outfile 2>$temp
status=$?
set -e
[ $status -ne 0 ]
grep -q "Invalid number" $temp


# ECC-1605: Out-of-bounds value for signed keys
# ----------------------------------------------------
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
    input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
    set +e
    ${tools_dir}/grib_set -s forecastTime=2147483648 $input $outfile 2>$temp
    status=$?
    set -e
    [ $status -ne 0 ]
    grep -q "Trying to encode value of 2147483648 but the allowable range is -2147483648 to 2147483647" $temp

    set +e
    ${tools_dir}/grib_set -s forecastTime=-2147483650 $input $outfile 2>$temp
    status=$?
    set -e
    [ $status -ne 0 ]
fi


# ECC-539: avoid output being the same as input
# -----------------------------------------------
set +e
${tools_dir}/grib_set -s centre=0 $outfile $outfile
status=$?
set -e
[ $status -ne 0 ]

# ECC-1777: Bad date/time
# -------------------------
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
${tools_dir}/grib_set -s dataDate=20180229 $input $outfile > $temp 2>&1
grep -q "Date is not valid" $temp

${tools_dir}/grib_set -s dataTime=4261 $input $outfile > $temp 2>&1
grep -q "Time is not valid" $temp

${tools_dir}/grib_set -s dataTime=2501 $input $outfile > $temp 2>&1
grep -q "Time is not valid" $temp

${tools_dir}/grib_set -s hour=33 $input $outfile
${tools_dir}/grib_get -ptime $outfile > $temp 2>&1
grep -q "Time is not valid" $temp


# Note for GRIB1 we DO fail on a bad date! This need to be consistent across editions
input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
set +e
${tools_dir}/grib_set -s dataDate=20180229 $input $outfile > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "invalid date 20180229" $temp

# 2016 did have 29th Feb
${tools_dir}/grib_set -s dataDate=20160229 $input $outfile

# GRIB2 invalid date
${tools_dir}/grib_set -s dataDate=20160233 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile 2> $temp
grep -q "ECCODES WARNING .* Date is not valid! year=2016 month=2 day=33" $temp

# ECC-1359: string that can be converted to an integer
# ---------------------------------------------------
${tools_dir}/grib_set -s month:s=6 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile
grib_check_key_equals $outfile month 6
# Now try an illegal value: a string that cannot be converted to an integer
set +e
${tools_dir}/grib_set -s month=BAD $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile 2> $temp
status=$?
set -e
[ $status -ne 0 ]
grep -q "String cannot be converted to an integer" $temp


# ECC-1363: Does not fail for invalid value for key of type 'double'
# ------------------------------------------------------------------
${tools_dir}/grib_set -s angleOfRotation:s=10.66 $ECCODES_SAMPLES_PATH/rotated_ll_sfc_grib2.tmpl $outfile
grib_check_key_equals $outfile angleOfRotation 10.66
# Now try an illegal value: a string that cannot be converted to an integer
set +e
${tools_dir}/grib_set -s angleOfRotation=BAD $ECCODES_SAMPLES_PATH/rotated_ll_sfc_grib2.tmpl $outfile 2>$temp
status=$?
set -e
[ $status -ne 0 ]
grep -q "String cannot be converted to a double" $temp


# Set ascii key via double or long
# --------------------------------
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=21 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile
${tools_dir}/grib_set -s marsDomain=x $outfile $temp
grib_check_key_equals $temp 'marsDomain' 'x'
set +e
${tools_dir}/grib_set -s marsDomain=9 $outfile $temp
status=$?
set -e
[ $status -ne 0 ]

set +e
${tools_dir}/grib_set -s marsDomain=1.2 $outfile $temp
status=$?
set -e
[ $status -ne 0 ]


# Codetable mismatch
# ------------------------
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
set +e
${tools_dir}/grib_set -s stepUnits=d $input $outfile > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Unit not found" $temp

set +e
${tools_dir}/grib_set -s centre=ECMF $input $outfile > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "centre: No such code table entry.*Did you mean.*ecmf" $temp

# Overflow/Underflow
# ------------------------
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
${tools_dir}/grib_set -s missingValue=9223372036854776666 $input $outfile > $temp 2>&1
grep -q "ECCODES WARNING :  Setting .* causes overflow/underflow" $temp

# ------------------------
# Unreadable message
# ------------------------
echo GRIB > $outfile
set +e
${tools_dir}/grib_set -s edition=2 $outfile /dev/null > $temp 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "unreadable message" $temp


# Clean up
rm -f $outfile $temp