Performance: Remove redundant keys

This commit is contained in:
Shahram Najm 2019-09-23 17:28:38 +01:00
parent 8898e0cf4b
commit 32b8cd4da2
4 changed files with 35 additions and 20 deletions

View File

@ -1563,9 +1563,12 @@ grib_handle *grib_new_from_file(grib_context *c, FILE *f, int headers_only, int
typedef struct codes_bufr_header { typedef struct codes_bufr_header {
off_t message_offset; off_t message_offset;
size_t message_size; size_t message_size;
/* Section 0 keys */
long edition; long edition;
unsigned long totalLength; unsigned long totalLength;
unsigned long section1Length;
/* Section 1 keys */
long masterTableNumber; long masterTableNumber;
long bufrHeaderSubCentre; long bufrHeaderSubCentre;
long bufrHeaderCentre; long bufrHeaderCentre;
@ -1581,7 +1584,7 @@ typedef struct codes_bufr_header {
long typicalHour; long typicalHour;
long typicalMinute; long typicalMinute;
/* Extra BUFR4 keys */ /* Section 1 keys: BUFR4-specific */
long internationalDataSubCategory; long internationalDataSubCategory;
long typicalYear; long typicalYear;
long typicalSecond; long typicalSecond;
@ -1613,9 +1616,10 @@ typedef struct codes_bufr_header {
long newSubtype; long newSubtype;
long daLoop; long daLoop;
/* Section 3 */ /* Section 3 keys */
unsigned long numberOfSubsets; unsigned long numberOfSubsets;
long section3Flags; long observedData;
long compressedData;
} codes_bufr_header; } codes_bufr_header;

View File

@ -1760,6 +1760,7 @@ static int bufr_decode_edition3(const void* message, codes_bufr_header* hdr)
const long nbits_totalLength = 3*8; const long nbits_totalLength = 3*8;
long pos_totalLength = 4*8; long pos_totalLength = 4*8;
unsigned long section1Length = 0;
const long nbits_section1Length = 3*8; const long nbits_section1Length = 3*8;
long pos_section1Length = 8*8; long pos_section1Length = 8*8;
@ -1808,11 +1809,13 @@ static int bufr_decode_edition3(const void* message, codes_bufr_header* hdr)
long offset_section3 = 0; long offset_section3 = 0;
long nbits_numberOfSubsets = 2*8; long nbits_numberOfSubsets = 2*8;
long pos_numberOfSubsets = 0; /*depends on offset_section3*/ long pos_numberOfSubsets = 0; /*depends on offset_section3*/
long section3Flags;
long nbits_section3Flags = 1*8; long nbits_section3Flags = 1*8;
long pos_section3Flags = 0; /*depends on offset_section3*/ long pos_section3Flags = 0; /*depends on offset_section3*/
hdr->totalLength = grib_decode_unsigned_long(message, &pos_totalLength, nbits_totalLength); hdr->totalLength = grib_decode_unsigned_long(message, &pos_totalLength, nbits_totalLength);
hdr->section1Length = grib_decode_unsigned_long(message, &pos_section1Length, nbits_section1Length); section1Length = grib_decode_unsigned_long(message, &pos_section1Length, nbits_section1Length);
hdr->masterTableNumber = (long)grib_decode_unsigned_long(message, &pos_masterTableNumber, nbits_masterTableNumber); hdr->masterTableNumber = (long)grib_decode_unsigned_long(message, &pos_masterTableNumber, nbits_masterTableNumber);
hdr->bufrHeaderSubCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderSubCentre, nbits_bufrHeaderSubCentre); hdr->bufrHeaderSubCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderSubCentre, nbits_bufrHeaderSubCentre);
hdr->bufrHeaderCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderCentre, nbits_bufrHeaderCentre); hdr->bufrHeaderCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderCentre, nbits_bufrHeaderCentre);
@ -1834,7 +1837,7 @@ static int bufr_decode_edition3(const void* message, codes_bufr_header* hdr)
if (hdr->localSectionPresent) { if (hdr->localSectionPresent) {
long pos_section2Length; long pos_section2Length;
const long nbits_section2Length = 3*8; const long nbits_section2Length = 3*8;
long offset_section2 = BUFR_SECTION0_LEN + hdr->section1Length; /*bytes*/ long offset_section2 = BUFR_SECTION0_LEN + section1Length; /*bytes*/
pos_section2Length = offset_section2*8; pos_section2Length = offset_section2*8;
hdr->section2Length = grib_decode_unsigned_long(message, &pos_section2Length, nbits_section2Length); hdr->section2Length = grib_decode_unsigned_long(message, &pos_section2Length, nbits_section2Length);
@ -1844,12 +1847,15 @@ static int bufr_decode_edition3(const void* message, codes_bufr_header* hdr)
} }
} }
offset_section3 = BUFR_SECTION0_LEN + hdr->section1Length + hdr->section2Length; /*bytes*/ offset_section3 = BUFR_SECTION0_LEN + section1Length + hdr->section2Length; /*bytes*/
nbits_numberOfSubsets = 2*8; nbits_numberOfSubsets = 2*8;
pos_numberOfSubsets = (offset_section3+4)*8; pos_numberOfSubsets = (offset_section3+4)*8;
hdr->numberOfSubsets = grib_decode_unsigned_long(message, &pos_numberOfSubsets, nbits_numberOfSubsets); hdr->numberOfSubsets = grib_decode_unsigned_long(message, &pos_numberOfSubsets, nbits_numberOfSubsets);
pos_section3Flags = (offset_section3+6)*8;
hdr->section3Flags = (long)grib_decode_unsigned_long(message, &pos_section3Flags, nbits_section3Flags); pos_section3Flags = (offset_section3+6)*8;
section3Flags = (long)grib_decode_unsigned_long(message, &pos_section3Flags, nbits_section3Flags);
hdr->observedData = (section3Flags & 1<<7) ? 1 : 0;
hdr->compressedData = (section3Flags & 1<<6) ? 1 : 0;
return err; return err;
} }
@ -1861,6 +1867,7 @@ static int bufr_decode_edition4(const void* message, codes_bufr_header* hdr)
const long nbits_totalLength = 3*8; const long nbits_totalLength = 3*8;
long pos_totalLength = 4*8; long pos_totalLength = 4*8;
unsigned long section1Length;
const long nbits_section1Length = 3*8; const long nbits_section1Length = 3*8;
long pos_section1Length = 8*8; long pos_section1Length = 8*8;
@ -1912,15 +1919,16 @@ static int bufr_decode_edition4(const void* message, codes_bufr_header* hdr)
long nbits_typicalSecond = 1*8; long nbits_typicalSecond = 1*8;
long pos_typicalSecond = 29*8; long pos_typicalSecond = 29*8;
//int ecmwfLocalSectionPresent = 0;
long offset_section3 = 0; long offset_section3 = 0;
long nbits_numberOfSubsets = 2*8; long nbits_numberOfSubsets = 2*8;
long pos_numberOfSubsets = 0; /*depends on offset_section3*/ long pos_numberOfSubsets = 0; /*depends on offset_section3*/
long section3Flags;
long nbits_section3Flags = 1*8; long nbits_section3Flags = 1*8;
long pos_section3Flags = 0; /*depends on offset_section3*/ long pos_section3Flags = 0; /*depends on offset_section3*/
hdr->totalLength = grib_decode_unsigned_long(message, &pos_totalLength, nbits_totalLength); hdr->totalLength = grib_decode_unsigned_long(message, &pos_totalLength, nbits_totalLength);
hdr->section1Length = grib_decode_unsigned_long(message, &pos_section1Length, nbits_section1Length); section1Length = grib_decode_unsigned_long(message, &pos_section1Length, nbits_section1Length);
hdr->masterTableNumber = (long)grib_decode_unsigned_long(message, &pos_masterTableNumber, nbits_masterTableNumber); hdr->masterTableNumber = (long)grib_decode_unsigned_long(message, &pos_masterTableNumber, nbits_masterTableNumber);
hdr->bufrHeaderCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderCentre, nbits_bufrHeaderCentre); hdr->bufrHeaderCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderCentre, nbits_bufrHeaderCentre);
hdr->bufrHeaderSubCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderSubCentre, nbits_bufrHeaderSubCentre); hdr->bufrHeaderSubCentre = (long)grib_decode_unsigned_long(message, &pos_bufrHeaderSubCentre, nbits_bufrHeaderSubCentre);
@ -1943,7 +1951,7 @@ static int bufr_decode_edition4(const void* message, codes_bufr_header* hdr)
if (hdr->localSectionPresent) { if (hdr->localSectionPresent) {
long pos_section2Length; long pos_section2Length;
const long nbits_section2Length = 3*8; const long nbits_section2Length = 3*8;
long offset_section2 = BUFR_SECTION0_LEN + hdr->section1Length; /*bytes*/ long offset_section2 = BUFR_SECTION0_LEN + section1Length; /*bytes*/
pos_section2Length = offset_section2*8; pos_section2Length = offset_section2*8;
hdr->section2Length = grib_decode_unsigned_long(message, &pos_section2Length, nbits_section2Length); hdr->section2Length = grib_decode_unsigned_long(message, &pos_section2Length, nbits_section2Length);
@ -1953,12 +1961,15 @@ static int bufr_decode_edition4(const void* message, codes_bufr_header* hdr)
} }
} }
offset_section3 = BUFR_SECTION0_LEN + hdr->section1Length + hdr->section2Length; /*bytes*/ offset_section3 = BUFR_SECTION0_LEN + section1Length + hdr->section2Length; /*bytes*/
nbits_numberOfSubsets = 2*8; nbits_numberOfSubsets = 2*8;
pos_numberOfSubsets = (offset_section3+4)*8; pos_numberOfSubsets = (offset_section3+4)*8;
hdr->numberOfSubsets = grib_decode_unsigned_long(message, &pos_numberOfSubsets, nbits_numberOfSubsets); hdr->numberOfSubsets = grib_decode_unsigned_long(message, &pos_numberOfSubsets, nbits_numberOfSubsets);
pos_section3Flags = (offset_section3+6)*8;
hdr->section3Flags = (long)grib_decode_unsigned_long(message, &pos_section3Flags, nbits_section3Flags); pos_section3Flags = (offset_section3+6)*8;
section3Flags = (long)grib_decode_unsigned_long(message, &pos_section3Flags, nbits_section3Flags);
hdr->observedData = (section3Flags & 1<<7) ? 1 : 0;
hdr->compressedData = (section3Flags & 1<<6) ? 1 : 0;
return err; return err;
} }

