ARTS  2.3.1285(git:92a29ea9-dirty)
xml_io.cc File Reference

This file contains basic functions to handle XML data files. More...

#include "xml_io.h"
#include "arts.h"
#include "bifstream.h"
#include "bofstream.h"
#include "file.h"
#include "parameters.h"
#include "xml_io_private.h"
#include "xml_io_types.h"
#include "xml_io_instantiation.h"

Go to the source code of this file.

Functions

void filename_xml (String &filename, const String &varname)
 Gives the default filename for the XML formats. More...
 
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. More...
 
void xml_open_output_file (ofstream &file, const String &name)
 Open file for XML output. More...
 
void xml_open_input_file (ifstream &ifs, const String &name, const Verbosity &verbosity)
 Open file for XML input. More...
 
void xml_find_and_open_input_file (std::shared_ptr< istream > &ifs, const String &filename, const Verbosity &verbosity)
 Open plain or zipped xml file. More...
 
void xml_parse_error (const String &str_error)
 Throws XML parser runtime error. More...
 
void xml_data_parse_error (ArtsXMLTag &tag, String str_error)
 Throws XML parser runtime error. More...
 
void xml_read_header_from_stream (istream &is, FileType &ftype, NumericType &ntype, EndianType &etype, const Verbosity &verbosity)
 Reads XML header and root tag. More...
 
void xml_read_footer_from_stream (istream &is, const Verbosity &verbosity)
 Reads closing root tag. More...
 
void xml_write_header_to_stream (ostream &os, FileType ftype, const Verbosity &verbosity)
 Writes XML header and root tag. More...
 
void xml_write_footer_to_stream (ostream &os, const Verbosity &verbosity)
 Write closing root tag. More...
 
void xml_set_stream_precision (ostream &os)
 
void parse_xml_tag_content_as_string (std::istream &is_xml, String &content)
 Get the content of an xml tag as a string. More...
 
template<typename T >
void xml_read_from_file (const String &filename, T &type, const Verbosity &verbosity)
 Reads data from XML file. More...
 
template<typename T >
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. More...
 

Detailed Description

This file contains basic functions to handle XML data files.

Author
Oliver Lemke olemk.nosp@m.e@co.nosp@m.re-du.nosp@m.mp.i.nosp@m.nfo
Date
2002-05-10

Definition in file xml_io.cc.

Function Documentation

◆ filename_xml()

void filename_xml ( String filename,
const String varname 
)

Gives the default filename for the XML formats.

The default name is only used if the filename is empty.

Parameters
filenamefilename
varnamevariable name

Definition at line 434 of file xml_io.cc.

References out_basename.

Referenced by ReadXML(), and WriteXML().

◆ filename_xml_with_index()

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.

The default name is only used if the filename is empty.

Parameters
[out]filenamefilename
[in]file_indexIndex appended to the filename
[in]varnamevariable name
[in]digitsWidth for padding with zeros

Definition at line 450 of file xml_io.cc.

References out_basename, and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().

Referenced by ppathWriteXMLPartial(), ReadXMLIndexed(), and WriteXMLIndexed().

◆ parse_xml_tag_content_as_string()

void parse_xml_tag_content_as_string ( std::istream &  is_xml,
String content 
)

Get the content of an xml tag as a string.

Definition at line 874 of file xml_io.cc.

Referenced by xml_read_from_stream().

◆ xml_data_parse_error()

void xml_data_parse_error ( ArtsXMLTag tag,
String  str_error 
)

Throws XML parser runtime error.

This is used quite often inside the data parsing routines so it's a function for itself.

Parameters
tagArtsXMLTag
str_errorError description

Definition at line 705 of file xml_io.cc.

References _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str(), and ArtsXMLTag::write_to_stream().

Referenced by xml_parse_from_stream(), and xml_read_from_stream().

◆ xml_find_and_open_input_file()

void xml_find_and_open_input_file ( std::shared_ptr< istream > &  ifs,
const String filename,
const Verbosity verbosity 
)

Open plain or zipped xml file.

Searches the include and data paths for the given filename.

Parameters
[out]ifsPointer to input file stream
[in]filenameInput filename
[in]verbosityVerbosity

Definition at line 648 of file xml_io.cc.

References CREATE_OUT2, find_xml_file(), and xml_open_input_file().

Referenced by ReadArrayOfARTSCAT(), and ReadARTSCAT().

◆ xml_open_input_file()

void xml_open_input_file ( ifstream &  ifs,
const String name,
const Verbosity verbosity 
)

Open file for XML input.

This function opens an XML file for reading.

