eckit::geo: exception handling and macros

This commit is contained in:
shahramn 2024-12-20 19:26:40 +00:00
parent 2af6a893c1
commit c59047f34f
3 changed files with 20 additions and 15 deletions

View File

@ -31,15 +31,21 @@ GeoIterator::GeoIterator(grib_handle* h, unsigned long flags) :
CODES_CHECK(codes_get_size(h_, "values", &nv_), ""); CODES_CHECK(codes_get_size(h_, "values", &nv_), "");
ECCODES_ASSERT(nv_ > 0); ECCODES_ASSERT(nv_ > 0);
data_ = (flags_ & GRIB_GEOITERATOR_NO_VALUES) ? nullptr : static_cast<double*>(grib_context_malloc(h_->context, nv_ * sizeof(double))); //long numberOfPoints = 0;
ECCODES_ASSERT(data_ != nullptr); //grib_get_long_internal(h, "numberOfPoints", &numberOfPoints);
auto size = nv_; if (flags_ & GRIB_GEOITERATOR_NO_VALUES) {
CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), ""); data_ = nullptr;
ECCODES_ASSERT(nv_ == size); } else {
data_ = static_cast<double*>(grib_context_malloc(h_->context, nv_ * sizeof(double)));
ECCODES_ASSERT(data_ != nullptr);
auto size = nv_;
CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), "");
// Check numberOfPoints equals nv_
// if not, throw an exception
}
} }
int GeoIterator::init(grib_handle*, grib_arguments*) int GeoIterator::init(grib_handle*, grib_arguments*)
{ {
NOTIMP; NOTIMP;

View File

@ -15,18 +15,12 @@
#include "eckit/geo/Grid.h" #include "eckit/geo/Grid.h"
// eccodes macros conflict with eckit
#ifdef Assert
#undef Assert
#endif
#include "geo/iterator/grib_iterator.h" #include "geo/iterator/grib_iterator.h"
namespace eccodes::geo namespace eccodes::geo
{ {
class GeoIterator : public geo_iterator::Iterator class GeoIterator : public geo_iterator::Iterator
{ {
public: public:
@ -47,5 +41,4 @@ private:
geo_iterator::Iterator* create() const override; geo_iterator::Iterator* create() const override;
}; };
} // namespace eccodes::geo } // namespace eccodes::geo

View File

@ -122,8 +122,14 @@ grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int
} }
} }
} static const init_main; } static const init_main;
try {
i->iterator = new eccodes::geo::GeoIterator(const_cast<grib_handle*>(ch), flags); i->iterator = new eccodes::geo::GeoIterator(const_cast<grib_handle*>(ch), flags);
}
catch(std::exception& e) {
grib_context_log(ch->context, GRIB_LOG_ERROR, "grib_iterator_new: Exception thrown (%s)", e.what());
*error = GRIB_GEOCALCULUS_PROBLEM;
return NULL;
}
} }
else else
#endif #endif