Skip to content

Commit 8aa27ec

Browse files
committed
Merge branch 'develop' into levelist
2 parents 2fdee5b + 250f0da commit 8aa27ec

File tree

314 files changed

+45114
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+45114
-181
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ ecbuild_add_option( FEATURE ODB
6060
DESCRIPTION "Add support for ODB data"
6161
REQUIRED_PACKAGES "NAME odc VERSION 1.0" )
6262

63+
# MARS2GRIB encoder
64+
65+
ecbuild_add_option( FEATURE MARS2GRIB
66+
DEFAULT ON
67+
DESCRIPTION "Build the MARS2GRIB encoder" )
68+
69+
# Python bindings for mars2grib encoder
70+
71+
ecbuild_add_option( FEATURE MARS2GRIB_PYTHON
72+
DEFAULT OFF
73+
CONDITION HAVE_MARS2GRIB
74+
DESCRIPTION "Build mars2grib python library"
75+
REQUIRED_PACKAGES
76+
"NAME Python VERSION 3.11 COMPONENTS Interpreter Development REQUIRED"
77+
"NAME pybind11 VERSION 3.0.1 REQUIRED" )
78+
6379
# METKIT config files support
6480

6581
ecbuild_add_option( FEATURE METKIT_CONFIG

src/metkit/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ if ( HAVE_GRIB )
129129
codes/BUFRDecoder.h
130130
codes/GRIBDecoder.cc
131131
codes/GRIBDecoder.h
132+
codes/CodesDataContent.cc
133+
codes/CodesDataContent.h
132134
codes/CodesContent.cc
133135
codes/CodesContent.h
134136
codes/BufrContent.cc
135137
codes/BufrContent.h
136-
codes/MallocCodesContent.cc
137-
codes/MallocCodesContent.h
138138
codes/CodesSplitter.cc
139139
codes/CodesSplitter.h
140140
codes/GribAccessor.cc
@@ -184,6 +184,15 @@ if ( HAVE_ODB )
184184
set( odc_libs odccore )
185185
endif()
186186

187+
if ( HAVE_MARS2GRIB )
188+
list( APPEND metkit_srcs
189+
mars2grib/api/Mars2Grib.cc
190+
mars2grib/api/Mars2Grib.h
191+
mars2grib/api/Options.h
192+
)
193+
set( mars2grib_libs eckit_geo )
194+
endif()
195+
187196
ecbuild_add_library(
188197

189198
TARGET metkit
@@ -211,4 +220,9 @@ ecbuild_add_library(
211220
eckit
212221
eckit_option
213222
${grib_libs}
223+
${mars2grib_libs}
214224
)
225+
226+
if( HAVE_MARS2GRIB_PYTHON )
227+
add_subdirectory(mars2grib/api/pymars2grib)
228+
endif()

src/metkit/codes/BUFRDecoder.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ void BUFRDecoder::getMetadata(const eckit::message::Message& msg, eckit::message
8989
// https://confluence.ecmwf.int/display/ECC/bufr_keys_iterator
9090
h->set("unpack", 1);
9191

92-
for (auto& k : h->keys()) {
92+
for (const auto& k : h->keys()) {
9393
auto name = k.name();
9494

9595
if (name == "subsetNumber") {
9696
continue;
9797
}
9898

99-
/* get key size to see if it is an array */
99+
// Get key size to see if it is an array
100+
// Only continue for scalar values
100101
if (h->size(name) != 1) {
101102
continue;
102103
}

src/metkit/codes/BufrContent.cc

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@
88
* does it submit to any jurisdiction.
99
*/
1010

11-
/// @author Baudouin Raoult
12-
/// @author Emanuele Danovaro
13-
/// @date Mar 2022
14-
1511
#include "metkit/codes/BufrContent.h"
1612

17-
#include "metkit/codes/GribHandle.h"
18-
1913
#include "eccodes.h"
2014

2115
namespace metkit {
@@ -24,29 +18,14 @@ namespace codes {
2418

2519
//----------------------------------------------------------------------------------------------------------------------
2620

27-
BufrContent::BufrContent(codes_handle* handle, bool delete_handle) : CodesContent(handle, delete_handle) {}
28-
29-
BufrContent::BufrContent(const codes_handle* handle) : BufrContent(const_cast<codes_handle*>(handle), false) {}
30-
31-
BufrContent::~BufrContent() {}
32-
21+
BufrContent::BufrContent(std::unique_ptr<CodesHandle> handle) : CodesDataContent(std::move(handle)) {}
3322

3423
//----------------------------------------------------------------------------------------------------------------------
3524

3625
void BufrContent::transform(const eckit::OrderedStringDict& dict) {
37-
38-
std::vector<codes_values> values;
39-
40-
for (auto& kv : dict) {
41-
codes_values v;
42-
v.name = kv.first.c_str();
43-
v.long_value = std::stol(kv.second);
44-
v.type = GRIB_TYPE_LONG;
45-
46-
values.push_back(v);
26+
for (const auto& [key, value] : dict) {
27+
handle_->set(key, std::stol(value));
4728
}
48-
49-
CODES_CALL(codes_set_values(handle_, values.data(), values.size()));
5029
}
5130

5231

src/metkit/codes/BufrContent.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@
1414

1515
#pragma once
1616

17-
#include "metkit/codes/CodesContent.h"
17+
#include "metkit/codes/CodesDataContent.h"
1818

1919
namespace metkit {
2020
namespace codes {
2121

2222

2323
//----------------------------------------------------------------------------------------------------------------------
2424

25-
class BufrContent : public CodesContent {
25+
class BufrContent : public CodesDataContent {
2626
public:
2727

28-
BufrContent(codes_handle* handle, bool delete_handle);
29-
explicit BufrContent(const codes_handle* handle);
28+
BufrContent(std::unique_ptr<CodesHandle> handle);
3029

31-
~BufrContent();
30+
virtual ~BufrContent() = default;
3231

3332
protected:
3433

35-
using CodesContent::transform;
34+
using CodesDataContent::transform;
3635
void transform(const eckit::OrderedStringDict& dict) override;
3736
};
3837

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* (C) Copyright 2017- ECMWF.
3+
*
4+
* This software is licensed under the terms of the Apache Licence Version 2.0
5+
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
* In applying this licence, ECMWF does not waive the privileges and immunities
7+
* granted to it by virtue of its status as an intergovernmental organisation nor
8+
* does it submit to any jurisdiction.
9+
*/
10+
11+
#include "metkit/codes/CodesDataContent.h"
12+
13+
#include "eccodes.h"
14+
15+
#include "eckit/exception/Exceptions.h"
16+
#include "eckit/io/DataHandle.h"
17+
#include "eckit/io/MemoryHandle.h"
18+
19+
#include "metkit/codes/GribHandle.h"
20+
21+
namespace metkit {
22+
namespace codes {
23+
24+
//----------------------------------------------------------------------------------------------------------------------
25+
26+
CodesDataContent::CodesDataContent(std::unique_ptr<CodesHandle> handle) :
27+
handle_(std::move(handle)), offset_(handle_->getLong("offset")) {}
28+
29+
30+
CodesDataContent::CodesDataContent(std::unique_ptr<CodesHandle> handle, eckit::Offset offset) :
31+
handle_(std::move(handle)), offset_(std::move(offset)) {}
32+
33+
34+
//----------------------------------------------------------------------------------------------------------------------
35+
36+
size_t CodesDataContent::length() const {
37+
return handle_->messageSize();
38+
}
39+
40+
41+
//----------------------------------------------------------------------------------------------------------------------
42+
43+
void CodesDataContent::write(eckit::DataHandle& handle) const {
44+
auto data = handle_->messageData();
45+
if (handle.write(data.data(), data.size()) != data.size()) {
46+
std::ostringstream oss;
47+
oss << "Write error to data handle " << handle;
48+
throw eckit::WriteError(oss.str(), Here());
49+
}
50+
}
51+
52+
53+
//----------------------------------------------------------------------------------------------------------------------
54+
55+
eckit::DataHandle* CodesDataContent::readHandle() const {
56+
auto data = handle_->messageData();
57+
return new eckit::MemoryHandle(data.data(), data.size());
58+
}
59+
60+
61+
//----------------------------------------------------------------------------------------------------------------------
62+
63+
void CodesDataContent::print(std::ostream& s) const {
64+
s << "CodesDataContent[]";
65+
}
66+
67+
68+
//----------------------------------------------------------------------------------------------------------------------
69+
70+
std::string CodesDataContent::getString(const std::string& key) const {
71+
return handle_->getString(key);
72+
}
73+
74+
//----------------------------------------------------------------------------------------------------------------------
75+
76+
long CodesDataContent::getLong(const std::string& key) const {
77+
return handle_->getLong(key);
78+
}
79+
80+
81+
//----------------------------------------------------------------------------------------------------------------------
82+
83+
double CodesDataContent::getDouble(const std::string& key) const {
84+
return handle_->getDouble(key);
85+
}
86+
87+
88+
//----------------------------------------------------------------------------------------------------------------------
89+
90+
void CodesDataContent::getDoubleArray(const std::string& key, std::vector<double>& values) const {
91+
values = handle_->getDoubleArray(key);
92+
}
93+
94+
//----------------------------------------------------------------------------------------------------------------------
95+
96+
void CodesDataContent::getFloatArray(const std::string& key, std::vector<float>& values) const {
97+
values = handle_->getFloatArray(key);
98+
}
99+
100+
101+
//----------------------------------------------------------------------------------------------------------------------
102+
103+
size_t CodesDataContent::getSize(const std::string& key) const {
104+
return handle_->size(key);
105+
}
106+
107+
108+
//----------------------------------------------------------------------------------------------------------------------
109+
110+
void CodesDataContent::getDoubleArray(const std::string& key, double* data, size_t len) const {
111+
auto arr = handle_->getDoubleArray(key);
112+
ASSERT(len == arr.size());
113+
std::copy(arr.begin(), arr.end(), data);
114+
}
115+
116+
//----------------------------------------------------------------------------------------------------------------------
117+
118+
void CodesDataContent::getFloatArray(const std::string& key, float* data, size_t len) const {
119+
auto arr = handle_->getFloatArray(key);
120+
ASSERT(len == arr.size());
121+
std::copy(arr.begin(), arr.end(), data);
122+
}
123+
124+
125+
//----------------------------------------------------------------------------------------------------------------------
126+
127+
void CodesDataContent::transform(const eckit::OrderedStringDict& dict) {
128+
for (auto& [key, value] : dict) {
129+
handle_->set(key, value);
130+
}
131+
}
132+
133+
//----------------------------------------------------------------------------------------------------------------------
134+
135+
eckit::Offset CodesDataContent::offset() const {
136+
return offset_;
137+
}
138+
139+
//----------------------------------------------------------------------------------------------------------------------
140+
141+
const void* CodesDataContent::data() const {
142+
return handle_->messageData().data();
143+
}
144+
145+
//----------------------------------------------------------------------------------------------------------------------
146+
147+
const CodesHandle& CodesDataContent::codesHandle() const {
148+
return *handle_.get();
149+
}
150+
151+
CodesHandle& CodesDataContent::codesHandle() {
152+
return *handle_.get();
153+
}
154+
155+
156+
} // namespace codes
157+
} // namespace metkit
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* (C) Copyright 2017- ECMWF.
3+
*
4+
* This software is licensed under the terms of the Apache Licence Version 2.0
5+
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
* In applying this licence, ECMWF does not waive the privileges and immunities
7+
* granted to it by virtue of its status as an intergovernmental organisation nor
8+
* does it submit to any jurisdiction.
9+
*/
10+
11+
#pragma once
12+
13+
#include "eckit/io/Offset.h"
14+
#include "metkit/codes/api/CodesAPI.h"
15+
16+
#include "eckit/message/MessageContent.h"
17+
18+
namespace metkit {
19+
namespace codes {
20+
21+
//----------------------------------------------------------------------------------------------------------------------
22+
23+
class CodesDataContent : public eckit::message::MessageContent {
24+
public:
25+
26+
CodesDataContent(std::unique_ptr<CodesHandle> handle, eckit::Offset offset);
27+
CodesDataContent(std::unique_ptr<CodesHandle> handle);
28+
29+
virtual ~CodesDataContent() = default;
30+
31+
const CodesHandle& codesHandle() const;
32+
CodesHandle& codesHandle();
33+
34+
protected:
35+
36+
std::unique_ptr<CodesHandle> handle_;
37+
eckit::Offset offset_;
38+
39+
using eckit::message::MessageContent::transform;
40+
void transform(const eckit::OrderedStringDict&) override;
41+
42+
private:
43+
44+
size_t length() const override;
45+
void write(eckit::DataHandle& handle) const override;
46+
eckit::DataHandle* readHandle() const override;
47+
void print(std::ostream& s) const override;
48+
std::string getString(const std::string& key) const override;
49+
long getLong(const std::string& key) const override;
50+
double getDouble(const std::string& key) const override;
51+
void getDoubleArray(const std::string& key, std::vector<double>& values) const override;
52+
void getFloatArray(const std::string& key, std::vector<float>& values) const override;
53+
size_t getSize(const std::string& key) const override;
54+
void getDoubleArray(const std::string& key, double* data, size_t lenExpected) const override;
55+
void getFloatArray(const std::string& key, float* data, size_t lenExpected) const override;
56+
57+
eckit::Offset offset() const override;
58+
const void* data() const override;
59+
};
60+
61+
62+
//----------------------------------------------------------------------------------------------------------------------
63+
64+
} // namespace codes
65+
} // namespace metkit

0 commit comments

Comments
 (0)