-
Notifications
You must be signed in to change notification settings - Fork 122
/
SaveCSV.h
105 lines (85 loc) · 3.62 KB
/
SaveCSV.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
96
97
98
99
100
101
102
103
104
105
// 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 "MantidDataObjects/Workspace2D.h"
namespace Mantid {
namespace DataHandling {
/** @class SaveCSV SaveCSV.h DataHandling/SaveCSV.h
Saves a 1D or 2D workspace to a CSV file. SaveCSV is an algorithm and as such
inherits from the Algorithm class, via DataHandlingCommand, and overrides
the init() & exec() methods.
Required Properties:
<UL>
<LI> Filename - The filename of the output CSV file </LI>
<LI> InputWorkspace - The name of a workspace containing the data you want to
save to a CSV file </LI>
</UL>
Optional Properties:
<UL>
<LI> Separator - defaults to "," </LI>
<LI> LineSeparator - defaults to "\n" </LI>
</UL>
The format of the saved ascii CSV file for a 1D worksspace consists of three
columns where the numbers of each row are seperated by the Seperator and
each line by the LineSeperator.
The format of the saved CSV file for a 2D workspace is as follows:
A 0, 200, 400, 600, ..., 50000 <BR>
0 10, 4, 234, 35, ..., 32 <BR>
1 4, 234, 4, 9, ..., 12 <BR>
A 0, 100, 200, 300, ..., 25000 <BR>
2 34, 0, 0, 0, ..., 23
ERRORS<BR>
0 0.1, 3.4, 2.4, 3.5, ..., 2 <BR>
1 3.1, 3.3, 2.5, 3.5, ..., 2 <BR>
2 1.1, 3.3, 2.4, 5, ..., 2.4
where for the matrix above the ERRORS line the first column
shows the content of the numbers on the of the same line; i.e.
'A' is followed by x-axis values (e.g. TOF values) and any number
(e.g. '2') followed by y-axis values (e.g. neutron counts). Multiple
'A' may be present to allow for the a-axis to change. So in
the example above the saved 2D workspace consists of three histograms
(y-axes) where the first two have the same x-axis but the third
histogram has a different x-axis.
The matrix following the ERRORS line lists the errors as recorded
for each histogram.
@author Anders Markvardsen, ISIS, RAL
@date 15/10/2007
*/
class DLLExport SaveCSV : public API::Algorithm {
public:
/// Default constructor
SaveCSV();
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "SaveCSV"; };
/// Summary of algorithms purpose
const std::string summary() const override { return "Saves a 1D or 2D workspace to a CSV file."; }
/// Algorithm's version for identification overriding a virtual method
int version() const override { return 1; };
const std::vector<std::string> seeAlso() const override { return {"SaveAscii"}; }
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "DataHandling\\Text"; }
private:
/// Overwrites Algorithm method. Does nothing at present
void init() override;
/// Overwrites Algorithm method
void exec() override;
/// Saves out x errors
void saveXerrors(std::ofstream &stream, const Mantid::DataObjects::Workspace2D_sptr &workspace,
const size_t numberOfHist);
/// The name of the file used for storing the workspace
std::string m_filename;
/// The seperator for the CSV file
std::string m_separator;
/// The line seperator for the CSV file
std::string m_lineSeparator;
};
} // namespace DataHandling
} // namespace Mantid