ECC-1018: Fixed the encoding of list of ascii keys. Added tests

This commit is contained in:
Shahram Najm 2019-12-08 17:23:28 +00:00
parent 9bd1fdc18b
commit ae5e8d2912
4 changed files with 50 additions and 16 deletions

View File

@ -8,12 +8,12 @@ unsigned[1] numberOfBytesPerInteger=4;
unsigned[2] reserved=0 : hidden ;
unsigned[3] numberOfCharacters ;
unsigned[3] numberOfCharacters : dump;
alias numberOfChars=numberOfCharacters ;
unsigned[3] numberOfFloats ;
unsigned[3] numberOfFloats : dump;
unsigned[3] numberOfIntegers=0;
unsigned[3] numberOfIntegers=0 : dump;
alias numberOfInts=numberOfIntegers ;
unsigned[3] numberOfLogicals ;
@ -22,20 +22,15 @@ unsigned[4] reserved=0 : hidden;
unsigned[4] reserved=0 : hidden;
unsigned[1] reserved=0 : hidden;
ibmfloat floatValues[numberOfFloats];
ibmfloat floatValues[numberOfFloats] : dump;
alias floatVal=floatValues;
if (numberOfIntegers) {
signed[4] integerValues[numberOfIntegers];
signed[4] integerValues[numberOfIntegers] : dump;
}
# TODO: temporary solution for variable-length list of ascii
#charValues list(numberOfCharacters) {
# ascii[1] char;
#}
if (numberOfCharacters) {
unsigned[1] charValues[numberOfCharacters];
alias charVal=charValues;
charList list(numberOfCharacters) {
ascii[1] charValues : dump;
}
# Final padding

View File

@ -489,7 +489,21 @@ static int pack_double(grib_accessor* a, const double *v, size_t *len)
static int pack_string_array(grib_accessor*a , const char** v, size_t *len)
{
return GRIB_NOT_IMPLEMENTED;
long i;
int err = 0;
size_t length = 0;
grib_accessor* as = 0;
as = a;
i = (long)*len - 1;
while(as && i >= 0) {
length = strlen(v[i]);
err = grib_pack_string(as, v[i], &length);
if (err) return err;
--i;
as = as->same;
}
return GRIB_SUCCESS;
}
static int pack_string(grib_accessor*a , const char* v, size_t *len){

View File

@ -55,7 +55,8 @@ EOF
diff $tempRef $tempTxt
echo 'set numberOfIntegers=4; set integerValues={33, 55, -44, 66}; set numberOfFloats=3; set floatValues={-8.8, 9.9, 10.10}; write;' | ${tools_dir}/grib_filter -o $tempOut - $sample
echo 'set numberOfIntegers=4; set integerValues={33, 55, -44, 66}; set numberOfFloats=3; set floatValues={-8.8, 9.9, 10.10}; write;' |\
${tools_dir}/grib_filter -o $tempOut - $sample
${tools_dir}/grib_dump -p numberOfFloats,numberOfIntegers,floatValues,integerValues $tempOut | sed 1d > $tempTxt
cat > $tempRef <<EOF
numberOfFloats = 3;
@ -70,5 +71,9 @@ EOF
diff $tempRef $tempTxt
echo 'set numberOfCharacters=4; set charValues={"J","u","m","p"}; write;'| ${tools_dir}/grib_filter -o $tempOut - $sample
res=`${tools_dir}/grib_dump $tempOut | grep charValues | tr -d '\n' | tr -d ' '`
[ "$res" = "charValues=J;charValues=u;charValues=m;charValues=p;" ]
# Clean up
rm -f $tempOut $tempRef

View File

@ -65,6 +65,7 @@ diff local.log local.good.log
rm -f local.log loc.grib1 loc.grib2 loc1.grib1 loc1.grib2 eps.grib1 eps.grib2
# Delete Local Definition
# -----------------------
sample_g1=$ECCODES_SAMPLES_PATH/reduced_gg_pl_640_grib1.tmpl
@ -79,6 +80,7 @@ ${tools_dir}/grib_set -s deleteLocalDefinition=1 $sample_g2 $temp
grib_check_key_equals $temp "localUsePresent,section2Used" "0 0"
rm -f $temp
# Empty local section for GRIB2
# ------------------------------
sample_g2=$ECCODES_SAMPLES_PATH/reduced_gg_pl_640_grib2.tmpl
@ -92,6 +94,7 @@ ${tools_dir}/grib_set -s addEmptySection2=1 $sample_g2 $temp
grib_check_key_equals $temp section2Length 5
rm -f $temp
# Local Definition 5
# -----------------------
sample_g1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
@ -106,13 +109,30 @@ grib_check_key_equals $temp.3 edition,productDefinitionTemplateNumber "2 5"
grib_check_key_equals $temp.3 forecastProbabilityNumber,totalNumberOfForecastProbabilities "2 25"
grib_check_key_equals $temp.3 probabilityType,scaledValueOfLowerLimit,scaledValueOfUpperLimit "2 54 56"
# Local Definition 42 for GRIB2 (LC-WFV)
# ---------------------------------------
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=42,lcwfvSuiteName=9 $sample_g2 $temp
grib_check_key_equals $temp 'mars.origin:s' 'lops'
# Extra key in Local Definition 16 for GRIB1. ECC-679
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=16,numberOfForecastsInEnsemble=51 $sample_g1 $temp
grib_check_key_equals $temp 'totalNumber' '51'
# Local Definition 18 (list of ascii keys)
# ----------------------------------------
${tools_dir}/grib_filter -o $temp - $sample_g1 << EOF
set setLocalDefinition=1;
set localDefinitionNumber=18;
set consensusCount=3;
set ccccIdentifiers={"kwbc","ecmf","sabm"};
write;
EOF
result=`echo 'print "[ccccIdentifiers]";' | ${tools_dir}/grib_filter - $temp`
[ "$result" = "kwbc ecmf sabm" ]
rm -f $temp $temp.1 $temp.2 $temp.3