ARTS  2.2.66
xml_io.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2012 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 
18 
20 // File description
22 
31 #include "arts.h"
32 #include "xml_io.h"
33 #include "xml_io_private.h"
34 #include "xml_io_types.h"
35 #include "bofstream.h"
36 #include "bifstream.h"
37 #include "file.h"
38 #include "parameters.h"
39 
40 #ifdef ENABLE_ZLIB
41 #include "gzstream.h"
42 #endif
43 
44 
46 // ArtsXMLTag implementation
48 
50 
56 void ArtsXMLTag::check_name(const String& expected_name)
57 {
58  if (name != expected_name)
59  xml_parse_error("Tag <" + expected_name + "> expected but <" + name + "> found.");
60 }
61 
62 
64 
69 void ArtsXMLTag::add_attribute(const String& aname, const String& value)
70 {
71  XMLAttribute attr;
72 
73  attr.name = aname;
74  attr.value = value;
75  attribs.push_back(attr);
76 }
77 
78 
80 
85 void ArtsXMLTag::add_attribute(const String& aname, const Index& value)
86 {
87  ostringstream v;
88 
89  v << value;
90  add_attribute(aname, v.str());
91 }
92 
93 
95 
103 void ArtsXMLTag::check_attribute(const String& aname, const String& value)
104 {
105  String actual_value;
106 
107  get_attribute_value(aname, actual_value);
108 
109  if (actual_value == "*not found*")
110  {
111  xml_parse_error("Required attribute " + aname + " does not exist");
112  }
113  else if (actual_value != value)
114  {
115  xml_parse_error("Attribute " + aname + " has value \""
116  + actual_value + "\" but \""
117  + value + "\" was expected.");
118  }
119 }
120 
121 
123 
132 {
133  value = "";
134 
136  while (it != attribs.end())
137  {
138  if (it->name == aname)
139  {
140  value = it->value;
141  it = attribs.end();
142  }
143  else
144  {
145  it++;
146  }
147  }
148 }
149 
150 
152 
160 void ArtsXMLTag::get_attribute_value(const String& aname, Index& value)
161 {
162  String attribute_value;
163  istringstream strstr("");
164 
165  get_attribute_value(aname, attribute_value);
166  strstr.str(attribute_value);
167  strstr >> value;
168  if (strstr.fail())
169  {
170  xml_parse_error("Error while parsing value of " + aname
171  + " from <" + name + ">");
172  }
173 }
174 
175 
176 
178 
184 {
185  CREATE_OUT3;
186 
187  String token;
188  stringbuf tag;
189  istringstream sstr("");
190  XMLAttribute attr;
191  char ch = 0;
192 
193  attribs.clear();
194 
195  while (is.good() && isspace(is.peek()))
196  {
197  is.get();
198  }
199 
200  is >> ch;
201 
202  if (ch != '<')
203  {
204  is >> token;
205  token = ch + token;
206 
207  xml_parse_error("'<' expected but " + token + " found.");
208  }
209 
210  is.get(tag, '>');
211 
212  // Hit EOF while looking for '>'
213  if (is.bad() || is.eof())
214  {
215  xml_parse_error("Unexpected end of file while looking for '>'");
216  }
217 
218  if (is.get() != '>')
219  {
220  xml_parse_error("Closing > not found in tag: " + tag.str());
221  }
222 
223  sstr.str(tag.str() + '>');
224  out3 << "Read: " << sstr.str() << '\n';
225 
226  sstr >> name;
227 
228  if (name[name.length() - 1] == '>')
229  {
230  // Because closin > was found, the tag for sure has no
231  // attributes, set token to ">" to skip reading of attributes
232  name.erase(name.length() - 1, 1);
233  token = ">";
234  }
235  else
236  {
237  // Tag may have attributes, so read next token
238  sstr >> token;
239  }
240  out3 << "Name: " << name << '\n';
241 
242  //extract attributes
243  while (token != ">")
244  {
245  String::size_type pos;
246 
247  pos = token.find("=", 0);
248  if (pos == String::npos)
249  {
250  xml_parse_error("Syntax error in tag: " + tag.str());
251  }
252 
253  attr.name = token.substr(0, pos);
254  token.erase(0, pos + 1);
255 
256  if (token[0] != '\"')
257  {
258  xml_parse_error("Missing \" in tag: " + tag.str());
259  }
260 
261  while ((pos = token.find("\"", 1)) == (String::size_type)String::npos && token != ">")
262  {
263  String ntoken;
264  sstr >> ntoken;
265  if (!ntoken.length()) break;
266  token += " " + ntoken;
267  }
268 
269  if (pos == (String::size_type)String::npos)
270  {
271  xml_parse_error("Missing \" in tag: " + sstr.str());
272  }
273 
274  if (pos == 1)
275  attr.value = "";
276  else
277  attr.value = token.substr(1, pos - 1);
278 
279  attribs.push_back(attr);
280 
281  out3 << "Attr: " << attr.name << '\n';
282  out3 << "Value: " << attr.value << '\n';
283 
284  if (token[token.length() - 1] == '>')
285  {
286  token = ">";
287  }
288  else
289  {
290  sstr >> token;
291  }
292  }
293 
294  out3 << '\n';
295 
296  // Skip comments
297  if (name == "comment")
298  {
299  is.get(tag, '<');
300 
301  // Hit EOF while looking for '<'
302  if (is.bad() || is.eof())
303  {
304  xml_parse_error("Unexpected end of file while looking for "
305  "comment tag");
306  }
307 
308  read_from_stream(is);
309  check_name("/comment");
310  read_from_stream(is);
311  }
312 }
313 
314 
316 
322 {
323  os << "<" << name;
324 
326 
327  while (it != attribs.end())
328  {
329  os << ' ' << it->name
330  << "=\"" << it->value << '\"';
331  it++;
332  }
333 
334  os << ">";
335 }
336 
337 
338 
340 // Default file name
342 
344 
350 void filename_xml(String& filename,
351  const String& varname)
352 {
353  if ("" == filename)
354  {
355  extern const String out_basename;
356  filename = out_basename + "." + varname + ".xml";
357  }
358 }
359 
360 
361 
363 
371  const Index& file_index,
372  const String& varname)
373 {
374  if ("" == filename)
375  {
376  extern const String out_basename;
377  ostringstream os;
378  os << out_basename << "." << varname << "." << file_index << ".xml";
379  filename = os.str();
380  }
381  else
382  {
383  ostringstream os;
384  os << filename << "." << file_index << ".xml";
385  filename = os.str();
386  }
387 }
388 
389 
390 
392 // Functions to open and read XML files
394 
396 
402 void xml_open_output_file(ofstream& file, const String& name)
403 {
404  // Tell the stream that it should throw exceptions.
405  // Badbit means that the entire stream is corrupted, failbit means
406  // that the last operation has failed, but the stream is still
407  // valid. We don't want either to happen!
408  // FIXME: This does not yet work in egcs-2.91.66, try again later.
409  file.exceptions(ios::badbit |
410  ios::failbit);
411 
412  // c_str explicitly converts to c String.
413  try
414  {
415  file.open(name.c_str());
416  }
417  catch (std::exception)
418  {
419  ostringstream os;
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());
424  }
425 
426 
427  // See if the file is ok.
428  // FIXME: This should not be necessary anymore in the future, when
429  // g++ stream exceptions work properly. (In that case we would not
430  // get here if there really was a problem, because of the exception
431  // thrown by open().)
432  if (!file)
433  {
434  ostringstream os;
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());
439  }
440 }
441 
442 #ifdef ENABLE_ZLIB
443 
445 
451 void xml_open_output_file(ogzstream& file, const String& name)
452 {
453  // Tell the stream that it should throw exceptions.
454  // Badbit means that the entire stream is corrupted, failbit means
455  // that the last operation has failed, but the stream is still
456  // valid. We don't want either to happen!
457  // FIXME: This does not yet work in egcs-2.91.66, try again later.
458  file.exceptions(ios::badbit |
459  ios::failbit);
460 
461  // c_str explicitly converts to c String.
462  String nname = name;
463 
464  if (nname.nelem() < 3 || nname.substr(nname.length()-3, 3) != ".gz")
465  {
466  nname += ".gz";
467  }
468 
469  try
470  {
471  file.open(nname.c_str());
472  }
473  catch (ios::failure)
474  {
475  ostringstream os;
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());
480  }
481 
482 
483  // See if the file is ok.
484  // FIXME: This should not be necessary anymore in the future, when
485  // g++ stream exceptions work properly. (In that case we would not
486  // get here if there really was a problem, because of the exception
487  // thrown by open().)
488  if (!file)
489  {
490  ostringstream os;
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());
495  }
496 }
497 
498 #endif /* ENABLE_ZLIB */
499 
501 
507 void xml_open_input_file(ifstream& ifs, const String& name, const Verbosity& verbosity)
508 {
509  CREATE_OUT3;
510 
511  // Tell the stream that it should throw exceptions.
512  // Badbit means that the entire stream is corrupted.
513  // On the other hand, end of file will not lead to an exception, you
514  // have to check this manually!
515  ifs.exceptions(ios::badbit);
516 
517  // c_str explicitly converts to c String.
518  try
519  {
520  ifs.open(name.c_str());
521  }
522  catch (ios::failure)
523  {
524  ostringstream os;
525  os << "Cannot open input file: " << name << '\n'
526  << "Maybe the file does not exist?";
527  throw runtime_error(os.str());
528  }
529 
530  // See if the file is ok.
531  // FIXME: This should not be necessary anymore in the future, when
532  // g++ stream exceptions work properly.
533  if (!ifs)
534  {
535  ostringstream os;
536  os << "Cannot open input file: " << name << '\n'
537  << "Maybe the file does not exist?";
538  throw runtime_error(os.str());
539  }
540 
541  out3 << "- Reading input file " << name << "\n";
542 }
543 
544 
545 #ifdef ENABLE_ZLIB
546 
548 
554 void xml_open_input_file(igzstream& ifs, const String& name, const Verbosity& verbosity)
555 {
556  CREATE_OUT3;
557 
558  // Tell the stream that it should throw exceptions.
559  // Badbit means that the entire stream is corrupted.
560  // On the other hand, end of file will not lead to an exception, you
561  // have to check this manually!
562  ifs.exceptions(ios::badbit);
563 
564  // c_str explicitly converts to c String.
565  try
566  {
567  ifs.open(name.c_str());
568  }
569  catch (ios::failure)
570  {
571  ostringstream os;
572  os << "Cannot open input file: " << name << '\n'
573  << "Maybe the file does not exist?";
574  throw runtime_error(os.str());
575  }
576 
577  // See if the file is ok.
578  // FIXME: This should not be necessary anymore in the future, when
579  // g++ stream exceptions work properly.
580  if (!ifs)
581  {
582  ostringstream os;
583  os << "Cannot open input file: " << name << '\n'
584  << "Maybe the file does not exist?";
585  throw runtime_error(os.str());
586  }
587 
588  out3 << "- Reading input file " << name << "\n";
589 }
590 
591 #endif /* ENABLE_ZLIB */
592 
593 
595 // General XML functions (file header, start root tag, end root tag)
597 
599 
605 void xml_parse_error(const String& str_error)
606 {
607  ostringstream os;
608  os << "XML parse error: " << str_error << '\n'
609  << "Check syntax of XML file\n";
610  throw runtime_error(os.str());
611 }
612 
613 
615 
623 {
624  ostringstream os;
625  os << "XML data parse error: Error reading ";
626  tag.write_to_stream(os);
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());
631 }
632 
633 
635 
644 void xml_read_header_from_stream(istream& is, FileType& ftype, NumericType& ntype,
645  EndianType& etype, const Verbosity& verbosity)
646 {
647  char str[6];
648  stringbuf strbuf;
649  ArtsXMLTag tag(verbosity);
650  String strtype;
651 
652  while (!is.fail() && isspace(is.peek()))
653  is.get();
654 
655  is.get(str, 6, ' ');
656 
657  if (string(str) != "<?xml")
658  {
659  xml_parse_error("Input file is not a valid xml file "
660  "(<?xml not found)");
661  }
662 
663  is.get(strbuf, '>');
664  is.get();
665 
666  if (is.fail())
667  {
668  xml_parse_error("Input file is not a valid xml file");
669  }
670 
671  tag.read_from_stream(is);
672  tag.check_name("arts");
673 
674  // Check file format
675  tag.get_attribute_value("format", strtype);
676  if (strtype == "binary")
677  {
678  ftype = FILE_TYPE_BINARY;
679  }
680  else
681  {
682  ftype = FILE_TYPE_ASCII;
683  }
684 
685  // Check endian type
686  tag.get_attribute_value("endian_type", strtype);
687  if (strtype == "little")
688  {
689  etype = ENDIAN_TYPE_LITTLE;
690  }
691  if (strtype == "big")
692  {
693  etype = ENDIAN_TYPE_BIG;
694  }
695  if (strtype == "")
696  {
697  /* out1 << " Warning: Endian type not specified in XML file, "
698  << "assuming little endian (PC)\n";*/
699  etype = ENDIAN_TYPE_LITTLE;
700  }
701  else
702  {
703  ostringstream os;
704  os << " Error: Unknown endian type \"" << strtype
705  << "\" specified in XML file.\n";
706  throw runtime_error(os.str());
707  }
708 
709  // Check numeric type
710  tag.get_attribute_value("numeric_type", strtype);
711  if (strtype == "float")
712  {
713  ntype = NUMERIC_TYPE_FLOAT;
714  }
715  else if (strtype == "double")
716  {
717  ntype = NUMERIC_TYPE_DOUBLE;
718  }
719  else if (strtype == "")
720  {
721  /* out1 << " Warning: Numeric type not specified in XML file, "
722  << "assuming double\n";*/
723  ntype = NUMERIC_TYPE_DOUBLE;
724  }
725  else
726  {
727  ostringstream os;
728  os << " Error: Unknown numeric type \"" << strtype
729  << "\" specified in XML file.\n";
730  throw runtime_error(os.str());
731  }
732 
733 }
734 
735 
737 
742 void xml_read_footer_from_stream(istream& is, const Verbosity& verbosity)
743 {
744  ArtsXMLTag tag(verbosity);
745 
746  tag.read_from_stream(is);
747  tag.check_name("/arts");
748 }
749 
750 
752 
756 void xml_write_header_to_stream(ostream& os, FileType ftype, const Verbosity& verbosity)
757 {
758  ArtsXMLTag tag(verbosity);
759 
760  os << "<?xml version=\"1.0\"?>"
761  << '\n';
762 
763  tag.set_name("arts");
764  switch (ftype)
765  {
766  case FILE_TYPE_ASCII:
768  tag.add_attribute("format", "ascii");
769  break;
770  case FILE_TYPE_BINARY:
771  tag.add_attribute("format", "binary");
772  break;
773  }
774 
775  tag.add_attribute("version", "1");
776 
777  tag.write_to_stream(os);
778 
779  os << '\n';
780 
781 }
782 
783 
785 
788 void xml_write_footer_to_stream(ostream& os, const Verbosity& verbosity)
789 {
790  ArtsXMLTag tag(verbosity);
791 
792  tag.set_name("/arts");
793  tag.write_to_stream(os);
794 
795  os << endl;
796 }
797 
798 
799 void xml_set_stream_precision(ostream& os)
800 {
801  // Determine the precision, depending on whether Numeric is double
802  // or float:
803  int precision;
804 #ifdef USE_FLOAT
805  precision = FLT_DIG;
806 #else
807 #ifdef USE_DOUBLE
808  precision = DBL_DIG;
809 #else
810 #error Numeric must be double or float
811 #endif
812 #endif
813 
814  os << setprecision(precision);
815 }
816 
817 
819 // Generic IO routines for XML files
821 
823 
830 template<typename T>
831 void xml_read_from_file(const String& filename,
832  T& type,
833  const Verbosity& verbosity)
834 {
835  CREATE_OUT2;
836 
837  String xml_file = filename;
838  find_xml_file(xml_file, verbosity);
839  out2 << " Reading " << xml_file << '\n';
840 
841  // Open input stream:
842  istream* ifs;
843  if (xml_file.nelem() > 2 && xml_file.substr(xml_file.length() - 3, 3) == ".gz")
844 #ifdef ENABLE_ZLIB
845  {
846  ifs = new igzstream();
847  xml_open_input_file(*(igzstream*)ifs, xml_file, verbosity);
848  }
849 #else
850  {
851  throw runtime_error(
852  "This arts version was compiled without zlib support.\n"
853  "Thus zipped xml files cannot be read.");
854  }
855 #endif /* ENABLE_ZLIB */
856  else
857  {
858  ifs = new ifstream();
859  xml_open_input_file(*(ifstream*)ifs, xml_file, verbosity);
860  }
861 
862  // No need to check for error, because xml_open_input_file throws a
863  // runtime_error with an appropriate error message.
864 
865  // Read the matrix from the stream. Here we catch the exception,
866  // because then we can issue a nicer error message that includes the
867  // filename.
868  try
869  {
870  FileType ftype;
871  NumericType ntype;
872  EndianType etype;
873 
874  xml_read_header_from_stream(*ifs, ftype, ntype, etype, verbosity);
875  if (ftype == FILE_TYPE_ASCII)
876  {
877  xml_read_from_stream(*ifs, type, NULL, verbosity);
878  }
879  else
880  {
881  String bfilename = xml_file + ".bin";
882  bifstream bifs(bfilename.c_str());
883  xml_read_from_stream(*ifs, type, &bifs, verbosity);
884  }
885  xml_read_footer_from_stream(*ifs, verbosity);
886  }
887  catch (runtime_error e)
888  {
889  delete ifs;
890  ostringstream os;
891  os << "Error reading file: " << xml_file << '\n'
892  << e.what();
893  throw runtime_error(os.str());
894  }
895 
896  delete ifs;
897 }
898 
899 
901  ArrayOfLineRecord& type,
902  const Numeric& fmin,
903  const Numeric& fmax,
904  const Verbosity& verbosity)
905 {
906  CREATE_OUT2;
907 
908  String xml_file = filename;
909  find_xml_file(xml_file, verbosity);
910  out2 << " Reading " << xml_file << '\n';
911 
912  // Open input stream:
913  istream* ifs;
914  if (xml_file.substr(xml_file.length() - 3, 3) == ".gz")
915 #ifdef ENABLE_ZLIB
916  {
917  ifs = new igzstream();
918  xml_open_input_file(*(igzstream*)ifs, xml_file, verbosity);
919  }
920 #else
921  {
922  throw runtime_error(
923  "This arts version was compiled without zlib support.\n"
924  "Thus zipped xml files cannot be read.");
925  }
926 #endif /* ENABLE_ZLIB */
927  else
928  {
929  ifs = new ifstream();
930  xml_open_input_file(*(ifstream*)ifs, xml_file, verbosity);
931  }
932 
933  // No need to check for error, because xml_open_input_file throws a
934  // runtime_error with an appropriate error message.
935 
936  // Read the matrix from the stream. Here we catch the exception,
937  // because then we can issue a nicer error message that includes the
938  // filename.
939  try
940  {
941  FileType ftype;
942  NumericType ntype;
943  EndianType etype;
944 
945  xml_read_header_from_stream(*ifs, ftype, ntype, etype, verbosity);
946  if (ftype == FILE_TYPE_ASCII)
947  {
948  xml_read_from_stream(*ifs, type, fmin, fmax, NULL, verbosity);
949  }
950  else
951  {
952  String bfilename = xml_file + ".bin";
953  bifstream bifs(bfilename.c_str());
954  xml_read_from_stream(*ifs, type, fmin, fmax, &bifs, verbosity);
955  }
956  xml_read_footer_from_stream(*ifs, verbosity);
957  }
958  catch (runtime_error e)
959  {
960  delete ifs;
961  ostringstream os;
962  os << "Error reading file: " << xml_file << '\n'
963  << e.what();
964  throw runtime_error(os.str());
965  }
966 
967  delete ifs;
968 }
969 
970 
972 
981 template<typename T>
982 void xml_write_to_file(const String& filename,
983  const T& type,
984  const FileType ftype,
985  const Index no_clobber,
986  const Verbosity& verbosity)
987 {
988  CREATE_OUT2;
989 
990  String efilename = add_basedir(filename);
991 
992  ostream* ofs;
993 
994  if (no_clobber)
995  make_filename_unique(efilename, ".xml");
996 
997  out2 << " Writing " << efilename << '\n';
998  if (ftype == FILE_TYPE_ZIPPED_ASCII)
999 #ifdef ENABLE_ZLIB
1000  {
1001  ofs = new ogzstream();
1002  xml_open_output_file(*(ogzstream*)ofs, efilename);
1003  }
1004 #else
1005  {
1006  throw runtime_error(
1007  "This arts version was compiled without zlib support.\n"
1008  "Thus zipped xml files cannot be written.");
1009  }
1010 #endif /* ENABLE_ZLIB */
1011  else
1012  {
1013  ofs = new ofstream();
1014  xml_open_output_file(*(ofstream*)ofs, efilename);
1015  }
1016 
1017 
1018  try
1019  {
1020  xml_write_header_to_stream(*ofs, ftype, verbosity);
1021  if (ftype == FILE_TYPE_ASCII || ftype == FILE_TYPE_ZIPPED_ASCII)
1022  {
1023  xml_write_to_stream(*ofs, type, NULL, "", verbosity);
1024  }
1025  else
1026  {
1027  String bfilename = efilename + ".bin";
1028  bofstream bofs(bfilename.c_str());
1029  xml_write_to_stream(*ofs, type, &bofs, "", verbosity);
1030  }
1031 
1032  xml_write_footer_to_stream(*ofs, verbosity);
1033  }
1034  catch (runtime_error e)
1035  {
1036  delete ofs;
1037  ostringstream os;
1038  os << "Error writing file: " << efilename << '\n'
1039  << e.what();
1040  throw runtime_error(os.str());
1041  }
1042 
1043  delete ofs;
1044 }
1045 
1046 // We can't do the instantiation at the beginning of this file, because the
1047 // implementation of xml_write_to_file and xml_read_from_file have to be known.
1048 
1049 #include "xml_io_instantiation.h"
NumericType
NumericType
Definition: xml_io.h:44
ArtsXMLTag::check_name
void check_name(const String &expected_name)
Check tag name.
Definition: xml_io.cc:56
XMLAttribute
XML attribute class.
Definition: xml_io_private.h:68
FILE_TYPE_BINARY
@ FILE_TYPE_BINARY
Definition: xml_io.h:41
xml_write_to_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.
Definition: xml_io_array_types.cc:93
igzstream
Definition: gzstream.h:92
xml_write_header_to_stream
void xml_write_header_to_stream(ostream &os, FileType ftype, const Verbosity &verbosity)
Writes XML header and root tag.
Definition: xml_io.cc:756
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:370
ArtsXMLTag::get_attribute_value
void get_attribute_value(const String &aname, String &value)
Returns value of attribute as String.
Definition: xml_io.cc:131
xml_open_input_file
void xml_open_input_file(ifstream &ifs, const String &name, const Verbosity &verbosity)
Open file for XML input.
Definition: xml_io.cc:507
xml_set_stream_precision
void xml_set_stream_precision(ostream &os)
Definition: xml_io.cc:799
ogzstream
Definition: gzstream.h:103
CREATE_OUT2
#define CREATE_OUT2
Definition: messages.h:213
ArtsXMLTag::check_attribute
void check_attribute(const String &aname, const String &value)
Checks whether attribute has the expected value.
Definition: xml_io.cc:103
ArtsXMLTag::name
String name
Definition: xml_io_private.h:104
ArtsXMLTag::write_to_stream
void write_to_stream(ostream &os)
Write XML tag.
Definition: xml_io.cc:321
my_basic_string< char >::size_type
Index size_type
Definition: mystring.h:107
Array
This can be used to make arrays out of anything.
Definition: array.h:107
xml_io_private.h
This file contains private function declarations and template instantiation to handle XML data files.
NUMERIC_TYPE_DOUBLE
@ NUMERIC_TYPE_DOUBLE
Definition: xml_io.h:44
FILE_TYPE_ZIPPED_ASCII
@ FILE_TYPE_ZIPPED_ASCII
Definition: xml_io.h:40
ArtsXMLTag::attribs
Array< XMLAttribute > attribs
Definition: xml_io_private.h:105
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:831
CREATE_OUT3
#define CREATE_OUT3
Definition: messages.h:214
ogzstream::open
void open(const char *name, int gz_open_mode=std::ios::out)
Definition: gzstream.h:109
ArtsXMLTag::read_from_stream
void read_from_stream(istream &is)
Reads next XML tag.
Definition: xml_io.cc:183
my_basic_string< char >
xml_io_instantiation.h
This file contains template instantiations to handle XML data files.
xml_open_output_file
void xml_open_output_file(ofstream &file, const String &name)
Open file for XML output.
Definition: xml_io.cc:402
xml_parse_error
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.
Definition: xml_io.cc:605
xml_io_types.h
This file contains private function declarations and template instantiation to handle XML data files.
find_xml_file
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
Definition: file.cc:464
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
Verbosity
Definition: messages.h:50
ArtsXMLTag::add_attribute
void add_attribute(const String &aname, const String &value)
Adds a String attribute to tag.
Definition: xml_io.cc:69
precision
#define precision
Definition: logic.cc:45
bifstream
Binary output file stream class.
Definition: bifstream.h:45
xml_read_arts_catalogue_from_file
void xml_read_arts_catalogue_from_file(const String &filename, ArrayOfLineRecord &type, const Numeric &fmin, const Numeric &fmax, const Verbosity &verbosity)
Definition: xml_io.cc:900
make_filename_unique
void make_filename_unique(String &filename, const String &extension)
Make filename unique.
Definition: file.cc:612
bifstream.h
This file contains the class declaration of bifstream.
bofstream.h
This file contains the class declaration of bofstream.
parameters.h
This file contains header information for the dealing with command line parameters.
out_basename
String out_basename
The basename for the report file and for all other output files.
Definition: messages.cc:42
my_basic_string::nelem
Index nelem() const
Number of elements.
Definition: mystring.h:278
ENDIAN_TYPE_LITTLE
@ ENDIAN_TYPE_LITTLE
Definition: xml_io.h:45
gzstream.h
igzstream::open
void open(const char *name, int gz_open_mode=std::ios::in)
Definition: gzstream.h:98
NUMERIC_TYPE_FLOAT
@ NUMERIC_TYPE_FLOAT
Definition: xml_io.h:44
FileType
FileType
Definition: xml_io.h:38
xml_write_to_file
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.
Definition: xml_io.cc:982
ENDIAN_TYPE_BIG
@ ENDIAN_TYPE_BIG
Definition: xml_io.h:45
EndianType
EndianType
Definition: xml_io.h:45
xml_data_parse_error
void xml_data_parse_error(ArtsXMLTag &tag, String str_error)
Throws XML parser runtime error.
Definition: xml_io.cc:622
xml_write_footer_to_stream
void xml_write_footer_to_stream(ostream &os, const Verbosity &verbosity)
Write closing root tag.
Definition: xml_io.cc:788
FILE_TYPE_ASCII
@ FILE_TYPE_ASCII
Definition: xml_io.h:39
add_basedir
String add_basedir(const String &path)
Definition: file.cc:530
xml_read_from_stream
void xml_read_from_stream(istream &is_xml, Array< SpeciesRecord > &asrecord, bifstream *pbifs, const Verbosity &verbosity)
Reads SpeciesData from XML input stream.
Definition: xml_io_array_types.cc:49
ArtsXMLTag
The ARTS XML tag class.
Definition: xml_io_private.h:79
file.h
This file contains basic functions to handle ASCII files.
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
my_basic_string::npos
static const Index npos
Define npos:
Definition: mystring.h:105
XMLAttribute::name
String name
Definition: xml_io_private.h:70
ArtsXMLTag::set_name
void set_name(const String &new_name)
Definition: xml_io_private.h:87
XMLAttribute::value
String value
Definition: xml_io_private.h:71
xml_read_footer_from_stream
void xml_read_footer_from_stream(istream &is, const Verbosity &verbosity)
Reads closing root tag.
Definition: xml_io.cc:742
filename_xml
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Definition: xml_io.cc:350
arts.h
The global header file for ARTS.
xml_io.h
This file contains basic functions to handle XML data files.
bofstream
Binary output file stream class.
Definition: bofstream.h:45
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.
Definition: xml_io.cc:644