Skip to content
Snippets Groups Projects
Commit 6791eff6 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

inline createPField2D

parent 554c85b7
No related branches found
No related tags found
1 merge request!1980cleanup DataUtil; improve table reading
......@@ -41,26 +41,6 @@ DataUtil::flatten2D(const std::vector<std::vector<double>>& vec)
return {nrows, ncols, outvec};
}
std::unique_ptr<Datafield> DataUtil::createPField2D(const std::vector<std::vector<double>>& vec,
const std::vector<std::vector<double>>& stdv)
{
const auto [nrows, ncols, outvec] = flatten2D(vec);
ASSERT(nrows > 0);
ASSERT(ncols > 0);
std::vector<const Scale*> axes{newEquiDivision("axis0", ncols, 0.0, (double)ncols),
newEquiDivision("axis1", nrows, 0.0, (double)nrows)};
if (stdv.empty())
return std::make_unique<Datafield>(std::move(axes), outvec);
const auto [nrows2, ncols2, outvec2] = flatten2D(stdv);
ASSERT(nrows2 == nrows);
ASSERT(ncols2 == ncols);
return std::make_unique<Datafield>(std::move(axes), outvec, outvec2);
}
std::vector<std::vector<double>> DataUtil::createVector2D(const Datafield& data)
{
std::vector<std::vector<double>> result;
......
......@@ -28,9 +28,6 @@ namespace DataUtil {
std::tuple<size_t, size_t, std::vector<double>> flatten2D(const std::vector<std::vector<double>>&);
std::unique_ptr<Datafield> createPField2D(const std::vector<std::vector<double>>& vec,
const std::vector<std::vector<double>>& stdv = {});
//! Returns new object with input data rotated by
//! n*90 deg counterclockwise (n > 0) or clockwise (n < 0)
//! Axes are swapped if the data is effectively rotated by 90 or 270 degrees
......
......@@ -104,7 +104,14 @@ Datafield* Util::RW::read2DTable(std::istream& input_stream)
return new Datafield(std::move(axes), vector1d);
}
return DataUtil::createPField2D(data).release();
std::vector<const Scale*> axes{newEquiDivision("axis0", ncols, 0.0, (double)ncols),
newEquiDivision("axis1", nrows, 0.0, (double)nrows)};
const auto [nrows2, ncols2, outvec] = DataUtil::flatten2D(data);
ASSERT(nrows2 == nrows);
ASSERT(ncols2 == ncols);
return new Datafield(std::move(axes), outvec);
}
void Util::RW::write2DTable(const Datafield& data, std::ostream& output_stream)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment