BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
OutputDataReadReflectometryStrategy Class Reference
Inheritance diagram for OutputDataReadReflectometryStrategy:
Collaboration diagram for OutputDataReadReflectometryStrategy:

Public Member Functions

OutputData< double > * readOutputData (std::istream &input_stream)
 

Detailed Description

Strategy to read Reflectometry data from ASCII file.

Definition at line 44 of file OutputDataReadStrategy.h.

Member Function Documentation

◆ readOutputData()

OutputData< double > * OutputDataReadReflectometryStrategy::readOutputData ( std::istream &  input_stream)
virtual

Implements IOutputDataReadStrategy.

Definition at line 62 of file OutputDataReadStrategy.cpp.

63 {
65  std::string line;
66  std::vector<std::vector<double>> vecVec;
67  std::map<double, double> QvsR;
68  std::map<double, double> QvsDR;
69  std::map<double, double> QvsDQ;
70 
71  // Read numbers from file:
72  while (std::getline(fin, line)) {
73  line = trim(line);
74  try {
75  std::vector<double> rowVec = DataFormatUtils::parse_doubles(line);
76  vecVec.push_back(rowVec);
77  } catch (...) {
78  continue;
79  }
80  }
81 
82  // validate - There is at least one row and at least two columns
83  size_t nrows = vecVec.size();
84  if (nrows < 1)
85  throw std::runtime_error("Import1dTextData: no numerical values found");
86  size_t ncols = vecVec[0].size();
87  if (ncols < 2)
88  throw std::runtime_error("Import1dTextData: Minimum 2 columns required");
89 
90  // Assign Q vs R, dR, dQ:
91  for (size_t row = 0; row < nrows; row++) {
92  if (vecVec[row].size() != ncols)
93  throw std::runtime_error("The number of columns varies among the rows");
94  double Q = vecVec[row][0];
95  switch (ncols) {
96  case 1:
97  break;
98  case 2:
99  QvsR[Q] = vecVec[row][1];
100  QvsDR[Q] = 0;
101  QvsDQ[Q] = 0;
102  break;
103  case 3:
104  QvsR[Q] = vecVec[row][1];
105  QvsDR[Q] = vecVec[row][2];
106  QvsDQ[Q] = 0;
107  break;
108  default:
109  QvsR[Q] = vecVec[row][1];
110  QvsDR[Q] = vecVec[row][2];
111  QvsDQ[Q] = vecVec[row][3];
112  break;
113  }
114  }
115 
116  std::vector<double> qVec;
117  std::vector<double> rVec;
118  for (auto it = QvsR.begin(); it != QvsR.end(); ++it) {
119  if (it->second <= 0)
120  continue;
121  qVec.push_back(it->first);
122  rVec.push_back(it->second);
123  }
124 
125  oData->addAxis(PointwiseAxis("qVector", qVec));
126  oData->setRawDataVector(rVec);
127  return oData;
128 }
void addAxis(const IAxis &new_axis)
Definition: OutputData.h:289
void setRawDataVector(const std::vector< T > &data_vector)
Sets new values to raw data vector.
Definition: OutputData.h:559
Axis containing arbitrary (non-equidistant) coordinate values.
Definition: PointwiseAxis.h:33
std::vector< double > parse_doubles(const std::string &str)
Parse double values from string to vector of double.
std::string trim(const std::string &str, const std::string &whitespace=" \t")

References OutputData< T >::addAxis(), DataFormatUtils::parse_doubles(), OutputData< T >::setRawDataVector(), and anonymous_namespace{OutputDataReadStrategy.cpp}::trim().

Here is the call graph for this function:

The documentation for this class was generated from the following files: