ARTS 2.5.0 (git: 9ee3ac6c)
m_xml.h
Go to the documentation of this file.
1/* Copyright (C) 2002-2012 Oliver Lemke <olemke@core-dump.info>
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 USA. */
17
27#ifndef m_xml_h
28#define m_xml_h
29
30#ifdef ENABLE_MPI
31#include "mpi.h"
32#endif
33
34#include "agenda_class.h"
35#include "exceptions.h"
36#include "workspace_ng.h"
37#include "xml_io.h"
38
39/* Workspace method: Doxygen documentation will be auto-generated */
40template <typename T>
41void ReadXML( // WS Generic Output:
42 T& v,
43 // WS Generic Output Names:
44 const String& v_name,
45 // WS Generic Input:
46 const String& f,
47 // WS Generic Input Names:
48 const String& f_name _U_,
49 const Verbosity& verbosity) {
50 String filename = f;
51
52 // Create default filename if empty
53 filename_xml(filename, v_name);
54
55 xml_read_from_file(filename, v, verbosity);
56}
57
58/* Workspace method: Doxygen documentation will be auto-generated */
59template <typename T>
61 // WS Generic Output:
62 T& v,
63 // WS Generic Output Names:
64 const String& v_name,
65 // WS Generic Input:
66 const String& f,
67 // WS Generic Input Names:
68 const String& f_name,
69 const Verbosity& verbosity) {
70 ReadXML(v, v_name, f, f_name, verbosity);
71}
72
73/* Workspace method: Doxygen documentation will be auto-generated */
74template <typename T>
75void ReadXMLIndexed( // WS Generic Output:
76 T& v,
77 // WS Generic Output Names:
78 const String& v_name,
79 // WS Input:
80 const Index& file_index,
81 // WS Generic Input:
82 const String& f,
83 const Index& digits,
84 // WS Generic Input Names:
85 const String& f_name _U_,
86 const String& digits_name _U_,
87 const Verbosity& verbosity) {
88 String filename = f;
89
90 // Create default filename if empty
91 filename_xml_with_index(filename, file_index, v_name, digits);
92
93 xml_read_from_file(filename, v, verbosity);
94}
95
96/* Workspace method: Doxygen documentation will be auto-generated */
97template <typename T>
99 // WS Generic Output:
100 T& v,
101 // WS Generic Output Names:
102 const String& v_name,
103 // WS Input:
104 const Index& file_index,
105 // WS Generic Input:
106 const String& f,
107 const Index& digits,
108 // WS Generic Input Names:
109 const String& f_name,
110 const String& digits_name,
111 const Verbosity& verbosity) {
113 v, v_name, file_index, f, digits, f_name, digits_name, verbosity);
114}
115
116/* Workspace method: Doxygen documentation will be auto-generated */
117template <typename T>
118void WriteXML( //WS Input:
119 const String& file_format,
120 // WS Generic Input:
121 const T& v,
122 const String& f,
123 const Index& no_clobber,
124 // WS Generic Input Names:
125 const String& v_name,
126 const String& f_name _U_,
127 const String& no_clobber_name _U_,
128 const Verbosity& verbosity)
129
130{
131 // If MPI is enabled make sure only master process performs the write.
132#ifdef ENABLE_MPI
133 int initialized;
134 MPI_Initialized(&initialized);
135 if (!initialized) {
136 MPI_Init(nullptr, nullptr);
137 }
138 int rank;
139 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
140 if (rank != 0) {
141 return;
142 }
143#endif // ENABLE_MPI
144
145 String filename = f;
146
147 // Create default filename if empty
148 filename_xml(filename, v_name);
149
150 const FileType ftype = string2filetype(file_format);
151
152 String errmsg;
153
154#pragma omp critical(WriteXML_critical_region)
155 {
156 try {
157 xml_write_to_file(filename, v, ftype, no_clobber, verbosity);
158 } catch (const std::exception& e) {
159 errmsg = e.what();
160 }
161 }
162
163 ARTS_USER_ERROR_IF (errmsg.length(), errmsg);
164}
165
166/* Workspace method: Doxygen documentation will be auto-generated */
167template <typename T>
169 //WS Input:
170 const String& file_format,
171 // WS Generic Input:
172 const T& v,
173 const String& f,
174 const Index& no_clobber,
175 // WS Generic Input Names:
176 const String& v_name,
177 const String& f_name,
178 const String& no_clobber_name,
179 const Verbosity& verbosity) {
180 WriteXML(file_format,
181 v,
182 f,
183 no_clobber,
184 v_name,
185 f_name,
186 no_clobber_name,
187 verbosity);
188}
189
190/* Workspace method: Doxygen documentation will be auto-generated */
191template <typename T>
192void WriteXMLIndexed( //WS Input:
193 const String& file_format,
194 const Index& file_index,
195 // WS Generic Input:
196 const T& v,
197 const String& f,
198 const Index& digits,
199 // WS Generic Input Names:
200 const String& v_name,
201 const String& f_name,
202 const String& digits_name _U_,
203 const Verbosity& verbosity) {
204 String filename = f;
205
206 // Create default filename if empty
207 filename_xml_with_index(filename, file_index, v_name, digits);
208
209 WriteXML(file_format, v, filename, 0, v_name, f_name, "", verbosity);
210}
211
212/* Workspace method: Doxygen documentation will be auto-generated */
213template <typename T>
215 //WS Input:
216 const String& file_format,
217 const Index& file_index,
218 // WS Generic Input:
219 const T& v,
220 const String& f,
221 const Index& digits,
222 // WS Generic Input Names:
223 const String& v_name,
224 const String& f_name,
225 const String& digits_name,
226 const Verbosity& verbosity) {
227 WriteXMLIndexed(file_format,
228 file_index,
229 v,
230 f,
231 digits,
232 v_name,
233 f_name,
234 digits_name,
235 verbosity);
236}
237
238#endif // m_xml_h
Declarations for agendas.
Workspace class.
Definition: workspace_ng.h:40
#define _U_
Definition: config.h:180
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
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:41
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:192
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:75
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:118
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
#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:234
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Definition: xml_io.cc:218
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:181
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Definition: xml_io.h:160
FileType string2filetype(const String &file_format)
Definition: xml_io_base.cc:313
FileType
Definition: xml_io_base.h:40