27 "An input workspace.");
29 "A DAVE grouped data format file that will be created");
31 "Transform all energy units from milli eV to micro eV");
34 "Transform the spectrum numbers to Q values");
38 std::map<std::string, std::string> result;
41 const bool toQsInQENSData =
getProperty(
"ToQsInQENSData");
42 if (toMicroEV && toQsInQENSData) {
43 result[
"ToQsInQENSData"] =
"'ToMicroEV' and 'ToQsInQENSData' can't be set to True at the same time."
44 "Set 'ToQsInQENSData' to False";
54 std::size_t
nSpectra = ws->getNumberHistograms();
55 std::size_t nBins = ws->blocksize();
57 throw std::invalid_argument(
"Either the number of bins or the number of histograms is 0");
58 std::string xcaption = ws->getAxis(0)->unit()->caption();
59 std::string ycaption = ws->getAxis(1)->unit()->caption();
60 const bool toQsInQENSData =
getProperty(
"ToQsInQENSData");
62 if (xcaption.length() == 0)
64 if (ycaption.length() == 0 || ycaption ==
"Spectrum")
65 ycaption = toQsInQENSData ?
"Q" :
"Y";
68 std::ofstream file(filename.c_str());
70 g_log.
error(
"Unable to create file: " + filename);
74 file <<
"# Number of " << xcaption <<
" values\n";
75 file << nBins <<
'\n';
76 file <<
"# Number of " << ycaption <<
" values\n";
80 bool xToMicroeV =
false, yToMicroeV =
false;
82 std::string xunit = ws->getAxis(0)->unit()->label();
83 std::string yunit = ws->getAxis(1)->unit()->label();
84 if (yunit ==
"Angstrom^-1")
85 yunit =
"1/Angstroms";
86 if (toMicroeV && (xunit ==
"meV"))
88 if (toMicroeV && (yunit ==
"meV"))
93 file <<
"# " << xcaption <<
" (" << xunit <<
") values\n";
94 auto x = ws->points(0);
95 for (std::size_t i = 0; i < nBins; i++) {
99 file << xvalue <<
'\n';
104 file <<
"# " << ycaption <<
" (" << yunit <<
") values\n";
106 if (toQsInQENSData) {
108 qsInQENSData->initialize();
109 qsInQENSData->setProperty(
"InputWorkspace", ws->getName());
110 qsInQENSData->execute();
111 std::vector<double> qvalues = qsInQENSData->getProperty(
"Qvalues");
112 for (
const auto &qvalue : qvalues) {
113 file << qvalue <<
'\n';
115 }
else if ((*ws->getAxis(1)).length() == (
nSpectra + 1)) {
116 for (std::size_t i = 0; i <
nSpectra; i++) {
117 yvalue = 0.5 * (((*ws->getAxis(1))(i)) + ((*ws->getAxis(1))(i + 1)));
120 file << yvalue <<
'\n';
123 for (std::size_t i = 0; i <
nSpectra; i++) {
124 yvalue = (*ws->getAxis(1))(i);
127 file << yvalue <<
'\n';
131 for (std::size_t i = 0; i <
nSpectra; i++) {
132 file <<
"# Group " << i <<
'\n';
135 auto itE = E.cbegin();
136 std::for_each(
Y.cbegin(),
Y.cend(), [&itE, &file](
const double y) { file << y <<
" " << *itE++ <<
"\n"; });
#define DECLARE_ALGORITHM(classname)
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.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
@ Save
to specify a file to write to, the file may or may not exist
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Run the algorithm.
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
void init() override
Initialise the properties.
Records the filename and the description of failure.
void error(const std::string &msg)
Logs at error level.
The concrete, templated class for properties.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
@ Input
An input workspace.