preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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::io {
11
15class TXTReader {
16public:
18 explicit TXTReader(const std::string &filename);
19
21 template <typename Scalar, int Rows, int Cols>
22 void read(Eigen::Matrix<Scalar, Rows, Cols> &matrix)
23 {
24 for (long i = 0; i < matrix.rows(); i++) {
25 for (long j = 0; j < matrix.cols(); j++) {
26 double scalar;
27 _file >> scalar;
28 matrix(i, j) = scalar;
29 }
30 }
31 }
32
33private:
34 logging::Logger _log{"io::TXTReader"};
35
38};
39
40} // namespace precice::io
File reader for matrix/vector in Matlab V7 ASCII format.
Definition TXTReader.hpp:15
std::ifstream _file
Filestream.
Definition TXTReader.hpp:37
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:22
logging::Logger _log
Definition TXTReader.hpp:34
This class provides a lightweight logger.
Definition Logger.hpp:17
provides Import and Export of the coupling mesh and data.