Skip to content

Commit be7d165

Browse files
committed
Extend example
1 parent af9f635 commit be7d165

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

examples/14_toml_template.cpp

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <openPMD/openPMD.hpp>
22

3-
int main()
3+
void write()
44
{
55
std::string config = R"(
66
{
@@ -16,7 +16,74 @@ int main()
1616
"../samples/tomlTemplate.toml", openPMD::Access::CREATE, config);
1717
auto iteration = writeTemplate.writeIterations()[0];
1818

19+
openPMD::Dataset ds{openPMD::Datatype::FLOAT, {5, 5}};
20+
1921
auto temperature =
2022
iteration.meshes["temperature"][openPMD::RecordComponent::SCALAR];
21-
temperature.resetDataset({openPMD::Datatype::FLOAT, {5, 5}});
23+
temperature.resetDataset(ds);
24+
25+
auto E = iteration.meshes["E"];
26+
E["x"].resetDataset(ds);
27+
E["y"].resetDataset(ds);
28+
/*
29+
* Don't specify datatype and extent for this one to indicate that this
30+
* information is not yet known.
31+
*/
32+
E["z"].resetDataset({openPMD::Datatype::UNDEFINED});
33+
34+
ds.extent = {10};
35+
36+
auto electrons = iteration.particles["e"];
37+
electrons["position"]["x"].resetDataset(ds);
38+
electrons["position"]["y"].resetDataset(ds);
39+
electrons["position"]["z"].resetDataset(ds);
40+
41+
electrons["positionOffset"]["x"].resetDataset(ds);
42+
electrons["positionOffset"]["y"].resetDataset(ds);
43+
electrons["positionOffset"]["z"].resetDataset(ds);
44+
electrons["positionOffset"]["x"].makeConstant(3.14);
45+
electrons["positionOffset"]["y"].makeConstant(3.14);
46+
electrons["positionOffset"]["z"].makeConstant(3.14);
47+
48+
ds.dtype = openPMD::determineDatatype<uint64_t>();
49+
electrons.particlePatches["numParticles"][openPMD::RecordComponent::SCALAR]
50+
.resetDataset(ds);
51+
electrons
52+
.particlePatches["numParticlesOffset"][openPMD::RecordComponent::SCALAR]
53+
.resetDataset(ds);
54+
electrons.particlePatches["offset"]["x"].resetDataset(ds);
55+
electrons.particlePatches["offset"]["y"].resetDataset(ds);
56+
electrons.particlePatches["offset"]["z"].resetDataset(ds);
57+
electrons.particlePatches["extent"]["x"].resetDataset(ds);
58+
electrons.particlePatches["extent"]["y"].resetDataset(ds);
59+
electrons.particlePatches["extent"]["z"].resetDataset(ds);
60+
}
61+
62+
void read()
63+
{
64+
/*
65+
* The config is entirely optional, these things are also detected
66+
* automatically when reading
67+
*/
68+
69+
// std::string config = R"(
70+
// {
71+
// "iteration_encoding": "variable_based",
72+
// "toml": {
73+
// "dataset": {"mode": "template"},
74+
// "attribute": {"mode": "short"}
75+
// }
76+
// }
77+
// )";
78+
79+
openPMD::Series read(
80+
"../samples/tomlTemplate.toml", openPMD::Access::READ_LINEAR);
81+
read.readIterations(); // @todo change to read.parseBase()
82+
openPMD::helper::listSeries(read);
83+
}
84+
85+
int main()
86+
{
87+
write();
88+
read();
2289
}

0 commit comments

Comments
 (0)