Parameters
ifsInput filestream
nameFilename

Definition at line 569 of file xml_io.cc.

References CREATE_OUT3, igzstream::open(), _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str(), ArtsXMLTag::verbosity, and xml_open_input_file().

Referenced by xml_find_and_open_input_file(), xml_open_input_file(), and xml_read_from_file().

◆ xml_open_output_file()

void xml_open_output_file ( ofstream &  file,
const String name 
)

Open file for XML output.

This function opens an XML file for writing.

Parameters
fileOutput filestream
nameFilename

Definition at line 479 of file xml_io.cc.

References ArtsXMLTag::name, my_basic_string< charT >::nelem(), ogzstream::open(), and _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().

Referenced by xml_write_to_file().

◆ xml_parse_error()

void xml_parse_error ( const String str_error)

Throws XML parser runtime error.

This is used quite often inside the parsing routines so it's a function for itself.

Parameters
str_errorError description

Definition at line 690 of file xml_io.cc.

References _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str().

Referenced by ArtsXMLTag::check_attribute(), ArtsXMLTag::check_name(), ArtsXMLTag::get_attribute_value(), ArtsXMLTag::read_from_stream(), xml_read_from_stream(), and xml_read_header_from_stream().

◆ xml_read_footer_from_stream()

void xml_read_footer_from_stream ( istream &  is,
const Verbosity verbosity 
)

Reads closing root tag.

Checks whether XML file ends correctly with </arts>.

Parameters
isInput stream

Definition at line 806 of file xml_io.cc.

References ArtsXMLTag::check_name(), and ArtsXMLTag::read_from_stream().

Referenced by xml_read_from_file().

◆ xml_read_from_file()

template<typename T >
void xml_read_from_file ( const String filename,
T &  type,
const Verbosity verbosity 
)

◆ xml_read_header_from_stream()

void xml_read_header_from_stream ( istream &  is,
FileType ftype,
NumericType ntype,
EndianType etype,
const Verbosity verbosity 
)

Reads XML header and root tag.

Check whether XML file has correct version tag and reads arts root tag information.

Parameters
isInput stream
ftypeFile type
ntypeNumeric type
etypeEndian type

Definition at line 725 of file xml_io.cc.

References ArtsXMLTag::check_name(), ENDIAN_TYPE_BIG, ENDIAN_TYPE_LITTLE, FILE_TYPE_ASCII, FILE_TYPE_BINARY, ArtsXMLTag::get_attribute_value(), NUMERIC_TYPE_DOUBLE, NUMERIC_TYPE_FLOAT, ArtsXMLTag::read_from_stream(), _CS_basic_sstream_base< _CS_cT, _CS_Tr, _CS_Al >::str(), and xml_parse_error().

Referenced by xml_read_from_file().

◆ xml_set_stream_precision()

void xml_set_stream_precision ( ostream &  os)

Definition at line 856 of file xml_io.cc.

References precision.

Referenced by xml_write_to_stream().

◆ xml_write_footer_to_stream()

void xml_write_footer_to_stream ( ostream &  os,
const Verbosity verbosity 
)

Write closing root tag.

Parameters
osOutput stream

Definition at line 847 of file xml_io.cc.

References ArtsXMLTag::set_name(), and ArtsXMLTag::write_to_stream().

Referenced by xml_write_to_file().

◆ xml_write_header_to_stream()

void xml_write_header_to_stream ( ostream &  os,
FileType  ftype,
const Verbosity verbosity 
)

Writes XML header and root tag.

Parameters
osOutput stream
ftypeFile type

Definition at line 818 of file xml_io.cc.

References ArtsXMLTag::add_attribute(), FILE_TYPE_ASCII, FILE_TYPE_BINARY, FILE_TYPE_ZIPPED_ASCII, ArtsXMLTag::set_name(), and ArtsXMLTag::write_to_stream().

Referenced by xml_write_to_file().

◆ xml_write_to_file()

template<typename T >
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.

This is a generic functions that is used to write the XML header and footer info and calls the overloaded functions to write the data.

Parameters
filenameXML filename
typeGeneric input value
no_clobber0: Overwrite, 1: Use unique filename
ftypeFile type

Definition at line 972 of file xml_io.cc.

References add_basedir(), CREATE_OUT2, FILE_TYPE_ASCII, FILE_TYPE_ZIPPED_ASCII, make_filename_unique(), xml_open_output_file(), xml_write_footer_to_stream(), xml_write_header_to_stream(), and xml_write_to_stream().

Referenced by DoitWriteIterationFields(), main(), test_xml_io(), WriteXML(), and ybatchMetProfilesClear().