Testing: ensure MARS key values (stream, class, type) are unique

This commit is contained in:
Shahram Najm 2021-04-27 13:17:50 +01:00
parent e3cad31163
commit ebe1670b66
3 changed files with 56 additions and 29 deletions

View File

@ -222,7 +222,7 @@ if( HAVE_BUILD_TOOLS )
grib_local_MeteoFrance
grib_neg_fctime
codes_split_file
grib_mars_types)
grib_mars_keys)
if( HAVE_FORTRAN AND ENABLE_EXTRA_TESTS )
list(APPEND tests_data_reqd bufr_dump_encode_fortran)

55
tests/grib_mars_keys.sh Executable file
View File

@ -0,0 +1,55 @@
#!/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.sh
set -u
label="grib_mars_keys"
grib1_sample=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
temp=temp.${label}.out
types_table=$ECCODES_DEFINITION_PATH/mars/type.table
classes_table=$ECCODES_DEFINITION_PATH/mars/class.table
streams_table=$ECCODES_DEFINITION_PATH/mars/stream.table
# Check numeric codes are unique
# -------------------------------
tables="$types_table $classes_table $streams_table"
for table in $tables; do
echo "Testing numeric codes in $table ..."
awk '{print $1}' < $table > $temp
count1=`sort -u $temp | wc -l`
count2=`wc -l $temp | awk '{print $1}'`
[ $count1 = $count2 ]
done
# Check abbreviations are unique
# -------------------------------
tables="$types_table $classes_table $streams_table"
for table in $tables; do
echo "Testing abbreviations in $table ..."
awk '{print $2}' < $table > $temp
count1=`sort -u $temp | wc -l`
count2=`wc -l $temp | awk '{print $1}'`
[ $count1 = $count2 ]
done
# Check MARS types
# ------------------------------
# Exclude type=34 (go, Gridded observations) as it loads definitions/mars/grib.oper.go.def
# which requires the key 'N' to exist
mars_types=`awk '$1 !~ /34/ {print $1}' < $types_table`
for t in $mars_types; do
#echo "Doing MARS type |$t|"
${tools_dir}/grib_set -s marsType=$t,edition=2 $grib1_sample $temp
grib_check_key_equals $temp "mars.type:i" $t
done
rm -f $temp

View File

@ -1,28 +0,0 @@
#!/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.sh
label="grib_mars_types"
grib1_sample=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
temp=temp.${label}.grib
types_table=$ECCODES_DEFINITION_PATH/mars/type.table
# Exclude type=34 (go, Gridded observations) as it loads definitions/mars/grib.oper.go.def
# which requires the key 'N' to exist
mars_types=`awk '$1 !~ /34/ {print $1}' < $types_table`
for t in $mars_types; do
#echo "Doing MARS type |$t|"
${tools_dir}/grib_set -s marsType=$t,edition=2 $grib1_sample $temp
grib_check_key_equals $temp "mars.type:i" $t
done
rm -f $temp