13#include "../../types/matrix.hpp"
14#include "../util_debug.hpp"
27template <
typename Tpath>
31 std::cerr <<
"NOT IMPLEMENTED YET!\n";
36 std::ifstream in(name, std::ios::in | std::ios::binary);
39 std::cerr <<
"Error in getFileContents. File " << name <<
" could not be opened.\n";
43 std::ostringstream fileContents;
44 fileContents << in.rdbuf();
46 return (fileContents.str());
51 std::cerr <<
"NOT IMPLEMENTED YET!\n";
53 static std::map<std::string, std::string> fileMap;
56template <
typename Tpath,
typename T,
size_t ROW,
size_t COL>
69 std::ifstream in(name, std::ios_base::in);
73 std::cerr <<
"Error in ReadCSVfiles::loadCSV_mat. File " << name <<
" could not be opened\n";
79 while (in.peek() <= 32)
82 for (
size_t i = 0; i < ROW; i++) {
84 for (
size_t j = 0; j < COL - 1; j++) {
93template <
typename Tpath,
typename T,
size_t ROW>
99 std::memcpy(&x, &temp,
sizeof temp);
113template <
typename Tpath,
typename Tx,
typename Ty>
131 std::ifstream in(name, std::ios_base::in);
135 std::cerr <<
"Error in ReadCSVfiles::loadCSV_2col. File " << name
136 <<
" could not be opened.\n";
144 if constexpr (std::is_same<std::vector<double>, Tx>::value) {
149 while ((n == 0 || j < n) && (in >> x_i >> c >> y_i))
156 while ((n == 0 || j < n) && (in >> x[j] >> c >> y[j]))
161template <
typename Tpath,
typename Tx>
179 std::ifstream in(name, std::ios_base::in);
183 std::cerr <<
"Error in ReadCSVfiles::loadCSV_2col. File " << name
184 <<
" could not be opened.\n";
195 while ((n == 0 || n_rows < n) && std::getline(in, line))
198 std::istringstream in_line(line);
201 while (in_line >> x_i) {
202 x.
data.push_back(x_i);
207 int n_cols = x.
data.size() / n_rows;
211 x.
data.shrink_to_fit();
220template <
typename Tpath>
221void loadCSV_2col(
const Tpath &name, std::span<double> &x, std::span<double> &y,
int n = 0)
238 static std::map<std::string, XYplain> XYdataMap;
240 auto name_str = name.string();
242 auto fm = XYdataMap.find(name_str);
244 if (fm == XYdataMap.end()) {
248 XYdataMap[name_str] = std::move(xyp);
252 x = std::span<double>(XYdataMap[name_str].x_vec);
253 y = std::span<double>(XYdataMap[name_str].y_vec);
255 x = std::span<double>(&XYdataMap[name_str].x_vec[0], &XYdataMap[name_str].x_vec[0] + n);
256 y = std::span<double>(&XYdataMap[name_str].y_vec[0], &XYdataMap[name_str].y_vec[0] + n);
Definition: DynamicMatrix.hpp:16
void reshape(VarType m_, VarType n_)
Definition: DynamicMatrix.hpp:35
std::vector< Tdata > data
Definition: DynamicMatrix.hpp:22
Slide namespace contains all the types, classes, and functions for the simulation framework.
Definition: Cell.hpp:27
std::array< std::array< T, COL >, ROW > Matrix
See source: http://cpptruths.blogspot.com/2011/10/multi-dimensional-arrays-in-c11....
Definition: matrix.hpp:21
void ignoreBOM(std::ifstream &in)
Definition: read_CSVfiles.hpp:102
void loadCSV_mat(const Tpath &name, Matrix< T, ROW, COL > &x)
Definition: read_CSVfiles.hpp:57
std::string getFileContents(const Tpath &name)
Definition: read_CSVfiles.hpp:28
void loadCSV_2col(Tpath &&name, slide::XYdata_vv &data, int n=0)
Definition: XYdata.hpp:90
auto getFile(std::string name)
Definition: read_CSVfiles.hpp:49
void loadCSV_Ncol(const Tpath &name, DynamicMatrix< Tx > &x, int n=0)
Definition: read_CSVfiles.hpp:162
void loadCSV_1col(const Tpath &name, std::array< T, ROW > &x)
Definition: read_CSVfiles.hpp:94
struct Data
Definition: read_CSVfiles.hpp:215
std::vector< double > x_vec
Definition: read_CSVfiles.hpp:216
std::vector< double > y_vec
Definition: read_CSVfiles.hpp:216