-
Notifications
You must be signed in to change notification settings - Fork 122
/
SaveAscii2.h
95 lines (83 loc) · 3.6 KB
/
SaveAscii2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/Axis.h"
#include "MantidAPI/ITableWorkspace_fwd.h"
#include "MantidAPI/MatrixWorkspace_fwd.h"
namespace Mantid {
namespace DataHandling {
/** @class SaveAscii2 SaveAscii2.h DataHandling/SaveAscii2.h
Saves a workspace or selected spectra in a coma-separated ascii file. Spectra
are saved in columns.
*/
namespace AxisHelper {
struct AxisProxy {
AxisProxy(Mantid::API::Axis *ax) : a(ax) {}
virtual double getCentre(const int index) { return a->getValue(index); }
virtual ~AxisProxy() = default;
protected:
Mantid::API::Axis *a;
};
struct BinEdgeAxisProxy : AxisProxy {
using AxisProxy::AxisProxy;
double getCentre(const int index) override { return (a->getValue(index) + a->getValue(index + 1)) / 2.; }
};
} // namespace AxisHelper
class DLLExport SaveAscii2 : public API::Algorithm {
public:
/// Default constructor
SaveAscii2();
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "SaveAscii"; }
/// Summary of algorithms purpose
const std::string summary() const override { return "Saves a 2D workspace to a ascii file."; }
/// Algorithm's version for identification overriding a virtual method
int version() const override { return 2; }
const std::vector<std::string> seeAlso() const override {
return {"LoadAscii", "SaveCSV", "SaveDiffFittingAscii", "SaveReflectometryAscii",
"SaveOpenGenieAscii", "SaveGSS", "SaveFocusedXYE"};
}
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "DataHandling\\Text"; }
private:
/// Overwrites Algorithm method.
void init() override;
/// Overwrites Algorithm method
void exec() override;
void writeTableWorkspace(const API::ITableWorkspace_const_sptr &tws, const std::string &filename, bool appendToFile,
bool writeHeader, int prec, bool scientific, const std::string &comment);
/// Writes a spectrum to the file using a workspace index
void writeSpectrum(const int &wsIndex, std::ofstream &file);
std::vector<std::string> stringListToVector(std::string &inputString);
void populateQMetaData();
void populateSpectrumNumberMetaData();
void populateAngleMetaData();
void populateAllMetaData();
bool findElementInUnorderedStringVector(const std::vector<std::string> &vector, const std::string &toFind);
/// Retrieve sample log value and its unit
std::pair<std::string, std::string> sampleLogValueUnit(const std::string &logName);
/// Write file header
void writeFileHeader(const std::vector<std::string> &logList, std::ofstream &file);
/// Map the separator options to their string equivalents
std::map<std::string, std::string> m_separatorIndex;
int m_nBins;
std::string m_sep;
bool m_writeDX;
bool m_writeID;
bool m_isCommonBins;
bool m_writeSpectrumAxisValue;
API::MatrixWorkspace_const_sptr m_ws;
std::vector<std::string> m_metaData;
std::map<std::string, std::vector<std::string>> m_metaDataMap;
std::unique_ptr<AxisHelper::AxisProxy> m_axisProxy;
};
} // namespace DataHandling
} // namespace Mantid