diff --git a/src/eccodes.cc b/src/eccodes.cc index a7984b396..70264eb10 100644 --- a/src/eccodes.cc +++ b/src/eccodes.cc @@ -337,6 +337,10 @@ int codes_get_double(const grib_handle* h, const char* key, double* value) { return grib_get_double(h, key, value); } +int codes_get_float(const grib_handle* h, const char* key, float* value) +{ + return grib_get_float(h, key, value); +} int codes_get_double_element(const grib_handle* h, const char* key, int i, double* value) { diff --git a/src/eccodes.h b/src/eccodes.h index 422c41539..c1b314671 100644 --- a/src/eccodes.h +++ b/src/eccodes.h @@ -775,6 +775,7 @@ int codes_get_long(const codes_handle* h, const char* key, long* value); * @return 0 if OK, integer value on error */ int codes_get_double(const codes_handle* h, const char* key, double* value); +int codes_get_float(const codes_handle* h, const char* key, float* value); /** * Get as double the i-th element of the "key" array diff --git a/src/grib_api.h b/src/grib_api.h index 718a1bb57..efc21dd79 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -783,6 +783,7 @@ int grib_get_long(const grib_handle* h, const char* key, long* value); * @return 0 if OK, integer value on error */ int grib_get_double(const grib_handle* h, const char* key, double* value); +int grib_get_float(const grib_handle* h, const char* key, float* value); /** * Get as double the i-th element of the "key" array diff --git a/src/grib_value.cc b/src/grib_value.cc index facb6e8a4..aeb07fcd6 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -1055,6 +1055,29 @@ int grib_get_double(const grib_handle* h, const char* name, double* val) return ret; } +int grib_get_float(const grib_handle* h, const char* name, float* val) +{ + size_t length = 1; + grib_accessor* a = NULL; + grib_accessors_list* al = NULL; + int ret = 0; + + if (name[0] == '/') { + al = grib_find_accessors_list(h, name); + if (!al) + return GRIB_NOT_FOUND; + ret = grib_unpack_float(al->accessor, val, &length); + grib_context_free(h->context, al); + } + else { + a = grib_find_accessor(h, name); + if (!a) + return GRIB_NOT_FOUND; + ret = grib_unpack_float(a, val, &length); + } + return ret; +} + int grib_get_double_element_internal(grib_handle* h, const char* name, int i, double* val) { int ret = grib_get_double_element(h, name, i, val);