-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,377 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* (C) Copyright 2024- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by | ||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. | ||
*/ | ||
|
||
|
||
#include "eccodes/geo/GeoIterator.h" | ||
|
||
#include "eckit/exception/Exceptions.h" | ||
|
||
#include "eccodes/geo/GribSpec.h" | ||
|
||
|
||
namespace eccodes::geo | ||
{ | ||
|
||
|
||
GeoIterator::GeoIterator(grib_handle* h, unsigned long flags) : | ||
spec_(new GribSpec(h)), grid_(eckit::geo::GridFactory::build(*spec_)), iter_(grid_->cbegin().release()), end_(grid_->cend().release()) | ||
{ | ||
h_ = h; | ||
class_name_ = "geo_iterator"; | ||
flags_ = flags; | ||
Assert(h_ != nullptr); | ||
|
||
CODES_CHECK(codes_get_size(h_, "values", &nv_), ""); | ||
Assert(nv_ > 0); | ||
|
||
data_ = (flags_ & GRIB_GEOITERATOR_NO_VALUES) ? nullptr : static_cast<double*>(grib_context_malloc(h_->context, nv_ * sizeof(double))); | ||
Assert(data_ != nullptr); | ||
|
||
auto size = nv_; | ||
CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), ""); | ||
Assert(nv_ == size); | ||
} | ||
|
||
|
||
int GeoIterator::init(grib_handle*, grib_arguments*) | ||
{ | ||
NOTIMP; | ||
} | ||
|
||
|
||
int GeoIterator::next(double* lat, double* lon, double* val) const | ||
{ | ||
if (iter_ == end_) { | ||
return 0; // (false) | ||
} | ||
|
||
const auto p = *iter_; | ||
const auto& q = std::get<eckit::geo::PointLonLat>(p); | ||
|
||
*lat = q.lat; | ||
*lon = q.lon; | ||
if (val != nullptr && data_ != nullptr) { | ||
*val = data_[iter_->index()]; | ||
} | ||
|
||
++iter_; | ||
return 1; // (true) | ||
} | ||
|
||
|
||
int GeoIterator::previous(double*, double*, double*) const | ||
{ | ||
return GRIB_NOT_IMPLEMENTED; | ||
} | ||
|
||
|
||
int GeoIterator::reset() | ||
{ | ||
iter_.reset(grid_->cbegin().release()); | ||
return GRIB_SUCCESS; | ||
} | ||
|
||
|
||
int GeoIterator::destroy() | ||
{ | ||
if (data_ != nullptr) { | ||
grib_context_free(h_->context, data_); | ||
} | ||
return Iterator::destroy(); | ||
} | ||
|
||
|
||
bool GeoIterator::has_next() const | ||
{ | ||
return iter_ != end_; | ||
} | ||
|
||
|
||
geo_iterator::Iterator* | ||
GeoIterator::create() const | ||
{ | ||
return new GeoIterator{ h_, flags_ }; | ||
} | ||
|
||
|
||
} // namespace eccodes::geo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* (C) Copyright 2024- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by | ||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "eckit/geo/Grid.h" | ||
|
||
// eccodes macros conflict with eckit | ||
#ifdef Assert | ||
#undef Assert | ||
#endif | ||
|
||
#include "geo_iterator/grib_iterator.h" | ||
|
||
|
||
namespace eccodes::geo | ||
{ | ||
|
||
|
||
class GeoIterator : public geo_iterator::Iterator | ||
{ | ||
public: | ||
explicit GeoIterator(grib_handle*, unsigned long flags); | ||
|
||
private: | ||
std::unique_ptr<const eckit::geo::Spec> spec_; | ||
std::unique_ptr<const eckit::geo::Grid> grid_; | ||
mutable eckit::geo::Grid::Iterator iter_; | ||
eckit::geo::Grid::Iterator end_; | ||
|
||
int init(grib_handle*, grib_arguments*) override; | ||
int next(double* lat, double* lon, double* val) const override; | ||
int previous(double* lat, double* lon, double* val) const override; | ||
int reset() override; | ||
int destroy() override; | ||
bool has_next() const override; | ||
geo_iterator::Iterator* create() const override; | ||
}; | ||
|
||
|
||
} // namespace eccodes::geo |
Oops, something went wrong.