Merge remote-tracking branch 'origin/feature/mtg2_tablesVersion_switch' into feature/mtg2_tablesVersion_switch_with_chem_param_split

This commit is contained in:
Matthew Griffith 2024-12-23 09:50:18 +00:00
commit 1da89f898f
4 changed files with 22 additions and 15 deletions

View File

@ -22,6 +22,8 @@ void grib_accessor_evaluate_t::init(const long l, grib_arguments* c)
int grib_accessor_evaluate_t::unpack_long(long* val, size_t* len) int grib_accessor_evaluate_t::unpack_long(long* val, size_t* len)
{ {
if (!arg_) return GRIB_INVALID_ARGUMENT;
grib_handle* h = grib_handle_of_accessor(this); grib_handle* h = grib_handle_of_accessor(this);
grib_expression* e = arg_->get_expression(h, 0); grib_expression* e = arg_->get_expression(h, 0);

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);
if (flags_ & GRIB_GEOITERATOR_NO_VALUES) {
data_ = nullptr;
} else {
data_ = static_cast<double*>(grib_context_malloc(h_->context, nv_ * sizeof(double)));
ECCODES_ASSERT(data_ != nullptr);
auto size = nv_; auto size = nv_;
CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), ""); CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), "");
ECCODES_ASSERT(nv_ == 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,9 +122,15 @@ 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
{ {