ARTS 2.5.11 (git: 725533f0)
m_xml.h
Go to the documentation of this file.
1
10#ifndef m_xml_h
11#define m_xml_h
12
13#ifdef ENABLE_MPI
14#include "mpi.h"
15#endif
16
17#include "agenda_class.h"
18#include "exceptions.h"
19#include "workspace_ng.h"
20#include "xml_io.h"
21
22/* Workspace method: Doxygen documentation will be auto-generated */
23template <typename T>
24void ReadXML( // WS Generic Output:
25 T& v,
26 // WS Generic Output Names:
27 const String& v_name,
28 // WS Generic Input:
29 const String& f,
30 // WS Generic Input Names:
31 const String& f_name _U_,
32 const Verbosity& verbosity) {
33 String filename = f;
34
35 // Create default filename if empty
36 filename_xml(filename, v_name);
37
38 xml_read_from_file(filename, v, verbosity);
39}
40
41/* Workspace method: Doxygen documentation will be auto-generated */
42template <typename T>
44 // WS Generic Output:
45 T& v,
46 // WS Generic Output Names:
47 const String& v_name,
48 // WS Generic Input:
49 const String& f,
50 // WS Generic Input Names:
51 const String& f_name,
52 const Verbosity& verbosity) {
53 ReadXML(v, v_name, f, f_name, verbosity);
54}
55
56/* Workspace method: Doxygen documentation will be auto-generated */
57template <typename T>
58void ReadXMLIndexed( // WS Generic Output:
59 T& v,
60 // WS Generic Output Names:
61 const String& v_name,
62 // WS Input:
63 const Index& file_index,
64 // WS Generic Input:
65 const String& f,
66 const Index& digits,
67 // WS Generic Input Names:
68 const String& f_name _U_,
69 const String& digits_name _U_,
70 const Verbosity& verbosity) {
71 String filename = f;
72
73 // Create default filename if empty
74 filename_xml_with_index(filename, file_index, v_name, digits);
75
76 xml_read_from_file(filename, v, verbosity);
77}
78
79/* Workspace method: Doxygen documentation will be auto-generated */
80template <typename T>
82 // WS Generic Output:
83 T& v,
84 // WS Generic Output Names:
85 const String& v_name,
86 // WS Input:
87 const Index& file_index,
88 // WS Generic Input:
89 const String& f,
90 const Index& digits,
91 // WS Generic Input Names:
92 const String& f_name,
93 const String& digits_name,
94 const Verbosity& verbosity) {
96 v, v_name, file_index, f, digits, f_name, digits_name, verbosity);
97}
98
99/* Workspace method: Doxygen documentation will be auto-generated */
100template <typename T>
101void WriteXML( //WS Input:
102 const String& file_format,
103 // WS Generic Input:
104 const T& v,
105 const String& f,
106 const Index& no_clobber,
107 // WS Generic Input Names:
108 const String& v_name,
109 const String& f_name _U_,
110 const String& no_clobber_name _U_,
111 const Verbosity& verbosity)
112
113{
114 // If MPI is enabled make sure only master process performs the write.
115#ifdef ENABLE_MPI
116 int initialized;
117 MPI_Initialized(&initialized);
118 if (!initialized) {
119 MPI_Init(nullptr, nullptr);
120 }
121 int rank;
122 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
123 if (rank != 0) {
124 return;
125 }
126#endif // ENABLE_MPI
127
128 String filename = f;
129
130 // Create default filename if empty
131 filename_xml(filename, v_name);
132
133 const FileType ftype = string2filetype(file_format);
134
135 String errmsg;
136
137#pragma omp critical(WriteXML_critical_region)
138 {
139 try {
140 xml_write_to_file(filename, v, ftype, no_clobber, verbosity);
141 } catch (const std::exception& e) {
142 errmsg = e.what();
143 }
144 }
145
146 ARTS_USER_ERROR_IF (errmsg.length(), errmsg);
147}
148
149/* Workspace method: Doxygen documentation will be auto-generated */
150template <typename T>
152 //WS Input:
153 const String& file_format,
154 // WS Generic Input:
155 const T& v,
156 const String& f,
157 const Index& no_clobber,
158 // WS Generic Input Names:
159 const String& v_name,
160 const String& f_name,
161 const String& no_clobber_name,
162 const Verbosity& verbosity) {
163 WriteXML(file_format,
164 v,
165 f,
166 no_clobber,
167 v_name,
168 f_name,
169 no_clobber_name,
170 verbosity);
171}
172
173/* Workspace method: Doxygen documentation will be auto-generated */
174template <typename T>
175void WriteXMLIndexed( //WS Input:
176 const String& file_format,
177 const Index& file_index,
178 // WS Generic Input:
179 const T& v,
180 const String& f,
181 const Index& digits,
182 // WS Generic Input Names:
183 const String& v_name,
184 const String& f_name,
185 const String& digits_name _U_,
186 const Verbosity& verbosity) {
187 String filename = f;
188
189 // Create default filename if empty
190 filename_xml_with_index(filename, file_index, v_name, digits);
191
192 WriteXML(file_format, v, filename, 0, v_name, f_name, "", verbosity);
193}
194
195/* Workspace method: Doxygen documentation will be auto-generated */
196template <typename T>
198 //WS Input:
199 const String& file_format,
200 const Index& file_index,
201 // WS Generic Input:
202 const T& v,
203 const String& f,
204 const Index& digits,
205 // WS Generic Input Names:
206 const String& v_name,
207 const String& f_name,
208 const String& digits_name,
209 const Verbosity& verbosity) {
210 WriteXMLIndexed(file_format,
211 file_index,
212 v,
213 f,
214 digits,
215 v_name,
216 f_name,
217 digits_name,
218 verbosity);
219}
220
221#endif // m_xml_h
Declarations for agendas.
Workspace class.
#define _U_
Definition config.h:177
#define ARTS_USER_ERROR_IF(condition,...)
Definition debug.h:137
The declarations of all the exception classes.
void ReadXML(T &v, const String &v_name, const String &f, const String &f_name, const Verbosity &verbosity)
WORKSPACE METHOD: ReadXML.
Definition m_xml.h:24
void WriteXMLIndexed(const String &file_format, const Index &file_index, const T &v, const String &f, const Index &digits, const String &v_name, const String &f_name, const String &digits_name, const Verbosity &verbosity)
WORKSPACE METHOD: WriteXMLIndexed.
Definition m_xml.h:175
void ReadXMLIndexed(T &v, const String &v_name, const Index &file_index, const String &f, const Index &digits, const String &f_name, const String &digits_name, const Verbosity &verbosity)
WORKSPACE METHOD: ReadXMLIndexed.
Definition m_xml.h:58
void WriteXML(const String &file_format, const T &v, const String &f, const Index &no_clobber, const String &v_name, const String &f_name, const String &no_clobber_name, const Verbosity &verbosity)
WORKSPACE METHOD: WriteXML.
Definition m_xml.h:101
#define v
This file contains the Workspace class.
void filename_xml_with_index(String &filename, const Index &file_index, const String &varname, const Index &digits)
Gives the default filename, with file index, for the XML formats.
Definition xml_io.cc:199
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Definition xml_io.cc:183
This file contains basic functions to handle XML data files.
void xml_write_to_file(const String &filename, const T &type, const FileType ftype, const Index no_clobber, const Verbosity &verbosity)
Write data to XML file.
Definition xml_io.h:155
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Definition xml_io.h:134
FileType string2filetype(const String &file_format)
FileType
Definition xml_io_base.h:25