ECC-991: Add centre key as string

This commit is contained in:
Shahram Najm 2019-11-20 15:39:55 +00:00
parent ee8fec3143
commit c3b81c12b4
3 changed files with 105 additions and 37 deletions

View File

@ -649,6 +649,56 @@ int codes_bufr_extract_headers_malloc(grib_context* c, const char* filename, cod
return GRIB_SUCCESS;
}
static char* codes_bufr_header_get_centre_name(long edition, long centre_code)
{
switch (centre_code) {
case 1: return "ammc";
case 4: return "rums";
case 7: return "kwbc";
case 24: return "fapr";
case 28: return "vabb";
case 29: return "dems";
case 34: return "rjtd";
case 38: return "babj";
case 40: return "rksl";
case 41: return "sabm";
case 46: return "sbsj";
case 54: return "cwao";
case 58: return "fnmo";
case 69: return "nzkl";
case 74: return "egrr";
case 78: return "edzw";
case 80: return "cnmc";
case 82: return "eswi";
case 84: return "lfpw";
case 85: return "lfpw";
case 86: return "efkl";
case 88: return "enmi";
case 94: return "ekmi";
case 98: return "ecmf";
case 173: return "nasa";
case 195: return "wiix";
case 204: return "niwa";
case 214: return "lemm";
case 215: return "lssw";
case 218: return "habp";
case 224: return "lowm";
case 227: return "ebum";
case 233: return "eidb";
case 235: return "ingv";
case 239: return "crfc";
case 244: return "vuwien";
case 245: return "knmi";
case 246: return "ifmk";
case 247: return "hadc";
case 250: return "cosmo";
case 252: return "mpim";
case 254: return "eums";
case 255: return "consensus";
default: return NULL;
}
}
#if 0
/* TODO: Not efficient as it opens the code table every time */
static char* codes_bufr_header_get_centre_name(long edition, long centre_code)
@ -728,13 +778,12 @@ int codes_bufr_header_get_string(codes_bufr_header* bh, const char* key, char *v
else if (strcmp(key, "bufrHeaderSubCentre")==0) *len = sprintf(val, "%ld", bh->bufrHeaderSubCentre);
else if (strcmp(key, "bufrHeaderCentre")==0) *len = sprintf(val, "%ld", bh->bufrHeaderCentre);
/*
else if (strcmp(key, "centre")==0) {
char* centre_str = codes_bufr_header_get_centre_name(bh->edition, bh->bufrHeaderCentre);
if (centre_str) *len = sprintf(val, "%s", centre_str);
else *len = sprintf(val, "%ld", bh->bufrHeaderCentre);
}
*/
else if (strcmp(key, "updateSequenceNumber")==0) *len = sprintf(val, "%ld", bh->updateSequenceNumber);
else if (strcmp(key, "dataCategory")==0) *len = sprintf(val, "%ld", bh->dataCategory);
else if (strcmp(key, "dataSubCategory")==0) *len = sprintf(val, "%ld", bh->dataSubCategory);

View File

@ -45,7 +45,8 @@ int main(int argc, char* argv[])
char value[512]={0,};
CODES_CHECK( codes_bufr_header_get_string(&header_array[i], requested_print_keys[j].name, value, &vlen), 0);
assert(vlen > 0);
printf("%s ", value);
if (j > 0) printf(" ");
printf("%s", value);
}
printf("\n");
}

View File

