28 "An input workspace.");
30 "A DAVE grouped data format file that will be created");
32 "Transform all energy units from milli eV to micro eV");
40 std::size_t
nSpectra = ws->getNumberHistograms();
41 std::size_t nBins = ws->blocksize();
43 throw std::invalid_argument(
"Either the number of bins or the number of histograms is 0");
44 std::string xcaption = ws->getAxis(0)->unit()->caption();
45 std::string ycaption = ws->getAxis(1)->unit()->caption();
46 if (xcaption.length() == 0)
48 if (ycaption.length() == 0 || ycaption ==
"Spectrum")
52 std::ofstream file(filename.c_str());
54 g_log.
error(
"Unable to create file: " + filename);
58 file <<
"# Number of " << xcaption <<
" values\n";
59 file << nBins <<
'\n';
60 file <<
"# Number of " << ycaption <<
" values\n";
64 bool xToMicroeV =
false, yToMicroeV =
false;
66 std::string xunit = ws->getAxis(0)->unit()->label();
67 std::string yunit = ws->getAxis(1)->unit()->label();
68 if (yunit ==
"Angstrom^-1")
69 yunit =
"1/Angstroms";
70 if (toMicroeV && (xunit ==
"meV"))
72 if (toMicroeV && (yunit ==
"meV"))
77 file <<
"# " << xcaption <<
" (" << xunit <<
") values\n";
78 auto x = ws->points(0);
79 for (std::size_t i = 0; i < nBins; i++) {
83 file << xvalue <<
'\n';
88 file <<
"# " << ycaption <<
" (" << yunit <<
") values\n";
90 if ((*ws->getAxis(1)).length() == (
nSpectra + 1)) {
91 for (std::size_t i = 0; i <
nSpectra; i++) {
92 yvalue = 0.5 * (((*ws->getAxis(1))(i)) + ((*ws->getAxis(1))(i + 1)));
95 file << yvalue <<
'\n';
98 for (std::size_t i = 0; i <
nSpectra; i++) {
99 yvalue = (*ws->getAxis(1))(i);
102 file << yvalue <<
'\n';
106 for (std::size_t i = 0; i <
nSpectra; i++) {
107 file <<
"# Group " << i <<
'\n';
110 auto itE = E.cbegin();
111 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.
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.
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.