29using namespace Kernel;
45 auto &file = descriptor.
data();
48 size_t axiscols(0), datacols(0);
51 const std::string sep =
" ";
54 while (std::getline(file, str)) {
57 if (str.empty() || str ==
"\r")
63 if (str.at(0) ==
'#') {
64 if (str.at(1) ==
'L') {
65 axiscols = tok.
count();
74 datacols = tok.
count();
77 }
catch (std::out_of_range &) {
80 if (snsspec && datacols == 3)
89 const std::vector<std::string> exts{
".dat",
".txt"};
91 "The name of the text file to read, including its full or "
92 "relative path. The file extension must be .txt or .dat.");
94 "The name of the workspace that will be created, filled with the read-in "
95 "data and stored in the [[Analysis Data Service]].");
97 std::vector<std::string> units = UnitFactory::Instance().getKeys();
98 units.insert(units.begin(),
"MomemtumTransfer");
99 declareProperty(
"Unit",
"Energy", std::make_shared<Kernel::StringListValidator>(units),
100 "The unit to assign to the X axis (anything known to the "
101 "[[Unit Factory]] or \"Dimensionless\")");
109 std::ifstream file(filename.c_str());
111 file.seekg(0, std::ios::end);
113 file.seekg(0, std::ios::beg);
116 std::vector<double> input;
119 auto localWorkspace =
122 localWorkspace->getAxis(0)->unit() = UnitFactory::Instance().create(
getProperty(
"Unit"));
125 file.seekg(0, std::ios::beg);
128 while (getline(file, str)) {
129 progress.report(
static_cast<int>(file.tellg()));
134 if (str.empty() && specNum != -1) {
135 auto histogram = localWorkspace->histogram(specNum);
137 localWorkspace->setHistogram(specNum, histogram);
149 throw "Undefined number of spectra";
151 if (
static_cast<size_t>(specNum) == (
nSpectra - 1)) {
152 auto histogram = localWorkspace->histogram(specNum);
154 localWorkspace->setHistogram(specNum, histogram);
171 size_t spectra_nbr = 0;
173 while (getline(file, str)) {
176 if (str[0] ==
'#' && str[1] ==
'L') {
190 if (!line.empty() && line[0] !=
'#') {
192 const std::string sep =
" ";
194 buffer.reserve(buffer.size() + tok.
size());
195 std::transform(tok.
cbegin(), tok.
cend(), std::back_inserter(buffer),
196 [](
const auto &beg) { return std::stod(beg); });
207 std::vector<double>
x,
y, e;
209 auto isHist = input.size() % 3 > 0;
210 auto nElements = (isHist) ? input.size() - 1 : input.size() - 2;
212 x.reserve(nElements);
213 y.reserve(nElements);
214 e.reserve(nElements);
217 x.emplace_back(input[
index]);
219 y.emplace_back(input[
index]);
221 e.emplace_back(input[
index]);
224 histogram.resize(
y.size());
229 x.emplace_back(input.back());
230 histogram.setBinEdges(
x);
232 histogram.setPoints(
x);
235 histogram.setCounts(
y);
236 histogram.setCountStandardDeviations(e);
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
@ Load
allowed here which will be passed to the algorithm
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Executes the algorithm.
void init() override
Initialisation method.
void readHistogram(const std::vector< double > &input, HistogramData::Histogram &histogram) const
Helper method for reading a single histogram.
void readLine(const std::string &line, std::vector< double > &buffer) const
Helper method for reading a line from the file.
int confidence(Kernel::FileDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
size_t readNumberOfSpectra(std::ifstream &file) const
Helper method for reading the number of spectra from the file.
LoadSpec()
Empty constructor.
Defines a wrapper around an open file.
static bool isAscii(const std::string &filename, const size_t nbytes=256)
Returns true if the file is considered ascii.
std::istream & data()
Access the open file stream.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ TOK_IGNORE_EMPTY
ignore empty tokens
std::size_t size() const noexcept
Get the total number of tokens.
ConstIterator cend() const
Const iterator referring to the past-the-end element in the container.
ConstIterator cbegin() const
Const iterator referring to first element in the container.
std::size_t count() const
Get the total number of tokens.
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.
@ Output
An output workspace.