@ -12,10 +12,56 @@
# Define a common label for all the tmp files
label="bufr_extract_headers_test"
temp1="temp.${label}.1"
temp2="temp.${label}.2"
# Multi-message BUFR
# --------------------
input=${data_dir}/bufr/aeolus_wmo_26.bufr
KEYS='offset,edition,totalLength'
$EXEC ${test_dir}/bufr_extract_headers $KEYS $input > $temp1
${tools_dir}/bufr_get -p $KEYS $input > $temp2
diff $temp1 $temp2
# Test local ECMWF keys; should be "not_found" for this input
# -----------------------------------------------------------
input=${data_dir}/bufr/PraticaTemp.bufr
KEYS='localSectionPresent,rdbType,ident,isSatellite,satelliteID'
$EXEC ${test_dir}/bufr_extract_headers $KEYS $input > $temp1
${tools_dir}/bufr_get -f -p $KEYS $input > $temp2
diff $temp1 $temp2
# Local Section keys
# --------------------
# DWD BUFR with a local section
input=${data_dir}/bufr/uegabe.bufr
r=`${test_dir}/bufr_extract_headers localSectionPresent,ecmwfLocalSectionPresent $input`
[ "$r" = "1 0" ]
# ECMWF BUFR but has no local section
input=${data_dir}/bufr/207003.bufr
r=`${test_dir}/bufr_extract_headers localSectionPresent,ecmwfLocalSectionPresent $input`
[ "$r" = "0 0" ]
# ECMWF BUFR with a local section
input=${data_dir}/bufr/aaen_55.bufr
r=`${test_dir}/bufr_extract_headers localSectionPresent,ecmwfLocalSectionPresent $input`
[ "$r" = "1 1" ]
# Key 'centre' as string
# -----------------------
r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/aaen_55.bufr`
[ "$r" = "ecmf" ]
r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/uegabe.bufr`
[ "$r" = "edzw" ]
r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/synop_multi_subset.bufr`
[ "$r" = "enmi" ]
r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/PraticaTemp.bufr`
[ "$r" = "cnmc" ]
r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/israel_observations_2017041010.bufr`
[ "$r" = "234" ]
# Test all BUFR files
# ---------------------
bufr_files=`cat ${data_dir}/bufr/bufr_data_files.txt`
KEYS='edition,totalLength,bufrHeaderCentre,dataCategory,masterTablesVersionNumber,typicalMonth,typicalDay,rdbType,localYear,qualityControl,numberOfSubsets,compressedData,ident'
@ -24,40 +70,12 @@ for bf in ${bufr_files}; do
input=${data_dir}/bufr/$bf
$EXEC ${test_dir}/bufr_extract_headers $KEYS $input > $temp1
${tools_dir}/bufr_get -f -p $KEYS $input > $temp2
diff -w $temp1 $temp2
diff $temp1 $temp2
done
# Multi-message BUFR
input=${data_dir}/bufr/aeolus_wmo_26.bufr
KEYS='offset,edition,totalLength'
$EXEC ${test_dir}/bufr_extract_headers $KEYS $input > $temp1
${tools_dir}/bufr_get -p $KEYS $input > $temp2
diff -w $temp1 $temp2
# Test local ECMWF keys; should be "not_found" for this input
input=${data_dir}/bufr/PraticaTemp.bufr
KEYS='localSectionPresent,rdbType,ident,isSatellite,satelliteID'
$EXEC ${test_dir}/bufr_extract_headers $KEYS $input > $temp1
${tools_dir}/bufr_get -f -p $KEYS $input > $temp2
diff -w $temp1 $temp2
# Local Section keys
# DWD BUFR with a local section
input=${data_dir}/bufr/uegabe.bufr
r=`${test_dir}/bufr_extract_headers localSectionPresent,ecmwfLocalSectionPresent $input`
[ "$r" = "1 0 " ]
# ECMWF BUFR but has no local section
input=${data_dir}/bufr/207003.bufr
r=`${test_dir}/bufr_extract_headers localSectionPresent,ecmwfLocalSectionPresent $input`
[ "$r" = "0 0 " ]
# ECMWF BUFR with a local section
input=${data_dir}/bufr/aaen_55.bufr
r=`${test_dir}/bufr_extract_headers localSectionPresent,ecmwfLocalSectionPresent $input`
[ "$r" = "1 1 " ]
# BUFRs with localLatitude1, localLongitude1, localLongitude2 etc
# BUFRs with localLatitude1, localLongitude2 etc
# ----------------------------------------------
bufr_files="
aaen_55.bufr
aben_55.bufr
@ -165,7 +183,7 @@ for bf in ${bufr_files}; do
input=${data_dir}/bufr/$bf
$EXEC ${test_dir}/bufr_extract_headers $KEYS $input > $temp1
${tools_dir}/bufr_get -f -p $KEYS $input > $temp2
diff -w $temp1 $temp2
diff $temp1 $temp2
done