Skip to content
Snippets Groups Projects
Commit 40be68d6 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

read data

parent efd7b262
No related branches found
No related tags found
1 merge request!1678Load GISAS data from REFSANS csv-table format (#580)
...@@ -15,15 +15,51 @@ ...@@ -15,15 +15,51 @@
#include "Device/IO/ReadRefsans.h" #include "Device/IO/ReadRefsans.h"
//#include "Base/Axis/Scale.h" //#include "Base/Axis/Scale.h"
#include "Base/Util/Assert.h" #include "Base/Util/Assert.h"
//#include "Base/Util/StringUtil.h" #include "Base/Util/StringUtil.h"
//#include "Device/Data/ArrayUtil.h" #include "Device/Data/ArrayUtil.h"
//#include "Device/Data/Datafield.h" #include "Device/Data/Datafield.h"
//#include "Device/IO/ParseUtil.h" #include "Device/IO/ParseUtil.h"
//#include <string> #include <vector>
//#include <vector>
namespace {
const std::vector<std::string> to_replace = {",", "\"", "(", ")", "[", "]"};
bool getNextLine(std::istream& input_stream, std::string& line)
{
while (std::getline(input_stream, line)) {
line = Base::String::trim(line);
Base::String::replaceItemsFromString(line, to_replace, " ");
if (!line.empty())
return true;
}
return false;
}
}
// From issue #580:
// 1. There is no header or metadata in any csv-file.
// 2. Each csv-matrix has 257 rows and 257 columns of comma-separated floating-point values with a period as the decimal separator.
// 3. The first row and the first column are Q-values for each matrix element.
// 4. q-units are A^-1
Datafield *Util::RW::readRefsans(std::istream &input_stream) Datafield *Util::RW::readRefsans(std::istream &input_stream)
{ {
std::cout << "readRefsans is not implemented yet\n"; std::cout << "readRefsans is not implemented yet\n";
return nullptr;
// read qx coords from first line
std::string line;
getNextLine(input_stream, line);
std::vector<double> dataInRow = Util::Parse::parse_doubles(line);
std::vector<double> qx(dataInRow.begin() + 1, dataInRow.end()); // first point is unused
// read qz coords from first column and all values
std::vector<double> qz;
std::vector<std::vector<double>> matrix;
while (getNextLine(input_stream, line)) {
dataInRow = Util::Parse::parse_doubles(line);
ASSERT(dataInRow.size() == (qx.size() + 1));
qz.push_back(dataInRow.front());
matrix.emplace_back(dataInRow.begin() + 1, dataInRow.end());
}
return DataUtil::Array::createPField2D(matrix).release();
} }
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