55 unsigned int width = 0;
56 unsigned int height = 0;
59 bool inFileSection =
false;
60 bool fileSectionFound =
false;
61 bool typeFound =
false;
62 while (std::getline(input_stream, line)) {
69 fileSectionFound =
true;
80 if (parts[1] !=
"SANSDRaw")
81 throw std::runtime_error(
82 lineRelatedError(
"Unsupported file type '" + parts[1] +
"'", lineNumber));
87 width = readAssignedPositiveIntValue(line, lineNumber);
89 height = readAssignedPositiveIntValue(line, lineNumber);
90 if (width != 0 && height != 0)
94 if (!fileSectionFound)
95 throw std::runtime_error(
"Could not find 'File' section");
97 throw std::runtime_error(
"File type not found");
99 throw std::runtime_error(
"Could not find 'DataSizeX' value");
101 throw std::runtime_error(
"Could not find 'DataSizeY' value");
103 auto frame =
new Frame(
106 auto result = std::make_unique<Datafield>(frame);
109 bool inCountSection =
false;
110 bool countSectionFound =
false;
111 unsigned int dataRow = 0;
113 while (std::getline(input_stream, line)) {
117 if (!inCountSection) {
119 inCountSection =
true;
120 countSectionFound =
true;
135 if (valuesAsString.size() != width)
136 throw std::runtime_error(
137 lineRelatedError(
"Number of found values (" + std::to_string(valuesAsString.size())
138 +
") does not match DataSizeX (" + std::to_string(width) +
")",
141 for (
unsigned col = 0; col < width; ++col) {
143 {col, height - 1 - dataRow});
148 throw std::runtime_error(lineRelatedError(
149 "Value '" + valuesAsString[col] +
"' could not be converted to integer",
152 (*result)[global_index] = value;
156 if (dataRow == height)
160 if (!countSectionFound)
161 throw std::runtime_error(
"Could not find 'Counts' section");
162 if (dataRow != height)
163 throw std::runtime_error(
"Number of found data rows (" + std::to_string(dataRow)
164 +
") does not match DataSizeY (" + std::to_string(height) +
")");
166 return result.release();
Axis with fixed bin size.
size_t toGlobalIndex(const std::vector< unsigned > &axes_indices) const
Returns global index for specified indices of axes.
std::vector< std::string > split(const std::string &text, const std::string &delimiter)
Split string into vector of string using delimiter.
std::string trim(const std::string &str, const std::string &whitespace=" \t")
Cuts any of the chars given in whitespace from start and end of str.
bool to_int(const std::string &str, int *result)
Interprets the contained text as an integer and returns it in result. Space chars at its begin and en...
std::string trimFront(const std::string &str, const std::string &whitespace=" \t")
Cuts any of the chars given in whitespace from start.
bool startsWith(const std::string &str, const std::string &substr)
True if the string starts with substr. The comparison is case sensitive.