OGS
CreatePiecewiseLinearCurve.cpp
Go to the documentation of this file.
1
14
15#include <boost/endian/conversion.hpp>
16#include <fstream>
17#include <iostream>
18#include <vector>
19
20#include "BaseLib/ConfigTree.h"
21#include "BaseLib/Error.h"
22#include "BaseLib/FileTools.h"
23#include "BaseLib/StringTools.h"
24
25namespace MathLib
26{
28 BaseLib::ConfigTree const& config)
29{
30 const bool read_from_file =
31 config.getConfigParameter<bool>("read_from_file", false);
32
33 std::vector<double> x;
34 std::vector<double> y;
35
36 if (read_from_file == true)
37 {
38 auto const coords_file_name =
40 config.getConfigParameter<std::string>("coords");
41
42 auto const values_file_name =
44 config.getConfigParameter<std::string>("values");
45
46 x = BaseLib::readDoublesFromBinaryFile(coords_file_name);
47
48 y = BaseLib::readDoublesFromBinaryFile(values_file_name);
49 }
50 else
51 {
52 x =
54 config.getConfigParameter<std::vector<double>>("coords");
55 y =
57 config.getConfigParameter<std::vector<double>>("values");
58 }
59
60 if (x.empty() || y.empty())
61 {
62 OGS_FATAL("The given coordinates or values vector is empty.");
63 }
64 if (x.size() != y.size())
65 {
67 "The given coordinates and values vector sizes are "
68 "different.");
69 }
70
71 return {std::move(x), std::move(y)};
72}
73} // namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:26
Filename manipulation routines.
Definition of string helper functions.
T getConfigParameter(std::string const &param) const
std::vector< double > readDoublesFromBinaryFile(const std::string &filename)
PiecewiseLinearCurveConfig parsePiecewiseLinearCurveConfig(BaseLib::ConfigTree const &config)