Go to the documentation of this file.
58 if (
name != expected_name)
116 if (actual_value ==
"*not found*")
119 +
" does not exist");
121 else if (actual_value != value)
124 + actual_value +
"\" but \""
125 + value +
"\" was expected.");
147 if (it->name == aname)
173 istringstream strstr (
"");
176 strstr.str (attribute_value);
181 +
" from <" +
name +
">");
200 istringstream sstr (
"");
206 while (is.good () && isspace (is.peek ()))
224 if (is.bad () || is.eof ())
229 if (is.get () !=
'>')
234 sstr.str (tag.str () +
'>');
235 out3 <<
"Read: " << sstr.str () <<
'\n';
239 if (
name [
name.length () - 1] ==
'>')
251 out3 <<
"Name: " <<
name <<
'\n';
258 pos = token.find (
"=", 0);
264 attr.
name = token.substr (0, pos);
265 token.erase (0, pos + 1);
267 if (token[0] !=
'\"')
276 if (!ntoken.length())
break;
277 token +=
" " + ntoken;
288 attr.
value = token.substr (1, pos - 1);
292 out3 <<
"Attr: " << attr.
name <<
'\n';
293 out3 <<
"Value: " << attr.
value <<
'\n';
295 if (token[token.length () - 1] ==
'>')
308 if (
name ==
"comment")
313 if (is.bad () || is.eof ())
342 os <<
' ' << it->name
343 <<
"=\"" << it->value <<
'\"';
387 const Index& file_index,
394 os <<
out_basename <<
"." << varname <<
"." << file_index <<
".xml";
400 os << filename <<
"." << file_index <<
".xml";
426 file.exceptions(ios::badbit |
431 file.open (name.c_str());
432 }
catch (ios::failure) {
434 os <<
"Cannot open output file: " << name <<
'\n'
435 <<
"Maybe you don't have write access "
436 <<
"to the directory or the file?";
437 throw runtime_error(os.str());
449 os <<
"Cannot open output file: " << name <<
'\n'
450 <<
"Maybe you don't have write access "
451 <<
"to the directory or the file?";
452 throw runtime_error(os.str());
473 file.exceptions(ios::badbit |
479 if (nname.substr (nname.length()-3, 3) !=
".gz")
485 file.
open (nname.c_str());
486 }
catch (ios::failure) {
488 os <<
"Cannot open output file: " << nname <<
'\n'
489 <<
"Maybe you don't have write access "
490 <<
"to the directory or the file?";
491 throw runtime_error(os.str());
503 os <<
"Cannot open output file: " << nname <<
'\n'
504 <<
"Maybe you don't have write access "
505 <<
"to the directory or the file?";
506 throw runtime_error(os.str());
528 ifs.exceptions (ios::badbit);
533 ifs.open (name.c_str ());
538 os <<
"Cannot open input file: " << name <<
'\n'
539 <<
"Maybe the file does not exist?";
540 throw runtime_error (os.str ());
549 os <<
"Cannot open input file: " << name <<
'\n'
550 <<
"Maybe the file does not exist?";
551 throw runtime_error (os.str ());
554 out3 <<
"- Reading input file " << name <<
"\n";
576 ifs.exceptions (ios::badbit);
581 ifs.
open (name.c_str ());
586 os <<
"Cannot open input file: " << name <<
'\n'
587 <<
"Maybe the file does not exist?";
588 throw runtime_error (os.str ());
597 os <<
"Cannot open input file: " << name <<
'\n'
598 <<
"Maybe the file does not exist?";
599 throw runtime_error (os.str ());
602 out3 <<
"- Reading input file " << name <<
"\n";
623 os <<
"XML parse error: " << str_error <<
'\n'
624 <<
"Check syntax of XML file\n";
625 throw runtime_error (os.str ());
641 os <<
"XML data parse error: Error reading ";
643 os << str_error <<
"\n"
644 <<
"Check syntax of XML file. A possible cause is that the file "
645 <<
"contains NaN or Inf values.\n";
646 throw runtime_error (os.str ());
669 while (!is.fail () && isspace (is.peek())) is.get();
671 is.get (str, 6,
' ');
673 if (
string(str) !=
"<?xml")
676 "(<?xml not found)");
679 is.get (strbuf,
'>');
692 if (strtype ==
"binary")
703 if (strtype ==
"little")
707 if (strtype ==
"big")
720 os <<
" Error: Unknown endian type \"" << strtype
721 <<
"\" specified in XML file.\n";
722 throw runtime_error(os.str());
727 if (strtype ==
"float")
731 else if (strtype ==
"double")
735 else if (strtype ==
"")
744 os <<
" Error: Unknown numeric type \"" << strtype
745 <<
"\" specified in XML file.\n";
746 throw runtime_error(os.str());
778 os <<
"<?xml version=\"1.0\"?>"
829 #error Numeric must be double or float
849 template<
typename T>
void
860 out2 <<
" Reading " << efilename <<
'\n';
862 String xml_file = efilename;
865 found_file =
find_file (xml_file,
".xml");
866 if (!found_file) found_file =
find_file (xml_file,
".xml.gz");
867 if (!found_file) found_file =
find_file (xml_file,
".gz");
870 if (xml_file.substr (xml_file.length () - 3, 3) ==
".gz")
878 throw runtime_error (
879 "This arts version was compiled without zlib support.\n"
880 "Thus zipped xml files cannot be read.");
885 ifs =
new ifstream();
908 String bfilename = efilename +
".bin";
914 catch (runtime_error e)
918 os <<
"Error reading file: " << efilename <<
'\n'
920 throw runtime_error (os.str ());
940 out2 <<
" Reading " << efilename <<
'\n';
942 String xml_file = efilename;
945 found_file =
find_file (xml_file,
".xml");
946 if (!found_file) found_file =
find_file (xml_file,
".xml.gz");
947 if (!found_file)
find_file (xml_file,
".gz");
950 if (xml_file.substr (xml_file.length () - 3, 3) ==
".gz")
958 throw runtime_error (
959 "This arts version was compiled without zlib support.\n"
960 "Thus zipped xml files cannot be read.");
965 ifs =
new ifstream();
988 String bfilename = efilename +
".bin";
994 catch (runtime_error e)
998 os <<
"Error reading file: " << efilename <<
'\n'
1000 throw runtime_error (os.str ());
1016 template<
typename T>
void
1028 out2 <<
" Writing " << efilename <<
'\n';
1037 throw runtime_error (
1038 "This arts version was compiled without zlib support.\n"
1039 "Thus zipped xml files cannot be written.");
1044 ofs =
new ofstream();
1058 String bfilename = efilename +
".bin";
1065 catch (runtime_error e)
1069 os <<
"Error writing file: " << efilename <<
'\n'
1071 throw runtime_error (os.str ());
void check_name(const String &expected_name)
Check tag name.
void xml_write_to_stream(ostream &os_xml, const Array< SpeciesRecord > &asrecord, bofstream *pbofs, const String &name, const Verbosity &verbosity)
Writes SpeciesData to XML output stream.
void xml_write_header_to_stream(ostream &os, FileType ftype, const Verbosity &verbosity)
Writes XML header and root tag.
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.
void get_attribute_value(const String &aname, String &value)
Returns value of attribute as String.
void xml_open_input_file(ifstream &ifs, const String &name, const Verbosity &verbosity)
Open file for XML input.
void xml_set_stream_precision(ostream &os)
void check_attribute(const String &aname, const String &value)
Checks whether attribute has the expected value.
void write_to_stream(ostream &os)
Write XML tag.
bool find_file(String &filename, const char *extension)
Find the given file.
This can be used to make arrays out of anything.
This file contains private function declarations and template instantiation to handle XML data files.
Array< XMLAttribute > attribs
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
void open(const char *name, int gz_open_mode=std::ios::out)
void read_from_stream(istream &is)
Reads next XML tag.
This file contains template instantiations to handle XML data files.
void xml_open_output_file(ofstream &file, const String &name)
Open file for XML output.
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.
This file contains private function declarations and template instantiation to handle XML data files.
NUMERIC Numeric
The type to use for all floating point numbers.
void add_attribute(const String &aname, const String &value)
Adds a String attribute to tag.
Binary output file stream class.
void xml_read_arts_catalogue_from_file(const String &filename, ArrayOfLineRecord &type, const Numeric &fmin, const Numeric &fmax, const Verbosity &verbosity)
This file contains the class declaration of bifstream.
This file contains the class declaration of bofstream.
String out_basename
The basename for the report file and for all other output files.
void open(const char *name, int gz_open_mode=std::ios::in)
String expand_path(const String &path)
void xml_data_parse_error(ArtsXMLTag &tag, String str_error)
Throws XML parser runtime error.
void xml_write_footer_to_stream(ostream &os, const Verbosity &verbosity)
Write closing root tag.
void xml_read_from_stream(istream &is_xml, Array< SpeciesRecord > &asrecord, bifstream *pbifs, const Verbosity &verbosity)
Reads SpeciesData from XML input stream.
This file contains basic functions to handle ASCII files.
void xml_write_to_file(const String &filename, const T &type, const FileType ftype, const Verbosity &verbosity)
Write data to XML file.
INDEX Index
The type to use for all integer numbers and indices.
static const Index npos
Define npos:
void set_name(const String &new_name)
void xml_read_footer_from_stream(istream &is, const Verbosity &verbosity)
Reads closing root tag.
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
The global header file for ARTS.
This file contains basic functions to handle XML data files.
Binary output file stream class.
void xml_read_header_from_stream(istream &is, FileType &ftype, NumericType &ntype, EndianType &etype, const Verbosity &verbosity)
Reads XML header and root tag.