Commit 82f238c6 authored by Markus Mirz's avatar Markus Mirz
Browse files

csvreader: add csv2eigen function


Signed-off-by: Markus Mirz's avatarMarkus Mirz <mmirz@eonerc.rwth-aachen.de>
parent bbe9d067
...@@ -64,7 +64,8 @@ namespace CPS { ...@@ -64,7 +64,8 @@ namespace CPS {
Real time_format_convert(const String& time); Real time_format_convert(const String& time);
/// Skip first row if it has no digits at beginning /// Skip first row if it has no digits at beginning
void doSkipFirstRow(Bool value = true) { mSkipFirstRow = value; } void doSkipFirstRow(Bool value = true) { mSkipFirstRow = value; }
///
MatrixRow csv2Eigen(const std::string& path);
std::vector<PQData> readLoadProfileDP(std::experimental::filesystem::path file, std::vector<PQData> readLoadProfileDP(std::experimental::filesystem::path file,
Real start_time = -1, Real time_step = 1, Real end_time = -1, Real scale_factor= 1, Real start_time = -1, Real time_step = 1, Real end_time = -1, Real scale_factor= 1,
......
...@@ -76,6 +76,8 @@ namespace CPS { ...@@ -76,6 +76,8 @@ namespace CPS {
/// @brief Dense matrix for integers. /// @brief Dense matrix for integers.
typedef Eigen::Matrix<Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> MatrixInt; typedef Eigen::Matrix<Int, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> MatrixInt;
/// ///
typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixRow;
///
typedef Eigen::PartialPivLU<Matrix> LUFactorized; typedef Eigen::PartialPivLU<Matrix> LUFactorized;
/// ///
typedef Eigen::SparseLU<SparseMatrix> LUFactorizedSparse; typedef Eigen::SparseLU<SparseMatrix> LUFactorizedSparse;
......
...@@ -6,12 +6,31 @@ ...@@ -6,12 +6,31 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/ *********************************************************************************/
#include <cps/CSVReader.h> #include <cps/CSVReader.h>
namespace fs = std::experimental::filesystem; namespace fs = std::experimental::filesystem;
using namespace CPS; using namespace CPS;
MatrixRow CSVReader::csv2Eigen(const std::string& path) {
std::ifstream inputFile;
inputFile.open(path);
std::string line;
std::vector<double> values;
uint rows = 0;
while (std::getline(inputFile, line)) {
std::stringstream lineStream(line);
std::string cell;
while (std::getline(lineStream, cell, ',')) {
values.push_back(std::stod(cell));
}
++rows;
}
uint columns = values.size()/rows;
return Eigen::Map<const MatrixRow>(values.data(), rows, columns);
}
void CSVRow::readNextRow(std::istream& str) { void CSVRow::readNextRow(std::istream& str) {
std::string line; std::string line;
std::getline(str, line); std::getline(str, line);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment