|
1 | 1 | #include <openPMD/openPMD.hpp> |
2 | 2 |
|
3 | | -#include <algorithm> |
| 3 | +#if __has_include(<blosc2_filter.h>) |
| 4 | +#include <blosc2_filter.h> |
| 5 | +#define OPENPMD_USE_BLOSC2_FILTER 1 |
| 6 | +#else |
| 7 | +#define OPENPMD_USE_BLOSC2_FILTER 0 |
| 8 | +#endif |
| 9 | + |
4 | 10 | #include <iostream> |
| 11 | +#include <numeric> |
| 12 | +#include <stdexcept> |
5 | 13 |
|
6 | 14 | int main() |
7 | 15 | { |
8 | 16 | namespace io = openPMD; |
9 | 17 |
|
| 18 | +#if OPENPMD_USE_BLOSC2_FILTER |
| 19 | + /* |
| 20 | + * This registers the Blosc2 plugin from |
| 21 | + * https://github.com/Blosc/HDF5-Blosc2 as a demonstration on how to |
| 22 | + * activate and configure dynamic HDF5 filter plugins through openPMD. |
| 23 | + */ |
| 24 | + |
| 25 | + char *version, *date; |
| 26 | + int r = register_blosc2(&version, &date); |
| 27 | + if (r < 1) |
| 28 | + { |
| 29 | + throw std::runtime_error("Unable to register Blosc2 plugin with HDF5."); |
| 30 | + } |
| 31 | + else |
| 32 | + { |
| 33 | + std::cout << "Blosc2 plugin registered in version " << version |
| 34 | + << " and date " << date << "." << std::endl; |
| 35 | + } |
| 36 | +#endif |
| 37 | + |
10 | 38 | { |
11 | 39 | auto f = io::Series( |
12 | 40 | "working/directory/2D_simData.h5", |
@@ -91,7 +119,7 @@ int main() |
91 | 119 | } |
92 | 120 |
|
93 | 121 | io::Mesh mesh = cur_it.meshes["lowRez_2D_field"]; |
94 | | - mesh.setAxisLabels({"x", "y"}); |
| 122 | + mesh.setAxisLabels({"x", "y", "z"}); |
95 | 123 |
|
96 | 124 | // data is assumed to reside behind a pointer as a contiguous |
97 | 125 | // column-major array shared data ownership during IO is indicated with |
@@ -134,6 +162,49 @@ int main() |
134 | 162 | d.options = datasetConfig; |
135 | 163 | mesh["x"].resetDataset(d); |
136 | 164 |
|
| 165 | +#if OPENPMD_USE_BLOSC2_FILTER |
| 166 | + /* |
| 167 | + * FILTER_BLOSC2 resolves to 32026, the permanent plugin ID registered |
| 168 | + * with the HDF Group. Plugin-specific options are given via c_values, |
| 169 | + * refer to the specific plugin's documentation. For the Blosc2 plugin, |
| 170 | + * parameters 0, 1, 2 and 3 are reserved. Parameter 4 is the compression |
| 171 | + * level, parameter 5 is a boolean for activating shuffling and |
| 172 | + * parameter 6 denotes the compression method. |
| 173 | + */ |
| 174 | + d.options = R"END( |
| 175 | +{ |
| 176 | + "adios2": { |
| 177 | + "dataset": { |
| 178 | + "operators": [ |
| 179 | + { |
| 180 | + "type": "zlib", |
| 181 | + "parameters": { |
| 182 | + "clevel": 9 |
| 183 | + } |
| 184 | + } |
| 185 | + ] |
| 186 | + } |
| 187 | + }, |
| 188 | + "hdf5": { |
| 189 | + "dataset": { |
| 190 | + "chunks": "auto", |
| 191 | + "permanent_filters": { |
| 192 | + "id": )END" + |
| 193 | + std::to_string(FILTER_BLOSC2) + R"END(, |
| 194 | + "flags": "mandatory", |
| 195 | + "c_values": [0, 0, 0, 0, 4, 1, )END" + |
| 196 | + std::to_string(BLOSC_ZSTD) + R"END(] |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | +})END"; |
| 201 | +#endif |
| 202 | + d.extent = {500, 500}; |
| 203 | + mesh["z"].resetDataset(d); |
| 204 | + auto span = mesh["z"].storeChunk<double>({0, 0}, {500, 500}); |
| 205 | + auto span_data = span.currentBuffer(); |
| 206 | + std::iota(span_data.begin(), span_data.end(), 41.); |
| 207 | + |
137 | 208 | io::ParticleSpecies electrons = cur_it.particles["electrons"]; |
138 | 209 |
|
139 | 210 | io::Extent mpiDims{4}; |
|
0 commit comments