16#include <Poco/DateTimeFormatter.h>
17#include <Poco/LocalDateTime.h>
31 "The name of the workspace to save");
32 const std::vector<std::string> fileExts{
".txt",
".Q",
".dat"};
34 "The name to use when saving the file");
35 declareProperty(
"Append",
true,
"If true and Filename already exists, append, else overwrite");
49 g_log.
error(
"This algorithm expects a 2d workspace to have been converted away from \
50 spectrum numbers on the vertical axis");
51 throw std::invalid_argument(
"Cannot write out this kind of workspace");
56 ios_base::openmode mode = (
getProperty(
"Append") ? (ios_base::out | ios_base::app) : ios_base::out);
58 const std::string filename =
getProperty(
"Filename");
59 m_outRKH.open(filename.c_str(), mode);
62 g_log.
error() <<
"An error occurred while attempting to open the file " << filename <<
"\n";
63 throw std::runtime_error(
"An error occurred while trying to open the output file for writing");
83 Poco::LocalDateTime timestamp;
86 m_outRKH << Poco::DateTimeFormatter::format(timestamp, std::string(
"%w")) <<
" "
87 << Poco::DateTimeFormatter::format(timestamp, std::string(
"%d")) <<
"-";
88 std::string month = Poco::DateTimeFormatter::format(timestamp, std::string(
"%b"));
89 std::transform(month.begin(), month.end(), month.begin(), toupper);
90 m_outRKH << month <<
"-" << Poco::DateTimeFormatter::format(timestamp, std::string(
"%Y %H:%M"))
97 const int unitCode1 = unit1->caption() ==
"q" ?
Q_CODE : 0;
98 const int unitCode2 = unit2->caption() ==
"q" ?
Q_CODE : 0;
99 m_outRKH <<
" " << unitCode1 <<
" " << unit1->caption() <<
" (" << unit1->label().ascii() <<
")\n"
100 <<
" " << unitCode2 <<
" " << unit2->caption() <<
" (" << unit2->label().ascii() <<
")\n"
109 m_outRKH << std::setw(5) << noDataPoints <<
" 0 0 0 1" << std::setw(5) << noDataPoints <<
" 0\n"
111 <<
" 3 (F12.5,2E16.6)\n";
118 const size_t nhist =
m_workspace->getNumberHistograms();
119 const bool horizontal = nhist == 1;
121 g_log.
notice() <<
"Values in first column are the X values\n";
125 g_log.
notice(
"Values in first column are spectrum numbers");
126 const bool histogram =
m_workspace->isHistogramData();
127 Progress prg(
this, 0.0, 1.0, noDataPoints);
130 for (
size_t i = 0; i < nhist; ++i) {
137 specid =
m_workspace->getSpectrum(i).getSpectrumNo();
143 auto dXvals =
m_workspace->pointStandardDeviations(i);
145 for (
size_t j = 0; j < nbins; ++j) {
149 xval = histogram ? 0.5 * (xdata[j] + xdata[j + 1]) : xdata[j];
151 xval =
static_cast<double>(specid);
154 m_outRKH << std::fixed << std::setw(12) << std::setprecision(5) << xval << std::scientific << std::setw(16)
155 << std::setprecision(6) << ydata[j] << std::setw(16) << edata[j];
158 m_outRKH << std::setw(16) << dXvals[j];
171 const size_t Xbins =
X->length();
173 for (
size_t i = 0; i < Xbins; ++i) {
174 m_outRKH << std::setw(14) << std::scientific << std::setprecision(6) << (*X)(i);
179 const size_t Ybins =
Y->length();
181 for (
size_t i = 0; i < Ybins; ++i) {
182 m_outRKH << std::setw(14) << std::scientific << std::setprecision(6) << (*Y)(i);
188 const size_t num_hist =
m_workspace->getNumberHistograms();
190 << std::setprecision(12) << 1.0 <<
"\n";
192 m_outRKH <<
" " << iflag <<
"(8E12.4)\n";
194 bool requireNewLine =
false;
196 for (
size_t i = 0; i < num_hist; ++i) {
198 m_outRKH << std::setw(12) << std::scientific << std::setprecision(4) << yVal;
199 requireNewLine =
true;
202 requireNewLine =
false;
215 for (
size_t i = 0; i < num_hist; ++i) {
217 m_outRKH << std::setw(12) << std::scientific << std::setprecision(4) << eVal;
#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.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Class to represent the axis of a workspace.
@ 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.
@ LINE_LENGTH
with the unit Q
@ Q_CODE
this is the integer code the RKH file format associates
std::ofstream m_outRKH
The output filehandle.
void init() override
Initialisation code.
API::MatrixWorkspace_const_sptr m_workspace
The input workspace.
void write2D()
Writes out the 2D data.
void exec() override
Execution code.
void write1D()
Writes out the 1D data.
void writeHeader()
Writes out the header of the output file.
bool m_2d
Whether this is a 2D dataset.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::shared_ptr< const Unit > Unit_const_sptr
Shared pointer to the Unit base class (const version)
int32_t specnum_t
Typedef for a spectrum Number.
@ Input
An input workspace.