Skip to content
Snippets Groups Projects
Commit 9047566f authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

don't catch errors while reading data file

parent 7e083e80
No related branches found
No related tags found
1 merge request!1628simplify and unify API and code for reading or writing data files
......@@ -173,13 +173,11 @@ std::vector<double> DataUtil::Format::parse_doubles(const std::string& str)
DataUtil::Format::readLineOfDoubles(result, iss);
if (result.empty()) {
std::string out = str;
const size_t max_string_length(10);
if (out.size() > max_string_length)
if (out.size() > 10) {
out.resize(max_string_length, ' ');
out += " ...";
throw std::runtime_error("DataUtil::Format::parse_doubles -> Error! Cannot parse double "
"values from a string '"
+ out + "'");
out += " ...";
}
throw std::runtime_error("Found '" + out + "' while expecting a floating-point number");
}
return result;
}
......
......@@ -31,15 +31,8 @@ Datafield* ReadReflectometry::readDatafield(std::istream& inStream)
// Read numbers from file:
while (std::getline(inStream, line)) {
line = BaseUtil::String::trim(line);
try {
std::vector<double> rowVec = DataUtil::Format::parse_doubles(line);
// take only non-negative Q values
if (rowVec[0] >= 0.0)
vecVec.push_back(rowVec);
} catch (...) { // #bamigration +++ This eats useful errors away...
continue;
}
std::vector<double> rowVec = DataUtil::Format::parse_doubles(line); // may throw
vecVec.push_back(rowVec);
}
// validate - There is at least one row and at least two columns
......@@ -55,6 +48,8 @@ Datafield* ReadReflectometry::readDatafield(std::istream& inStream)
if (vecVec[row].size() != ncols)
throw std::runtime_error("The number of columns varies among the rows");
double Q = vecVec[row][0];
if (Q < 0)
continue; // just ignore invalid Q entries
switch (ncols) {
case 2:
QvsR[Q] = vecVec[row][1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment