mirror of https://github.com/ecmwf/eccodes.git
ECC-1528: Tools: Setting -w constraint with count=0 should issue an error
This commit is contained in:
parent
bb3dcc0602
commit
f516a62f02
|
@ -62,8 +62,7 @@ regular_latlon_surface.grib1
|
|||
regular_latlon_surface.grib2
|
||||
"
|
||||
|
||||
for file in $files
|
||||
do
|
||||
for file in $files; do
|
||||
[ -f "$file" ]
|
||||
echo $file >> $tempLog
|
||||
${tools_dir}/grib_ls -l 40,28 $file | grep index | awk '{print $4;}' >> $tempLog
|
||||
|
@ -72,7 +71,8 @@ done
|
|||
diff $tempLog ls.log
|
||||
rm -f $tempLog
|
||||
|
||||
# Test for bug GRIB-56
|
||||
echo "Test for bug GRIB-56..."
|
||||
# ------------------------------
|
||||
${tools_dir}/grib_set -s typeOfLevel=depthBelowLandLayer,topLevel=missing regular_latlon_surface.grib1 tmp_rlls.grib1
|
||||
${tools_dir}/grib_ls -plevels tmp_rlls.grib1 | grep MISSING>/dev/null
|
||||
|
||||
|
@ -80,18 +80,23 @@ ${tools_dir}/grib_set -s typeOfLevel=depthBelowLandLayer,bottomLevel=missing reg
|
|||
${tools_dir}/grib_ls -plevels tmp_rlls.grib1 | grep MISSING>/dev/null
|
||||
rm -f tmp_rlls.grib1
|
||||
|
||||
# GRIB-305. GRIB edition 1 file with one large message
|
||||
echo "GRIB-305. GRIB edition 1 file with one large message..."
|
||||
# ----------------------------------------------------------
|
||||
if [ -f "sst_globus0083.grib" ]; then
|
||||
${tools_dir}/grib_ls sst_globus0083.grib > /dev/null
|
||||
${tools_dir}/grib_ls sst_globus0083.grib > /dev/null
|
||||
fi
|
||||
|
||||
# GRIB-387 printing key of type byte
|
||||
|
||||
echo "GRIB-387 printing key of type byte..."
|
||||
# ----------------------------------------------------------
|
||||
${tools_dir}/grib_ls -p uuidOfVGrid test_uuid.grib2 > /dev/null
|
||||
|
||||
type=`${tools_dir}/grib_get -wcount=1 -p typeOfLevel test_uuid.grib2`
|
||||
[ "$type" = "generalVertical" ]
|
||||
|
||||
# GRIB-213 nearest with land-sea mask
|
||||
|
||||
echo "GRIB-213 nearest with land-sea mask..."
|
||||
# ----------------------------------------------------------
|
||||
temp_ls=temp.grib_ls.grib-213.txt
|
||||
${tools_dir}/grib_ls -l 85,13,1,reduced_gaussian_lsm.grib1 reduced_gaussian_surface.grib1 >$temp_ls
|
||||
grep -q 'Point chosen #3 index=21 .* distance=11\.' $temp_ls
|
||||
|
@ -100,7 +105,8 @@ ${tools_dir}/grib_ls -l 53,2,1,reduced_gaussian_lsm.grib1 reduced_gaussian_surfa
|
|||
grep -q 'Point chosen #2 index=749 .* distance=204\.' $temp_ls
|
||||
|
||||
|
||||
# ECC-278: grib_ls -n namespace
|
||||
echo "ECC-278: grib_ls -n namespace..."
|
||||
# ----------------------------------------------------------
|
||||
${tools_dir}/grib_ls -n geography $ECCODES_SAMPLES_PATH/reduced_ll_sfc_grib2.tmpl
|
||||
${tools_dir}/grib_ls -n data $sample_g1
|
||||
|
||||
|
@ -118,7 +124,9 @@ diff $temp1 $temp2
|
|||
# Section pointers
|
||||
grib_check_key_equals $sample_g2 'section0Pointer,section1Pointer,section3Pointer,section4Pointer' '0_16 16_21 37_72 109_34'
|
||||
|
||||
# constraints: -w option
|
||||
|
||||
echo "Test constraints: -w option..."
|
||||
# ----------------------------------------------------------
|
||||
file=tigge_pf_ecmwf.grib2 # Has 38 messages
|
||||
${tools_dir}/grib_ls -w count!=1 $file > $temp_ls
|
||||
grep -q "37 of 38 messages" $temp_ls
|
||||
|
@ -160,6 +168,19 @@ grep -q "3 of 14 messages" $temp_ls
|
|||
${tools_dir}/grib_ls -w shortName=t/10u,gridType=regular_gg $file > $temp_ls
|
||||
grep -q "5 of 14 messages" $temp_ls
|
||||
|
||||
|
||||
# ECC-1528: Try some invalid values for the count constraint
|
||||
for cval in -1 0 xx; do
|
||||
set +e
|
||||
rm -f $temp_ls
|
||||
${tools_dir}/grib_ls -w count=$cval $file > $temp_ls 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q "Invalid value for key 'count'" $temp_ls
|
||||
done
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $temp1 $temp2
|
||||
rm -f $temp_ls
|
||||
|
|
|
@ -808,6 +808,11 @@ static int to_skip(grib_handle* h, grib_values* v, int* err)
|
|||
size_t len = MAX_STRING_LEN;
|
||||
*err = 0;
|
||||
|
||||
if (strcmp(v->name, "count")==0 && v->long_value < 1) {
|
||||
fprintf(dump_file, "ERROR: Invalid value for key '%s' (must be an integer greater than 0)\n", v->name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
switch (v->type) {
|
||||
case GRIB_TYPE_STRING:
|
||||
*err = grib_get_string(h, v->name, value, &len);
|
||||
|
|
Loading…
Reference in New Issue