16#include <boost/algorithm/string.hpp>
17#include <boost/algorithm/string/split.hpp>
18#include <boost/algorithm/string/trim.hpp>
46 const std::string &extn = descriptor.extension();
48 if (extn !=
"sq" && extn !=
"sqa" && extn !=
"sqb" && extn !=
"gr" && extn !=
"ain" && extn !=
"braw" &&
53 if (!descriptor.isAscii())
56 auto &file = descriptor.data();
58 std::getline(file, str);
60 std::getline(file, str);
73 const std::vector<std::string> exts{
".sq",
".sqa",
".sqb",
".gr",
".ain",
".braw",
".bsmo"};
76 this->
declareProperty(std::move(fileproperty),
"The input filename of the stored data");
82 "Workspace name to load into.");
108 ifile.open((filename.c_str()));
110 if (!ifile.is_open()) {
112 errmsg <<
"Unable to open file " << filename <<
". Quit!";
114 throw std::runtime_error(errmsg.str());
116 g_log.
notice() <<
"Open PDFgetN File " << filename <<
'\n';
120 bool readdata =
false;
123 while (ifile.getline(line, 256)) {
133 for (
size_t i = 0; i < numcols; ++i) {
134 std::vector<double> tempvec;
135 mData.emplace_back(tempvec);
138 }
else if (readdata) {
149 errmsg <<
"Unable to find a line staring with #L as the indicator of data "
152 throw std::runtime_error(errmsg.str());
162 if (s.size() < header.size()) {
165 size_t numchars = header.size();
166 for (
size_t i = 0; i < numchars; ++i) {
183 vector<string> terms;
184 boost::split(terms, line, is_any_of(
" \t\n"), token_compress_on);
188 throw std::runtime_error(
"There is nothing in the input line!");
191 string header = terms[0];
192 if (header !=
"#L") {
194 errmsg <<
"Expecting header as #L. Input line has header as " << header <<
". Unable to proceed. ";
196 throw std::runtime_error(errmsg.str());
200 size_t numcols = terms.size() - 1;
202 msgss <<
"Column Names: ";
203 for (
size_t i = 0; i < numcols; ++i) {
205 msgss << setw(-3) << i <<
": " << setw(-10) <<
mColumnNames[i];
215 vector<string> terms;
216 boost::split(terms, line, is_any_of(
" \t\n"), token_compress_on);
219 size_t numcols =
mData.size();
220 if (line[0] ==
'#') {
223 }
else if (terms.size() != numcols) {
226 warnss <<
"Line (" << line <<
") has incorrect number of columns other than " << numcols <<
" as expected. ";
232 for (
size_t i = 0; i < numcols; ++i) {
233 string temps = terms[i];
235 if (temps ==
"NaN") {
239 }
else if (temps ==
"-NaN") {
244 tempvalue = std::stod(temps);
247 mData[i].emplace_back(tempvalue);
256 if (xcolname ==
"Q") {
257 string unit =
"MomentumTransfer";
258 ws->getAxis(0)->setUnit(unit);
259 }
else if (xcolname ==
"r") {
260 ws->getAxis(0)->setUnit(
"AtomicDistance");
263 errss <<
"X axis " << xcolname <<
" is not supported for unit. \n";
270 if (ycolname ==
"G(r)") {
272 }
else if (ycolname ==
"S") {
275 ylabel =
"Intensity";
277 ws->setYUnitLabel(ylabel);
280size_t calcVecSize(
const std::vector<double> &data0, std::vector<size_t> &numptsvec,
size_t &numsets,
bool xascend) {
282 auto prex = data0[0];
283 for (
size_t i = 1; i < data0.size(); ++i) {
284 double curx = data0[i];
285 if (((xascend) && (curx < prex)) || ((!xascend) && (curx > prex))) {
290 numptsvec.emplace_back(vecsize);
304 bool samesize =
true;
305 for (
size_t i = 0; i < numsets; ++i) {
307 if (numptsvec[i] != numptsvec[i - 1]) {
311 g_log.
information() <<
"Set " << i <<
": Number of Points = " << numptsvec[i] <<
'\n';
315 errmsg <<
"Multiple bank (number of banks = " << numsets
316 <<
") have different size of data array. Unable to handle this "
319 throw std::runtime_error(errmsg.str());
329 throw runtime_error(
"Data set has not been initialized. Quit!");
339 vector<size_t> numptsvec;
340 size_t arraysize =
mData[0].size();
341 if (arraysize <= 1) {
342 throw runtime_error(
"Number of columns in data is less and equal to 1. It "
343 "is unphysically too small.");
352 size_t size = numptsvec[0];
355 outWS = std::dynamic_pointer_cast<Workspace2D>(
361 size_t numspec =
outWS->getNumberHistograms();
362 for (
size_t i = 0; i < numspec; ++i) {
363 auto &
X =
outWS->mutableX(i);
364 auto &
Y =
outWS->mutableY(i);
365 auto &E =
outWS->mutableE(i);
367 size_t baseindex = i * size;
368 for (
size_t j = 0; j < size; ++j) {
373 index = (size - 1) - j;
std::map< DeltaEMode::Type, std::string > index
#define DECLARE_FILELOADER_ALGORITHM(classname)
DECLARE_FILELOADER_ALGORITHM should be used in place of the standard DECLARE_ALGORITHM macro when wri...
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
@ Load
allowed here which will be passed to the algorithm
A property class for workspaces.
LoadPDFgetNFile : TODO: DESCRIPTION.
void parseDataFile(const std::string &filename)
Parse PDFgetN data file.
void init() override
Implement abstract Algorithm methods.
void setUnit(const DataObjects::Workspace2D_sptr &ws)
Set X and Y axis unit and lebel.
void generateDataWorkspace()
Generate output workspace.
std::vector< std::string > mColumnNames
Names of the columns of the data.
DataObjects::Workspace2D_sptr outWS
Output data workspace.
void checkSameSize(const std::vector< size_t > &numptsvec, size_t numsets)
void parseDataLine(std::string line)
Parse data line.
bool startsWith(const std::string &s, const std::string &header) const
Check whether a string starts from a specified sub-string.
void parseColumnNameLine(std::string line)
Parse column name line staring with #L.
std::vector< std::vector< double > > mData
Data structure to hold input: Size = Number of columns in input file.
void exec() override
Implement abstract Algorithm methods.
Defines a wrapper around an open file.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Kernel::Logger g_log("ExperimentInfo")
static logger object
bool startsWith(const string &str, const string &prefix)
Returns true if str starts with prefix.
size_t calcVecSize(const std::vector< double > &data0, std::vector< size_t > &numptsvec, size_t &numsets, bool xascend)
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
Helper class which provides the Collimation Length for SANS instruments.
@ Input
An input workspace.
@ Output
An output workspace.