24#include <boost/algorithm/string/trim.hpp>
25#include <boost/lexical_cast.hpp>
43 const std::list<Index> *list) {
47 out_dS << setprecision(8);
49 throw runtime_error(
string(
"error, cannot open file ") + file);
52 if (list ==
nullptr) {
54 out_dS << dS.
x(i) <<
" " << dS.
y(i) << endl;
57 for (
Index i : *list) {
58 out_dS << dS.
x(i) <<
" " << dS.
y(i) << endl;
63 cout <<
"written " << file << endl;
67 const std::list<Index> *list) {
70 out_A << setprecision(8);
73 throw runtime_error(
string(
"error, cannot open file ") + file);
76 if (list ==
nullptr) {
77 for (
Index i = 0; i < gmc.rows(); ++i) {
78 for (
Index j = 0; j < gmc.cols(); ++j) {
79 out_A << gmc(i, j) <<
" ";
84 for (
Index i : *list) {
85 for (
Index j : *list) {
86 out_A << gmc(i, j) <<
" ";
92 cout <<
"written " << file << endl;
97 const std::vector<std::pair<std::string, tools::RangeParser> > &ranges) {
103 throw runtime_error(
string(
"error, cannot open file ") + file);
106 for (
const auto &range : ranges) {
107 out_idx << range.first <<
" " << range.second << endl;
110 cout <<
"written " << file << endl;
117 throw std::runtime_error(std::string(
"error, cannot open file ") +
122 std::vector<double> result;
126 if (line[0] ==
'#') {
130 std::vector<std::string> tokens = tok.
ToVector();
132 numcols = tokens.size();
133 }
else if (numcols != tokens.size()) {
134 throw std::runtime_error(
135 "Matrix has not the same number of entries in each row.");
137 for (
const std::string &s : tokens) {
138 result.push_back(std::stod(s));
144 return Eigen::Map<Eigen::MatrixXd>(result.data(), numrows, numcols);
148 const string &filename) {
152 throw runtime_error(
string(
"error, cannot open file ") + filename);
155 std::vector<std::pair<std::string, tools::RangeParser> > indeces;
160 line = line.substr(0, line.find(
"#"));
161 line = line.substr(0, line.find(
"@"));
164 size_t found = line.find(
" ");
165 if (found == string::npos) {
166 throw runtime_error(
string(
"wrong format in ") + filename);
169 string name = line.substr(0, found);
170 string range = line.substr(found);
173 indeces.push_back(std::pair<std::string, tools::RangeParser>(name, rp));
std::vector< std::pair< std::string, tools::RangeParser > > imcio_read_index(const std::string &filename)
void imcio_write_dS(const std::string &file, const tools::Table &dS, const std::list< Index > *list=nullptr)
Eigen::MatrixXd imcio_read_matrix(const std::string &filename)
void imcio_write_index(const std::string &file, const std::vector< std::pair< std::string, tools::RangeParser > > &ranges)
void imcio_write_matrix(const std::string &file, const Eigen::MatrixXd &gmc, const std::list< Index > *list=nullptr)
Eigen::MatrixXd group_matrix
base class for all analysis tools