metkitlib 1.16.0.9__cp312-cp312-manylinux_2_28_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. metkitlib/__init__.py +3 -0
  2. metkitlib/bin/bufr-sanity-check +0 -0
  3. metkitlib/bin/compare-mars-requests.py +265 -0
  4. metkitlib/bin/mars-archive-script +0 -0
  5. metkitlib/bin/parse-mars-request +0 -0
  6. metkitlib/include/metkit/api/metkit_c.h +255 -0
  7. metkitlib/include/metkit/codes/BUFRDecoder.h +47 -0
  8. metkitlib/include/metkit/codes/BufrContent.h +43 -0
  9. metkitlib/include/metkit/codes/CodesContent.h +67 -0
  10. metkitlib/include/metkit/codes/CodesHandleDeleter.h +41 -0
  11. metkitlib/include/metkit/codes/CodesSplitter.h +40 -0
  12. metkitlib/include/metkit/codes/GRIBDecoder.h +42 -0
  13. metkitlib/include/metkit/codes/GribAccessor.h +75 -0
  14. metkitlib/include/metkit/codes/GribHandle.h +121 -0
  15. metkitlib/include/metkit/codes/GribIterator.h +48 -0
  16. metkitlib/include/metkit/codes/LibEccodes.h +38 -0
  17. metkitlib/include/metkit/codes/MallocCodesContent.h +46 -0
  18. metkitlib/include/metkit/codes/api/CodesAPI.h +365 -0
  19. metkitlib/include/metkit/codes/api/CodesTypes.h +93 -0
  20. metkitlib/include/metkit/codes/api/GeoIterator.h +104 -0
  21. metkitlib/include/metkit/codes/api/KeyIterator.h +187 -0
  22. metkitlib/include/metkit/config/LibMetkit.h +56 -0
  23. metkitlib/include/metkit/fields/FieldIndex.h +58 -0
  24. metkitlib/include/metkit/fields/FieldIndexList.h +40 -0
  25. metkitlib/include/metkit/fields/SimpleFieldIndex.h +41 -0
  26. metkitlib/include/metkit/hypercube/HyperCube.h +105 -0
  27. metkitlib/include/metkit/hypercube/HyperCubePayloaded.h +88 -0
  28. metkitlib/include/metkit/mars/BaseProtocol.h +95 -0
  29. metkitlib/include/metkit/mars/ClientTask.h +206 -0
  30. metkitlib/include/metkit/mars/DHSProtocol.h +106 -0
  31. metkitlib/include/metkit/mars/MarsExpandContext.h +42 -0
  32. metkitlib/include/metkit/mars/MarsExpansion.h +83 -0
  33. metkitlib/include/metkit/mars/MarsExpension.h +28 -0
  34. metkitlib/include/metkit/mars/MarsHandle.h +83 -0
  35. metkitlib/include/metkit/mars/MarsLanguage.h +106 -0
  36. metkitlib/include/metkit/mars/MarsLocation.h +100 -0
  37. metkitlib/include/metkit/mars/MarsParsedRequest.h +44 -0
  38. metkitlib/include/metkit/mars/MarsParser.h +70 -0
  39. metkitlib/include/metkit/mars/MarsRequest.h +198 -0
  40. metkitlib/include/metkit/mars/MarsRequestHandle.h +79 -0
  41. metkitlib/include/metkit/mars/Matcher.h +88 -0
  42. metkitlib/include/metkit/mars/Param.b +43 -0
  43. metkitlib/include/metkit/mars/Param.h +84 -0
  44. metkitlib/include/metkit/mars/ParamID.h +306 -0
  45. metkitlib/include/metkit/mars/Parameter.h +87 -0
  46. metkitlib/include/metkit/mars/Quantile.h +73 -0
  47. metkitlib/include/metkit/mars/RequestEnvironment.h +58 -0
  48. metkitlib/include/metkit/mars/StepRange.b +43 -0
  49. metkitlib/include/metkit/mars/StepRange.h +164 -0
  50. metkitlib/include/metkit/mars/StepRangeNormalise.h +95 -0
  51. metkitlib/include/metkit/mars/Type.h +265 -0
  52. metkitlib/include/metkit/mars/TypeAny.h +39 -0
  53. metkitlib/include/metkit/mars/TypeDate.h +42 -0
  54. metkitlib/include/metkit/mars/TypeEnum.h +67 -0
  55. metkitlib/include/metkit/mars/TypeExpver.h +40 -0
  56. metkitlib/include/metkit/mars/TypeFloat.h +41 -0
  57. metkitlib/include/metkit/mars/TypeInteger.h +55 -0
  58. metkitlib/include/metkit/mars/TypeLowercase.h +38 -0
  59. metkitlib/include/metkit/mars/TypeMixed.h +47 -0
  60. metkitlib/include/metkit/mars/TypeParam.h +45 -0
  61. metkitlib/include/metkit/mars/TypeRange.h +41 -0
  62. metkitlib/include/metkit/mars/TypeRegex.h +49 -0
  63. metkitlib/include/metkit/mars/TypeTime.h +44 -0
  64. metkitlib/include/metkit/mars/TypeToByList.h +137 -0
  65. metkitlib/include/metkit/mars/TypeToByListQuantile.h +41 -0
  66. metkitlib/include/metkit/mars/TypesFactory.h +92 -0
  67. metkitlib/include/metkit/metkit_config.h +26 -0
  68. metkitlib/include/metkit/metkit_ecbuild_config.h +72 -0
  69. metkitlib/include/metkit/metkit_version.h +30 -0
  70. metkitlib/include/metkit/pointdb/DataSource.h +91 -0
  71. metkitlib/include/metkit/pointdb/FieldIndexer.h +128 -0
  72. metkitlib/include/metkit/pointdb/GribDataSource.h +47 -0
  73. metkitlib/include/metkit/pointdb/GribFieldInfo.h +76 -0
  74. metkitlib/include/metkit/pointdb/GribHandleDataSource.h +58 -0
  75. metkitlib/include/metkit/pointdb/PointIndex.h +121 -0
  76. metkitlib/include/metkit/pointdb/bits.h +1834 -0
  77. metkitlib/include/metkit/pointdb/masks.h +22 -0
  78. metkitlib/include/metkit/tool/MetkitTool.h +79 -0
  79. metkitlib/lib64/cmake/metkit/metkit-config-version.cmake +43 -0
  80. metkitlib/lib64/cmake/metkit/metkit-config.cmake +112 -0
  81. metkitlib/lib64/cmake/metkit/metkit-import.cmake +14 -0
  82. metkitlib/lib64/cmake/metkit/metkit-targets-relwithdebinfo.cmake +46 -0
  83. metkitlib/lib64/cmake/metkit/metkit-targets.cmake +116 -0
  84. metkitlib/lib64/libmetkit.so +0 -0
  85. metkitlib/lib64/pkgconfig/metkit.pc +33 -0
  86. metkitlib/share/metkit/axis.yaml +63 -0
  87. metkitlib/share/metkit/bufr-subtypes.yaml +140 -0
  88. metkitlib/share/metkit/chemids.yaml +209 -0
  89. metkitlib/share/metkit/language.yaml +1707 -0
  90. metkitlib/share/metkit/modifiers.yaml +341 -0
  91. metkitlib/share/metkit/obstype.yaml +182 -0
  92. metkitlib/share/metkit/odb/marsrequest.yaml +9 -0
  93. metkitlib/share/metkit/param-matching.yaml +16 -0
  94. metkitlib/share/metkit/paramids.yaml +24034 -0
  95. metkitlib/share/metkit/params-static.yaml +212 -0
  96. metkitlib/share/metkit/params.yaml +9833 -0
  97. metkitlib/share/metkit/reportype.yaml +525 -0
  98. metkitlib/share/metkit/shortname-context.yaml +192 -0
  99. metkitlib-1.16.0.9.dist-info/METADATA +75 -0
  100. metkitlib-1.16.0.9.dist-info/RECORD +104 -0
  101. metkitlib-1.16.0.9.dist-info/WHEEL +5 -0
  102. metkitlib-1.16.0.9.dist-info/licenses/AUTHORS +12 -0
  103. metkitlib-1.16.0.9.dist-info/licenses/LICENSE +190 -0
  104. metkitlib-1.16.0.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,365 @@
