58 if (
name != expected_name)
109 if (actual_value ==
"*not found*")
113 else if (actual_value != value)
116 + actual_value +
"\" but \"" 117 + value +
"\" was expected.");
138 if (it->name == aname)
163 istringstream strstr(
"");
166 strstr.str(attribute_value);
171 +
" from <" +
name +
">");
189 istringstream sstr(
"");
195 while (is.good() && isspace(is.peek()))
213 if (is.bad() || is.eof())
223 sstr.str(tag.str() +
'>');
224 out3 <<
"Read: " << sstr.str() <<
'\n';
228 if (name[name.length() - 1] ==
'>')
232 name.erase(name.length() - 1, 1);
240 out3 <<
"Name: " << name <<
'\n';
247 pos = token.find(
"=", 0);
253 attr.
name = token.substr(0, pos);
254 token.erase(0, pos + 1);
256 if (token[0] !=
'\"')
265 if (!ntoken.length())
break;
266 token +=
" " + ntoken;
277 attr.
value = token.substr(1, pos - 1);
281 out3 <<
"Attr: " << attr.
name <<
'\n';
282 out3 <<
"Value: " << attr.
value <<
'\n';
284 if (token[token.length() - 1] ==
'>')
297 if (name ==
"comment")
302 if (is.bad() || is.eof())
329 os <<
' ' << it->name
330 <<
"=\"" << it->value <<
'\"';
356 filename = out_basename +
"." + varname +
".xml";
371 const Index& file_index,
378 os << out_basename <<
"." << varname <<
"." << file_index <<
".xml";
384 os << filename <<
"." << file_index <<
".xml";
409 file.exceptions(ios::badbit |
415 file.open(name.c_str());
417 catch (std::exception)
420 os <<
"Cannot open output file: " << name <<
'\n' 421 <<
"Maybe you don't have write access " 422 <<
"to the directory or the file?";
423 throw runtime_error(os.str());
435 os <<
"Cannot open output file: " << name <<
'\n' 436 <<
"Maybe you don't have write access " 437 <<
"to the directory or the file?";
438 throw runtime_error(os.str());
458 file.exceptions(ios::badbit |
464 if (nname.
nelem() < 3 || nname.substr(nname.length()-3, 3) !=
".gz")
471 file.
open(nname.c_str());
476 os <<
"Cannot open output file: " << nname <<
'\n' 477 <<
"Maybe you don't have write access " 478 <<
"to the directory or the file?";
479 throw runtime_error(os.str());
491 os <<
"Cannot open output file: " << nname <<
'\n' 492 <<
"Maybe you don't have write access " 493 <<
"to the directory or the file?";
494 throw runtime_error(os.str());
515 ifs.exceptions(ios::badbit);
520 ifs.open(name.c_str());
525 os <<
"Cannot open input file: " << name <<
'\n' 526 <<
"Maybe the file does not exist?";
527 throw runtime_error(os.str());
536 os <<
"Cannot open input file: " << name <<
'\n' 537 <<
"Maybe the file does not exist?";
538 throw runtime_error(os.str());
541 out3 <<
"- Reading input file " << name <<
"\n";
562 ifs.exceptions(ios::badbit);
567 ifs.
open(name.c_str());
572 os <<
"Cannot open input file: " << name <<
'\n' 573 <<
"Maybe the file does not exist?";
574 throw runtime_error(os.str());
583 os <<
"Cannot open input file: " << name <<
'\n' 584 <<
"Maybe the file does not exist?";
585 throw runtime_error(os.str());
588 out3 <<
"- Reading input file " << name <<
"\n";
608 os <<
"XML parse error: " << str_error <<
'\n' 609 <<
"Check syntax of XML file\n";
610 throw runtime_error(os.str());
625 os <<
"XML data parse error: Error reading ";
627 os << str_error <<
"\n" 628 <<
"Check syntax of XML file. A possible cause is that the file " 629 <<
"contains NaN or Inf values.\n";
630 throw runtime_error(os.str());
652 while (!is.fail() && isspace(is.peek()))
657 if (
string(str) !=
"<?xml")
660 "(<?xml not found)");
676 if (strtype ==
"binary")
687 if (strtype ==
"little")
691 if (strtype ==
"big")
704 os <<
" Error: Unknown endian type \"" << strtype
705 <<
"\" specified in XML file.\n";
706 throw runtime_error(os.str());
711 if (strtype ==
"float")
715 else if (strtype ==
"double")
719 else if (strtype ==
"")
728 os <<
" Error: Unknown numeric type \"" << strtype
729 <<
"\" specified in XML file.\n";
730 throw runtime_error(os.str());
760 os <<
"<?xml version=\"1.0\"?>" 810 #error Numeric must be double or float 814 os << setprecision(precision);
837 String xml_file = filename;
839 out2 <<
" Reading " << xml_file <<
'\n';
843 if (xml_file.nelem() > 2 && xml_file.substr(xml_file.length() - 3, 3) ==
".gz")
852 "This arts version was compiled without zlib support.\n" 853 "Thus zipped xml files cannot be read.");
858 ifs =
new ifstream();
881 String bfilename = xml_file +
".bin";
887 catch (runtime_error e)
891 os <<
"Error reading file: " << xml_file <<
'\n' 893 throw runtime_error(os.str());
908 String xml_file = filename;
910 out2 <<
" Reading " << xml_file <<
'\n';
914 if (xml_file.substr(xml_file.length() - 3, 3) ==
".gz")
923 "This arts version was compiled without zlib support.\n" 924 "Thus zipped xml files cannot be read.");
929 ifs =
new ifstream();
952 String bfilename = xml_file +
".bin";
958 catch (runtime_error e)
962 os <<
"Error reading file: " << xml_file <<
'\n' 964 throw runtime_error(os.str());
985 const Index no_clobber,
997 out2 <<
" Writing " << efilename <<
'\n';
1006 throw runtime_error(
1007 "This arts version was compiled without zlib support.\n" 1008 "Thus zipped xml files cannot be written.");
1013 ofs =
new ofstream();
1027 String bfilename = efilename +
".bin";
1034 catch (runtime_error e)
1038 os <<
"Error writing file: " << efilename <<
'\n' 1040 throw runtime_error(os.str());
INDEX Index
The type to use for all integer numbers and indices.
void add_attribute(const String &aname, const String &value)
Adds a String attribute to tag.
void xml_write_header_to_stream(ostream &os, FileType ftype, const Verbosity &verbosity)
Writes XML header and root tag.
This file contains template instantiations to handle XML data files.
void xml_read_footer_from_stream(istream &is, const Verbosity &verbosity)
Reads closing root tag.
void read_from_stream(istream &is)
Reads next XML tag.
void xml_read_header_from_stream(istream &is, FileType &ftype, NumericType &ntype, EndianType &etype, const Verbosity &verbosity)
Reads XML header and root tag.
void open(const char *name, int gz_open_mode=std::ios::in)
This file contains private function declarations and template instantiation to handle XML data files...
This file contains basic functions to handle XML data files.
This file contains basic functions to handle ASCII files.
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
void xml_open_output_file(ofstream &file, const String &name)
Open file for XML output.
String out_basename
The basename for the report file and for all other output files.
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.
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.
const Verbosity & verbosity
The global header file for ARTS.
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 xml_read_arts_catalogue_from_file(const String &filename, ArrayOfLineRecord &type, const Numeric &fmin, const Numeric &fmax, const Verbosity &verbosity)
void xml_read_from_stream(istream &is_xml, Array< SpeciesRecord > &asrecord, bifstream *pbifs, const Verbosity &verbosity)
Reads SpeciesData from XML input stream.
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 set_name(const String &new_name)
Binary output file stream class.
This file contains the class declaration of bifstream.
This file contains the class declaration of bofstream.
void xml_read_from_file(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
NUMERIC Numeric
The type to use for all floating point numbers.
void get_attribute_value(const String &aname, String &value)
Returns value of attribute as String.
Index nelem() const
Number of elements.
void xml_write_footer_to_stream(ostream &os, const Verbosity &verbosity)
Write closing root tag.
void check_name(const String &expected_name)
Check tag name.
This can be used to make arrays out of anything.
void open(const char *name, int gz_open_mode=std::ios::out)
void check_attribute(const String &aname, const String &value)
Checks whether attribute has the expected value.
Array< XMLAttribute > attribs
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Binary output file stream class.
String add_basedir(const String &path)
void make_filename_unique(String &filename, const String &extension)
Make filename unique.
static const Index npos
Define npos:
This file contains header information for the dealing with command line parameters.
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 file contains private function declarations and template instantiation to handle XML data files...
void xml_data_parse_error(ArtsXMLTag &tag, String str_error)
Throws XML parser runtime error.
void write_to_stream(ostream &os)
Write XML tag.