diff --git a/src/bufr_util.c b/src/bufr_util.c index 2e4d6bfd6..ad510bfb6 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -1107,3 +1107,13 @@ int codes_bufr_header_get_string(codes_bufr_header* bh, const char* key, char* v return GRIB_SUCCESS; } + +int codes_bufr_key_is_header(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_DATA) == 0); +} diff --git a/src/eccodes.h b/src/eccodes.h index 054870348..d9f6f197d 100644 --- a/src/eccodes.h +++ b/src/eccodes.h @@ -1205,6 +1205,9 @@ int codes_is_missing(const codes_handle* h, const char* key, int* err); /* Returns a bool i.e. 0 or 1 */ int codes_is_defined(const codes_handle* h, const char* key); +/* Returns 1 if the BUFR key is in the header and 1 if it is in the data section. The error code is an argument */ +int codes_bufr_key_is_header(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); diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index 70b3eb140..7a35752ce 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -1489,7 +1489,7 @@ char** codes_bufr_copy_data_return_copied_keys(grib_handle* hin, grib_handle* ho 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); /* string_util.c */ int strcmp_nocase(const char* s1, const char* s2);