Skip to content

Commit

Permalink
Don't write unitSI in custom datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Nov 14, 2023
1 parent d4ac9fc commit 01030c9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ class RecordComponent : public BaseRecordComponent
static constexpr char const *const SCALAR = "\vScalar";

private:
void flush(std::string const &, internal::FlushParams const &);
void flush(
std::string const &, internal::FlushParams const &, bool set_defaults);
virtual void read();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/CustomHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ void CustomHierarchy::flush_internal(
}
for (auto &[name, dataset] : get().embeddedDatasets())
{
dataset.flush(name, flushParams);
dataset.flush(name, flushParams, /* set_defaults = */ false);
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ void Record::flush_impl(
{
if (scalar())
{
T_RecordComponent::flush(SCALAR, flushParams);
T_RecordComponent::flush(
SCALAR, flushParams, /* set_defaults = */ true);
}
else
{
for (auto &comp : *this)
comp.second.flush(comp.first, flushParams);
comp.second.flush(
comp.first, flushParams, /* set_defaults = */ true);
}
}
else
Expand All @@ -65,7 +67,7 @@ void Record::flush_impl(
if (scalar())
{
RecordComponent &rc = *this;
rc.flush(name, flushParams);
rc.flush(name, flushParams, /* set_defaults = */ true);
}
else
{
Expand All @@ -75,7 +77,8 @@ void Record::flush_impl(
for (auto &comp : *this)
{
comp.second.parent() = getWritable(this);
comp.second.flush(comp.first, flushParams);
comp.second.flush(
comp.first, flushParams, /* set_defaults = */ true);
}
}
}
Expand All @@ -84,12 +87,14 @@ void Record::flush_impl(

if (scalar())
{
T_RecordComponent::flush(name, flushParams);
T_RecordComponent::flush(
name, flushParams, /* set_defaults = */ true);
}
else
{
for (auto &comp : *this)
comp.second.flush(comp.first, flushParams);
comp.second.flush(
comp.first, flushParams, /* set_defaults = */ true);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ bool RecordComponent::empty() const
}

void RecordComponent::flush(
std::string const &name, internal::FlushParams const &flushParams)
std::string const &name,
internal::FlushParams const &flushParams,
bool set_defaults)
{
auto &rc = get();
if (flushParams.flushLevel == FlushLevel::SkeletonOnly)
Expand Down Expand Up @@ -258,7 +260,7 @@ void RecordComponent::flush(
"before flushing (see RecordComponent::resetDataset()).");
}
}
if (!containsAttribute("unitSI"))
if (set_defaults && !containsAttribute("unitSI"))
{
setUnitSI(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/MeshRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void MeshRecordComponent::flush(
{
setPosition(std::vector<double>{0});
}
RecordComponent::flush(name, params);
RecordComponent::flush(name, params, /* set_defaults = */ true);
}

template <typename T>
Expand Down

0 comments on commit 01030c9

Please sign in to comment.