From 52e12d56984150af93ad31bfa9fc081c6717e017 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 20 Nov 2019 16:20:25 +0000 Subject: [PATCH] ECC-991: Add rdbSubtype --- src/bufr_util.c | 8 +++++--- src/grib_api.h | 1 + tests/bufr_extract_headers.sh | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/bufr_util.c b/src/bufr_util.c index 9d73c31a7..134dd82fa 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -192,6 +192,7 @@ static int bufr_decode_rdb_keys(const void* message, long offset_section2, codes hdr->qualityControl = (long)grib_decode_unsigned_long(message, &pos_qualityControl, nbits_qualityControl); hdr->newSubtype = (long)grib_decode_unsigned_long(message, &pos_newSubtype, nbits_newSubtype); hdr->daLoop = (long)grib_decode_unsigned_long(message, &pos_daLoop, nbits_daLoop); + hdr->rdbSubtype = (hdr->oldSubtype < 255) ? hdr->oldSubtype : hdr->newSubtype; return GRIB_SUCCESS; } @@ -219,7 +220,7 @@ static int bufr_decode_extra_rdb_keys(const void* message, long offset_section2, } else { hdr->isSatellite = 0; } - + if (hdr->isSatellite) { unsigned char* pKeyMoreLong = (unsigned char*)message + offset_keyMore; /* as an integer */ unsigned char* pKeySat = (unsigned char*)message + offset_keySat; @@ -236,7 +237,7 @@ static int bufr_decode_extra_rdb_keys(const void* message, long offset_section2, start = 32; lValue = (long)grib_decode_unsigned_long(pKeyMoreLong, &start, 25); hdr->localLatitude2 = (lValue - 9000000)/100000.0; - + if (hdr->oldSubtype == 255 || hdr->numberOfSubsets > 255 || (hdr->oldSubtype >= 121 && hdr->oldSubtype <= 130) || hdr->oldSubtype==31) @@ -353,7 +354,7 @@ static int bufr_decode_edition3(const void* message, codes_bufr_header* hdr) hdr->dataCategory = (long)grib_decode_unsigned_long(message, &pos_dataCategory, nbits_dataCategory); hdr->dataSubCategory = (long)grib_decode_unsigned_long(message, &pos_dataSubCategory, nbits_dataSubCategory); hdr->masterTablesVersionNumber = (long)grib_decode_unsigned_long( - message, &pos_masterTablesVersionNumber, nbits_masterTablesVersionNumber); + message, &pos_masterTablesVersionNumber, nbits_masterTablesVersionNumber); hdr->localTablesVersionNumber = (long)grib_decode_unsigned_long(message, &pos_localTablesVersionNumber, nbits_localTablesVersionNumber); typicalYearOfCentury = (long)grib_decode_unsigned_long(message, &pos_typicalYearOfCentury, nbits_typicalYearOfCentury); hdr->typicalYear = (typicalCentury - 1) * 100 + typicalYearOfCentury; @@ -831,6 +832,7 @@ int codes_bufr_header_get_string(codes_bufr_header* bh, const char* key, char *v else if (strcmp(key, "localLongitude")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLongitude); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "qualityControl")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->qualityControl); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "newSubtype")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->newSubtype); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rdbSubtype")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbSubtype); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "daLoop")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->daLoop); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "localNumberOfObservations")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localNumberOfObservations); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "satelliteID")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->satelliteID); else strcpy(val, NOT_FOUND); } diff --git a/src/grib_api.h b/src/grib_api.h index f086577b2..dd9b6f25f 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -1596,6 +1596,7 @@ typedef struct codes_bufr_header { /* ECMWF local section keys */ long rdbType; long oldSubtype; + long rdbSubtype; char ident[9]; long localYear; long localMonth; diff --git a/tests/bufr_extract_headers.sh b/tests/bufr_extract_headers.sh index 39cc5c20f..3bd9b5506 100755 --- a/tests/bufr_extract_headers.sh +++ b/tests/bufr_extract_headers.sh @@ -60,6 +60,23 @@ r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/PraticaTemp.bufr` r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/israel_observations_2017041010.bufr` [ "$r" = "234" ] + +# Test rdbSubtype +# --------------- +fBufr3Input=$ECCODES_SAMPLES_PATH/BUFR3_local.tmpl +fBufr4Input=$ECCODES_SAMPLES_PATH/BUFR4_local.tmpl +inputs="$fBufr3Input $fBufr4Input" +for fin in $inputs; do + ${tools_dir}/bufr_set -s oldSubtype=2,newSubtype=300 $fin $temp1 + r=`${test_dir}/bufr_extract_headers rdbSubtype,oldSubtype,newSubtype $temp1` + [ "$r" = "2 2 300" ] + + ${tools_dir}/bufr_set -s oldSubtype=255,newSubtype=300 $fin $temp1 + res=`${test_dir}/bufr_extract_headers rdbSubtype,oldSubtype,newSubtype $temp1` + [ "$res" = "300 255 300" ] +done + + # Test all BUFR files # --------------------- bufr_files=`cat ${data_dir}/bufr/bufr_data_files.txt`