Go to the documentation of this file.
55 if (
name != expected_name)
100 for(
size_t i=0; i<value.size()-1; i++)
112 v << LineShape::self_broadening;
114 v <<
' ' << value[i].SpeciesNameMain();
116 v <<
' ' << LineShape::bath_broadening;
136 if (actual_value ==
"*not found*") {
138 }
else if (actual_value != value) {
139 xml_parse_error(
"Attribute " + aname +
" has value \"" + actual_value +
140 "\" but \"" + value +
"\" was expected.");
158 if (it->name == aname) {
178 istringstream strstr(
"");
181 strstr.str(attribute_value);
191 istringstream strstr(
"");
194 strstr.str(attribute_value);
215 istringstream strstr(
"");
218 if (attribute_value.
nelem() == 0)
return;
220 strstr.str(attribute_value);
223 while(not strstr.eof()) {
230 if(val == LineShape::self_broadening) {
234 else if(val == LineShape::bath_broadening) {
247 istringstream strstr(
"");
250 if (attribute_value.
nelem() == 0)
return;
252 strstr.str(attribute_value);
255 while(not strstr.eof()) {
267 istringstream strstr(
"");
271 strstr.str(attribute_value);
294 istringstream sstr(
"");
300 while (is.good() && isspace(is.peek())) {
316 if (is.bad() || is.eof()) {
320 if (is.get() !=
'>') {
324 sstr.str(tag.str() +
'>');
325 out3 <<
"Read: " << sstr.str() <<
'\n';
329 if (
name[
name.length() - 1] ==
'>') {
338 out3 <<
"Name: " <<
name <<
'\n';
341 while (token !=
">") {
344 pos = token.find(
"=", 0);
349 attr.
name = token.substr(0, pos);
350 token.erase(0, pos + 1);
352 if (token[0] !=
'\"') {
360 if (!ntoken.length())
break;
361 token +=
" " + ntoken;
371 attr.
value = token.substr(1, pos - 1);
375 out3 <<
"Attr: " << attr.
name <<
'\n';
376 out3 <<
"Value: " << attr.
value <<
'\n';
378 if (token[token.length() - 1] ==
'>') {
388 if (
name ==
"comment") {
392 if (is.bad() || is.eof()) {
394 "Unexpected end of file while looking for "
416 os <<
' ' << it->name <<
"=\"" << it->value <<
'\"';
435 if (
"" == filename) {
453 const Index& digits) {
454 if (
"" == filename) {
457 os <<
out_basename <<
"." << varname <<
"." << std::setw((
int)digits)
462 os << filename <<
"." << std::setw((
int)digits) << std::setfill(
'0')
485 file.exceptions(ios::badbit | ios::failbit);
489 file.open(name.c_str());
490 }
catch (
const std::exception&) {
492 os <<
"Cannot open output file: " << name <<
'\n'
493 <<
"Maybe you don't have write access "
494 <<
"to the directory or the file?";
495 throw runtime_error(os.str());
505 os <<
"Cannot open output file: " << name <<
'\n'
506 <<
"Maybe you don't have write access "
507 <<
"to the directory or the file?";
508 throw runtime_error(os.str());
527 file.exceptions(ios::badbit | ios::failbit);
532 if (nname.
nelem() < 3 || nname.substr(nname.length() - 3, 3) !=
".gz") {
537 file.
open(nname.c_str());
538 }
catch (
const ios::failure&) {
540 os <<
"Cannot open output file: " << nname <<
'\n'
541 <<
"Maybe you don't have write access "
542 <<
"to the directory or the file?";
543 throw runtime_error(os.str());
553 os <<
"Cannot open output file: " << nname <<
'\n'
554 <<
"Maybe you don't have write access "
555 <<
"to the directory or the file?";
556 throw runtime_error(os.str());
578 ifs.exceptions(ios::badbit);
582 ifs.open(name.c_str());
583 }
catch (
const ios::failure&) {
585 os <<
"Cannot open input file: " << name <<
'\n'
586 <<
"Maybe the file does not exist?";
587 throw runtime_error(os.str());
595 os <<
"Cannot open input file: " << name <<
'\n'
596 <<
"Maybe the file does not exist?";
597 throw runtime_error(os.str());
600 out3 <<
"- Reading input file " << name <<
"\n";
621 ifs.exceptions(ios::badbit);
625 ifs.
open(name.c_str());
626 }
catch (
const ios::failure&) {
628 os <<
"Cannot open input file: " << name <<
'\n'
629 <<
"Maybe the file does not exist?";
630 throw runtime_error(os.str());
638 os <<
"Cannot open input file: " << name <<
'\n'
639 <<
"Maybe the file does not exist?";
640 throw runtime_error(os.str());
643 out3 <<
"- Reading input file " << name <<
"\n";
653 String xml_file = filename;
655 out2 <<
" Reading " << xml_file <<
'\n';
658 if (xml_file.substr(xml_file.length() - 3, 3) ==
".gz")
661 ifs = std::shared_ptr<istream>(
new igzstream());
663 *(std::static_pointer_cast<igzstream>(ifs)), xml_file,
verbosity);
668 "This arts version was compiled without zlib support.\n"
669 "Thus zipped xml files cannot be read.");
673 ifs = shared_ptr<istream>(
new ifstream());
675 *(std::static_pointer_cast<ifstream>(ifs)), xml_file,
verbosity);
692 os <<
"XML parse error: " << str_error <<
'\n'
693 <<
"Check syntax of XML file\n";
694 throw runtime_error(os.str());
707 os <<
"XML data parse error: Error reading ";
709 os << str_error <<
"\n"
710 <<
"Check syntax of XML file. A possible cause is that the file "
711 <<
"contains NaN or Inf values.\n";
712 throw runtime_error(os.str());
735 while (!is.fail() && isspace(is.peek())) is.get();
739 if (
string(str) !=
"<?xml") {
741 "Input file is not a valid xml file "
742 "(<?xml not found)");
757 if (strtype ==
"binary") {
765 if (strtype ==
"little") {
768 if (strtype ==
"big") {
777 os <<
" Error: Unknown endian type \"" << strtype
778 <<
"\" specified in XML file.\n";
779 throw runtime_error(os.str());
784 if (strtype ==
"float") {
786 }
else if (strtype ==
"double") {
788 }
else if (strtype ==
"") {
794 os <<
" Error: Unknown numeric type \"" << strtype
795 <<
"\" specified in XML file.\n";
796 throw runtime_error(os.str());
823 os <<
"<?xml version=\"1.0\"?>" <<
'\n';
866 #error Numeric must be double or float
878 dummy = (char)is_xml.peek();
879 while (is_xml && dummy !=
'<') {
882 dummy = (char)is_xml.peek();
885 if (!is_xml)
throw std::runtime_error(
"Unexpected end of file.");
900 template <
typename T>
906 String xml_file = filename;
908 out2 <<
" Reading " + xml_file +
'\n';
912 if (xml_file.nelem() > 2 &&
913 xml_file.substr(xml_file.length() - 3, 3) ==
".gz")
922 "This arts version was compiled without zlib support.\n"
923 "Thus zipped xml files cannot be read.");
927 ifs =
new ifstream();
946 String bfilename = xml_file +
".bin";
951 }
catch (
const std::runtime_error& e) {
954 os <<
"Error reading file: " << xml_file <<
'\n' << e.what();
955 throw runtime_error(os.str());
971 template <
typename T>
975 const Index no_clobber,
985 out2 <<
" Writing " << efilename <<
'\n';
995 "This arts version was compiled without zlib support.\n"
996 "Thus zipped xml files cannot be written.");
1000 ofs =
new ofstream();
1009 String bfilename = efilename +
".bin";
1015 }
catch (
const std::runtime_error& e) {
1018 os <<
"Error writing file: " << efilename <<
'\n' << e.what();
1019 throw runtime_error(os.str());
Container class for Quantum Numbers.
void check_name(const String &expected_name)
Check tag name.
String out_basename
The basename for the report file and for all other output files.
Verbosity verbosity(Workspace &ws) noexcept
void xml_write_header_to_stream(ostream &os, FileType ftype, const Verbosity &verbosity)
Writes XML header and root tag.
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)
QuantumNumberType string2quantumnumbertype(const String &s)
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.
void parse_xml_tag_content_as_string(std::istream &is_xml, String &content)
Get the content of an xml tag as a string.
This file contains private function declarations and template instantiation to handle XML data files.
A tag group can consist of the sum of several of these.
void xml_read_from_stream(istream &is_xml, ArrayOfAgenda &aa, bifstream *pbifs, const Verbosity &)
Reads ArrayOfAgenda from XML input stream.
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.
String quantumnumbertype2string(QuantumNumberType s)
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.
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
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 make_filename_unique(String &filename, const String &extension)
Make filename unique.
This file contains the class declaration of bifstream.
This file contains the class declaration of bofstream.
This file contains header information for the dealing with command line parameters.
Index nelem() const
Number of elements.
void open(const char *name, int gz_open_mode=std::ios::in)
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.
void xml_write_to_stream(ostream &os_xml, const ArrayOfAgenda &aa, bofstream *pbofs, const String &name, const Verbosity &)
Writes ArrayOfAgenda to XML output stream.
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.
String add_basedir(const String &path)
This file contains basic functions to handle ASCII files.
Index file_index(Workspace &ws) noexcept
INDEX Index
The type to use for all integer numbers and indices.
static const Index npos
Define npos:
void Set(Index qn, Rational r)
Set quantum number at position.
void set_name(const String &new_name)
void xml_find_and_open_input_file(std::shared_ptr< istream > &ifs, const String &filename, const Verbosity &verbosity)
Open plain or zipped xml file.
void xml_read_footer_from_stream(istream &is, const Verbosity &verbosity)
Reads closing root tag.
Index nelem() const
Number of elements.
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Implements rational numbers to work with other ARTS types.
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 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.