ARTS  2.0.49
xml_io.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008 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 
39 #ifdef ENABLE_ZLIB
40 #include "gzstream.h"
41 #endif
42 
43 
45 // ArtsXMLTag implementation
47 
49 
55 void
56 ArtsXMLTag::check_name (const String& expected_name)
57 {
58  if (name != expected_name)
59  {
60  xml_parse_error ("Tag <" + expected_name + "> expected but <"
61  + name + "> found.");
62  }
63 
64 }
65 
66 
68 
73 void
74 ArtsXMLTag::add_attribute (const String& aname, const String& value)
75 {
76  XMLAttribute attr;
77 
78  attr.name = aname;
79  attr.value = value;
80  attribs.push_back (attr);
81 }
82 
83 
85 
90 void
91 ArtsXMLTag::add_attribute (const String& aname, const Index& value)
92 {
93  ostringstream v;
94 
95  v << value;
96  add_attribute (aname, v.str ());
97 }
98 
99 
101 
109 void
110 ArtsXMLTag::check_attribute (const String& aname, const String& value)
111 {
112  String actual_value;
113 
114  get_attribute_value (aname, actual_value);
115 
116  if (actual_value == "*not found*")
117  {
118  xml_parse_error ("Required attribute " + aname
119  + " does not exist");
120  }
121  else if (actual_value != value)
122  {
123  xml_parse_error ("Attribute " + aname + " has value \""
124  + actual_value + "\" but \""
125  + value + "\" was expected.");
126  }
127 }
128 
129 
131 
139 void
141 {
142  value = "";
143 
145  while (it != attribs.end ())
146  {
147  if (it->name == aname)
148  {
149  value = it->value;
150  it = attribs.end ();
151  }
152  else
153  {
154  it++;
155  }
156  }
157 }
158 
159 
161 
169 void
171 {
172  String attribute_value;
173  istringstream strstr ("");
174 
175  get_attribute_value (aname, attribute_value);
176  strstr.str (attribute_value);
177  strstr >> value;
178  if (strstr.fail ())
179  {
180  xml_parse_error ("Error while parsing value of " + aname
181  + " from <" + name + ">");
182  }
183 }
184 
185 
186 
188 
193 void
195 {
197 
198  String token;
199  stringbuf tag;
200  istringstream sstr ("");
201  XMLAttribute attr;
202  char ch;
203 
204  attribs.clear ();
205 
206  while (is.good () && isspace (is.peek ()))
207  {
208  is.get ();
209  }
210 
211  is >> ch;
212 
213  if (ch != '<')
214  {
215  is >> token;
216  token = ch + token;
217 
218  xml_parse_error ("'<' expected but " + token + " found.");
219  }
220 
221  is.get (tag, '>');
222 
223  // Hit EOF while looking for '>'
224  if (is.bad () || is.eof ())
225  {
226  xml_parse_error ("Unexpected end of file while looking for '>'");
227  }
228 
229  if (is.get () != '>')
230  {
231  xml_parse_error ("Closing > not found in tag: " + tag.str ());
232  }
233 
234  sstr.str (tag.str () + '>');
235  out3 << "Read: " << sstr.str () << '\n';
236 
237  sstr >> name;
238 
239  if (name [name.length () - 1] == '>')
240  {
241  // Because closin > was found, the tag for sure has no
242  // attributes, set token to ">" to skip reading of attributes
243  name.erase (name.length () - 1, 1);
244  token = ">";
245  }
246  else
247  {
248  // Tag may have attributes, so read next token
249  sstr >> token;
250  }
251  out3 << "Name: " << name << '\n';
252 
253  //extract attributes
254  while (token != ">")
255  {
256  String::size_type pos;
257 
258  pos = token.find ("=", 0);
259  if (pos == String::npos)
260  {
261  xml_parse_error ("Syntax error in tag: " + tag.str ());
262  }
263 
264  attr.name = token.substr (0, pos);
265  token.erase (0, pos + 1);
266 
267  if (token[0] != '\"')
268  {
269  xml_parse_error ("Missing \" in tag: " + tag.str ());
270  }
271 
272  while ((pos = token.find ("\"", 1)) == (String::size_type)String::npos && token != ">")
273  {
274  String ntoken;
275  sstr >> ntoken;
276  if (!ntoken.length()) break;
277  token += " " + ntoken;
278  }
279 
280  if (pos == (String::size_type)String::npos)
281  {
282  xml_parse_error ("Missing \" in tag: " + sstr.str ());
283  }
284 
285  if (pos == 1)
286  attr.value = "";
287  else
288  attr.value = token.substr (1, pos - 1);
289 
290  attribs.push_back (attr);
291 
292  out3 << "Attr: " << attr.name << '\n';
293  out3 << "Value: " << attr.value << '\n';
294 
295  if (token[token.length () - 1] == '>')
296  {
297  token = ">";
298  }
299  else
300  {
301  sstr >> token;
302  }
303  }
304 
305  out3 << '\n';
306 
307  // Skip comments
308  if (name == "comment")
309  {
310  is.get (tag, '<');
311 
312  // Hit EOF while looking for '<'
313  if (is.bad () || is.eof ())
314  {
315  xml_parse_error ("Unexpected end of file while looking for "
316  "comment tag");
317  }
318 
319  read_from_stream (is);
320  check_name ("/comment");
321  read_from_stream (is);
322  }
323 }
324 
325 
327 
332 void
334 {
335 
336  os << "<" << name;
337 
339 
340  while (it != attribs.end ())
341  {
342  os << ' ' << it->name
343  << "=\"" << it->value << '\"';
344  it++;
345  }
346 
347  os << ">";
348 }
349 
350 
351 
353 // Default file name
355 
357 
363 void
364 filename_xml (String& filename,
365  const String& varname )
366 {
367  if ("" == filename)
368  {
369  extern const String out_basename;
370  filename = out_basename + "." + varname + ".xml";
371  }
372 }
373 
374 
375 
377 
384 void
386  String& filename,
387  const Index& file_index,
388  const String& varname )
389 {
390  if ("" == filename)
391  {
392  extern const String out_basename;
393  ostringstream os;
394  os << out_basename << "." << varname << "." << file_index << ".xml";
395  filename = os.str();
396  }
397  else
398  {
399  ostringstream os;
400  os << filename << "." << file_index << ".xml";
401  filename = os.str();
402  }
403 }
404 
405 
406 
408 // Functions to open and read XML files
410 
412 
418 void
419 xml_open_output_file (ofstream& file, const String& name)
420 {
421  // Tell the stream that it should throw exceptions.
422  // Badbit means that the entire stream is corrupted, failbit means
423  // that the last operation has failed, but the stream is still
424  // valid. We don't want either to happen!
425  // FIXME: This does not yet work in egcs-2.91.66, try again later.
426  file.exceptions(ios::badbit |
427  ios::failbit);
428 
429  // c_str explicitly converts to c String.
430  try {
431  file.open (name.c_str());
432  } catch (ios::failure) {
433  ostringstream os;
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());
438  }
439 
440 
441  // See if the file is ok.
442  // FIXME: This should not be necessary anymore in the future, when
443  // g++ stream exceptions work properly. (In that case we would not
444  // get here if there really was a problem, because of the exception
445  // thrown by open().)
446  if (!file)
447  {
448  ostringstream os;
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());
453  }
454 }
455 
456 #ifdef ENABLE_ZLIB
457 
459 
465 void
466 xml_open_output_file (ogzstream& file, const String& name)
467 {
468  // Tell the stream that it should throw exceptions.
469  // Badbit means that the entire stream is corrupted, failbit means
470  // that the last operation has failed, but the stream is still
471  // valid. We don't want either to happen!
472  // FIXME: This does not yet work in egcs-2.91.66, try again later.
473  file.exceptions(ios::badbit |
474  ios::failbit);
475 
476  // c_str explicitly converts to c String.
477  String nname = name;
478 
479  if (nname.substr (nname.length()-3, 3) != ".gz")
480  {
481  nname += ".gz";
482  }
483 
484  try {
485  file.open (nname.c_str());
486  } catch (ios::failure) {
487  ostringstream os;
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());
492  }
493 
494 
495  // See if the file is ok.
496  // FIXME: This should not be necessary anymore in the future, when
497  // g++ stream exceptions work properly. (In that case we would not
498  // get here if there really was a problem, because of the exception
499  // thrown by open().)
500  if (!file)
501  {
502  ostringstream os;
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());
507  }
508 }
509 
510 #endif /* ENABLE_ZLIB */
511 
513 
519 void
520 xml_open_input_file (ifstream& ifs, const String& name, const Verbosity& verbosity)
521 {
523 
524  // Tell the stream that it should throw exceptions.
525  // Badbit means that the entire stream is corrupted.
526  // On the other hand, end of file will not lead to an exception, you
527  // have to check this manually!
528  ifs.exceptions (ios::badbit);
529 
530  // c_str explicitly converts to c String.
531  try
532  {
533  ifs.open (name.c_str ());
534  }
535  catch (ios::failure)
536  {
537  ostringstream os;
538  os << "Cannot open input file: " << name << '\n'
539  << "Maybe the file does not exist?";
540  throw runtime_error (os.str ());
541  }
542 
543  // See if the file is ok.
544  // FIXME: This should not be necessary anymore in the future, when
545  // g++ stream exceptions work properly.
546  if (!ifs)
547  {
548  ostringstream os;
549  os << "Cannot open input file: " << name << '\n'
550  << "Maybe the file does not exist?";
551  throw runtime_error (os.str ());
552  }
553 
554  out3 << "- Reading input file " << name << "\n";
555 }
556 
557 
558 #ifdef ENABLE_ZLIB
559 
561 
567 void
568 xml_open_input_file (igzstream& ifs, const String& name, const Verbosity& verbosity)
569 {
571 
572  // Tell the stream that it should throw exceptions.
573  // Badbit means that the entire stream is corrupted.
574  // On the other hand, end of file will not lead to an exception, you
575  // have to check this manually!
576  ifs.exceptions (ios::badbit);
577 
578  // c_str explicitly converts to c String.
579  try
580  {
581  ifs.open (name.c_str ());
582  }
583  catch (ios::failure)
584  {
585  ostringstream os;
586  os << "Cannot open input file: " << name << '\n'
587  << "Maybe the file does not exist?";
588  throw runtime_error (os.str ());
589  }
590 
591  // See if the file is ok.
592  // FIXME: This should not be necessary anymore in the future, when
593  // g++ stream exceptions work properly.
594  if (!ifs)
595  {
596  ostringstream os;
597  os << "Cannot open input file: " << name << '\n'
598  << "Maybe the file does not exist?";
599  throw runtime_error (os.str ());
600  }
601 
602  out3 << "- Reading input file " << name << "\n";
603 }
604 
605 #endif /* ENABLE_ZLIB */
606 
607 
609 // General XML functions (file header, start root tag, end root tag)
611 
613 
619 void
620 xml_parse_error (const String& str_error)
621 {
622  ostringstream os;
623  os << "XML parse error: " << str_error << '\n'
624  << "Check syntax of XML file\n";
625  throw runtime_error (os.str ());
626 }
627 
628 
630 
637 void
639 {
640  ostringstream os;
641  os << "XML data parse error: Error reading ";
642  tag.write_to_stream (os);
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 ());
647 }
648 
649 
651 
660 void
661 xml_read_header_from_stream (istream& is, FileType& ftype, NumericType& ntype,
662  EndianType& etype, const Verbosity& verbosity)
663 {
664  char str[6];
665  stringbuf strbuf;
666  ArtsXMLTag tag(verbosity);
667  String strtype;
668 
669  while (!is.fail () && isspace (is.peek())) is.get();
670 
671  is.get (str, 6, ' ');
672 
673  if (string(str) != "<?xml")
674  {
675  xml_parse_error ("Input file is not a valid xml file "
676  "(<?xml not found)");
677  }
678 
679  is.get (strbuf, '>');
680  is.get ();
681 
682  if (is.fail ())
683  {
684  xml_parse_error ("Input file is not a valid xml file");
685  }
686 
687  tag.read_from_stream (is);
688  tag.check_name ("arts");
689 
690  // Check file format
691  tag.get_attribute_value ("format", strtype);
692  if (strtype == "binary")
693  {
694  ftype = FILE_TYPE_BINARY;
695  }
696  else
697  {
698  ftype = FILE_TYPE_ASCII;
699  }
700 
701  // Check endian type
702  tag.get_attribute_value ("endian_type", strtype);
703  if (strtype == "little")
704  {
705  etype = ENDIAN_TYPE_LITTLE;
706  }
707  if (strtype == "big")
708  {
709  etype = ENDIAN_TYPE_BIG;
710  }
711  if (strtype == "")
712  {
713 /* out1 << " Warning: Endian type not specified in XML file, "
714  << "assuming little endian (PC)\n";*/
715  etype = ENDIAN_TYPE_LITTLE;
716  }
717  else
718  {
719  ostringstream os;
720  os << " Error: Unknown endian type \"" << strtype
721  << "\" specified in XML file.\n";
722  throw runtime_error(os.str());
723  }
724 
725  // Check numeric type
726  tag.get_attribute_value ("numeric_type", strtype);
727  if (strtype == "float")
728  {
729  ntype = NUMERIC_TYPE_FLOAT;
730  }
731  else if (strtype == "double")
732  {
733  ntype = NUMERIC_TYPE_DOUBLE;
734  }
735  else if (strtype == "")
736  {
737 /* out1 << " Warning: Numeric type not specified in XML file, "
738  << "assuming double\n";*/
739  ntype = NUMERIC_TYPE_DOUBLE;
740  }
741  else
742  {
743  ostringstream os;
744  os << " Error: Unknown numeric type \"" << strtype
745  << "\" specified in XML file.\n";
746  throw runtime_error(os.str());
747  }
748 
749 }
750 
751 
753 
758 void
759 xml_read_footer_from_stream (istream& is, const Verbosity& verbosity)
760 {
761  ArtsXMLTag tag(verbosity);
762 
763  tag.read_from_stream (is);
764  tag.check_name ("/arts");
765 }
766 
767 
769 
773 void
774 xml_write_header_to_stream (ostream& os, FileType ftype, const Verbosity& verbosity)
775 {
776  ArtsXMLTag tag(verbosity);
777 
778  os << "<?xml version=\"1.0\"?>"
779  << '\n';
780 
781  tag.set_name ("arts");
782  switch (ftype)
783  {
784  case FILE_TYPE_ASCII:
786  tag.add_attribute ("format", "ascii");
787  break;
788  case FILE_TYPE_BINARY:
789  tag.add_attribute ("format", "binary");
790  break;
791  }
792 
793  tag.add_attribute ("version", "1");
794 
795  tag.write_to_stream (os);
796 
797  os << '\n';
798 
799 }
800 
801 
803 
806 void
807 xml_write_footer_to_stream (ostream& os, const Verbosity& verbosity)
808 {
809  ArtsXMLTag tag(verbosity);
810 
811  tag.set_name ("/arts");
812  tag.write_to_stream (os);
813 
814  os << endl;
815 }
816 
817 void
819 {
820  // Determine the precision, depending on whether Numeric is double
821  // or float:
822  int precision;
823 #ifdef USE_FLOAT
824  precision = FLT_DIG;
825 #else
826 #ifdef USE_DOUBLE
827  precision = DBL_DIG;
828 #else
829 #error Numeric must be double or float
830 #endif
831 #endif
832 
833  os << setprecision (precision);
834 }
835 
836 
838 // Generic IO routines for XML files
840 
842 
849 template<typename T> void
850 xml_read_from_file (const String& filename,
851  T& type,
852  const Verbosity& verbosity)
853 {
855 
856  String efilename = expand_path(filename);
857 
858  istream* ifs;
859 
860  out2 << " Reading " << efilename << '\n';
861 
862  String xml_file = efilename;
863  bool found_file;
864 
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");
868 
869  // Open input stream:
870  if (xml_file.substr (xml_file.length () - 3, 3) == ".gz")
871 #ifdef ENABLE_ZLIB
872  {
873  ifs = new igzstream();
874  xml_open_input_file (*(igzstream *)ifs, xml_file, verbosity);
875  }
876 #else
877  {
878  throw runtime_error (
879  "This arts version was compiled without zlib support.\n"
880  "Thus zipped xml files cannot be read.");
881  }
882 #endif /* ENABLE_ZLIB */
883  else
884  {
885  ifs = new ifstream();
886  xml_open_input_file (*(ifstream *)ifs, xml_file, verbosity);
887  }
888 
889  // No need to check for error, because xml_open_input_file throws a
890  // runtime_error with an appropriate error message.
891 
892  // Read the matrix from the stream. Here we catch the exception,
893  // because then we can issue a nicer error message that includes the
894  // filename.
895  try
896  {
897  FileType ftype;
898  NumericType ntype;
899  EndianType etype;
900 
901  xml_read_header_from_stream (*ifs, ftype, ntype, etype, verbosity);
902  if (ftype == FILE_TYPE_ASCII)
903  {
904  xml_read_from_stream (*ifs, type, NULL, verbosity);
905  }
906  else
907  {
908  String bfilename = efilename + ".bin";
909  bifstream bifs (bfilename.c_str ());
910  xml_read_from_stream (*ifs, type, &bifs, verbosity);
911  }
912  xml_read_footer_from_stream (*ifs, verbosity);
913  }
914  catch (runtime_error e)
915  {
916  delete ifs;
917  ostringstream os;
918  os << "Error reading file: " << efilename << '\n'
919  << e.what ();
920  throw runtime_error (os.str ());
921  }
922 
923  delete ifs;
924 }
925 
926 
927 void
929  ArrayOfLineRecord& type,
930  const Numeric& fmin,
931  const Numeric& fmax,
932  const Verbosity& verbosity)
933 {
935 
936  String efilename = expand_path(filename);
937 
938  istream* ifs;
939 
940  out2 << " Reading " << efilename << '\n';
941 
942  String xml_file = efilename;
943  bool found_file;
944 
945  found_file = find_file (xml_file, ".xml");
946  if (!found_file) found_file = find_file (xml_file, ".xml.gz");
947  if (!found_file) /* found_file = */ find_file (xml_file, ".gz");
948 
949  // Open input stream:
950  if (xml_file.substr (xml_file.length () - 3, 3) == ".gz")
951 #ifdef ENABLE_ZLIB
952  {
953  ifs = new igzstream();
954  xml_open_input_file (*(igzstream *)ifs, xml_file, verbosity);
955  }
956 #else
957  {
958  throw runtime_error (
959  "This arts version was compiled without zlib support.\n"
960  "Thus zipped xml files cannot be read.");
961  }
962 #endif /* ENABLE_ZLIB */
963  else
964  {
965  ifs = new ifstream();
966  xml_open_input_file (*(ifstream *)ifs, xml_file, verbosity);
967  }
968 
969  // No need to check for error, because xml_open_input_file throws a
970  // runtime_error with an appropriate error message.
971 
972  // Read the matrix from the stream. Here we catch the exception,
973  // because then we can issue a nicer error message that includes the
974  // filename.
975  try
976  {
977  FileType ftype;
978  NumericType ntype;
979  EndianType etype;
980 
981  xml_read_header_from_stream (*ifs, ftype, ntype, etype, verbosity);
982  if (ftype == FILE_TYPE_ASCII)
983  {
984  xml_read_from_stream (*ifs, type, fmin, fmax, NULL, verbosity);
985  }
986  else
987  {
988  String bfilename = efilename + ".bin";
989  bifstream bifs (bfilename.c_str ());
990  xml_read_from_stream (*ifs, type, fmin, fmax, &bifs, verbosity);
991  }
992  xml_read_footer_from_stream (*ifs, verbosity);
993  }
994  catch (runtime_error e)
995  {
996  delete ifs;
997  ostringstream os;
998  os << "Error reading file: " << efilename << '\n'
999  << e.what ();
1000  throw runtime_error (os.str ());
1001  }
1002 
1003  delete ifs;
1004 }
1005 
1006 
1008 
1016 template<typename T> void
1017 xml_write_to_file (const String& filename,
1018  const T& type,
1019  const FileType ftype,
1020  const Verbosity& verbosity)
1021 {
1022  CREATE_OUT2
1023 
1024  String efilename = expand_path(filename);
1025 
1026  ostream* ofs;
1027 
1028  out2 << " Writing " << efilename << '\n';
1029  if (ftype == FILE_TYPE_ZIPPED_ASCII)
1030 #ifdef ENABLE_ZLIB
1031  {
1032  ofs = new ogzstream();
1033  xml_open_output_file(*(ogzstream *)ofs, efilename);
1034  }
1035 #else
1036  {
1037  throw runtime_error (
1038  "This arts version was compiled without zlib support.\n"
1039  "Thus zipped xml files cannot be written.");
1040  }
1041 #endif /* ENABLE_ZLIB */
1042  else
1043  {
1044  ofs = new ofstream();
1045  xml_open_output_file(*(ofstream *)ofs, efilename);
1046  }
1047 
1048 
1049  try
1050  {
1051  xml_write_header_to_stream (*ofs, ftype, verbosity);
1052  if (ftype == FILE_TYPE_ASCII || ftype == FILE_TYPE_ZIPPED_ASCII)
1053  {
1054  xml_write_to_stream (*ofs, type, NULL, "", verbosity);
1055  }
1056  else
1057  {
1058  String bfilename = efilename + ".bin";
1059  bofstream bofs (bfilename.c_str ());
1060  xml_write_to_stream (*ofs, type, &bofs, "", verbosity);
1061  }
1062 
1063  xml_write_footer_to_stream (*ofs, verbosity);
1064  }
1065  catch (runtime_error e)
1066  {
1067  delete ofs;
1068  ostringstream os;
1069  os << "Error writing file: " << efilename << '\n'
1070  << e.what ();
1071  throw runtime_error (os.str ());
1072  }
1073 
1074  delete ofs;
1075 }
1076 
1077 // We can't do the instantiation at the beginning of this file, because the
1078 // implementation of xml_write_to_file and xml_read_from_file have to be known.
1079 
1080 #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:71
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:774
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:385
ArtsXMLTag::get_attribute_value
void get_attribute_value(const String &aname, String &value)
Returns value of attribute as String.
Definition: xml_io.cc:140
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:520
xml_set_stream_precision
void xml_set_stream_precision(ostream &os)
Definition: xml_io.cc:818
ogzstream
Definition: gzstream.h:103
CREATE_OUT2
#define CREATE_OUT2
Definition: messages.h:207
ArtsXMLTag::check_attribute
void check_attribute(const String &aname, const String &value)
Checks whether attribute has the expected value.
Definition: xml_io.cc:110
ArtsXMLTag::name
String name
Definition: xml_io_private.h:118
ArtsXMLTag::write_to_stream
void write_to_stream(ostream &os)
Write XML tag.
Definition: xml_io.cc:333
find_file
bool find_file(String &filename, const char *extension)
Find the given file.
Definition: file.cc:379
my_basic_string< char >::size_type
Index size_type
Definition: mystring.h:98
Array
This can be used to make arrays out of anything.
Definition: array.h:103
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:119
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:850
CREATE_OUT3
#define CREATE_OUT3
Definition: messages.h:208
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:194
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:419
xml_parse_error
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.
Definition: xml_io.cc:620
xml_io_types.h
This file contains private function declarations and template instantiation to handle XML data files.
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
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:74
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:928
bifstream.h
This file contains the class declaration of bifstream.
bofstream.h
This file contains the class declaration of bofstream.
out_basename
String out_basename
The basename for the report file and for all other output files.
Definition: messages.cc:42
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
expand_path
String expand_path(const String &path)
Definition: file.cc:274
NUMERIC_TYPE_FLOAT
@ NUMERIC_TYPE_FLOAT
Definition: xml_io.h:44
FileType
FileType
Definition: xml_io.h:38
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:638
xml_write_footer_to_stream
void xml_write_footer_to_stream(ostream &os, const Verbosity &verbosity)
Write closing root tag.
Definition: xml_io.cc:807
FILE_TYPE_ASCII
@ FILE_TYPE_ASCII
Definition: xml_io.h:39
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:50
ArtsXMLTag
The ARTS XML tag class.
Definition: xml_io_private.h:83
file.h
This file contains basic functions to handle ASCII files.
xml_write_to_file
void xml_write_to_file(const String &filename, const T &type, const FileType ftype, const Verbosity &verbosity)
Write data to XML file.
Definition: xml_io.cc:1017
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
my_basic_string::npos
static const Index npos
Define npos:
Definition: mystring.h:96
XMLAttribute::name
String name
Definition: xml_io_private.h:73
ArtsXMLTag::set_name
void set_name(const String &new_name)
Definition: xml_io_private.h:94
XMLAttribute::value
String value
Definition: xml_io_private.h:74
xml_read_footer_from_stream
void xml_read_footer_from_stream(istream &is, const Verbosity &verbosity)
Reads closing root tag.
Definition: xml_io.cc:759
filename_xml
void filename_xml(String &filename, const String &varname)
Gives the default filename for the XML formats.
Definition: xml_io.cc:364
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:661