From 87a34bfd0f4409de635bab9d106ab761f8de15c7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 21 Jun 2018 11:33:01 +0100 Subject: [PATCH] ECC-445: Refactoring: put test for key in one place --- src/grib_api_prototypes.h | 1 + src/grib_gaussian_reduced.c | 5 +---- src/grib_iterator_class_gaussian_reduced.c | 4 +--- src/grib_util.c | 10 ++++++++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index 8e098df3d..18e8abcb2 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -1462,6 +1462,7 @@ int is_productDefinitionTemplateNumber_Aerosol(long productDefinitionTemplateNum int is_index_file(const char *filename); char get_dir_separator_char(void); char *codes_getenv(const char *name); +int expandedBoundingBox(grib_handle* h); /* bufr_util.c */ int compute_bufr_key_rank(grib_handle *h, grib_string_list *keys, const char *key); diff --git a/src/grib_gaussian_reduced.c b/src/grib_gaussian_reduced.c index 8cd0bc4be..280fd1476 100644 --- a/src/grib_gaussian_reduced.c +++ b/src/grib_gaussian_reduced.c @@ -291,10 +291,7 @@ static void gaussian_reduced_row( /* --------------------------------------------------------------------------------------------------- */ void grib_get_reduced_row_wrapper(grib_handle* h, long pl, double lon_first, double lon_last, long* npoints, long* ilon_first, long* ilon_last) { - int err = 0; - long expandedBoundingBox = 0; - err = grib_get_long(h, "expandedBoundingBox", &expandedBoundingBox); - if (!err && expandedBoundingBox == 1) { + if (expandedBoundingBox(h)) { grib_get_reduced_row2(pl, lon_first, lon_last, npoints, ilon_first, ilon_last); } else { grib_get_reduced_row(pl, lon_first, lon_last, npoints, ilon_first, ilon_last); diff --git a/src/grib_iterator_class_gaussian_reduced.c b/src/grib_iterator_class_gaussian_reduced.c index 2ec20fc77..1b219a6e3 100644 --- a/src/grib_iterator_class_gaussian_reduced.c +++ b/src/grib_iterator_class_gaussian_reduced.c @@ -185,9 +185,7 @@ static int iterate_reduced_gaussian_subarea_wrapper(grib_iterator* iter, grib_ha double* lats, long* pl, size_t plsize) { int err = 0; - long expandedBoundingBox = 0; - err = grib_get_long(h, "expandedBoundingBox", &expandedBoundingBox); - if (!err && expandedBoundingBox == 1) { + if (expandedBoundingBox(h)) { return iterate_reduced_gaussian_subarea(iter, h, lat_first, lon_first, lat_last, lon_last, lats, pl, plsize, 1); } diff --git a/src/grib_util.c b/src/grib_util.c index 2241f6b85..a13ac8743 100644 --- a/src/grib_util.c +++ b/src/grib_util.c @@ -1848,3 +1848,13 @@ char* codes_getenv(const char* name) } return result; } + +int expandedBoundingBox(grib_handle* h) +{ + long expandedBoundingBox = 0; + int err = grib_get_long(h, "expandedBoundingBox", &expandedBoundingBox); + if (!err && expandedBoundingBox == 1) { + return 1; + } + return 0; +}