-
Notifications
You must be signed in to change notification settings - Fork 122
/
SaveCanSAS1D.h
171 lines (144 loc) · 5.32 KB
/
SaveCanSAS1D.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef MANTID_DATAHANDLING_SaveCanSAS1D_H
#define MANTID_DATAHANDLING_SaveCanSAS1D_H
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include <fstream>
namespace Poco {
namespace XML {
class Document;
class Element;
class Text;
}
}
namespace Mantid {
namespace DataHandling {
/** @class SaveCanSAS1D DataHandling/SaveCanSAS1D.h
@verbatim
This algorithm saves workspace into CanSAS1d format. This is an xml format
except
the <Idata>, </Idata> tags and all data in between must be one line, which
necesitates
the files be written iostream functions outside xml libraries.
The structure of CanSAS1d xml is:
<SASroot version="1.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<SASentry>
<Title></Title>
<Run></Run>
<SASdata>
<Idata><Q unit="1/A"></Q><I unit="a.u."></I><Idev unit="a.u."></Idev><Qdev
unit="1/A"></Qdev></Idata>
</SASdata>
<SASsample>
<ID></ID>
</SASsample>
<SASinstrument>
<name></name>
<SASsource>
<radiation></radiation>
<wavelength unit="A"></wavelength>
</SASsource>
<SAScollimation/>
<SASdetector>
<name></name>
<SDD></SDD>
</SASdetector>
</SASinstrument>
<SASprocess>
<name></name>
<date></date>
<term name="svn"></term>
<term name="user_file"></term>
</SASprocess>
<SASnote>
</SASnote>
</SASentry>
</SASroot>
@endverbatim
Required properties:
<UL>
<LI> InputWorkspace - The name workspace to save.</LI>
<LI> Filename - The path save the file</LI>
</UL>
@author Sofia Antony, Rutherford Appleton Laboratory
@date 19/01/2010
Copyright © 2007-10 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport SaveCanSAS1D : public API::Algorithm {
public:
const std::string name() const override { return "SaveCanSAS1D"; }
const std::string summary() const override {
return "Save a MatrixWorkspace to a file in the canSAS 1-D format";
}
int version() const override { return 1; }
const std::string category() const override {
return "DataHandling\\XML;SANS\\DataHandling";
}
protected:
/// Overwrites Algorithm method.
void init() override;
/// overriden method sets appending for workspace groups
void setOtherProperties(API::IAlgorithm *alg, const std::string &propertyName,
const std::string &propertyValue,
int perioidNum) override;
/// Overwrites Algorithm method
void exec() override;
/// Opens the output file and, as necessary blanks it, writes the file header
/// and moves the file pointer
void prepareFileToWriteEntry();
/// opens the named file if possible or returns false
bool openForAppending(const std::string &filename);
/// Moves to the end of the last entry in the file
void findEndofLastEntry();
/// Write xml header tags
virtual void writeHeader(const std::string &fileName);
/// this method searches for xml special characters and replace with entity
/// references
void searchandreplaceSpecialChars(std::string &input);
/// replaces the charcter at index in the input string with xml entity
/// reference(eg.replace '&' with "&")
void replacewithEntityReference(std::string &input,
const std::string::size_type &index);
/// sasroot element
virtual void createSASRootElement(std::string &rootElem);
/// this method creates a sasTitle element
void createSASTitleElement(std::string &sasTitle);
/// this method creates a sasSample element
void createSASSampleElement(std::string &sasSample);
/// this method creates a sasRun Element
void createSASRunElement(std::string &sasRun);
/// this method creates a sasData element
void createSASDataElement(std::string &sasData);
/// this method creates a sasSource element
void createSASSourceElement(std::string &sasSource);
/// this method creates a sasDetector element
void createSASDetectorElement(std::string &sasDet);
/// this method creates a sasProcess element
void createSASProcessElement(std::string &sasProcess);
/// this method creates a sasInstrument element
void createSASInstrument(std::string &sasInstrument);
/// points to the workspace that will be written to file
API::MatrixWorkspace_const_sptr m_workspace;
/// an fstream object is used to write the xml manually as the user requires a
/// specific format with new line characters and this can't be done in using
/// the stylesheet part in Poco or libXML
std::fstream m_outFile;
};
}
}
#endif