From fa985d7c5cd2d3195ef61e39d56a7cfe46f78a33 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 11 Nov 2019 16:24:15 +0000 Subject: [PATCH] ECC-991: Added typicalDate and typicalTime --- src/bufr_util.c | 13 ++++++++++++- src/grib_api.h | 11 ++++++----- tests/bufr_extract_headers.c | 7 +++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/bufr_util.c b/src/bufr_util.c index 99b86b29e..2a8d36889 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -313,6 +313,8 @@ static int bufr_decode_edition3(const void* message, codes_bufr_header* hdr) long nbits_localTablesVersionNumber = 1*8; long pos_localTablesVersionNumber = 19*8; + const long typicalCentury = 21; /* This century */ + long typicalYearOfCentury = 0; long nbits_typicalYearOfCentury = 1*8; long pos_typicalYearOfCentury = 20*8; @@ -353,11 +355,15 @@ static int bufr_decode_edition3(const void* message, codes_bufr_header* hdr) hdr->masterTablesVersionNumber = (long)grib_decode_unsigned_long( message, &pos_masterTablesVersionNumber, nbits_masterTablesVersionNumber); hdr->localTablesVersionNumber = (long)grib_decode_unsigned_long(message, &pos_localTablesVersionNumber, nbits_localTablesVersionNumber); - hdr->typicalYearOfCentury = (long)grib_decode_unsigned_long(message, &pos_typicalYearOfCentury, nbits_typicalYearOfCentury); + typicalYearOfCentury = (long)grib_decode_unsigned_long(message, &pos_typicalYearOfCentury, nbits_typicalYearOfCentury); + hdr->typicalYear = (typicalCentury - 1) * 100 + typicalYearOfCentury; hdr->typicalMonth = (long)grib_decode_unsigned_long(message, &pos_typicalMonth, nbits_typicalMonth); hdr->typicalDay = (long)grib_decode_unsigned_long(message, &pos_typicalDay, nbits_typicalDay); hdr->typicalHour = (long)grib_decode_unsigned_long(message, &pos_typicalHour, nbits_typicalHour); hdr->typicalMinute = (long)grib_decode_unsigned_long(message, &pos_typicalMinute, nbits_typicalMinute); + hdr->typicalSecond = 0; + hdr->typicalDate = hdr->typicalYear * 10000 + hdr->typicalMonth * 100 + hdr->typicalDay; + hdr->typicalTime = hdr->typicalHour * 10000 + hdr->typicalMinute * 100 + hdr->typicalSecond; offset_section2 = BUFR_SECTION0_LEN + section1Length; /*bytes*/ section2Length = 0; @@ -434,6 +440,7 @@ static int bufr_decode_edition4(const void* message, codes_bufr_header* hdr) long nbits_localTablesVersionNumber = 1*8; long pos_localTablesVersionNumber = 22*8; + long typicalYear2 = 0; // corrected long nbits_typicalYear = 2*8; long pos_typicalYear = 23*8; @@ -477,12 +484,16 @@ static int bufr_decode_edition4(const void* message, codes_bufr_header* hdr) hdr->dataSubCategory = (long)grib_decode_unsigned_long(message, &pos_dataSubCategory, nbits_dataSubCategory); hdr->masterTablesVersionNumber = (long)grib_decode_unsigned_long(message, &pos_masterTablesVersionNumber, nbits_masterTablesVersionNumber); hdr->localTablesVersionNumber = (long)grib_decode_unsigned_long(message, &pos_localTablesVersionNumber, nbits_localTablesVersionNumber); + hdr->typicalYear = (long)grib_decode_unsigned_long(message, &pos_typicalYear, nbits_typicalYear); + typicalYear2 = hdr->typicalYear < 100 ? 2000 + hdr->typicalYear : hdr->typicalYear; // ECC-556 hdr->typicalMonth = (long)grib_decode_unsigned_long(message, &pos_typicalMonth, nbits_typicalMonth); hdr->typicalDay = (long)grib_decode_unsigned_long(message, &pos_typicalDay, nbits_typicalDay); hdr->typicalHour = (long)grib_decode_unsigned_long(message, &pos_typicalHour, nbits_typicalHour); hdr->typicalMinute = (long)grib_decode_unsigned_long(message, &pos_typicalMinute, nbits_typicalMinute); hdr->typicalSecond = (long)grib_decode_unsigned_long(message, &pos_typicalSecond, nbits_typicalSecond); + hdr->typicalDate = typicalYear2 * 10000 + hdr->typicalMonth * 100 + hdr->typicalDay; + hdr->typicalTime = hdr->typicalHour * 10000 + hdr->typicalMinute * 100 + hdr->typicalSecond; offset_section2 = BUFR_SECTION0_LEN + section1Length; /*bytes*/ section2Length = 0; diff --git a/src/grib_api.h b/src/grib_api.h index c1a0a68de..9243fc6c1 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -1577,16 +1577,17 @@ typedef struct codes_bufr_header { long dataSubCategory; long masterTablesVersionNumber; long localTablesVersionNumber; - long typicalYearOfCentury; + + long typicalYear; long typicalMonth; long typicalDay; long typicalHour; long typicalMinute; - - /* Section 1 keys: BUFR4-specific */ - long internationalDataSubCategory; - long typicalYear; long typicalSecond; + long typicalDate; // computed key + long typicalTime; // computed key + + long internationalDataSubCategory; /*BUFR4-specific*/ long ecmwfLocalSectionPresent; diff --git a/tests/bufr_extract_headers.c b/tests/bufr_extract_headers.c index 31f71e8f7..aad4637bf 100644 --- a/tests/bufr_extract_headers.c +++ b/tests/bufr_extract_headers.c @@ -70,13 +70,16 @@ int main(int argc, char* argv[]) if (strstr(keys, "dataSubCategory")) printf("%ld ", bh.dataSubCategory); if (strstr(keys, "masterTablesVersionNumber")) printf("%ld ", bh.masterTablesVersionNumber); if (strstr(keys, "localTablesVersionNumber")) printf("%ld ", bh.localTablesVersionNumber); - if (strstr(keys, "typicalYearOfCentury")) printf("%ld ", bh.typicalYearOfCentury); + if (strstr(keys, "typicalYear")) printf("%ld ", bh.typicalYear); if (strstr(keys, "typicalMonth")) printf("%ld ", bh.typicalMonth); if (strstr(keys, "typicalDay")) printf("%ld ", bh.typicalDay); if (strstr(keys, "typicalHour")) printf("%ld ", bh.typicalHour); if (strstr(keys, "typicalMinute")) printf("%ld ", bh.typicalMinute); + + if (strstr(keys, "typicalDate")) printf("%ld ", bh.typicalDate); + if (strstr(keys, "typicalTime")) printf("%ld ", bh.typicalTime); + if (strstr(keys, "internationalDataSubCategory")) printf("%ld ", bh.internationalDataSubCategory); - if (strstr(keys, "typicalYear")) printf("%ld ", bh.typicalYear); if (strstr(keys, "typicalSecond")) printf("%ld ", bh.typicalSecond); if (strstr(keys, "localSectionPresent")) printf("%ld ", bh.ecmwfLocalSectionPresent);