Skip to content

Commit

Permalink
ECC-1847: Fix case when input has typeOfLevel=unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Jun 22, 2024
1 parent 19d7125 commit 97dd174
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions definitions/grib2/typeOfLevelConcept.def
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@
'road' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=255;}
'roadLayer' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=187;}
'urbanCanyon' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=185;}
'unknown' = {dummy=0;}
27 changes: 18 additions & 9 deletions tests/grib_typeOfLevel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
. ./include.ctest.sh

label="grib_typeOfLevel_test"
temp=temp.$label.txt
tempGrib=temp.$label.grib
tempText=temp.$label.txt
tempGribA=temp.$label.A.grib
tempGribB=temp.$label.B.grib

if [ ! -d "$ECCODES_DEFINITION_PATH" ]; then
echo "Test $0 disabled. No definitions directory"
Expand All @@ -23,32 +24,40 @@ sample_g1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
sample_g2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl

# Make sure all typeOfLevel values are unique
# --------------------------------------------
def_file="$ECCODES_DEFINITION_PATH/grib2/typeOfLevelConcept.def"

rm -f $temp
rm -f $tempText

# uniq -d outputs a single copy of each line that is repeated in the input
grep "^'" $def_file | awk -F= '{print $1}' | tr -d "' " | sort | uniq -d > $temp
grep "^'" $def_file | awk -F= '{print $1}' | tr -d "' " | sort | uniq -d > $tempText

if [ -s "$temp" ]; then
if [ -s "$tempText" ]; then
# File exists and has a size greater than zero
echo "ERROR: Duplicates found in $def_file" >&2
cat $temp
cat $tempText
exit 1
else
echo "No duplicates in $def_file"
fi

# ECC-1847: Setting invalid value for 'typeOfLevel' does not fail
# ----------------------------------------------------------------
for sample in $sample_g1 $sample_g2; do
set +e
${tools_dir}/grib_set -s typeOfLevel=rubbish $sample $tempGrib 2>$temp
${tools_dir}/grib_set -s typeOfLevel=rubbish $sample $tempGribA 2>$tempText
status=$?
set -e
[ $status -ne 0 ]
grep -q "Concept no match" $temp
grep -q "Concept no match" $tempText
done

# Change of PDT with typeOfLevel=unknown
${tools_dir}/grib_set -s productDefinitionTemplateNumber=0,typeOfFirstFixedSurface=0 $sample_g2 $tempGribA
grib_check_key_equals $tempGribA typeOfLevel 'unknown'
${tools_dir}/grib_set -s productDefinitionTemplateNumber=1 $tempGribA $tempGribB
grib_check_key_equals $tempGribB typeOfLevel,productDefinitionTemplateNumber 'unknown 1'


# Clean up
rm -f $temp $tempGrib
rm -f $tempText $tempGribA $tempGribB

0 comments on commit 97dd174

Please sign in to comment.