1
+ /*
2
+ * (C) Copyright 2025- 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 "metkit/codes/api/CodesTypes.h"
14
+ #include "metkit/codes/api/GeoIterator.h"
15
+ #include "metkit/codes/api/KeyIterator.h"
16
+
17
+ #include <cstdint>
18
+ #include <optional>
19
+ #include <string>
20
+ #include <type_traits>
21
+ #include <vector>
22
+
23
+ /// This file contains the important parts for an eccodes c api wrapper.
24
+ /// It does not wrap the whole `eccodes.h`.
25
+ /// The most important interface is the `CodesHandle` - it use to work on specific GRIB or BUFR messages.
26
+ /// An addition to that, a few factory functions (`codesHandleFromMessage`, `codesHandleFromSample`,
27
+ /// `codesHandleFromFile`) and iterators are wrapped.
28
+ ///
29
+ /// Missing components:
30
+ /// * codes_context
31
+ /// * codes_index
32
+ /// * codes_fieldset
33
+ /// * codes_values
34
+ /// * multio_handle
35
+ /// * codes_nearest
36
+ /// * GTS handling
37
+ /// * GRIBEX
38
+
39
+ namespace metkit::codes {
40
+
41
+ //----------------------------------------------------------------------------------------------------------------------
42
+
43
+ /// Retrieve information about the configured samples path.
44
+ /// @return The configured path to sample files.
45
+ std::string samplesPath();
46
+
47
+ /// Retrieve information about the configured definition path.
48
+ /// @return The configured path to the definition files.
49
+ std::string definitionPath();
50
+
51
+ /// Retrieve eccodes version
52
+ /// @return The eccodes version.
53
+ long apiVersion();
54
+
55
+ /// Retrieve repository information of the built.
56
+ /// @return The SHA1 of the latest commit the eccodes library has been built on.
57
+ std::string gitSha1();
58
+
59
+ /// Retrieve repository information of the built.
60
+ /// @return The branch the eccodes library has been built on.
61
+ std::string gitBranch();
62
+
63
+ /// Retrieve repository information of the built.
64
+ /// @return The built date of the eccodes library.
65
+ std::string buildDate();
66
+
67
+ /// Retrieve repository information of the built.
68
+ /// @return The package name the library has been distributed with.
69
+ std::string packageName();
70
+
71
+ //----------------------------------------------------------------------------------------------------------------------
72
+
73
+
74
+ /// Abstract interface wrapping eccodes handles.
75
+ ///
76
+ /// Eccodes exposed `codes_handle*` is used to handle GRIB1, GRIB2 and BUFR data.
77
+ class CodesHandle {
78
+ friend class KeyRange;
79
+ friend class GeoRange;
80
+
81
+ public:
82
+
83
+ virtual ~CodesHandle() = default;
84
+
85
+ /// Retrieve binary size of the handled message.
86
+ /// @return Size of the message in bytes.
87
+ virtual size_t messageSize() const = 0;
88
+
89
+ /// Check if a key is defined.
90
+ /// @param key Name of the field that is checked to be defined.
91
+ /// @return True if the field is defined.
92
+ virtual bool isDefined(const std::string& key) const = 0;
93
+
94
+ /// Check if a key is missing.
95
+ /// @param key Name of the field that is checked to be missing.
96
+ /// @return True if the field is missing.
97
+ virtual bool isMissing(const std::string& key) const = 0;
98
+
99
+ /// Check if a key is defined and not missing.
100
+ /// @param key Name of the field that is checked to exist and have a value.
101
+ /// @return True if the field exists and has a value.
102
+ virtual bool has(const std::string& key) const = 0;
103
+
104
+ /// Set a key to its missing value.
105
+ /// @param key Name of the field that is supposed to be set to its missing value.
106
+ virtual void setMissing(const std::string& key) = 0;
107
+
108
+ /// Set scalar string value for a specific field.
109
+ /// @param key Name of the field that is supposed to be set.
110
+ /// @param value Value the field is supposed to be set to.
111
+ virtual void set(const std::string& key, const std::string& value) = 0;
112
+
113
+ /// Set scalar double value for a specific field.
114
+ /// @param key Name of the field that is supposed to be set.
115
+ /// @param value Value the field is supposed to be set to.
116
+ virtual void set(const std::string& key, double value) = 0;
117
+
118
+ /// Set scalar long value for a specific field.
119
+ /// @param key Name of the field that is supposed to be set.
120
+ /// @param value Value the field is supposed to be set to.
121
+ virtual void set(const std::string& key, long value) = 0;
122
+
123
+ /// Set scalar floating point value for a specific field.
124
+ ///
125
+ /// Overload for other floating point types.
126
+ /// @param key Name of the field that is supposed to be set.
127
+ /// @param value Value the field is supposed to be set to.
128
+ template <typename T, std::enable_if_t<!std::is_same_v<T, double> && std::is_floating_point_v<T>, bool> = true>
129
+ void set(const std::string& key, const T& v) {
130
+ set(key, static_cast<double>(v));
131
+ }
132
+
133
+ /// Set scalar integral value for a specific field.
134
+ ///
135
+ /// Overload for other integral types.
136
+ /// @param key Name of the field that is supposed to be set.
137
+ /// @param value Value the field is supposed to be set on.
138
+ template <typename T, std::enable_if_t<!std::is_same_v<T, long> && std::is_integral_v<T>, bool> = true>
139
+ void set(const std::string& key, const T& v) {
140
+ set(key, static_cast<long>(v));
141
+ }
142
+
143
+ /// Set array of string through `span` as general contiguous memory container.
144
+ /// @param key Name of the field that is supposed to be set.
145
+ /// @param value Contiguous array the field is supposed to be set to.
146
+ virtual void set(const std::string& key, Span<const std::string> value) = 0;
147
+
148
+ /// Set array of c-string through `span` as general contiguous memory container.
149
+ /// @param key Name of the field that is supposed to be set.
150
+ /// @param value Contiguous array the field is supposed to be set to.
151
+ virtual void set(const std::string& key, Span<const char*> value) = 0;
152
+
153
+ /// Set array of double through `span` as general contiguous memory container.
154
+ /// @param key Name of the field that is supposed to be set.
155
+ /// @param value Contiguous array the field is supposed to be set to.
156
+ virtual void set(const std::string& key, Span<const double> value) = 0;
157
+
158
+ /// Set array of float through `span` as general contiguous memory container.
159
+ /// @param key Name of the field that is supposed to be set.
160
+ /// @param value Contiguous array the field is supposed to be set to.
161
+ virtual void set(const std::string& key, Span<const float> value) = 0;
162
+
163
+ /// Set array of long through `span` as general contiguous memory container.
164
+ /// @param key Name of the field that is supposed to be set.
165
+ /// @param value Contiguous array the field is supposed to be set to.
166
+ virtual void set(const std::string& key, Span<const long> value) = 0;
167
+
168
+ /// Set array of uint8_t (bytes) through `span` as general contiguous memory container.
169
+ /// @param key Name of the field that is supposed to be set.
170
+ /// @param value Contiguous array the field is supposed to be set to.
171
+ virtual void set(const std::string& key, Span<const uint8_t> value) = 0;
172
+
173
+ /// Set any type of value as sum type for a specific field.
174
+ /// Visits the value and calls the corresponding `set` overload.
175
+ /// A template and SFINAE is used to match exactly the type `CodesValue`,
176
+ /// this avoids abiguous overloads through implict convertion.
177
+ /// @param key Name of the field that is supposed to be set.
178
+ /// @param value Value the field is supposed to be set to.
179
+ template <typename T, std::enable_if_t<std::is_same_v<T, CodesValue>, bool> = true>
180
+ void set(const std::string& key, const T& value) {
181
+ std::visit([&](const auto& v) { this->set(key, v); }, value);
182
+ }
183
+
184
+
185
+ /// Force setting arrays of double through `span` as general contiguous memory container.
186
+ ///
187
+ /// Allows setting arrays that usually get computed through other keys
188
+ /// @param key Name of the field that is supposed to be set to a specific value.
189
+ /// @param value Value the field is supposed to be set on.
190
+ virtual void forceSet(const std::string& key, Span<const double> value) = 0;
191
+
192
+ /// Force setting arrays of float through `span` as general contiguous memory container
193
+ ///
194
+ /// Allows setting arrays that usually get computed through other keys
195
+ /// @param key Name of the field that is supposed to be set to a specific value.
196
+ /// @param value Value the field is supposed to be set on.
197
+ virtual void forceSet(const std::string& key, Span<const float> value) = 0;
198
+
199
+ /// Returns the number of elements contained for a given key
200
+ ///
201
+ /// Can be used to determine if a field is storing a scalar or an array.
202
+ /// @param key Name of the field that is supposed to be inspected.
203
+ /// @return For given scalars 1 is returned. For given arrays the size of the array is returned..
204
+ virtual size_t size(const std::string& key) const = 0;
205
+
206
+ /// Get the value of the key.
207
+ ///
208
+ /// High-level functionality:
209
+ /// Inspection on the contained valued is performed with `type` and `size`.
210
+ /// Then the more specific `getXXX` call is performed.
211
+ /// @param key Name of the field that is supposed to be retrieved.
212
+ /// @return Variant of all possible value types.
213
+ virtual CodesValue get(const std::string& key) const = 0;
214
+
215
+ /// Get the type of the key
216
+ /// @param key Name of the field that is supposed to be inspected.
217
+ /// @return Enum of the native types ECCODES exposes.
218
+ virtual NativeType type(const std::string& key) const = 0;
219
+
220
+ /// Get the contained value for a key as long.
221
+ /// @param key Name of the field that is supposed to be retrieved.
222
+ /// @return Retrieved value contained for the passed key.
223
+ virtual long getLong(const std::string& key) const = 0;
224
+
225
+ /// Get the contained value for a key as double.
226
+ /// @param key Name of the field that is supposed to be retrieved.
227
+ /// @return Retrieved value contained for the passed key.
228
+ virtual double getDouble(const std::string& key) const = 0;
229
+
230
+ /// Get the contained value for a key as string.
231
+ ///
232
+ /// This should be possible for all key types.
233
+ /// @param key Name of the field that is supposed to be retrieved.
234
+ /// @return Retrieved value contained for the passed key.
235
+ virtual std::string getString(const std::string& key) const = 0;
236
+
237
+ /// Get the contained values for a key as array of long.
238
+ /// @param key Name of the field that is supposed to be retrieved.
239
+ /// @return Retrieved values contained for the passed key.
240
+ virtual std::vector<long> getLongArray(const std::string& key) const = 0;
241
+
242
+ /// Get the contained values for a key as array of double.
243
+ /// @param key Name of the field that is supposed to be retrieved.
244
+ /// @return Retrieved values contained for the passed key.
245
+ virtual std::vector<double> getDoubleArray(const std::string& key) const = 0;
246
+
247
+ /// Get the contained values for a key as array of float.
248
+ /// @param key Name of the field that is supposed to be retrieved.
249
+ /// @return Retrieved values contained for the passed key.
250
+ virtual std::vector<float> getFloatArray(const std::string& key) const = 0;
251
+
252
+ /// Get the contained values for a key as array of string.
253
+ ///
254
+ /// This should be possible for all key types.
255
+ /// @param key Name of the field that is supposed to be retrieved.
256
+ /// @return Retrieved values contained for the passed key.
257
+ virtual std::vector<std::string> getStringArray(const std::string& key) const = 0;
258
+
259
+ /// Get the contained values for a key as array of uint8_t (bytes).
260
+ /// @param key Name of the field that is supposed to be retrieved.
261
+ /// @return Retrieved values contained for the passed key.
262
+ virtual std::vector<uint8_t> getBytes(const std::string& key) const = 0;
263
+
264
+ /// Clones the underyling handle.
265
+ /// Uses `codes_handle_clone` internally.
266
+ /// @return Unique pointer to a cloned `CodesHandle` instance.
267
+ virtual std::unique_ptr<CodesHandle> clone() const = 0;
268
+
269
+ /// Copy the message into a new allocated buffer
270
+ /// @param data Pointer to an allocated array
271
+ /// @param size Size of the allocated array.
272
+ /// Should be containing at least the size returned by `messageSize`.
273
+ virtual void copyInto(uint8_t* data, size_t size) const = 0;
274
+
275
+
276
+ /// Iterate keys in a GRIB2 or BUFR handle.
277
+ ///
278
+ /// @param flags Iterator flags to filter keys
279
+ /// @param ns A specific namespace that is iterated (e.g. "mars" or "ls").
280
+ /// Namespaces are defined within definition files,
281
+ /// that means custom namespaces can be provided by users.
282
+ /// Common namespaces that are available by the default definition files
283
+ /// are listed in the namespace `codes::namespaces`
284
+ /// @return A Range that can be iterated on with a range-based for-loop.
285
+ /// @see KeyIterator
286
+ virtual KeyRange keys(KeyIteratorFlags flags = KeyIteratorFlags::AllKeys,
287
+ std::optional<Namespace> ns = std::optional<Namespace>{}) const = 0;
288
+
289
+ /// Iterate keys in a GRIB2 or BUFR handle.
290
+ ///
291
+ /// @param ns A specific namespace that is iterated (e.g. "mars" or "ls").
292
+ /// Namespaces are defined within definition files,
293
+ /// that means custom namespaces can be provided by users.
294
+ /// Common namespaces that are available by the default definition files
295
+ /// are listed in the namespace `codes::namespaces`
296
+ /// @return A Range that can be iterated on with a range-based for-loop.
297
+ /// @see KeyIterator
298
+ virtual KeyRange keys(Namespace ns) const = 0;
299
+
300
+ /// Iterate values with longitude and latituted.
301
+ ///
302
+ /// @return A Range that can be iterated on with a range-based for-loop.
303
+ /// The iterated value contains a type `GeoData`
304
+ /// with members `longitude`, `latitude` and `value`.
305
+ /// @see GeoIterator
306
+ virtual GeoRange values() const = 0;
307
+
308
+ /// Release the underlying `codes_handle*`.
309
+ ///
310
+ /// After calling `release` the instance of this type is in an inoperable state.
311
+ /// Used to pass ownership out of C++ (e.g. python).
312
+ ///
313
+ /// Example use:
314
+ /// ```cpp
315
+ /// auto rawHandle = reinterpret_cast<codes_handle*>(handl->release());
316
+ /// ```
317
+ ///
318
+ /// @return Pointer to `codes_handle*`
319
+ [[nodiscard]]
320
+ virtual void* release() = 0;
321
+ };
322
+
323
+ /// Create a new `CodesHandle` from a byte array.
324
+ ///
325
+ /// ECCODES does not copy the array until a modification is made.
326
+ /// The user needs to maintain the lifetime of the passed array.
327
+ /// @param data Array to an contiguous array of bytes.
328
+ /// Lifetime of the array need to be maintained till the first change is made on the handle.
329
+ /// @return Instance of a `CodesHandle` wrapped in a `unique_ptr`.
330
+ /// @see codesHandleFromMessageCopy
331
+ std::unique_ptr<CodesHandle> codesHandleFromMessage(Span<const uint8_t> data);
332
+
333
+ /// Create a new `CodesHandle` from a byte array.
334
+ ///
335
+ /// ECCODES copies the array. No lifetime requirements exist on `data`.
336
+ /// @param data Array to an contiguous array of bytes the message is created from.
337
+ /// @return Instance of a `CodesHandle` wrapped in a `unique_ptr`.
338
+ /// @see codesHandleFromMessage
339
+ std::unique_ptr<CodesHandle> codesHandleFromMessageCopy(Span<const uint8_t> data);
340
+
341
+ /// Create a new `CodesHandle` from a sample existing in the configured samples path.
342
+ ///
343
+ /// ECCODES does not copy the array until a modification is made.
344
+ /// The user needs to maintain the lifetime of the passed array.
345
+ /// @param sample Name of the sample in the sample path. Usually without the ".tmpl" suffix, e.g. "GRIB2".
346
+ /// @param product The intented type of handle that is supposed to be loaded (BUFR or GRIB).
347
+ /// Does not need to be specified.
348
+ /// @return Instance of a `CodesHandle` wrapped in a `unique_ptr`.
349
+ /// @see samplesPath
350
+ std::unique_ptr<CodesHandle> codesHandleFromSample(const std::string& sampleName,
351
+ std::optional<Product> product = std::optional<Product>{});
352
+
353
+ /// Create a new `CodesHandle` from a file.
354
+ ///
355
+ /// ECCODES does not copy the array until a modification is made.
356
+ /// The user needs to maintain the lifetime of the passed array.
357
+ /// @param file Pointer to a implementation dependent file handle containing a BUFR or GRIB message.
358
+ /// @param product The intented type of handle that is supposed to be loaded (BUFR or GRIB).
359
+ /// @return Instance of a `CodesHandle` wrapped in a `unique_ptr`.
360
+ std::unique_ptr<CodesHandle> codesHandleFromFile(const std::string& fpath, Product);
361
+
362
+
363
+ //----------------------------------------------------------------------------------------------------------------------
364
+
365
+ } // namespace metkit::codes
@@ -0,0 +1,93 @@
1
+ /*
2
+ * (C) Copyright 2025- 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 <array>
14
+ #include <cstdint>
15
+ #include <string>
16
+ #include <variant>
17
+ #include <vector>
18
+ #include "eckit/exception/Exceptions.h"
19
+
20
+
21
+ namespace metkit::codes {
22
+
23
+ /// Exception that is thrown by the API to wrap eccodes errors
24
+ class CodesException : public eckit::Exception {
25
+ public:
26
+
27
+ CodesException(const std::string& reason, const eckit::CodeLocation& l = eckit::CodeLocation());
28
+ };
29
+
30
+
31
+ /// Enum to classify types of handles
32
+ enum class Product {
33
+ GRIB,
34
+ BUFR,
35
+ };
36
+
37
+
38
+ /// Enum that redefines eccodes specific key types
39
+ enum class NativeType {
40
+ Undefined,
41
+ Long,
42
+ Double,
43
+ String,
44
+ Bytes,
45
+ Section,
46
+ Label,
47
+ Missing,
48
+ };
49
+
50
+
51
+ /// Sum type of possible values returned by eccodes.
52
+ using CodesValue = std::variant<long, double, float, std::string, std::vector<long>, std::vector<double>,
53
+ std::vector<float>, std::vector<std::string>, std::vector<uint8_t>>;
54
+
55
+
56
+ //----------------------------------------------------------------------------------------------------------------------
57
+
58
+ /// To be replaced with std::span in C++20.
59
+ template <typename T>
60
+ struct Span {
61
+ using element_type = T;
62
+ using value_type = std::remove_cv_t<T>;
63
+
64
+ const value_type* data_ = nullptr;
65
+ std::size_t size_ = 0;
66
+
67
+ const value_type* data() { return data_; }
68
+ std::size_t size() { return size_; }
69
+
70
+ Span() = default;
71
+
72
+ Span(const T* p, std::size_t n) : data_(p), size_(n) {}
73
+
74
+ // from std::vector
75
+ template <typename Alloc>
76
+ Span(const std::vector<value_type, Alloc>& v) : data_(v.data()), size_(v.size()) {}
77
+
78
+ // from std::array
79
+ template <std::size_t N>
80
+ Span(const std::array<value_type, N>& arr) : data_(arr.data()), size_(N) {}
81
+
82
+ // from C array
83
+ template <std::size_t N>
84
+ Span(const value_type (&arr)[N]) : data_(arr), size_(N) {}
85
+
86
+ // from std::basic_string
87
+ template <typename CharT = value_type, std::enable_if_t<std::is_same<T, CharT>::value, bool> = true>
88
+ Span(const std::basic_string<CharT>& s) : data_(s.data()), size_(s.size()) {}
89
+ };
90
+
91
+ //----------------------------------------------------------------------------------------------------------------------
92
+
93
+ } // namespace metkit::codes
@@ -0,0 +1,104 @@
1
+ /*
2
+ * (C) Copyright 2025- 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 "metkit/codes/api/CodesTypes.h"
14
+
15
+ #include <memory>
16
+ #include <optional>
17
+ #include <string>
18
+ #include <variant>
19
+ #include <vector>
20
+
21
+
22
+ namespace metkit::codes {
23
+
24
+ //----------------------------------------------------------------------------------------------------------------------
25
+
26
+ class GeoRange;
27
+
28
+ /// Aggregate that stores a value with lon/lat.
29
+ struct GeoData {
30
+ double value;
31
+ double longitude;
32
+ double latitude;
33
+ };
34
+
35
+ /// Abstract interface wrapping C API calls on on key_iterator.
36
+ class GeoIterator {
37
+ friend class GeoRange;
38
+
39
+ public:
40
+
41
+ virtual ~GeoIterator() = default;
42
+
43
+ /// Access to the iterated data.
44
+ /// @return Reference to the iterated geo data object.
45
+ virtual const GeoData& data() const = 0;
46
+
47
+ /// Check if there are follow up values.
48
+ /// @return True if there are more values to iterate on.
49
+ virtual bool hasNext() const = 0;
50
+
51
+
52
+ protected:
53
+
54
+ /// Iterates the next element.
55
+ virtual void next() = 0;
56
+
57
+ /// Check if the iterator is valid.
58
+ /// @return True if the iterator is still valid and holds a value. False indicates end of iteration.
59
+ virtual bool isValid() const = 0;
60
+ };
61
+
62
+
63
+ //----------------------------------------------------------------------------------------------------------------------
64
+
65
+ /// Implements the geo iterator (codes_iterator) based on a C++ range.
66
+ /// Enables use of range-based for-loop.
67
+ class GeoRange {
68
+ public:
69
+
70
+ struct EndIterator;
71
+
72
+ struct Iterator {
73
+ friend struct EndIterator;
74
+ Iterator& operator++() {
75
+ state->next();
76
+ return *this;
77
+ }
78
+ const GeoData& operator*() const { return state->data(); }
79
+ const GeoData* operator->() const { return &state->data(); }
80
+
81
+ inline bool operator!=(const EndIterator&) { return state->isValid(); }
82
+
83
+ GeoIterator* state;
84
+ };
85
+
86
+ struct EndIterator {
87
+ inline bool operator!=(const Iterator& it) { return it.state->isValid(); }
88
+ };
89
+
90
+
91
+ Iterator begin() const { return Iterator{impl_.get()}; };
92
+ EndIterator end() const { return {}; }
93
+
94
+ GeoRange(std::unique_ptr<GeoIterator> impl) : impl_{std::move(impl)} {};
95
+
96
+ private:
97
+
98
+ std::unique_ptr<GeoIterator> impl_;
99
+ };
100
+
101
+
102
+ //----------------------------------------------------------------------------------------------------------------------
103
+
104
+ } // namespace metkit::codes