preCICE v3.1.2
Loading...
Searching...
No Matches
TXTReader.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <fstream>
5#include <string>
6#include "logging/Logger.hpp"
7
8// ----------------------------------------------------------- CLASS DEFINITION
9
10namespace precice {
11namespace io {
12
16class TXTReader {
17public:
19 explicit TXTReader(const std::string &filename);
20
22 template <typename Scalar, int Rows, int Cols>
23 void read(Eigen::Matrix<Scalar, Rows, Cols> &matrix)
24 {
25 for (long i = 0; i < matrix.rows(); i++) {
26 for (long j = 0; j < matrix.cols(); j++) {
27 double scalar;
28 _file >> scalar;
29 matrix(i, j) = scalar;
30 }
31 }
32 }
33
34private:
35 logging::Logger _log{"io::TXTReader"};
36
39};
40
41} // namespace io
42} // namespace precice
File reader for matrix/vector in Matlab V7 ASCII format.
Definition TXTReader.hpp:16
std::ifstream _file
Filestream.
Definition TXTReader.hpp:38
TXTReader(const std::string &filename)
Constructor, opens file and sets format.
Definition TXTReader.cpp:6
void read(Eigen::Matrix< Scalar, Rows, Cols > &matrix)
Reads the Eigen::Matrix from the file.
Definition TXTReader.hpp:23
logging::Logger _log
Definition TXTReader.hpp:35
This class provides a lightweight logger.
Definition Logger.hpp:16
Main namespace of the precice library.