From 507338cca2eb4d558fedd5f2b53eeea03941c88b Mon Sep 17 00:00:00 2001 From: chn Date: Thu, 5 Oct 2023 19:38:27 +0800 Subject: [PATCH] add hdf5 output support --- src/unfold.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/unfold.cpp b/src/unfold.cpp index c489514..78143ec 100644 --- a/src/unfold.cpp +++ b/src/unfold.cpp @@ -70,12 +70,13 @@ namespace ufo throw std::runtime_error("QPointDataOutputFile.SameAsConfigFile should not be set."); if ( - !std::set{"yaml", "yaml-human-readable", "zpp"} + !std::set{"yaml", "yaml-human-readable", "zpp", "hdf5"} .contains(QPointDataOutputFile[i].Format) ) throw std::runtime_error(fmt::format ( - "Unknown QPointDataOutputFile[{}].Format: {}, should be \"yaml\", \"yaml-human-readable\" or \"zpp\".", + "Unknown QPointDataOutputFile[{}].Format: {}, should be " + "\"yaml\", \"yaml-human-readable\", \"zpp\" or \"hdf5\".", i, QPointDataOutputFile[i].Format )); } @@ -240,6 +241,36 @@ namespace ufo file.exceptions(std::ios::badbit | std::ios::failbit); file.write(reinterpret_cast(data.data()), data.size()); } + else if (format == "hdf5") + { + std::vector> Qpoint; + std::vector> Source; + std::vector> Frequency; + std::vector> Weight; + for (auto& qpoint : QPointData) + { + Qpoint.emplace_back(qpoint.QPoint.data(), qpoint.QPoint.data() + 3); + Source.emplace_back(qpoint.Source.data(), qpoint.Source.data() + 3); + Frequency.emplace_back(); + Weight.emplace_back(); + for (auto& mode : qpoint.ModeData) + { + Frequency.back().push_back(mode.Frequency); + Weight.back().push_back(mode.Weight); + } + } + + HighFive::File file(filename, + HighFive::File::ReadWrite | HighFive::File::Create | HighFive::File::Truncate); + file.createDataSet("QPoint", + HighFive::DataSpace::From(Qpoint)).write(Qpoint); + file.createDataSet("Source", + HighFive::DataSpace::From(Source)).write(Source); + file.createDataSet("Frequency", + HighFive::DataSpace::From(Frequency)).write(Frequency); + file.createDataSet("Weight", + HighFive::DataSpace::From(Weight)).write(Weight); + } } UnfoldSolver::UnfoldSolver(std::string config_file) : Input_([&]