24#include <boost/algorithm/string/replace.hpp>
25#include <boost/range/algorithm.hpp>
39 x_.conservativeResize(N);
40 y_.conservativeResize(N);
43 yerr_.conservativeResize(N);
51 throw runtime_error(
string(
"error, cannot open file ") + filename);
63 throw runtime_error(
string(
"error, cannot open file ") + filename);
68 boost::replace_all(str,
"\n",
"\n# ");
69 boost::replace_all(str,
"\\n",
"\n# ");
98 Index line_number = 0;
105 boost::lexical_cast<string>(line_number);
108 line = line.substr(0, line.find(
"#"));
109 line = line.substr(0, line.find(
"@"));
115 if (tokens.size() == 0) {
120 if (tokens.size() == 1) {
123 }
else if (tokens.size() == 2) {
125 t.
push_back(std::stod(tokens[0]), std::stod(tokens[1]),
'i');
126 }
else if (tokens.size() > 2) {
128 string sflag = tokens.back();
129 if (sflag ==
"i" || sflag ==
"o" || sflag ==
"u") {
132 t.
push_back(std::stod(tokens[0]), std::stod(tokens[1]), flag);
134 throw runtime_error(
"error, wrong table format");
142 boost::lexical_cast<string>(line_number);
145 line = line.substr(0, line.find(
"#"));
146 line = line.substr(0, line.find(
"@"));
152 if (tokens.size() == 0) {
157 if (tokens.size() == 2) {
158 t.
push_back(std::stod(tokens[0]), std::stod(tokens[1]),
'i');
159 }
else if (tokens.size() > 2) {
161 if (tokens[2] ==
"i" || tokens[2] ==
"o" || tokens[2] ==
"u") {
164 t.
push_back(std::stod(tokens[0]), std::stod(tokens[1]), flag);
167 throw runtime_error(
"error, wrong table format");
181 Index vec_size = (
Index)((max - min) / spacing + 1.00000001);
184 double spacing_scaled = (max - min) / (
double(vec_size) - 1.0);
188 for (r_init = min, i = 0; i < vec_size - 1; r_init += spacing_scaled) {
198 throw std::runtime_error(
199 "Smoothing only works for arrays of size 3 and larger");
201 for (
Index i = 0; i < Nsmooth; i++) {
203 (0.25 * (
y_.head(n_2) + 2 *
y_.segment(1, n_2) +
y_.tail(n_2))).eval();
212 for (
Index i = 0; i < t.
x_.size(); ++i) {
213 out << t.
x_[i] <<
" " << t.
y_[i] <<
" " << t.
yerr_[i];
217 out <<
" " << t.
flags_[i] <<
"\n";
221 for (
Index i = 0; i < t.
x_.size(); ++i) {
222 out << t.
x_[i] <<
" " << t.
y_[i];
226 out <<
" " << t.
flags_[i] <<
"\n";
base class for all analysis tools