Select Git revision
ASTBuilder.cpp
GnuplotWriterBase.cpp 3.02 KiB
#include <output/GnuplotWriterBase.hpp>
#include <output/OutputNamedItemValueSet.hpp>
#include <utils/RevisionInfo.hpp>
#include <ctime>
#include <iomanip>
#include <sstream>
std::string
GnuplotWriterBase::_getDateAndVersionComment() const
{
std::ostringstream os;
std::time_t now = std::time(nullptr);
os << "# Generated by pugs: " << std::ctime(&now);
os << "# version: " << RevisionInfo::version() << '\n';
os << "# tag: " << RevisionInfo::gitTag() << '\n';
os << "# HEAD: " << RevisionInfo::gitHead() << '\n';
os << "# hash: " << RevisionInfo::gitHash() << " (" << ((RevisionInfo::gitIsClean()) ? "clean" : "dirty") << ")\n";
os << '\n';
return os.str();
}
std::string
GnuplotWriterBase::_getFilename() const
{
std::ostringstream sout;
sout << m_base_filename;
if (m_period_manager.has_value()) {
sout << '.' << std::setfill('0') << std::setw(4) << m_period_manager->nbSavedTimes();
}
sout << ".gnu";
return sout.str();
}
void
GnuplotWriterBase::_writePreamble(const size_t& dimension,
const OutputNamedItemDataSet& output_named_item_data_set,
const bool& store_coordinates,
std::ostream& fout) const
{
fout << "# list of data\n";
uint64_t i = 0;
fout << "#";
if (store_coordinates) {
fout << " 1:x";
if (dimension > 1) {
fout << " 2:y";
}
i = dimension;
}
for (const auto& i_named_item_data : output_named_item_data_set) {
const std::string name = i_named_item_data.first;
const auto& item_data_variant = i_named_item_data.second;
std::visit(
[&](auto&& item_data) {
using ItemDataType = std::decay_t<decltype(item_data)>;
using DataType = std::decay_t<typename ItemDataType::data_type>;
if constexpr (is_item_value_v<ItemDataType>) {
if constexpr (std::is_arithmetic_v<DataType>) {
fout << ' ' << i++ << ':' << name;
} else if constexpr (is_tiny_vector_v<DataType>) {
for (size_t j = 0; j < DataType{}.dimension(); ++j) {
fout << ' ' << i++ << ':' << name << '[' << j << ']';
}
} else if constexpr (is_tiny_matrix_v<DataType>) {
for (size_t j = 0; j < DataType{}.numberOfRows(); ++j) {
for (size_t k = 0; k < DataType{}.numberOfColumns(); ++k) {
fout << ' ' << i++ << ':' << name << '(' << j << ',' << k << ')';
}
}
} else {
throw UnexpectedError("invalid data type");
}
} else if constexpr (is_item_array_v<ItemDataType>) {
if constexpr (std::is_arithmetic_v<DataType>) {
for (size_t j = 0; j < item_data.sizeOfArrays(); ++j) {
fout << ' ' << i++ << ':' << name << '[' << j << ']';
}
} else {
throw UnexpectedError("invalid data type");
}
} else {
throw UnexpectedError("invalid ItemData type");
}
},
item_data_variant);
}
fout << "\n\n";
}