BUFR: Add function to determine if a key is a coordinate descriptor

This commit is contained in:
Shahram Najm 2023-06-12 20:11:07 +01:00 committed by shahramn
parent cca1a8b743
commit 7c08ef63e3
5 changed files with 38 additions and 16 deletions

View File

@ -1123,3 +1123,14 @@ int codes_bufr_key_is_header(const grib_handle* h, const char* key, int* err)
}
return ((acc->flags & GRIB_ACCESSOR_FLAG_BUFR_DATA) == 0);
}
/* Returns 1 if the BUFR key is a coordinate descriptor */
int codes_bufr_key_is_coordinate(const grib_handle* h, const char* key, int* err)
{
grib_accessor* acc = grib_find_accessor(h, key);
if (!acc) {
*err = GRIB_NOT_FOUND;
return 0;
}
return ((acc->flags & GRIB_ACCESSOR_FLAG_BUFR_COORD) != 0);
}

View File

@ -1360,6 +1360,10 @@ int codes_is_defined(const codes_handle* h, const char* key);
The error code is the final argument */
int codes_bufr_key_is_header(const codes_handle* h, const char* key, int* err);
/* Returns 1 if the BUFR key is a coordinate descriptor and 0 otherwise.
The error code is the final argument */
int codes_bufr_key_is_coordinate(const codes_handle* h, const char* key, int* err);
int codes_set_missing(codes_handle* h, const char* key);
/* The truncation is the Gaussian number (or order) */
int codes_get_gaussian_latitudes(long truncation, double* latitudes);

View File

@ -1479,6 +1479,7 @@ int codes_bufr_copy_data(grib_handle* hin, grib_handle* hout);
int codes_bufr_extract_headers_malloc(grib_context* c, const char* filename, codes_bufr_header** result, int* num_messages, int strict_mode);
int codes_bufr_header_get_string(codes_bufr_header* bh, const char* key, char* val, size_t* len);
int codes_bufr_key_is_header(const grib_handle* h, const char* key, int* err);
int codes_bufr_key_is_coordinate(const grib_handle* h, const char* key, int* err);
/* string_util.cc*/
int strcmp_nocase(const char* s1, const char* s2);

View File

@ -2562,6 +2562,8 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset
gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL);
gaGroup->sub_section = grib_section_create(hand, gaGroup);
gaGroup->bufr_group_number = groupNumber;
//gaGroup->flags |= GRIB_ACCESSOR_FLAG_BUFR_COORD; //??
accessor_constant_set_type(gaGroup, GRIB_TYPE_LONG);
accessor_constant_set_dval(gaGroup, groupNumber);
grib_push_accessor(gaGroup, groupSection->block);
@ -2734,6 +2736,9 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset
}
}
if (add_key) {
if (descriptor->F == 0 && IS_COORDINATE_DESCRIPTOR(descriptor->X)) { //??
elementAccessor->flags |= GRIB_ACCESSOR_FLAG_BUFR_COORD;
}
grib_push_accessor(elementAccessor, section->block);
rank = grib_data_accessors_trie_push(self->dataAccessorsTrie, elementAccessor);
grib_accessors_list_push(self->dataAccessors, elementAccessor, rank);

View File

@ -562,23 +562,24 @@ struct grib_accessor
grib_accessor* parent_as_attribute;
};
#define GRIB_ACCESSOR_FLAG_READ_ONLY (1 << 1)
#define GRIB_ACCESSOR_FLAG_DUMP (1 << 2)
#define GRIB_ACCESSOR_FLAG_READ_ONLY (1 << 1)
#define GRIB_ACCESSOR_FLAG_DUMP (1 << 2)
#define GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC (1 << 3)
#define GRIB_ACCESSOR_FLAG_CAN_BE_MISSING (1 << 4)
#define GRIB_ACCESSOR_FLAG_HIDDEN (1 << 5)
#define GRIB_ACCESSOR_FLAG_CONSTRAINT (1 << 6)
#define GRIB_ACCESSOR_FLAG_BUFR_DATA (1 << 7)
#define GRIB_ACCESSOR_FLAG_NO_COPY (1 << 8)
#define GRIB_ACCESSOR_FLAG_COPY_OK (1 << 9)
#define GRIB_ACCESSOR_FLAG_FUNCTION (1 << 10)
#define GRIB_ACCESSOR_FLAG_DATA (1 << 11)
#define GRIB_ACCESSOR_FLAG_NO_FAIL (1 << 12)
#define GRIB_ACCESSOR_FLAG_TRANSIENT (1 << 13)
#define GRIB_ACCESSOR_FLAG_STRING_TYPE (1 << 14)
#define GRIB_ACCESSOR_FLAG_LONG_TYPE (1 << 15)
#define GRIB_ACCESSOR_FLAG_DOUBLE_TYPE (1 << 16)
#define GRIB_ACCESSOR_FLAG_LOWERCASE (1 << 17)
#define GRIB_ACCESSOR_FLAG_CAN_BE_MISSING (1 << 4)
#define GRIB_ACCESSOR_FLAG_HIDDEN (1 << 5)
#define GRIB_ACCESSOR_FLAG_CONSTRAINT (1 << 6)
#define GRIB_ACCESSOR_FLAG_BUFR_DATA (1 << 7)
#define GRIB_ACCESSOR_FLAG_NO_COPY (1 << 8)
#define GRIB_ACCESSOR_FLAG_COPY_OK (1 << 9)
#define GRIB_ACCESSOR_FLAG_FUNCTION (1 << 10)
#define GRIB_ACCESSOR_FLAG_DATA (1 << 11)
#define GRIB_ACCESSOR_FLAG_NO_FAIL (1 << 12)
#define GRIB_ACCESSOR_FLAG_TRANSIENT (1 << 13)
#define GRIB_ACCESSOR_FLAG_STRING_TYPE (1 << 14)
#define GRIB_ACCESSOR_FLAG_LONG_TYPE (1 << 15)
#define GRIB_ACCESSOR_FLAG_DOUBLE_TYPE (1 << 16)
#define GRIB_ACCESSOR_FLAG_LOWERCASE (1 << 17)
#define GRIB_ACCESSOR_FLAG_BUFR_COORD (1 << 18)
/**
* a section accessor