From 1790fbe2f8b628b99eeb1a4c3cda6495ff34b25d Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 22 Oct 2024 11:53:50 +0100 Subject: [PATCH] Geoiterators: Remove unused data members --- src/geo_iterator/grib_iterator.cc | 12 +++++------ src/geo_iterator/grib_iterator.h | 1 - .../grib_iterator_class_gaussian_reduced.cc | 2 +- src/geo_iterator/grib_iterator_class_gen.cc | 20 +++++++++---------- src/geo_iterator/grib_iterator_class_gen.h | 3 +-- .../grib_iterator_class_healpix.cc | 10 +++++----- ...ator_class_lambert_azimuthal_equal_area.cc | 2 +- .../grib_iterator_class_lambert_conformal.cc | 2 +- .../grib_iterator_class_latlon_reduced.cc | 2 +- .../grib_iterator_class_mercator.cc | 2 +- ...grib_iterator_class_polar_stereographic.cc | 2 +- .../grib_iterator_class_regular.cc | 1 + .../grib_iterator_class_space_view.cc | 2 +- 13 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/geo_iterator/grib_iterator.cc b/src/geo_iterator/grib_iterator.cc index 75938146e..5e4026943 100644 --- a/src/geo_iterator/grib_iterator.cc +++ b/src/geo_iterator/grib_iterator.cc @@ -25,19 +25,17 @@ int Iterator::init(grib_handle* h, grib_arguments* args) /* For this one, ALL destroy are called */ int Iterator::destroy() { - delete context_; delete this; return GRIB_SUCCESS; } eccodes::geo_iterator::Iterator* gribIteratorNew(const grib_handle* ch, unsigned long flags, int* error) { - grib_handle* h = (grib_handle*)ch; - grib_accessor* a = NULL; - grib_accessor_iterator_t* ita = NULL; - *error = GRIB_NOT_IMPLEMENTED; - a = grib_find_accessor(h, "ITERATOR"); - ita = (grib_accessor_iterator_t*)a; + *error = GRIB_NOT_IMPLEMENTED; + + grib_handle* h = (grib_handle*)ch; + grib_accessor* a = grib_find_accessor(h, "ITERATOR"); + grib_accessor_iterator_t* ita = (grib_accessor_iterator_t*)a; if (!a) return NULL; diff --git a/src/geo_iterator/grib_iterator.h b/src/geo_iterator/grib_iterator.h index adb00b41b..ac87d9005 100644 --- a/src/geo_iterator/grib_iterator.h +++ b/src/geo_iterator/grib_iterator.h @@ -33,7 +33,6 @@ public: unsigned long flags_; protected: - grib_context* context_; grib_handle* h_; double* data_; /** data values */ mutable long e_; /** current element */ diff --git a/src/geo_iterator/grib_iterator_class_gaussian_reduced.cc b/src/geo_iterator/grib_iterator_class_gaussian_reduced.cc index eb90c8420..cb06386e7 100644 --- a/src/geo_iterator/grib_iterator_class_gaussian_reduced.cc +++ b/src/geo_iterator/grib_iterator_class_gaussian_reduced.cc @@ -366,8 +366,8 @@ finalise: int GaussianReduced::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; - grib_context_free(c, lats_); grib_context_free(c, lons_); diff --git a/src/geo_iterator/grib_iterator_class_gen.cc b/src/geo_iterator/grib_iterator_class_gen.cc index 4ee02d007..1e14b9e37 100644 --- a/src/geo_iterator/grib_iterator_class_gen.cc +++ b/src/geo_iterator/grib_iterator_class_gen.cc @@ -15,25 +15,25 @@ namespace eccodes::geo_iterator { int Gen::init(grib_handle* h, grib_arguments* args) { int err = GRIB_SUCCESS; - lats_ = lons_ = NULL; + lats_ = lons_ = data_ = NULL; if ((err = Iterator::init(h, args)) != GRIB_SUCCESS) return err; - size_t dli = 0; - const char* s_rawData = NULL; - const char* s_numPoints = NULL; - long numberOfPoints = 0; - carg_ = 1; + // Skip the 1st argument which is the name of the iterator itself + // e.g., latlon, gaussian_reduced etc + carg_ = 1; // start from 1 and not 0 - s_numPoints = grib_arguments_get_name(h, args, carg_++); - missingValue_ = grib_arguments_get_name(h, args, carg_++); - s_rawData = grib_arguments_get_name(h, args, carg_++); + const char* s_numPoints = grib_arguments_get_name(h, args, carg_++); + // The missingValue argument is not currently used. Skip it + carg_++; //const char* s_missingValue = grib_arguments_get_name(h, args, carg_++); + const char* s_rawData = grib_arguments_get_name(h, args, carg_++); - data_ = NULL; + size_t dli = 0; if ((err = grib_get_size(h, s_rawData, &dli)) != GRIB_SUCCESS) return err; + long numberOfPoints = 0; if ((err = grib_get_long_internal(h, s_numPoints, &numberOfPoints)) != GRIB_SUCCESS) return err; diff --git a/src/geo_iterator/grib_iterator_class_gen.h b/src/geo_iterator/grib_iterator_class_gen.h index 0cca14c08..2b1e1b25d 100644 --- a/src/geo_iterator/grib_iterator_class_gen.h +++ b/src/geo_iterator/grib_iterator_class_gen.h @@ -34,8 +34,7 @@ protected: double* lons_; private: - const char* missingValue_; - // int get(double*, double*, double*); + //int get(double*, double*, double*); }; } // namespace eccodes::geo_iterator diff --git a/src/geo_iterator/grib_iterator_class_healpix.cc b/src/geo_iterator/grib_iterator_class_healpix.cc index fcba61678..7b4ac56ef 100644 --- a/src/geo_iterator/grib_iterator_class_healpix.cc +++ b/src/geo_iterator/grib_iterator_class_healpix.cc @@ -280,9 +280,7 @@ int Healpix::init(grib_handle* h, grib_arguments* args) return GRIB_WRONG_GRID; } - char ordering[32] = { - 0, - }; + char ordering[32] = {0,}; size_t slen = sizeof(ordering); if ((err = grib_get_string_internal(h, sorder, ordering, &slen)) != GRIB_SUCCESS) { return err; @@ -349,8 +347,10 @@ int Healpix::next(double* lat, double* lon, double* val) const int Healpix::destroy() { - grib_context_free(context_, lats_); - grib_context_free(context_, lons_); + DEBUG_ASSERT(h_); + const grib_context* c = h_->context; + grib_context_free(c, lats_); + grib_context_free(c, lons_); return Gen::destroy(); } diff --git a/src/geo_iterator/grib_iterator_class_lambert_azimuthal_equal_area.cc b/src/geo_iterator/grib_iterator_class_lambert_azimuthal_equal_area.cc index 009665ea4..9db20fe81 100644 --- a/src/geo_iterator/grib_iterator_class_lambert_azimuthal_equal_area.cc +++ b/src/geo_iterator/grib_iterator_class_lambert_azimuthal_equal_area.cc @@ -429,8 +429,8 @@ int LambertAzimuthalEqualArea::init(grib_handle* h, grib_arguments* args) int LambertAzimuthalEqualArea::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; - grib_context_free(c, lats_); grib_context_free(c, lons_); diff --git a/src/geo_iterator/grib_iterator_class_lambert_conformal.cc b/src/geo_iterator/grib_iterator_class_lambert_conformal.cc index 6b8a6fe93..13162da77 100644 --- a/src/geo_iterator/grib_iterator_class_lambert_conformal.cc +++ b/src/geo_iterator/grib_iterator_class_lambert_conformal.cc @@ -478,8 +478,8 @@ int LambertConformal::next(double* lat, double* lon, double* val) const int LambertConformal::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; - grib_context_free(c, lats_); grib_context_free(c, lons_); diff --git a/src/geo_iterator/grib_iterator_class_latlon_reduced.cc b/src/geo_iterator/grib_iterator_class_latlon_reduced.cc index ba0396912..784320d99 100644 --- a/src/geo_iterator/grib_iterator_class_latlon_reduced.cc +++ b/src/geo_iterator/grib_iterator_class_latlon_reduced.cc @@ -130,8 +130,8 @@ int LatlonReduced::init(grib_handle* h, grib_arguments* args) int LatlonReduced::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; - grib_context_free(c, lats_); grib_context_free(c, lons_); diff --git a/src/geo_iterator/grib_iterator_class_mercator.cc b/src/geo_iterator/grib_iterator_class_mercator.cc index e4a5496be..248ba7872 100644 --- a/src/geo_iterator/grib_iterator_class_mercator.cc +++ b/src/geo_iterator/grib_iterator_class_mercator.cc @@ -273,8 +273,8 @@ int Mercator::next(double* lat, double* lon, double* val) const int Mercator::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; - grib_context_free(c, lats_); grib_context_free(c, lons_); diff --git a/src/geo_iterator/grib_iterator_class_polar_stereographic.cc b/src/geo_iterator/grib_iterator_class_polar_stereographic.cc index 181becee8..beff11bd6 100644 --- a/src/geo_iterator/grib_iterator_class_polar_stereographic.cc +++ b/src/geo_iterator/grib_iterator_class_polar_stereographic.cc @@ -302,8 +302,8 @@ int PolarStereographic::init(grib_handle* h, grib_arguments* args) int PolarStereographic::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; - grib_context_free(c, lats_); grib_context_free(c, lons_); diff --git a/src/geo_iterator/grib_iterator_class_regular.cc b/src/geo_iterator/grib_iterator_class_regular.cc index 98b58050c..11d32ff03 100644 --- a/src/geo_iterator/grib_iterator_class_regular.cc +++ b/src/geo_iterator/grib_iterator_class_regular.cc @@ -48,6 +48,7 @@ int Regular::previous(double* lat, double* lon, double* val) const int Regular::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; grib_context_free(c, lats_); grib_context_free(c, lons_); diff --git a/src/geo_iterator/grib_iterator_class_space_view.cc b/src/geo_iterator/grib_iterator_class_space_view.cc index 15b57156b..d3085dd81 100644 --- a/src/geo_iterator/grib_iterator_class_space_view.cc +++ b/src/geo_iterator/grib_iterator_class_space_view.cc @@ -313,8 +313,8 @@ int SpaceView::init(grib_handle* h, grib_arguments* args) int SpaceView::destroy() { + DEBUG_ASSERT(h_); const grib_context* c = h_->context; - grib_context_free(c, lats_); grib_context_free(c, lons_);