View File

@ -34,11 +34,11 @@ int main(int argc,char* argv[])
const int has_ecmwf_local = (bh.localSectionPresent == 1 && bh.bufrHeaderCentre == 98); const int has_ecmwf_local = (bh.localSectionPresent == 1 && bh.bufrHeaderCentre == 98);
char rdbTypeStr[32] = "not_found"; char rdbTypeStr[32] = "not_found";
if (has_ecmwf_local) sprintf(rdbTypeStr, "%ld", bh.rdbType); if (has_ecmwf_local) sprintf(rdbTypeStr, "%ld", bh.rdbType);
printf("%ld %lu %ld %ld %ld %ld %s %lu\n", printf("%ld %lu %ld %ld %ld %ld %s %lu %ld\n",
bh.edition, bh.totalLength, bh.dataCategory, bh.edition, bh.totalLength, bh.dataCategory,
bh.masterTablesVersionNumber, bh.masterTablesVersionNumber,
bh.typicalMonth, bh.typicalDay, bh.typicalMonth, bh.typicalDay,
rdbTypeStr, bh.numberOfSubsets); rdbTypeStr, bh.numberOfSubsets, bh.compressedData);
} }
free(headers); free(headers);

View File

@ -18,7 +18,7 @@ temp2="temp.${label}.2"
bufr_files=`cat ${data_dir}/bufr/bufr_data_files.txt` bufr_files=`cat ${data_dir}/bufr/bufr_data_files.txt`
KEYS='edition,totalLength,dataCategory,masterTablesVersionNumber,typicalMonth,typicalDay,rdbType,numberOfSubsets' KEYS='edition,totalLength,dataCategory,masterTablesVersionNumber,typicalMonth,typicalDay,rdbType,numberOfSubsets,compressedData'
for bf in ${bufr_files}; do for bf in ${bufr_files}; do
input=${data_dir}/bufr/$bf input=${data_dir}/bufr/$bf