ARTS  2.0.49
m_xml.h
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008 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
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  ReadXML (v, v_name, f, f_name, verbosity);
70 }
71 
72 
73 /* Workspace method: Doxygen documentation will be auto-generated */
74 template<typename T> void
75 WriteXML (//WS Input:
76  const String& file_format,
77  // WS Generic Input:
78  const T& v,
79  const String& f,
80  // WS Generic Input Names:
81  const String& v_name,
82  const String& f_name _U_,
83  const Verbosity& verbosity)
84 
85 {
86  String filename = f;
87  FileType ftype;
88 
89  // Create default filename if empty
90  filename_xml (filename, v_name);
91 
92  if (file_format == "ascii")
93  ftype = FILE_TYPE_ASCII;
94  else if (file_format == "zascii")
95  ftype = FILE_TYPE_ZIPPED_ASCII;
96  else if (file_format == "binary")
97  ftype = FILE_TYPE_BINARY;
98  else
99  throw runtime_error ("file_format contains illegal string. "
100  "Valid values are:\n"
101  " ascii: XML output\n"
102  " zascii: Zipped XML output\n"
103  " binary: XML + binary output");
104 
105  xml_write_to_file (filename, v, ftype, verbosity);
106 }
107 
108 
109 /* Workspace method: Doxygen documentation will be auto-generated */
110 void
112  //WS Input:
113  const String& file_format,
114  // WS Generic Input:
115  const Agenda& v,
116  const String& f,
117  // WS Generic Input Names:
118  const String& v_name,
119  const String& f_name,
120  const Verbosity& verbosity)
121 {
122  WriteXML (file_format, v, f, v_name, f_name, verbosity);
123 }
124 
125 
126 /* Workspace method: Doxygen documentation will be auto-generated */
127 template<typename T> void
128 WriteXMLIndexed (//WS Input:
129  const String& file_format,
130  const Index& file_index,
131  // WS Generic Input:
132  const T& v,
133  const String& f,
134  // WS Generic Input Names:
135  const String& v_name,
136  const String& f_name _U_,
137  const Verbosity& verbosity)
138 {
139  String filename = f;
140 
141  // Create default filename if empty
142  filename_xml_with_index( filename, file_index, v_name );
143 
144  WriteXML( file_format, v, filename, v_name, f_name, verbosity );
145 }
146 
147 
148 /* Workspace method: Doxygen documentation will be auto-generated */
149 void
151  //WS Input:
152  const String& file_format,
153  const Index& file_index,
154  // WS Generic Input:
155  const Agenda& v,
156  const String& f,
157  // WS Generic Input Names:
158  const String& v_name,
159  const String& f_name,
160  const Verbosity& verbosity)
161 {
162  WriteXMLIndexed (file_format, file_index, v, f, v_name, f_name, verbosity);
163 }
164 
165 
166 /* Workspace method: Doxygen documentation will be auto-generated */
167 void
169  String& file_format,
170  const Verbosity&)
171 {
172  file_format = "ascii";
173 }
174 
175 
176 /* Workspace method: Doxygen documentation will be auto-generated */
177 void
179  String& file_format,
180  const Verbosity&)
181 {
182  file_format = "zascii";
183 }
184 
185 
186 /* Workspace method: Doxygen documentation will be auto-generated */
187 void
189  String& file_format,
190  const Verbosity&)
191 {
192  file_format = "binary";
193 }
194 
195 
196 #endif // m_xml_h
197 
WriteXML
void WriteXML(const String &file_format, const T &v, const String &f, const String &v_name, const String &f_name, const Verbosity &verbosity)
WORKSPACE METHOD: WriteXML.
Definition: m_xml.h:75
output_file_formatSetBinary
void output_file_formatSetBinary(String &file_format, const Verbosity &)
WORKSPACE METHOD: output_file_formatSetBinary.
Definition: m_xml.h:188
exceptions.h
The declarations of all the exception classes.
FILE_TYPE_BINARY
@ FILE_TYPE_BINARY
Definition: xml_io.h:41
WriteXMLIndexed
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:128
filename_xml_with_index
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:385
Agenda
The Agenda class.
Definition: agenda_class.h:44
ReadXML
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
FILE_TYPE_ZIPPED_ASCII
@ FILE_TYPE_ZIPPED_ASCII
Definition: xml_io.h:40
agenda_class.h
Declarations for agendas.
xml_read_from_file
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Definition: xml_io.cc:850
_U_
#define _U_
Definition: config.h:158
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
output_file_formatSetZippedAscii
void output_file_formatSetZippedAscii(String &file_format, const Verbosity &)
WORKSPACE METHOD: output_file_formatSetZippedAscii.
Definition: m_xml.h:178
Verbosity
Definition: messages.h:50
output_file_formatSetAscii
void output_file_formatSetAscii(String &file_format, const Verbosity &)
WORKSPACE METHOD: output_file_formatSetAscii.
Definition: m_xml.h:168
FileType
FileType
Definition: xml_io.h:38
workspace_ng.h
This file contains the declaration and partly the implementation of the workspace class.
Workspace
Workspace class.
Definition: workspace_ng.h:47
FILE_TYPE_ASCII
@ FILE_TYPE_ASCII
Definition: xml_io.h:39
xml_write_to_file
void xml_write_to_file(const String &filename, const T &type, const FileType ftype, const Verbosity &verbosity)
Write data to XML file.
Definition: xml_io.cc:1017
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
filename_xml
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Definition: xml_io.cc:364
xml_io.h
This file contains basic functions to handle XML data files.