@@ -209,14 +209,10 @@ namespace
209209{
210210 uint64_t retrieveMeshDimensionality (Mesh const &m)
211211 {
212- try
212+ if (m. containsAttribute ( " axisLabels " ))
213213 {
214214 return m.axisLabels ().size ();
215215 }
216- catch (no_such_attribute_error const &)
217- {
218- // no-op, continue with fallback below
219- }
220216
221217 // maybe we have record components and can ask them
222218 if (auto it = m.begin (); it != m.end ())
@@ -233,7 +229,27 @@ namespace
233229
234230std::vector<double > Mesh::gridUnitSIPerDimension () const
235231{
236- return getAttribute (" gridUnitSI" ).get <std::vector<double >>();
232+ if (containsAttribute (" gridUnitSI" ))
233+ {
234+ if (auto series_opt = retrieveSeries_optional (); series_opt.has_value ())
235+ {
236+ if (auto version = series_opt->openPMD (); version < " 2." )
237+ {
238+ // If the openPMD version is lower than 2.0, the gridUnitSI is a
239+ // scalar interpreted for all axes. Copy it d times.
240+ return std::vector<double >(
241+ retrieveMeshDimensionality (*this ),
242+ getAttribute (" gridUnitSI" ).get <double >());
243+ }
244+ }
245+ return getAttribute (" gridUnitSI" ).get <std::vector<double >>();
246+ }
247+ else
248+ {
249+ // gridUnitSI is an optional attribute
250+ // if it is missing, the mesh is interpreted as unscaled
251+ return std::vector<double >(retrieveMeshDimensionality (*this ), 1 .);
252+ }
237253}
238254
239255Mesh &Mesh::setGridUnitSIPerDimension (std::vector<double > gridUnitSI)
@@ -328,7 +344,7 @@ std::vector<std::array<double, 7>> Mesh::gridUnitDimension() const
328344 }
329345 else
330346 {
331- // gridUnitSI is an optional attribute
347+ // gridUnitDimension is an optional attribute
332348 // if it is missing, the mesh is interpreted as spatial
333349 std::array<double , 7 > spatialMesh;
334350 fromMapOfUnitDimension (spatialMesh.begin (), {{UnitDimension::L, 1 }});
0 commit comments