ARTS  2.2.66
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 #include "exceptions.h"
31 #include "xml_io.h"
32 #include "workspace_ng.h"
33 #include "agenda_class.h"
34 
35 /* Workspace method: Doxygen documentation will be auto-generated */
36 template<typename T> void
37 ReadXML (// WS Generic Output:
38  T& v,
39  // WS Generic Output Names:
40  const String& v_name,
41  // WS Generic Input:
42  const String& f,
43  // WS Generic Input Names:
44  const String& f_name _U_,
45  const Verbosity& verbosity)
46 {
47  String filename = f;
48 
49  // Create default filename if empty
50  filename_xml (filename, v_name);
51 
52  xml_read_from_file (filename, v, verbosity);
53 }
54 
55 
56 /* Workspace method: Doxygen documentation will be auto-generated */
57 void
58 ReadXML (Workspace& ws _U_,
59  // WS Generic Output:
60  Agenda& v,
61  // WS Generic Output Names:
62  const String& v_name,
63  // WS Generic Input:
64  const String& f,
65  // WS Generic Input Names:
66  const String& f_name,
67  const Verbosity& verbosity);
68 
69 
70 /* Workspace method: Doxygen documentation will be auto-generated */
71 template<typename T> void
72 ReadXMLIndexed (// WS Generic Output:
73  T& v,
74  // WS Generic Output Names:
75  const String& v_name,
76  // WS Input:
77  const Index& file_index,
78  // WS Generic Input:
79  const String& f,
80  // WS Generic Input Names:
81  const String& f_name _U_,
82  const Verbosity& verbosity)
83 {
84  String filename = f;
85 
86  // Create default filename if empty
87  filename_xml_with_index( filename, file_index, v_name );
88 
89  xml_read_from_file (filename, v, verbosity);
90 }
91 
92 
93 /* Workspace method: Doxygen documentation will be auto-generated */
94 void
96  // WS Generic Output:
97  Agenda& v,
98  // WS Generic Output Names:
99  const String& v_name,
100  // WS Generic Input:
101  const String& f,
102  // WS Generic Input Names:
103  const String& f_name,
104  const Verbosity& verbosity);
105 
106 
107 /* Workspace method: Doxygen documentation will be auto-generated */
108 template<typename T> void
109 WriteXML (//WS Input:
110  const String& file_format,
111  // WS Generic Input:
112  const T& v,
113  const String& f,
114  const Index& no_clobber,
115  // WS Generic Input Names:
116  const String& v_name,
117  const String& f_name _U_,
118  const String& no_clobber_name _U_,
119  const Verbosity& verbosity)
120 
121 {
122  String filename = f;
123  FileType ftype;
124 
125  // Create default filename if empty
126  filename_xml (filename, v_name);
127 
128  if (file_format == "ascii")
129  ftype = FILE_TYPE_ASCII;
130  else if (file_format == "zascii")
131  ftype = FILE_TYPE_ZIPPED_ASCII;
132  else if (file_format == "binary")
133  ftype = FILE_TYPE_BINARY;
134  else
135  throw runtime_error ("file_format contains illegal string. "
136  "Valid values are:\n"
137  " ascii: XML output\n"
138  " zascii: Zipped XML output\n"
139  " binary: XML + binary output");
140 
141  String errmsg;
142 
143 #pragma omp critical(WriteXML_critical_region)
144  try
145  {
146  xml_write_to_file (filename, v, ftype, no_clobber, verbosity);
147  }
148  catch (std::runtime_error e)
149  {
150  errmsg = e.what();
151  }
152 
153  if (errmsg.length())
154  {
155  throw std::runtime_error(errmsg);
156  }
157 }
158 
159 
160 /* Workspace method: Doxygen documentation will be auto-generated */
161 void
162 WriteXML (Workspace& ws _U_,
163  //WS Input:
164  const String& file_format,
165  // WS Generic Input:
166  const Agenda& v,
167  const String& f,
168  const Index& no_clobber,
169  // WS Generic Input Names:
170  const String& v_name,
171  const String& f_name,
172  const String& no_clobber_name,
173  const Verbosity& verbosity);
174 
175 /* Workspace method: Doxygen documentation will be auto-generated */
176 template<typename T> void
177 WriteXMLIndexed (//WS Input:
178  const String& file_format,
179  const Index& file_index,
180  // WS Generic Input:
181  const T& v,
182  const String& f,
183  // WS Generic Input Names:
184  const String& v_name,
185  const String& f_name,
186  const Verbosity& verbosity)
187 {
188  String filename = f;
189 
190  // Create default filename if empty
191  filename_xml_with_index( filename, file_index, v_name );
192 
193  WriteXML( file_format, v, filename, 0,
194  v_name, f_name, "", verbosity );
195 }
196 
197 
198 /* Workspace method: Doxygen documentation will be auto-generated */
199 void
201  //WS Input:
202  const String& file_format,
203  const Index& file_index,
204  // WS Generic Input:
205  const Agenda& v,
206  const String& f,
207  // WS Generic Input Names:
208  const String& v_name,
209  const String& f_name,
210  const Verbosity& verbosity);
211 
212 #endif // m_xml_h
213 
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
The Agenda class.
Definition: agenda_class.h:44
void WriteXMLIndexed(const String &file_format, const Index &file_index, const T &v, const String &f, const String &v_name, const String &f_name, const Verbosity &verbosity)
WORKSPACE METHOD: WriteXMLIndexed.
Definition: m_xml.h:177
This file contains basic functions to handle XML data files.
This file contains the declaration and partly the implementation of the workspace class...
void filename_xml_with_index(String &filename, const Index &file_index, const String &varname)
Gives the default filename, with file index, for the XML formats.
Definition: xml_io.cc:370
The implementation for String, the ARTS string class.
Definition: mystring.h:63
void ReadXMLIndexed(T &v, const String &v_name, const Index &file_index, const String &f, const String &f_name, const Verbosity &verbosity)
WORKSPACE METHOD: ReadXMLIndexed.
Definition: m_xml.h:72
Declarations for agendas.
The declarations of all the exception classes.
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Definition: xml_io.cc:831
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:37
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Definition: xml_io.cc:350
Workspace class.
Definition: workspace_ng.h:47
#define _U_
Definition: config.h:167
FileType
Definition: xml_io.h:38
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:109
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.cc:982