From 9b5ddb9be78f38941d0d0a1b75e4a6e387d48c31 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Sun, 3 Nov 2024 21:29:50 +0100 Subject: [PATCH] Modernisation: Nearest: Move shared variables to the base class --- src/geo_nearest/grib_nearest_class_gen.cc | 10 +++++-- src/geo_nearest/grib_nearest_class_gen.h | 12 ++++++++ src/geo_nearest/grib_nearest_class_healpix.cc | 18 ++---------- src/geo_nearest/grib_nearest_class_healpix.h | 13 --------- ...rest_class_lambert_azimuthal_equal_area.cc | 19 ++----------- ...arest_class_lambert_azimuthal_equal_area.h | 13 --------- .../grib_nearest_class_lambert_conformal.cc | 18 ++---------- .../grib_nearest_class_lambert_conformal.h | 13 --------- .../grib_nearest_class_latlon_reduced.cc | 28 ++++--------------- .../grib_nearest_class_latlon_reduced.h | 9 ------ .../grib_nearest_class_mercator.cc | 24 ++++------------ src/geo_nearest/grib_nearest_class_mercator.h | 13 --------- .../grib_nearest_class_polar_stereographic.cc | 22 ++++----------- .../grib_nearest_class_polar_stereographic.h | 13 --------- src/geo_nearest/grib_nearest_class_reduced.cc | 23 ++++----------- src/geo_nearest/grib_nearest_class_reduced.h | 8 ------ src/geo_nearest/grib_nearest_class_regular.cc | 14 ---------- src/geo_nearest/grib_nearest_class_regular.h | 13 --------- .../grib_nearest_class_space_view.cc | 22 +++------------ .../grib_nearest_class_space_view.h | 13 --------- 20 files changed, 52 insertions(+), 266 deletions(-) diff --git a/src/geo_nearest/grib_nearest_class_gen.cc b/src/geo_nearest/grib_nearest_class_gen.cc index 16e31508e..68a257367 100644 --- a/src/geo_nearest/grib_nearest_class_gen.cc +++ b/src/geo_nearest/grib_nearest_class_gen.cc @@ -30,8 +30,14 @@ int Gen::init(grib_handle* h, grib_arguments* args) int Gen::destroy() { grib_context* c = grib_context_get_default(); - if (values_) - grib_context_free(c, values_); + + if (lats_) grib_context_free(c, lats_); + if (lons_) grib_context_free(c, lons_); + if (i_) grib_context_free(c, i_); + if (j_) grib_context_free(c, j_); + if (k_) grib_context_free(c, k_); + if (distances_) grib_context_free(c, distances_); + if (values_) grib_context_free(c, values_); return Nearest::destroy(); } diff --git a/src/geo_nearest/grib_nearest_class_gen.h b/src/geo_nearest/grib_nearest_class_gen.h index 8ef4fa05c..0e35c62e5 100644 --- a/src/geo_nearest/grib_nearest_class_gen.h +++ b/src/geo_nearest/grib_nearest_class_gen.h @@ -25,6 +25,18 @@ protected: int cargs_ = 0; const char* values_key_ = nullptr; + double* lats_ = nullptr; + int lats_count_ = 0; + double* lons_ = nullptr; + int lons_count_ = 0; + + double* distances_ = nullptr; + size_t* k_ = nullptr; + size_t* i_ = nullptr; + size_t* j_ = nullptr; + const char* Ni_ = nullptr; + const char* Nj_ = nullptr; + private: const char* radius_ = nullptr; }; diff --git a/src/geo_nearest/grib_nearest_class_healpix.cc b/src/geo_nearest/grib_nearest_class_healpix.cc index d55f220d4..8a2bd8820 100644 --- a/src/geo_nearest/grib_nearest_class_healpix.cc +++ b/src/geo_nearest/grib_nearest_class_healpix.cc @@ -23,8 +23,8 @@ int Healpix::init(grib_handle* h, grib_arguments* args) Ni_ = grib_arguments_get_name(h, args, cargs_++); Nj_ = grib_arguments_get_name(h, args, cargs_++); - i_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); - j_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); + i_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); return ret; } @@ -48,18 +48,4 @@ int Healpix::find(grib_handle* h, values, distances, indexes, len); } -int Healpix::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (i_) grib_context_free(c, i_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - - return GRIB_SUCCESS; -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_healpix.h b/src/geo_nearest/grib_nearest_class_healpix.h index 709f8cb56..37e6e5f83 100644 --- a/src/geo_nearest/grib_nearest_class_healpix.h +++ b/src/geo_nearest/grib_nearest_class_healpix.h @@ -22,19 +22,6 @@ public: Nearest* create() override { return new Healpix(); }; int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; - -private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - int lons_count_ = 0; - double* distances_ = nullptr; - int* k_ = nullptr; - int* i_ = nullptr; - int* j_ = nullptr; - const char* Ni_ = nullptr; - const char* Nj_ = nullptr; }; } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.cc b/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.cc index d2d4d4523..c2911fa77 100644 --- a/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.cc +++ b/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.cc @@ -23,8 +23,9 @@ int LambertAzimuthalEqualArea::init(grib_handle* h, grib_arguments* args) Ni_ = grib_arguments_get_name(h, args, cargs_++); Nj_ = grib_arguments_get_name(h, args, cargs_++); - i_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); - j_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); + i_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + return ret; } @@ -47,18 +48,4 @@ int LambertAzimuthalEqualArea::find(grib_handle* h, values, distances, indexes, len); } -int LambertAzimuthalEqualArea::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (i_) grib_context_free(c, i_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - - return Gen::destroy(); -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.h b/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.h index ae3a2403a..38ec127ba 100644 --- a/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.h +++ b/src/geo_nearest/grib_nearest_class_lambert_azimuthal_equal_area.h @@ -22,19 +22,6 @@ public: Nearest* create() override { return new LambertAzimuthalEqualArea(); } int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; - -private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - int lons_count_ = 0; - double* distances_ = nullptr; - int* k_ = nullptr; - int* i_ = nullptr; - int* j_ = nullptr; - const char* Ni_ = nullptr; - const char* Nj_ = nullptr; }; } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_lambert_conformal.cc b/src/geo_nearest/grib_nearest_class_lambert_conformal.cc index eb0241020..fe4955518 100644 --- a/src/geo_nearest/grib_nearest_class_lambert_conformal.cc +++ b/src/geo_nearest/grib_nearest_class_lambert_conformal.cc @@ -23,8 +23,8 @@ int LambertConformal::init(grib_handle* h, grib_arguments* args) Ni_ = grib_arguments_get_name(h, args, cargs_++); Nj_ = grib_arguments_get_name(h, args, cargs_++); - i_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); - j_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); + i_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); return ret; } @@ -48,18 +48,4 @@ int LambertConformal::find(grib_handle* h, values, distances, indexes, len); } -int LambertConformal::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (i_) grib_context_free(c, i_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - - return Gen::destroy(); -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_lambert_conformal.h b/src/geo_nearest/grib_nearest_class_lambert_conformal.h index fc1970399..bcb3d27e2 100644 --- a/src/geo_nearest/grib_nearest_class_lambert_conformal.h +++ b/src/geo_nearest/grib_nearest_class_lambert_conformal.h @@ -22,19 +22,6 @@ public: Nearest* create() override { return new LambertConformal(); }; int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; - -private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - int lons_count_ = 0; - double* distances_ = nullptr; - int* k_ = nullptr; - int* i_ = nullptr; - int* j_ = nullptr; - const char* Ni_ = nullptr; - const char* Nj_ = nullptr; }; } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_latlon_reduced.cc b/src/geo_nearest/grib_nearest_class_latlon_reduced.cc index 024e5d3a9..f9e3a4ae5 100644 --- a/src/geo_nearest/grib_nearest_class_latlon_reduced.cc +++ b/src/geo_nearest/grib_nearest_class_latlon_reduced.cc @@ -21,11 +21,11 @@ int LatlonReduced::init(grib_handle* h, grib_arguments* args) if ((ret = Gen::init(h, args) != GRIB_SUCCESS)) return ret; - Nj_ = grib_arguments_get_name(h, args, cargs_++); - pl_ = grib_arguments_get_name(h, args, cargs_++); - lonFirst_ = grib_arguments_get_name(h, args, cargs_++); - lonLast_ = grib_arguments_get_name(h, args, cargs_++); - j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + Nj_ = grib_arguments_get_name(h, args, cargs_++); + pl_ = grib_arguments_get_name(h, args, cargs_++); + lonFirst_ = grib_arguments_get_name(h, args, cargs_++); + lonLast_ = grib_arguments_get_name(h, args, cargs_++); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); if (!j_) return GRIB_OUT_OF_MEMORY; k_ = (size_t*)grib_context_malloc(h->context, 4 * sizeof(size_t)); @@ -227,6 +227,7 @@ int LatlonReduced::find_global(grib_handle* h, if (!distances_) return GRIB_OUT_OF_MEMORY; + //void grib_binary_search(const double xx[], const size_t n, double x, size_t* ju, size_t* jl) grib_binary_search(lats_, ilat - 1, inlat, &(j_[0]), &(j_[1])); @@ -340,21 +341,4 @@ int LatlonReduced::find_global(grib_handle* h, return GRIB_SUCCESS; } -int LatlonReduced::destroy() -{ - grib_context* c = grib_context_get_default(); - if (lats_) - grib_context_free(c, lats_); - if (lons_) - grib_context_free(c, lons_); - if (j_) - grib_context_free(c, j_); - if (k_) - grib_context_free(c, k_); - if (distances_) - grib_context_free(c, distances_); - - return Gen::destroy(); -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_latlon_reduced.h b/src/geo_nearest/grib_nearest_class_latlon_reduced.h index 743f7d4a3..99ebb930b 100644 --- a/src/geo_nearest/grib_nearest_class_latlon_reduced.h +++ b/src/geo_nearest/grib_nearest_class_latlon_reduced.h @@ -22,21 +22,12 @@ public: Nearest* create() override { return new LatlonReduced(); } int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - double* distances_ = nullptr; - size_t* k_ = nullptr; - size_t* j_ = nullptr; - const char* Nj_ = nullptr; const char* pl_ = nullptr; const char* lonFirst_ = nullptr; const char* lonLast_ = nullptr; - int find_global(grib_handle*, double, double, unsigned long, double*, double*, double*, diff --git a/src/geo_nearest/grib_nearest_class_mercator.cc b/src/geo_nearest/grib_nearest_class_mercator.cc index e494af5b2..4faa54917 100644 --- a/src/geo_nearest/grib_nearest_class_mercator.cc +++ b/src/geo_nearest/grib_nearest_class_mercator.cc @@ -21,12 +21,11 @@ int Mercator::init(grib_handle* h, grib_arguments* args) if ((ret = Gen::init(h, args) != GRIB_SUCCESS)) return ret; - Ni_ = grib_arguments_get_name(h, args, cargs_++); - Nj_ = grib_arguments_get_name(h, args, cargs_++); - lats_ = lons_ = distances_ = NULL; - lats_count_ = lons_count_ = 0; - i_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); - j_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); + Ni_ = grib_arguments_get_name(h, args, cargs_++); + Nj_ = grib_arguments_get_name(h, args, cargs_++); + i_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + return ret; } @@ -49,17 +48,4 @@ int Mercator::find(grib_handle* h, values, distances, indexes, len); } -int Mercator::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (i_) grib_context_free(c, i_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - return GRIB_SUCCESS; -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_mercator.h b/src/geo_nearest/grib_nearest_class_mercator.h index 5bdb50a2b..9d79cee4c 100644 --- a/src/geo_nearest/grib_nearest_class_mercator.h +++ b/src/geo_nearest/grib_nearest_class_mercator.h @@ -22,19 +22,6 @@ public: Nearest* create() override { return new Mercator(); }; int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; - -private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - int lons_count_ = 0; - double* distances_ = nullptr; - int* k_ = nullptr; - int* i_ = nullptr; - int* j_ = nullptr; - const char* Ni_ = nullptr; - const char* Nj_ = nullptr; }; } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_polar_stereographic.cc b/src/geo_nearest/grib_nearest_class_polar_stereographic.cc index 5f1da4b35..37baf493d 100644 --- a/src/geo_nearest/grib_nearest_class_polar_stereographic.cc +++ b/src/geo_nearest/grib_nearest_class_polar_stereographic.cc @@ -21,10 +21,11 @@ int PolarStereographic::init(grib_handle* h, grib_arguments* args) if ((ret = Gen::init(h, args) != GRIB_SUCCESS)) return ret; - Ni_ = grib_arguments_get_name(h, args, cargs_++); - Nj_ = grib_arguments_get_name(h, args, cargs_++); - i_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); - j_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); + Ni_ = grib_arguments_get_name(h, args, cargs_++); + Nj_ = grib_arguments_get_name(h, args, cargs_++); + i_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + return ret; } @@ -47,17 +48,4 @@ int PolarStereographic::find(grib_handle* h, values, distances, indexes, len); } -int PolarStereographic::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (i_) grib_context_free(c, i_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - return GRIB_SUCCESS; -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_polar_stereographic.h b/src/geo_nearest/grib_nearest_class_polar_stereographic.h index 0af9ebb4c..8580dffd8 100644 --- a/src/geo_nearest/grib_nearest_class_polar_stereographic.h +++ b/src/geo_nearest/grib_nearest_class_polar_stereographic.h @@ -22,19 +22,6 @@ public: Nearest* create() override { return new PolarStereographic(); } int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; - -private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - int lons_count_ = 0; - double* distances_ = nullptr; - int* k_ = nullptr; - int* i_ = nullptr; - int* j_ = nullptr; - const char* Ni_ = nullptr; - const char* Nj_ = nullptr; }; } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_reduced.cc b/src/geo_nearest/grib_nearest_class_reduced.cc index f5c976282..6d4b65241 100644 --- a/src/geo_nearest/grib_nearest_class_reduced.cc +++ b/src/geo_nearest/grib_nearest_class_reduced.cc @@ -23,11 +23,11 @@ int Reduced::init(grib_handle* h, grib_arguments* args) if ((ret = Gen::init(h, args) != GRIB_SUCCESS)) return ret; - Nj_ = grib_arguments_get_name(h, args, cargs_++); - pl_ = grib_arguments_get_name(h, args, cargs_++); - j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); - legacy_ = -1; - rotated_ = -1; + Nj_ = grib_arguments_get_name(h, args, cargs_++); + pl_ = grib_arguments_get_name(h, args, cargs_++); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + legacy_ = -1; + rotated_ = -1; if (!j_) return GRIB_OUT_OF_MEMORY; k_ = (size_t*)grib_context_malloc(h->context, NUM_NEIGHBOURS * sizeof(size_t)); @@ -433,17 +433,4 @@ int Reduced::find_global(grib_handle* h, return GRIB_SUCCESS; } -int Reduced::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - - return GRIB_SUCCESS; -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_reduced.h b/src/geo_nearest/grib_nearest_class_reduced.h index ccf499cf5..6132c26b9 100644 --- a/src/geo_nearest/grib_nearest_class_reduced.h +++ b/src/geo_nearest/grib_nearest_class_reduced.h @@ -22,16 +22,8 @@ public: Nearest* create() override { return new Reduced(); } int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - double* distances_ = nullptr; - size_t* k_ = nullptr; - size_t* j_ = nullptr; - const char* Nj_ = nullptr; const char* pl_ = nullptr; long global_ = 0.0; double lon_first_ = 0.0; diff --git a/src/geo_nearest/grib_nearest_class_regular.cc b/src/geo_nearest/grib_nearest_class_regular.cc index 5f04c1839..9b5700310 100644 --- a/src/geo_nearest/grib_nearest_class_regular.cc +++ b/src/geo_nearest/grib_nearest_class_regular.cc @@ -285,18 +285,4 @@ int Regular::find(grib_handle* h, return GRIB_SUCCESS; } -int Regular::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (i_) grib_context_free(c, i_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - - return Gen::destroy(); -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_regular.h b/src/geo_nearest/grib_nearest_class_regular.h index 0113100da..481b6a1c8 100644 --- a/src/geo_nearest/grib_nearest_class_regular.h +++ b/src/geo_nearest/grib_nearest_class_regular.h @@ -22,19 +22,6 @@ public: Nearest* create() override { return new Regular(); } int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; - -private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - int lons_count_ = 0; - double* distances_ = nullptr; - size_t* k_ = nullptr; - size_t* i_ = nullptr; - size_t* j_ = nullptr; - const char* Ni_ = nullptr; - const char* Nj_ = nullptr; }; } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_space_view.cc b/src/geo_nearest/grib_nearest_class_space_view.cc index 59d4edec5..172e5d357 100644 --- a/src/geo_nearest/grib_nearest_class_space_view.cc +++ b/src/geo_nearest/grib_nearest_class_space_view.cc @@ -21,10 +21,10 @@ int SpaceView::init(grib_handle* h, grib_arguments* args) if ((ret = Gen::init(h, args) != GRIB_SUCCESS)) return ret; - Ni_ = grib_arguments_get_name(h, args, cargs_++); - Nj_ = grib_arguments_get_name(h, args, cargs_++); - i_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); - j_ = (int*)grib_context_malloc(h->context, 2 * sizeof(int)); + Ni_ = grib_arguments_get_name(h, args, cargs_++); + Nj_ = grib_arguments_get_name(h, args, cargs_++); + i_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); + j_ = (size_t*)grib_context_malloc(h->context, 2 * sizeof(size_t)); return ret; } @@ -48,18 +48,4 @@ int SpaceView::find(grib_handle* h, values, distances, indexes, len); } -int SpaceView::destroy() -{ - grib_context* c = grib_context_get_default(); - - if (lats_) grib_context_free(c, lats_); - if (lons_) grib_context_free(c, lons_); - if (i_) grib_context_free(c, i_); - if (j_) grib_context_free(c, j_); - if (k_) grib_context_free(c, k_); - if (distances_) grib_context_free(c, distances_); - - return Gen::destroy(); -} - } // namespace eccodes::geo_nearest diff --git a/src/geo_nearest/grib_nearest_class_space_view.h b/src/geo_nearest/grib_nearest_class_space_view.h index 161fb583a..4f6447ed0 100644 --- a/src/geo_nearest/grib_nearest_class_space_view.h +++ b/src/geo_nearest/grib_nearest_class_space_view.h @@ -22,19 +22,6 @@ public: Nearest* create() override { return new SpaceView(); } int init(grib_handle*, grib_arguments*) override; int find(grib_handle*, double, double, unsigned long, double*, double*, double*, double*, int*, size_t*) override; - int destroy() override; - -private: - double* lats_ = nullptr; - int lats_count_ = 0; - double* lons_ = nullptr; - int lons_count_ = 0; - double* distances_ = nullptr; - int* k_ = nullptr; - int* i_ = nullptr; - int* j_ = nullptr; - const char* Ni_ = nullptr; - const char* Nj_ = nullptr; }; } // namespace eccodes::geo_nearest