ARTS  2.4.0(git:4fb77825)
xml_io_basic_types.cc
Go to the documentation of this file.
1 /* Copyright (C) 2003-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 
19 // File description
21 
30 #include "arts.h"
31 #include "file.h"
32 #include "xml_io.h"
33 #include "xml_io_private.h"
34 #include "xml_io_types.h"
35 
37 // Overloaded functions for reading/writing data from/to XML stream
39 
40 //=== Index ==================================================================
41 
43 
48 void xml_read_from_stream(istream& is_xml,
49  Index& index,
50  bifstream* pbifs,
51  const Verbosity& verbosity) {
52  ArtsXMLTag tag(verbosity);
53 
54  tag.read_from_stream(is_xml);
55  tag.check_name("Index");
56 
57  if (pbifs) {
58  *pbifs >> index;
59  if (pbifs->fail()) {
60  xml_data_parse_error(tag, "");
61  }
62  } else {
63  is_xml >> index;
64  if (is_xml.fail()) {
65  xml_data_parse_error(tag, "");
66  }
67  }
68 
69  tag.read_from_stream(is_xml);
70  tag.check_name("/Index");
71 }
72 
74 
80 void xml_write_to_stream(ostream& os_xml,
81  const Index& index,
82  bofstream* pbofs,
83  const String& name,
84  const Verbosity& verbosity) {
85  ArtsXMLTag open_tag(verbosity);
86  ArtsXMLTag close_tag(verbosity);
87 
88  open_tag.set_name("Index");
89  if (name.length()) open_tag.add_attribute("name", name);
90 
91  open_tag.write_to_stream(os_xml);
92 
93  if (pbofs)
94  *pbofs << index;
95  else
96  os_xml << index;
97 
98  close_tag.set_name("/Index");
99  close_tag.write_to_stream(os_xml);
100  os_xml << '\n';
101 }
102 
103 //=== Matrix ==========================================================
104 
106 
111 void xml_read_from_stream(istream& is_xml,
112  Matrix& matrix,
113  bifstream* pbifs,
114  const Verbosity& verbosity) {
115  ArtsXMLTag tag(verbosity);
116  Index nrows, ncols;
117 
118  tag.read_from_stream(is_xml);
119  tag.check_name("Matrix");
120 
121  tag.get_attribute_value("nrows", nrows);
122  tag.get_attribute_value("ncols", ncols);
123  matrix.resize(nrows, ncols);
124 
125  for (Index r = 0; r < nrows; r++) {
126  for (Index c = 0; c < ncols; c++) {
127  if (pbifs) {
128  *pbifs >> matrix(r, c);
129  if (pbifs->fail()) {
130  ostringstream os;
131  os << " near "
132  << "\n Row : " << r << "\n Column: " << c;
133  xml_data_parse_error(tag, os.str());
134  }
135  } else {
136  is_xml >> double_imanip() >> matrix(r, c);
137  if (is_xml.fail()) {
138  ostringstream os;
139  os << " near "
140  << "\n Row : " << r << "\n Column: " << c;
141  xml_data_parse_error(tag, os.str());
142  }
143  }
144  }
145  }
146 
147  tag.read_from_stream(is_xml);
148  tag.check_name("/Matrix");
149 }
150 
152 
158 void xml_write_to_stream(ostream& os_xml,
159  const Matrix& matrix,
160  bofstream* pbofs,
161  const String& name,
162  const Verbosity& verbosity) {
163  ArtsXMLTag open_tag(verbosity);
164  ArtsXMLTag close_tag(verbosity);
165 
166  open_tag.set_name("Matrix");
167  if (name.length()) open_tag.add_attribute("name", name);
168  open_tag.add_attribute("nrows", matrix.nrows());
169  open_tag.add_attribute("ncols", matrix.ncols());
170 
171  open_tag.write_to_stream(os_xml);
172  os_xml << '\n';
173 
174  xml_set_stream_precision(os_xml);
175 
176  // Write the elements:
177  for (Index r = 0; r < matrix.nrows(); ++r) {
178  if (pbofs)
179  *pbofs << matrix(r, 0);
180  else
181  os_xml << matrix(r, 0);
182 
183  for (Index c = 1; c < matrix.ncols(); ++c) {
184  if (pbofs)
185  *pbofs << matrix(r, c);
186  else
187  os_xml << " " << matrix(r, c);
188  }
189 
190  if (!pbofs) os_xml << '\n';
191  }
192 
193  close_tag.set_name("/Matrix");
194  close_tag.write_to_stream(os_xml);
195 
196  os_xml << '\n';
197 }
198 
199 //=== Numeric =========================================================
200 
202 
207 void xml_read_from_stream(istream& is_xml,
208  Numeric& numeric,
209  bifstream* pbifs,
210  const Verbosity& verbosity) {
211  ArtsXMLTag tag(verbosity);
212 
213  tag.read_from_stream(is_xml);
214  tag.check_name("Numeric");
215 
216  if (pbifs) {
217  *pbifs >> numeric;
218  if (pbifs->fail()) {
219  xml_data_parse_error(tag, "");
220  }
221  } else {
222  is_xml >> double_imanip() >> numeric;
223  if (is_xml.fail()) {
224  xml_data_parse_error(tag, "");
225  }
226  }
227 
228  tag.read_from_stream(is_xml);
229  tag.check_name("/Numeric");
230 }
231 
233 
239 void xml_write_to_stream(ostream& os_xml,
240  const Numeric& numeric,
241  bofstream* pbofs,
242  const String& name,
243  const Verbosity& verbosity) {
244  ArtsXMLTag open_tag(verbosity);
245  ArtsXMLTag close_tag(verbosity);
246 
247  open_tag.set_name("Numeric");
248  if (name.length()) open_tag.add_attribute("name", name);
249 
250  open_tag.write_to_stream(os_xml);
251 
252  xml_set_stream_precision(os_xml);
253 
254  if (pbofs)
255  *pbofs << numeric;
256  else
257  os_xml << numeric;
258 
259  close_tag.set_name("/Numeric");
260  close_tag.write_to_stream(os_xml);
261  os_xml << '\n';
262 }
263 
264 //=== Rational =========================================================
265 
267 
272 void xml_read_from_stream(istream& is_xml,
273  Rational& rational,
274  bifstream* pbifs,
275  const Verbosity& verbosity) {
276  ArtsXMLTag tag(verbosity);
277 
278  tag.read_from_stream(is_xml);
279  tag.check_name("Rational");
280 
281  if (pbifs) {
282  *pbifs >> rational;
283  if (pbifs->fail()) {
284  xml_data_parse_error(tag, "");
285  }
286  } else {
287  is_xml >> rational;
288  if (is_xml.fail()) {
289  xml_data_parse_error(tag, "");
290  }
291  }
292 
293  tag.read_from_stream(is_xml);
294  tag.check_name("/Rational");
295 }
296 
298 
304 void xml_write_to_stream(ostream& os_xml,
305  const Rational& rational,
306  bofstream* pbofs,
307  const String& name,
308  const Verbosity& verbosity) {
309  ArtsXMLTag open_tag(verbosity);
310  ArtsXMLTag close_tag(verbosity);
311 
312  open_tag.set_name("Rational");
313  if (name.length()) open_tag.add_attribute("name", name);
314 
315  open_tag.write_to_stream(os_xml);
316 
317  if (pbofs)
318  *pbofs << rational;
319  else
320  os_xml << rational;
321 
322  close_tag.set_name("/Rational");
323  close_tag.write_to_stream(os_xml);
324  os_xml << '\n';
325 }
326 
327 //=== Sparse ====================================================
328 
330 
335 void xml_read_from_stream(istream& is_xml,
336  Sparse& sparse,
337  bifstream* pbifs,
338  const Verbosity& verbosity) {
339  ArtsXMLTag tag(verbosity);
340  Index nrows, ncols, nnz;
341 
342  tag.read_from_stream(is_xml);
343  tag.check_name("Sparse");
344 
345  tag.get_attribute_value("nrows", nrows);
346  tag.get_attribute_value("ncols", ncols);
347  sparse.resize(nrows, ncols);
348 
349  tag.read_from_stream(is_xml);
350  tag.check_name("RowIndex");
351  tag.get_attribute_value("nelem", nnz);
352 
353  ArrayOfIndex rowind(nnz), colind(nnz);
354  Vector data(nnz);
355 
356  for (Index i = 0; i < nnz; i++) {
357  if (pbifs) {
358  *pbifs >> rowind[i];
359  if (pbifs->fail()) {
360  ostringstream os;
361  os << " near "
362  << "\n Row index: " << i;
363  xml_data_parse_error(tag, os.str());
364  }
365  } else {
366  is_xml >> rowind[i];
367  if (is_xml.fail()) {
368  ostringstream os;
369  os << " near "
370  << "\n Row index: " << i;
371  xml_data_parse_error(tag, os.str());
372  }
373  }
374  }
375  tag.read_from_stream(is_xml);
376  tag.check_name("/RowIndex");
377 
378  tag.read_from_stream(is_xml);
379  tag.check_name("ColIndex");
380 
381  for (Index i = 0; i < nnz; i++) {
382  if (pbifs) {
383  *pbifs >> colind[i];
384  if (pbifs->fail()) {
385  ostringstream os;
386  os << " near "
387  << "\n Column index: " << i;
388  xml_data_parse_error(tag, os.str());
389  }
390  } else {
391  is_xml >> colind[i];
392  if (is_xml.fail()) {
393  ostringstream os;
394  os << " near "
395  << "\n Column index: " << i;
396  xml_data_parse_error(tag, os.str());
397  }
398  }
399  }
400  tag.read_from_stream(is_xml);
401  tag.check_name("/ColIndex");
402 
403  tag.read_from_stream(is_xml);
404  tag.check_name("SparseData");
405 
406  for (Index i = 0; i < nnz; i++) {
407  if (pbifs) {
408  *pbifs >> data[i];
409  if (pbifs->fail()) {
410  ostringstream os;
411  os << " near "
412  << "\n Data element: " << i;
413  xml_data_parse_error(tag, os.str());
414  }
415  } else {
416  is_xml >> double_imanip() >> data[i];
417  if (is_xml.fail()) {
418  ostringstream os;
419  os << " near "
420  << "\n Data element: " << i;
421  xml_data_parse_error(tag, os.str());
422  }
423  }
424  }
425  tag.read_from_stream(is_xml);
426  tag.check_name("/SparseData");
427 
428  tag.read_from_stream(is_xml);
429  tag.check_name("/Sparse");
430 
431  sparse.insert_elements(nnz, rowind, colind, data);
432 }
433 
435 
441 void xml_write_to_stream(ostream& os_xml,
442  const Sparse& sparse,
443  bofstream* pbofs,
444  const String& name,
445  const Verbosity& verbosity) {
446  ArtsXMLTag sparse_tag(verbosity);
447  ArtsXMLTag row_tag(verbosity);
448  ArtsXMLTag col_tag(verbosity);
449  ArtsXMLTag data_tag(verbosity);
450  ArtsXMLTag close_tag(verbosity);
451 
452  sparse_tag.set_name("Sparse");
453  if (name.length()) sparse_tag.add_attribute("name", name);
454  sparse_tag.add_attribute("nrows", sparse.nrows());
455  sparse_tag.add_attribute("ncols", sparse.ncols());
456  //sparse_tag.add_attribute ("nnz", sparse.nnz());
457  row_tag.set_name("RowIndex");
458  row_tag.add_attribute("nelem", sparse.nnz());
459  col_tag.set_name("ColIndex");
460  col_tag.add_attribute("nelem", sparse.nnz());
461  data_tag.set_name("SparseData");
462  data_tag.add_attribute("nelem", sparse.nnz());
463 
464  sparse_tag.write_to_stream(os_xml);
465  os_xml << '\n';
466 
467  row_tag.write_to_stream(os_xml);
468  os_xml << '\n';
469 
470  ArrayOfIndex rowind(sparse.nnz()), colind(sparse.nnz());
471  Vector data(sparse.nnz());
472  sparse.list_elements(data, rowind, colind);
473 
474  // Write row indices.
475 
476  for (Index i = 0; i < sparse.nnz(); i++) {
477  if (pbofs)
478  //FIXME: It should be the longer lines
479  *pbofs << rowind[i];
480  else
481  os_xml << rowind[i] << '\n';
482  }
483 
484  close_tag.set_name("/RowIndex");
485  close_tag.write_to_stream(os_xml);
486  os_xml << '\n';
487 
488  col_tag.write_to_stream(os_xml);
489  os_xml << '\n';
490 
491  // Write column indices.
492 
493  for (Index i = 0; i < sparse.nnz(); i++) {
494  if (pbofs)
495  //FIXME: It should be the longer lines
496  *pbofs << colind[i];
497  else
498  os_xml << colind[i] << '\n';
499  }
500 
501  close_tag.set_name("/ColIndex");
502  close_tag.write_to_stream(os_xml);
503  os_xml << '\n';
504 
505  data_tag.write_to_stream(os_xml);
506  os_xml << '\n';
507  xml_set_stream_precision(os_xml);
508 
509  // Write data.
510 
511  for (Index i = 0; i < sparse.nnz(); i++) {
512  if (pbofs)
513  *pbofs << data[i];
514  else
515  os_xml << data[i] << ' ';
516  }
517  os_xml << '\n';
518  close_tag.set_name("/SparseData");
519  close_tag.write_to_stream(os_xml);
520  os_xml << '\n';
521 
522  close_tag.set_name("/Sparse");
523  close_tag.write_to_stream(os_xml);
524 
525  os_xml << '\n';
526 }
527 
528 //=== String ===========================================================
529 
531 
535 /* param pbifs Pointer to binary input stream. NULL in case of ASCII file.
536  Ignored because strings are always stored in ASCII format. */
537 void xml_read_from_stream(istream& is_xml,
538  String& str,
539  bifstream* /* pbifs */,
540  const Verbosity& verbosity) {
541  ArtsXMLTag tag(verbosity);
542  char dummy;
543 
544  tag.read_from_stream(is_xml);
545  tag.check_name("String");
546 
547  // Skip whitespaces
548  bool string_starts_with_quotes = true;
549  do {
550  is_xml >> dummy;
551  switch (dummy) {
552  case ' ':
553  case '\"':
554  case '\n':
555  case '\r':
556  case '\t':
557  break;
558  default:
559  string_starts_with_quotes = false;
560  }
561  } while (is_xml.good() && dummy != '"' && string_starts_with_quotes);
562 
563  // Throw exception if first char after whitespaces is not a quote
564  if (!string_starts_with_quotes) {
565  xml_parse_error("String must begin with \"");
566  }
567 
568  //catch case where string is empty. CPD 29/8/05
569  dummy = (char)is_xml.peek();
570  if (dummy == '"') {
571  str = "";
572  } else {
573  stringbuf strbuf;
574 
575  is_xml.get(strbuf, '"');
576  if (is_xml.fail()) {
577  xml_parse_error("String must end with \"");
578  }
579  str = strbuf.str();
580  }
581 
582  // Ignore quote
583  is_xml >> dummy;
584 
585  tag.read_from_stream(is_xml);
586  tag.check_name("/String");
587 }
588 
590 
595 /* param pbofs Pointer to binary file stream. NULL for ASCII output.
596  Ignored because strings are always in ASCII format. */
597 void xml_write_to_stream(ostream& os_xml,
598  const String& str,
599  bofstream* /* pbofs */,
600  const String& name,
601  const Verbosity& verbosity) {
602  ArtsXMLTag open_tag(verbosity);
603  ArtsXMLTag close_tag(verbosity);
604 
605  open_tag.set_name("String");
606  if (name.length()) open_tag.add_attribute("name", name);
607 
608  open_tag.write_to_stream(os_xml);
609 
610  os_xml << '\"' << str << '\"';
611 
612  close_tag.set_name("/String");
613  close_tag.write_to_stream(os_xml);
614  os_xml << '\n';
615 }
616 
617 //=== Tensor3 ================================================================
618 
620 
625 void xml_read_from_stream(istream& is_xml,
626  Tensor3& tensor,
627  bifstream* pbifs,
628  const Verbosity& verbosity) {
629  ArtsXMLTag tag(verbosity);
631 
632  tag.read_from_stream(is_xml);
633  tag.check_name("Tensor3");
634 
635  tag.get_attribute_value("npages", npages);
636  tag.get_attribute_value("nrows", nrows);
637  tag.get_attribute_value("ncols", ncols);
638  tensor.resize(npages, nrows, ncols);
639 
640  for (Index p = 0; p < npages; p++) {
641  for (Index r = 0; r < nrows; r++) {
642  for (Index c = 0; c < ncols; c++) {
643  if (pbifs) {
644  *pbifs >> tensor(p, r, c);
645  if (pbifs->fail()) {
646  ostringstream os;
647  os << " near "
648  << "\n Page : " << p << "\n Row : " << r
649  << "\n Column: " << c;
650  xml_data_parse_error(tag, os.str());
651  }
652  } else {
653  is_xml >> double_imanip() >> tensor(p, r, c);
654  if (is_xml.fail()) {
655  ostringstream os;
656  os << " near "
657  << "\n Page : " << p << "\n Row : " << r
658  << "\n Column: " << c;
659  xml_data_parse_error(tag, os.str());
660  }
661  }
662  }
663  }
664  }
665 
666  tag.read_from_stream(is_xml);
667  tag.check_name("/Tensor3");
668 }
669 
671 
677 void xml_write_to_stream(ostream& os_xml,
678  const Tensor3& tensor,
679  bofstream* pbofs,
680  const String& name,
681  const Verbosity& verbosity) {
682  ArtsXMLTag open_tag(verbosity);
683  ArtsXMLTag close_tag(verbosity);
684 
685  open_tag.set_name("Tensor3");
686  if (name.length()) open_tag.add_attribute("name", name);
687  open_tag.add_attribute("npages", tensor.npages());
688  open_tag.add_attribute("nrows", tensor.nrows());
689  open_tag.add_attribute("ncols", tensor.ncols());
690 
691  open_tag.write_to_stream(os_xml);
692  os_xml << '\n';
693 
694  xml_set_stream_precision(os_xml);
695 
696  // Write the elements:
697  for (Index p = 0; p < tensor.npages(); ++p) {
698  for (Index r = 0; r < tensor.nrows(); ++r) {
699  if (pbofs)
700  *pbofs << tensor(p, r, 0);
701  else
702  os_xml << tensor(p, r, 0);
703  for (Index c = 1; c < tensor.ncols(); ++c) {
704  if (pbofs)
705  *pbofs << tensor(p, r, c);
706  else
707  os_xml << " " << tensor(p, r, c);
708  }
709  if (!pbofs) os_xml << '\n';
710  }
711  }
712 
713  close_tag.set_name("/Tensor3");
714  close_tag.write_to_stream(os_xml);
715 
716  os_xml << '\n';
717 }
718 
719 //=== Tensor4 =========================================================
720 
722 
727 void xml_read_from_stream(istream& is_xml,
728  Tensor4& tensor,
729  bifstream* pbifs,
730  const Verbosity& verbosity) {
731  ArtsXMLTag tag(verbosity);
733 
734  tag.read_from_stream(is_xml);
735  tag.check_name("Tensor4");
736 
737  tag.get_attribute_value("nbooks", nbooks);
738  tag.get_attribute_value("npages", npages);
739  tag.get_attribute_value("nrows", nrows);
740  tag.get_attribute_value("ncols", ncols);
741  tensor.resize(nbooks, npages, nrows, ncols);
742 
743  for (Index b = 0; b < nbooks; b++) {
744  for (Index p = 0; p < npages; p++) {
745  for (Index r = 0; r < nrows; r++) {
746  for (Index c = 0; c < ncols; c++) {
747  if (pbifs) {
748  *pbifs >> tensor(b, p, r, c);
749  if (pbifs->fail()) {
750  ostringstream os;
751  os << " near "
752  << "\n Book : " << b << "\n Page : " << p
753  << "\n Row : " << r << "\n Column: " << c;
754  xml_data_parse_error(tag, os.str());
755  }
756  } else {
757  is_xml >> double_imanip() >> tensor(b, p, r, c);
758  if (is_xml.fail()) {
759  ostringstream os;
760  os << " near "
761  << "\n Book : " << b << "\n Page : " << p
762  << "\n Row : " << r << "\n Column: " << c;
763  xml_data_parse_error(tag, os.str());
764  }
765  }
766  }
767  }
768  }
769  }
770 
771  tag.read_from_stream(is_xml);
772  tag.check_name("/Tensor4");
773 }
774 
776 
782 void xml_write_to_stream(ostream& os_xml,
783  const Tensor4& tensor,
784  bofstream* pbofs,
785  const String& name,
786  const Verbosity& verbosity) {
787  ArtsXMLTag open_tag(verbosity);
788  ArtsXMLTag close_tag(verbosity);
789 
790  open_tag.set_name("Tensor4");
791  if (name.length()) open_tag.add_attribute("name", name);
792  open_tag.add_attribute("nbooks", tensor.nbooks());
793  open_tag.add_attribute("npages", tensor.npages());
794  open_tag.add_attribute("nrows", tensor.nrows());
795  open_tag.add_attribute("ncols", tensor.ncols());
796 
797  open_tag.write_to_stream(os_xml);
798  os_xml << '\n';
799 
800  xml_set_stream_precision(os_xml);
801 
802  // Write the elements:
803  for (Index b = 0; b < tensor.nbooks(); ++b) {
804  for (Index p = 0; p < tensor.npages(); ++p) {
805  for (Index r = 0; r < tensor.nrows(); ++r) {
806  if (pbofs)
807  *pbofs << tensor(b, p, r, 0);
808  else
809  os_xml << tensor(b, p, r, 0);
810  for (Index c = 1; c < tensor.ncols(); ++c) {
811  if (pbofs)
812  *pbofs << tensor(b, p, r, c);
813  else
814  os_xml << " " << tensor(b, p, r, c);
815  }
816  if (!pbofs) os_xml << '\n';
817  }
818  }
819  }
820 
821  close_tag.set_name("/Tensor4");
822  close_tag.write_to_stream(os_xml);
823 
824  os_xml << '\n';
825 }
826 
827 //=== Tensor5 =========================================================
828 
830 
835 void xml_read_from_stream(istream& is_xml,
836  Tensor5& tensor,
837  bifstream* pbifs,
838  const Verbosity& verbosity) {
839  ArtsXMLTag tag(verbosity);
841 
842  tag.read_from_stream(is_xml);
843  tag.check_name("Tensor5");
844 
845  tag.get_attribute_value("nshelves", nshelves);
846  tag.get_attribute_value("nbooks", nbooks);
847  tag.get_attribute_value("npages", npages);
848  tag.get_attribute_value("nrows", nrows);
849  tag.get_attribute_value("ncols", ncols);
850  tensor.resize(nshelves, nbooks, npages, nrows, ncols);
851 
852  for (Index s = 0; s < nshelves; s++) {
853  for (Index b = 0; b < nbooks; b++) {
854  for (Index p = 0; p < npages; p++) {
855  for (Index r = 0; r < nrows; r++) {
856  for (Index c = 0; c < ncols; c++) {
857  if (pbifs) {
858  *pbifs >> tensor(s, b, p, r, c);
859  if (pbifs->fail()) {
860  ostringstream os;
861  os << " near "
862  << "\n Shelf : " << s << "\n Book : " << b
863  << "\n Page : " << p << "\n Row : " << r
864  << "\n Column: " << c;
865  xml_data_parse_error(tag, os.str());
866  }
867  } else {
868  is_xml >> double_imanip() >> tensor(s, b, p, r, c);
869  if (is_xml.fail()) {
870  ostringstream os;
871  os << " near "
872  << "\n Shelf : " << s << "\n Book : " << b
873  << "\n Page : " << p << "\n Row : " << r
874  << "\n Column: " << c;
875  xml_data_parse_error(tag, os.str());
876  }
877  }
878  }
879  }
880  }
881  }
882  }
883 
884  tag.read_from_stream(is_xml);
885  tag.check_name("/Tensor5");
886 }
887 
889 
895 void xml_write_to_stream(ostream& os_xml,
896  const Tensor5& tensor,
897  bofstream* pbofs,
898  const String& name,
899  const Verbosity& verbosity) {
900  ArtsXMLTag open_tag(verbosity);
901  ArtsXMLTag close_tag(verbosity);
902 
903  open_tag.set_name("Tensor5");
904  if (name.length()) open_tag.add_attribute("name", name);
905  open_tag.add_attribute("nshelves", tensor.nshelves());
906  open_tag.add_attribute("nbooks", tensor.nbooks());
907  open_tag.add_attribute("npages", tensor.npages());
908  open_tag.add_attribute("nrows", tensor.nrows());
909  open_tag.add_attribute("ncols", tensor.ncols());
910 
911  open_tag.write_to_stream(os_xml);
912  os_xml << '\n';
913 
914  xml_set_stream_precision(os_xml);
915 
916  // Write the elements:
917  for (Index s = 0; s < tensor.nshelves(); ++s) {
918  for (Index b = 0; b < tensor.nbooks(); ++b) {
919  for (Index p = 0; p < tensor.npages(); ++p) {
920  for (Index r = 0; r < tensor.nrows(); ++r) {
921  if (pbofs)
922  *pbofs << tensor(s, b, p, r, 0);
923  else
924  os_xml << tensor(s, b, p, r, 0);
925  for (Index c = 1; c < tensor.ncols(); ++c) {
926  if (pbofs)
927  *pbofs << tensor(s, b, p, r, c);
928  else
929  os_xml << " " << tensor(s, b, p, r, c);
930  }
931  if (!pbofs) os_xml << '\n';
932  }
933  }
934  }
935  }
936 
937  close_tag.set_name("/Tensor5");
938  close_tag.write_to_stream(os_xml);
939 
940  os_xml << '\n';
941 }
942 
943 //=== Tensor6 =========================================================
944 
946 
951 void xml_read_from_stream(istream& is_xml,
952  Tensor6& tensor,
953  bifstream* pbifs,
954  const Verbosity& verbosity) {
955  ArtsXMLTag tag(verbosity);
957 
958  tag.read_from_stream(is_xml);
959  tag.check_name("Tensor6");
960 
961  tag.get_attribute_value("nvitrines", nvitrines);
962  tag.get_attribute_value("nshelves", nshelves);
963  tag.get_attribute_value("nbooks", nbooks);
964  tag.get_attribute_value("npages", npages);
965  tag.get_attribute_value("nrows", nrows);
966  tag.get_attribute_value("ncols", ncols);
968 
969  for (Index v = 0; v < nvitrines; v++) {
970  for (Index s = 0; s < nshelves; s++) {
971  for (Index b = 0; b < nbooks; b++) {
972  for (Index p = 0; p < npages; p++) {
973  for (Index r = 0; r < nrows; r++) {
974  for (Index c = 0; c < ncols; c++) {
975  if (pbifs) {
976  *pbifs >> tensor(v, s, b, p, r, c);
977  if (pbifs->fail()) {
978  ostringstream os;
979  os << " near "
980  << "\n Vitrine: " << v << "\n Shelf : " << s
981  << "\n Book : " << b << "\n Page : " << p
982  << "\n Row : " << r << "\n Column : " << c;
983  xml_data_parse_error(tag, os.str());
984  }
985  } else {
986  is_xml >> double_imanip() >> tensor(v, s, b, p, r, c);
987  if (is_xml.fail()) {
988  ostringstream os;
989  os << " near "
990  << "\n Vitrine: " << v << "\n Shelf : " << s
991  << "\n Book : " << b << "\n Page : " << p
992  << "\n Row : " << r << "\n Column : " << c;
993  xml_data_parse_error(tag, os.str());
994  }
995  }
996  }
997  }
998  }
999  }
1000  }
1001  }
1002 
1003  tag.read_from_stream(is_xml);
1004  tag.check_name("/Tensor6");
1005 }
1006 
1008 
1014 void xml_write_to_stream(ostream& os_xml,
1015  const Tensor6& tensor,
1016  bofstream* pbofs,
1017  const String& name,
1018  const Verbosity& verbosity) {
1019  ArtsXMLTag open_tag(verbosity);
1020  ArtsXMLTag close_tag(verbosity);
1021 
1022  open_tag.set_name("Tensor6");
1023  if (name.length()) open_tag.add_attribute("name", name);
1024  open_tag.add_attribute("nvitrines", tensor.nvitrines());
1025  open_tag.add_attribute("nshelves", tensor.nshelves());
1026  open_tag.add_attribute("nbooks", tensor.nbooks());
1027  open_tag.add_attribute("npages", tensor.npages());
1028  open_tag.add_attribute("nrows", tensor.nrows());
1029  open_tag.add_attribute("ncols", tensor.ncols());
1030 
1031  open_tag.write_to_stream(os_xml);
1032  os_xml << '\n';
1033 
1034  xml_set_stream_precision(os_xml);
1035 
1036  // Write the elements:
1037  for (Index v = 0; v < tensor.nvitrines(); ++v) {
1038  for (Index s = 0; s < tensor.nshelves(); ++s) {
1039  for (Index b = 0; b < tensor.nbooks(); ++b) {
1040  for (Index p = 0; p < tensor.npages(); ++p) {
1041  for (Index r = 0; r < tensor.nrows(); ++r) {
1042  if (pbofs)
1043  *pbofs << tensor(v, s, b, p, r, 0);
1044  else
1045  os_xml << tensor(v, s, b, p, r, 0);
1046  for (Index c = 1; c < tensor.ncols(); ++c) {
1047  if (pbofs)
1048  *pbofs << tensor(v, s, b, p, r, c);
1049  else
1050  os_xml << " " << tensor(v, s, b, p, r, c);
1051  }
1052  if (!pbofs) os_xml << '\n';
1053  }
1054  }
1055  }
1056  }
1057  }
1058 
1059  close_tag.set_name("/Tensor6");
1060  close_tag.write_to_stream(os_xml);
1061 
1062  os_xml << '\n';
1063 }
1064 
1065 //=== Tensor7 =========================================================
1066 
1068 
1073 void xml_read_from_stream(istream& is_xml,
1074  Tensor7& tensor,
1075  bifstream* pbifs,
1076  const Verbosity& verbosity) {
1077  ArtsXMLTag tag(verbosity);
1079 
1080  tag.read_from_stream(is_xml);
1081  tag.check_name("Tensor7");
1082 
1083  tag.get_attribute_value("nlibraries", nlibraries);
1084  tag.get_attribute_value("nvitrines", nvitrines);
1085  tag.get_attribute_value("nshelves", nshelves);
1086  tag.get_attribute_value("nbooks", nbooks);
1087  tag.get_attribute_value("npages", npages);
1088  tag.get_attribute_value("nrows", nrows);
1089  tag.get_attribute_value("ncols", ncols);
1091 
1092  for (Index l = 0; l < nlibraries; l++) {
1093  for (Index v = 0; v < nvitrines; v++) {
1094  for (Index s = 0; s < nshelves; s++) {
1095  for (Index b = 0; b < nbooks; b++) {
1096  for (Index p = 0; p < npages; p++) {
1097  for (Index r = 0; r < nrows; r++) {
1098  for (Index c = 0; c < ncols; c++) {
1099  if (pbifs) {
1100  *pbifs >> tensor(l, v, s, b, p, r, c);
1101  if (pbifs->fail()) {
1102  ostringstream os;
1103  os << " near "
1104  << "\n Library: " << l << "\n Vitrine: " << v
1105  << "\n Shelf : " << s << "\n Book : " << b
1106  << "\n Page : " << p << "\n Row : " << r
1107  << "\n Column : " << c;
1108  xml_data_parse_error(tag, os.str());
1109  }
1110  } else {
1111  is_xml >> double_imanip() >> tensor(l, v, s, b, p, r, c);
1112  if (is_xml.fail()) {
1113  ostringstream os;
1114  os << " near "
1115  << "\n Library: " << l << "\n Vitrine: " << v
1116  << "\n Shelf : " << s << "\n Book : " << b
1117  << "\n Page : " << p << "\n Row : " << r
1118  << "\n Column : " << c;
1119  xml_data_parse_error(tag, os.str());
1120  }
1121  }
1122  }
1123  }
1124  }
1125  }
1126  }
1127  }
1128  }
1129 
1130  tag.read_from_stream(is_xml);
1131  tag.check_name("/Tensor7");
1132 }
1133 
1135 
1141 void xml_write_to_stream(ostream& os_xml,
1142  const Tensor7& tensor,
1143  bofstream* pbofs,
1144  const String& name,
1145  const Verbosity& verbosity) {
1146  ArtsXMLTag open_tag(verbosity);
1147  ArtsXMLTag close_tag(verbosity);
1148 
1149  open_tag.set_name("Tensor7");
1150  if (name.length()) open_tag.add_attribute("name", name);
1151  open_tag.add_attribute("nlibraries", tensor.nlibraries());
1152  open_tag.add_attribute("nvitrines", tensor.nvitrines());
1153  open_tag.add_attribute("nshelves", tensor.nshelves());
1154  open_tag.add_attribute("nbooks", tensor.nbooks());
1155  open_tag.add_attribute("npages", tensor.npages());
1156  open_tag.add_attribute("nrows", tensor.nrows());
1157  open_tag.add_attribute("ncols", tensor.ncols());
1158 
1159  open_tag.write_to_stream(os_xml);
1160  os_xml << '\n';
1161 
1162  xml_set_stream_precision(os_xml);
1163 
1164  // Write the elements:
1165  for (Index l = 0; l < tensor.nlibraries(); ++l) {
1166  for (Index v = 0; v < tensor.nvitrines(); ++v) {
1167  for (Index s = 0; s < tensor.nshelves(); ++s) {
1168  for (Index b = 0; b < tensor.nbooks(); ++b) {
1169  for (Index p = 0; p < tensor.npages(); ++p) {
1170  for (Index r = 0; r < tensor.nrows(); ++r) {
1171  if (pbofs)
1172  *pbofs << tensor(l, v, s, b, p, r, 0);
1173  else
1174  os_xml << tensor(l, v, s, b, p, r, 0);
1175  for (Index c = 1; c < tensor.ncols(); ++c) {
1176  if (pbofs)
1177  *pbofs << tensor(l, v, s, b, p, r, c);
1178  else
1179  os_xml << " " << tensor(l, v, s, b, p, r, c);
1180  }
1181  if (!pbofs) os_xml << '\n';
1182  }
1183  }
1184  }
1185  }
1186  }
1187  }
1188 
1189  close_tag.set_name("/Tensor7");
1190  close_tag.write_to_stream(os_xml);
1191 
1192  os_xml << '\n';
1193 }
1194 
1195 //=== Vector ==========================================================
1196 
1198 
1204 void xml_parse_from_stream(istream& is_xml,
1205  Vector& vector,
1206  bifstream* pbifs,
1207  ArtsXMLTag& tag,
1208  const Verbosity&) {
1209  Index nelem;
1210 
1211  tag.get_attribute_value("nelem", nelem);
1212  vector.resize(nelem);
1213 
1214  for (Index n = 0; n < nelem; n++) {
1215  if (pbifs) {
1216  *pbifs >> vector[n];
1217  if (pbifs->fail()) {
1218  ostringstream os;
1219  os << " near "
1220  << "\n Element: " << n;
1221  xml_data_parse_error(tag, os.str());
1222  }
1223  } else {
1224  is_xml >> double_imanip() >> vector[n];
1225  if (is_xml.fail()) {
1226  ostringstream os;
1227  os << " near "
1228  << "\n Element: " << n;
1229  xml_data_parse_error(tag, os.str());
1230  }
1231  }
1232  }
1233 }
1234 
1236 
1241 void xml_read_from_stream(istream& is_xml,
1242  Vector& vector,
1243  bifstream* pbifs,
1244  const Verbosity& verbosity) {
1245  ArtsXMLTag tag(verbosity);
1246 
1247  tag.read_from_stream(is_xml);
1248  tag.check_name("Vector");
1249 
1250  xml_parse_from_stream(is_xml, vector, pbifs, tag, verbosity);
1251 
1252  tag.read_from_stream(is_xml);
1253  tag.check_name("/Vector");
1254 }
1255 
1257 
1263 void xml_write_to_stream(ostream& os_xml,
1264  const Vector& vector,
1265  bofstream* pbofs,
1266  const String& name,
1267  const Verbosity& verbosity) {
1268  ArtsXMLTag open_tag(verbosity);
1269  ArtsXMLTag close_tag(verbosity);
1270  Index n = vector.nelem();
1271  ostringstream v;
1272 
1273  // Convert nelem to string
1274  v << n;
1275 
1276  open_tag.set_name("Vector");
1277  if (name.length()) open_tag.add_attribute("name", name);
1278  open_tag.add_attribute("nelem", v.str());
1279 
1280  open_tag.write_to_stream(os_xml);
1281  os_xml << '\n';
1282 
1283  xml_set_stream_precision(os_xml);
1284 
1285  for (Index i = 0; i < n; ++i)
1286  if (pbofs)
1287  *pbofs << vector[i];
1288  else
1289  os_xml << vector[i] << '\n';
1290 
1291  close_tag.set_name("/Vector");
1292  close_tag.write_to_stream(os_xml);
1293 
1294  os_xml << '\n';
1295 }
1296 
1297 //=== TransmissionMatrix ================================================================
1298 
1300 
1305 void xml_read_from_stream(istream& is_xml,
1306  TransmissionMatrix& tm,
1307  bifstream* pbifs,
1308  const Verbosity& verbosity) {
1309  ArtsXMLTag tag(verbosity);
1310  Index stokes_dim, nf;
1311 
1312  tag.read_from_stream(is_xml);
1313  tag.check_name("TransmissionMatrix");
1314 
1315  tag.get_attribute_value("Stokes", stokes_dim);
1316  tag.get_attribute_value("Freqs", nf);
1317  tm = TransmissionMatrix(nf, stokes_dim);
1318  if (pbifs) {
1319  *pbifs >> tm;
1320  if (pbifs->fail()) {
1321  ostringstream os;
1322  os << "TransmissionMatrix has wrong dimensions";
1323  xml_data_parse_error(tag, os.str());
1324  }
1325  } else {
1326  is_xml >> tm;
1327  if (is_xml.fail()) {
1328  ostringstream os;
1329  os << "TransmissionMatrix has wrong dimensions";
1330  xml_data_parse_error(tag, os.str());
1331  }
1332  }
1333 
1334  tag.read_from_stream(is_xml);
1335  tag.check_name("/TransmissionMatrix");
1336 }
1337 
1339 
1345 void xml_write_to_stream(ostream& os_xml,
1346  const TransmissionMatrix& tm,
1347  bofstream* pbofs,
1348  const String& name,
1349  const Verbosity& verbosity) {
1350  ArtsXMLTag open_tag(verbosity);
1351  ArtsXMLTag close_tag(verbosity);
1352 
1353  open_tag.set_name("TransmissionMatrix");
1354  if (name.length()) open_tag.add_attribute("name", name);
1355  open_tag.add_attribute("Stokes", tm.StokesDim());
1356  open_tag.add_attribute("Freqs", tm.Frequencies());
1357 
1358  open_tag.write_to_stream(os_xml);
1359  os_xml << '\n';
1360 
1361  xml_set_stream_precision(os_xml);
1362  if (pbofs)
1363  *pbofs << tm;
1364  else
1365  os_xml << tm;
1366 
1367  close_tag.set_name("/TransmissionMatrix");
1368  close_tag.write_to_stream(os_xml);
1369 
1370  os_xml << '\n';
1371 }
1372 
1373 //=== RadiationVector ================================================================
1374 
1376 
1381 void xml_read_from_stream(istream& is_xml,
1382  RadiationVector& rv,
1383  bifstream* pbifs,
1384  const Verbosity& verbosity) {
1385  ArtsXMLTag tag(verbosity);
1386  Index stokes_dim, nf;
1387 
1388  tag.read_from_stream(is_xml);
1389  tag.check_name("RadiationVector");
1390 
1391  tag.get_attribute_value("Stokes", stokes_dim);
1392  tag.get_attribute_value("Freqs", nf);
1393  rv = RadiationVector(nf, stokes_dim);
1394  if (pbifs) {
1395  *pbifs >> rv;
1396  if (pbifs->fail()) {
1397  ostringstream os;
1398  os << "RadiationVector has wrong dimensions";
1399  xml_data_parse_error(tag, os.str());
1400  }
1401  } else {
1402  is_xml >> rv;
1403  if (is_xml.fail()) {
1404  ostringstream os;
1405  os << "RadiationVector has wrong dimensions";
1406  xml_data_parse_error(tag, os.str());
1407  }
1408  }
1409 
1410  tag.read_from_stream(is_xml);
1411  tag.check_name("/RadiationVector");
1412 }
1413 
1415 
1421 void xml_write_to_stream(ostream& os_xml,
1422  const RadiationVector& rv,
1423  bofstream* pbofs,
1424  const String& name,
1425  const Verbosity& verbosity) {
1426  ArtsXMLTag open_tag(verbosity);
1427  ArtsXMLTag close_tag(verbosity);
1428 
1429  open_tag.set_name("RadiationVector");
1430  if (name.length()) open_tag.add_attribute("name", name);
1431  open_tag.add_attribute("Stokes", rv.StokesDim());
1432  open_tag.add_attribute("Freqs", rv.Frequencies());
1433 
1434  open_tag.write_to_stream(os_xml);
1435  os_xml << '\n';
1436 
1437  xml_set_stream_precision(os_xml);
1438  if (pbofs)
1439  *pbofs << rv;
1440  else
1441  os_xml << rv;
1442 
1443  close_tag.set_name("/RadiationVector");
1444  close_tag.write_to_stream(os_xml);
1445 
1446  os_xml << '\n';
1447 }
1448 
1449 //=== Time ================================================================
1450 
1452 
1457 void xml_read_from_stream(istream& is_xml,
1458  Time& t,
1459  bifstream* pbifs,
1460  const Verbosity& verbosity) {
1461  ArtsXMLTag tag(verbosity);
1462 
1463  tag.read_from_stream(is_xml);
1464  tag.check_name("Time");
1465 
1466  Index version;
1467  tag.get_attribute_value("version", version);
1468  if (version == 1) {/* OK */}
1469  else {
1470  throw std::runtime_error("Your version of ARTS can only handle version 1 of Time");
1471  }
1472 
1473  if (pbifs) {
1474  throw std::runtime_error("Cannot read binary Time");
1475  } else {
1476  is_xml >> t;
1477  if (is_xml.fail()) {
1478  xml_data_parse_error(tag, "Time is poorly formatted");
1479  }
1480  }
1481 
1482  tag.read_from_stream(is_xml);
1483  tag.check_name("/Time");
1484 }
1485 
1487 
1493 void xml_write_to_stream(ostream& os_xml,
1494  const Time& t,
1495  bofstream* pbofs,
1496  const String&,
1497  const Verbosity& verbosity) {
1498  ArtsXMLTag open_tag(verbosity);
1499  ArtsXMLTag close_tag(verbosity);
1500 
1501  open_tag.set_name("Time");
1502  open_tag.add_attribute("version", t.Version());
1503  open_tag.write_to_stream(os_xml);
1504 
1505  xml_set_stream_precision(os_xml);
1506  if (pbofs)
1507  throw std::runtime_error("Cannot write binary time");
1508  else
1509  os_xml << ' ' << t << ' ';
1510 
1511  close_tag.set_name("/Time");
1512  close_tag.write_to_stream(os_xml);
1513  os_xml << '\n';
1514 }
1515 
1516 //=== AbsorptionLines ================================================================
1517 
1519 
1524 void xml_read_from_stream(istream& is_xml,
1525  AbsorptionLines& al,
1526  bifstream* pbifs,
1527  const Verbosity& verbosity) {
1528  ArtsXMLTag tag(verbosity);
1529 
1530  tag.read_from_stream(is_xml);
1531  tag.check_name("AbsorptionLines");
1532 
1533  // Number of lines
1534  Index nlines;
1535  tag.get_attribute_value("nlines", nlines);
1536 
1537  // Species of the lines
1538  SpeciesTag spec;
1539  tag.get_attribute_value("species", spec);
1540 
1541  // Cutoff type
1542  String s_cutoff;
1543  tag.get_attribute_value("cutofftype", s_cutoff);
1544  const Absorption::CutoffType cutoff = Absorption::string2cutofftype(s_cutoff);
1545 
1546  // Mirroring type
1547  String s_mirroring;
1548  tag.get_attribute_value("mirroringtype", s_mirroring);
1549  const Absorption::MirroringType mirroring = Absorption::string2mirroringtype(s_mirroring);
1550 
1551  // Line population type
1552  String s_population;
1553  tag.get_attribute_value("populationtype", s_population);
1554  const Absorption::PopulationType population = Absorption::string2populationtype(s_population);
1555 
1556  // Normalization type
1557  String s_normalization;
1558  tag.get_attribute_value("normalizationtype", s_normalization);
1559  const Absorption::NormalizationType normalization = Absorption::string2normalizationtype(s_normalization);
1560 
1561  // Normalization type
1562  String s_lineshapetype;
1563  tag.get_attribute_value("lineshapetype", s_lineshapetype);
1564  const LineShape::Type lineshapetype = LineShape::string2shapetype(s_lineshapetype);
1565 
1567  Numeric T0;
1568  tag.get_attribute_value("T0", T0);
1569 
1571  Numeric cutofffreq;
1572  tag.get_attribute_value("cutofffreq", cutofffreq);
1573 
1575  Numeric linemixinglimit;
1576  tag.get_attribute_value("linemixinglimit", linemixinglimit);
1577 
1579  std::vector<QuantumNumberType> localquanta;
1580  tag.get_attribute_value("localquanta", localquanta);
1581 
1583  QuantumNumbers upperglobalquanta;
1584  tag.get_attribute_value("upperglobalquanta", upperglobalquanta);
1585  QuantumNumbers lowerglobalquanta;
1586  tag.get_attribute_value("lowerglobalquanta", lowerglobalquanta);
1587 
1589  ArrayOfSpeciesTag broadeningspecies;
1590  bool selfbroadening;
1591  bool bathbroadening;
1592  tag.get_attribute_value("broadeningspecies", broadeningspecies, selfbroadening, bathbroadening);
1593 
1594  String temperaturemodes;
1595  tag.get_attribute_value("temperaturemodes", temperaturemodes);
1596  auto metamodel = LineShape::MetaData2ModelShape(temperaturemodes);
1597 
1598  al = AbsorptionLines(selfbroadening, bathbroadening,
1599  nlines, cutoff, mirroring,
1600  population, normalization,
1601  lineshapetype, T0, cutofffreq,
1602  linemixinglimit, QuantumIdentifier(spec.Species(),
1603  spec.Isotopologue(), upperglobalquanta, lowerglobalquanta),
1604  localquanta, broadeningspecies, metamodel);
1605 
1606  if (pbifs) {
1607  al.read(*pbifs);
1608  if (pbifs->fail()) {
1609  ostringstream os;
1610  os << "AbsorptionLines has wrong dimensions";
1611  xml_data_parse_error(tag, os.str());
1612  }
1613  } else {
1614  is_xml >> al;
1615  if (is_xml.fail()) {
1616  ostringstream os;
1617  os << "AbsorptionLines has wrong dimensions";
1618  xml_data_parse_error(tag, os.str());
1619  }
1620  }
1621 
1622  tag.read_from_stream(is_xml);
1623  tag.check_name("/AbsorptionLines");
1624 }
1625 
1627 
1633 void xml_write_to_stream(ostream& os_xml,
1634  const AbsorptionLines& al,
1635  bofstream* pbofs,
1636  const String&,
1637  const Verbosity& verbosity) {
1638  ArtsXMLTag open_comment_tag(verbosity);
1639  ArtsXMLTag close_comment_tag(verbosity);
1640  open_comment_tag.set_name("comment");
1641  open_comment_tag.write_to_stream(os_xml);
1642  os_xml << al.MetaData();
1643  close_comment_tag.set_name("/comment");
1644  close_comment_tag.write_to_stream(os_xml);
1645  os_xml << '\n';
1646 
1647  ArtsXMLTag open_tag(verbosity);
1648  ArtsXMLTag close_tag(verbosity);
1649 
1650  open_tag.set_name("AbsorptionLines");
1651  open_tag.add_attribute("nlines", al.NumLines());
1652  open_tag.add_attribute("species", al.SpeciesName());
1653  open_tag.add_attribute("cutofftype", Absorption::cutofftype2string(al.Cutoff()));
1654  open_tag.add_attribute("mirroringtype", Absorption::mirroringtype2string(al.Mirroring()));
1655  open_tag.add_attribute("populationtype", Absorption::populationtype2string(al.Population()));
1656  open_tag.add_attribute("normalizationtype", Absorption::normalizationtype2string(al.Normalization()));
1657  open_tag.add_attribute("lineshapetype", LineShape::shapetype2string(al.LineShapeType()));
1658  open_tag.add_attribute("T0", al.T0());
1659  open_tag.add_attribute("cutofffreq", al.CutoffFreqValue());
1660  open_tag.add_attribute("linemixinglimit", al.LinemixingLimit());
1661  open_tag.add_attribute("localquanta", al.LocalQuanta());
1662  open_tag.add_attribute("upperglobalquanta", al.UpperQuantumNumbers());
1663  open_tag.add_attribute("lowerglobalquanta", al.LowerQuantumNumbers());
1664  open_tag.add_attribute("broadeningspecies", al.BroadeningSpecies(), al.Self(), al.Bath());
1665  open_tag.add_attribute("temperaturemodes", al.LineShapeMetaData());
1666 
1667  open_tag.write_to_stream(os_xml);
1668  os_xml << '\n';
1669 
1670  xml_set_stream_precision(os_xml);
1671  if (pbofs)
1672  al.write(*pbofs);
1673  else
1674  os_xml << al;
1675 
1676  close_tag.set_name("/AbsorptionLines");
1677  close_tag.write_to_stream(os_xml);
1678 
1679  os_xml << '\n';
1680 }
1681 
1683 // Dummy funtion for groups for which
1684 // IO function have not yet been implemented
1686 
1687 // FIXME: These should be implemented, sooner or later...
1688 
1689 void xml_read_from_stream(istream&,
1690  Timer&,
1691  bifstream* /* pbifs */,
1692  const Verbosity&) {
1693  throw runtime_error("Method not implemented!");
1694 }
1695 
1696 void xml_write_to_stream(ostream&,
1697  const Timer&,
1698  bofstream* /* pbofs */,
1699  const String& /* name */,
1700  const Verbosity&) {
1701  throw runtime_error("Method not implemented!");
1702 }
Matrix
The Matrix class.
Definition: matpackI.h:1193
Absorption::Lines::Cutoff
CutoffType Cutoff() const noexcept
Returns cutoff style.
Definition: absorptionlines.h:1128
ARTS::Var::nlibraries
Index nlibraries(Workspace &ws) noexcept
Definition: autoarts.h:4560
Tensor4::resize
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1064
ConstTensor7View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackVII.cc:48
ConstTensor6View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackVI.cc:45
QuantumNumbers
Container class for Quantum Numbers.
Definition: quantum.h:222
ConstTensor5View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:47
ArtsXMLTag::check_name
void check_name(const String &expected_name)
Check tag name.
Definition: xml_io.cc:54
Tensor6::resize
void resize(Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVI.cc:2175
Sparse::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackII.cc:69
Time::Version
Index Version() const noexcept
Definition: artstime.h:48
Absorption::Lines::LineShapeType
LineShape::Type LineShapeType() const noexcept
Returns lineshapetype style.
Definition: absorptionlines.h:1180
Tensor3
The Tensor3 class.
Definition: matpackIII.h:339
ConstTensor5View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
ConstTensor6View::npages
Index npages() const
Returns the number of pages.
Definition: matpackVI.cc:51
Absorption::Lines::NumLines
Index NumLines() const noexcept
Number of lines.
Definition: absorptionlines.h:852
Absorption::normalizationtype2string
String normalizationtype2string(NormalizationType in)
Definition: absorptionlines.h:117
ConstTensor7View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackVII.cc:60
Absorption::Lines::T0
Numeric T0() const noexcept
Returns reference temperature.
Definition: absorptionlines.h:1311
ARTS::Var::verbosity
Verbosity verbosity(Workspace &ws) noexcept
Definition: autoarts.h:7112
Absorption::NormalizationType
NormalizationType
Describes the type of normalization line effects.
Definition: absorptionlines.h:97
ARTS::Var::nvitrines
Index nvitrines(Workspace &ws) noexcept
Definition: autoarts.h:4696
Absorption::Lines::Bath
bool Bath() const noexcept
Returns bath broadening status.
Definition: absorptionlines.h:1371
Sparse
The Sparse class.
Definition: matpackII.h:60
Absorption::Lines::Normalization
NormalizationType Normalization() const noexcept
Returns normalization style.
Definition: absorptionlines.h:1102
TransmissionMatrix::Frequencies
Index Frequencies() const
Number of frequencies.
Definition: transmissionmatrix.h:268
ConstTensor6View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackVI.cc:54
Vector::resize
void resize(Index n)
Resize function.
Definition: matpackI.cc:404
LineShape::MetaData2ModelShape
Model MetaData2ModelShape(const String &s)
Definition: lineshapemodel.cc:563
Absorption::Lines::UpperQuantumNumbers
String UpperQuantumNumbers() const noexcept
Upper quantum numbers string.
Definition: absorptionlines.cc:2560
data
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Definition: arts_api_classes.cc:232
ArtsXMLTag::get_attribute_value
void get_attribute_value(const String &aname, String &value)
Returns value of attribute as String.
Definition: xml_io.cc:153
ARTS::Var::stokes_dim
Index stokes_dim(Workspace &ws) noexcept
Definition: autoarts.h:6650
ConstMatrixView::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackI.cc:429
xml_set_stream_precision
void xml_set_stream_precision(ostream &os)
Definition: xml_io.cc:856
ARTS::Var::nshelves
Index nshelves(Workspace &ws) noexcept
Definition: autoarts.h:4689
Tensor4
The Tensor4 class.
Definition: matpackIV.h:421
Sparse::list_elements
void list_elements(Vector &values, ArrayOfIndex &row_indices, ArrayOfIndex &column_indices) const
List elements in matrix.
Definition: matpackII.cc:270
ArtsXMLTag::write_to_stream
void write_to_stream(ostream &os)
Write XML tag.
Definition: xml_io.cc:410
Absorption::populationtype2string
String populationtype2string(PopulationType in)
Definition: absorptionlines.h:171
Tensor3::resize
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.cc:664
ConstTensor5View::npages
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:50
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:144
Timer
Definition: m_general.h:68
ConstTensor7View::nlibraries
Index nlibraries() const
Returns the number of libraries.
Definition: matpackVII.cc:42
Absorption::Lines::CutoffFreqValue
Numeric CutoffFreqValue() const noexcept
Returns internal cutoff frequency value.
Definition: absorptionlines.h:1321
xml_parse_from_stream
void xml_parse_from_stream(istream &is_xml, Vector &vector, bifstream *pbifs, ArtsXMLTag &tag, const Verbosity &)
Parses Vector from XML input stream.
Definition: xml_io_basic_types.cc:1204
Array
This can be used to make arrays out of anything.
Definition: array.h:108
xml_io_private.h
This file contains private function declarations and template instantiation to handle XML data files.
AbsorptionLines
Absorption::Lines AbsorptionLines
Definition: absorptionlines.h:1850
SpeciesTag
A tag group can consist of the sum of several of these.
Definition: abs_species_tags.h:44
Absorption::nelem
Index nelem(const Lines &l)
Number of lines.
Definition: absorptionlines.h:1820
Sparse::insert_elements
void insert_elements(Index nnz, const ArrayOfIndex &rowind, const ArrayOfIndex &colind, ConstVectorView data)
Insert vector of elements with given row and column indices.
Definition: matpackII.cc:337
ConstTensor6View::nvitrines
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVI.cc:42
Tensor7::resize
void resize(Index l, Index v, Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackVII.cc:5484
TransmissionMatrix::StokesDim
Index StokesDim() const
Stokes dimensionaility.
Definition: transmissionmatrix.h:265
Tensor5::resize
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:1743
Sparse::nnz
Index nnz() const
Returns the number of nonzero elements.
Definition: matpackII.cc:72
xml_read_from_stream
void xml_read_from_stream(istream &is_xml, Index &index, bifstream *pbifs, const Verbosity &verbosity)
Reads Index from XML input stream.
Definition: xml_io_basic_types.cc:48
ConstMatrixView::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackI.cc:432
Absorption::Lines::Mirroring
MirroringType Mirroring() const noexcept
Returns mirroring style.
Definition: absorptionlines.h:1076
ArtsXMLTag::read_from_stream
void read_from_stream(istream &is)
Reads next XML tag.
Definition: xml_io.cc:289
my_basic_string< char >
xml_parse_error
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.
Definition: xml_io.cc:690
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
double_imanip
Input manipulator class for doubles to enable nan and inf parsing.
Definition: file.h:117
ConstTensor7View::nvitrines
Index nvitrines() const
Returns the number of vitrines.
Definition: matpackVII.cc:45
xml_io_types.h
This file contains private function declarations and template instantiation to handle XML data files.
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:66
ConstTensor7View::npages
Index npages() const
Returns the number of pages.
Definition: matpackVII.cc:54
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Verbosity
Definition: messages.h:49
ArtsXMLTag::add_attribute
void add_attribute(const String &aname, const String &value)
Adds a String attribute to tag.
Definition: xml_io.cc:66
bifstream
Binary output file stream class.
Definition: bifstream.h:42
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:60
Absorption::mirroringtype2string
String mirroringtype2string(MirroringType in)
Definition: absorptionlines.h:69
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:57
ARTS::Var::npages
Index npages(Workspace &ws) noexcept
Definition: autoarts.h:4675
Absorption::MirroringType
MirroringType
Describes the type of mirroring line effects.
Definition: absorptionlines.h:49
Absorption::Lines
Definition: absorptionlines.h:547
Matrix::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackI.cc:1056
Absorption::Lines::SpeciesName
String SpeciesName() const noexcept
Species Name.
Definition: absorptionlines.cc:2547
LineShape::Type
Type
Type of line shape to compute.
Definition: lineshapemodel.h:788
ConstTensor3View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:147
ConstTensor6View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackVI.cc:48
Absorption::Lines::Population
PopulationType Population() const noexcept
Returns population style.
Definition: absorptionlines.h:1152
Tensor5
The Tensor5 class.
Definition: matpackV.h:506
ARTS::Var::nrows
Index nrows(Workspace &ws) noexcept
Definition: autoarts.h:4682
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:63
Sparse::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackII.cc:361
nlines
#define nlines
Definition: legacy_continua.cc:22187
RadiationVector
Radiation Vector for Stokes dimension 1-4.
Definition: transmissionmatrix.h:395
ConstTensor7View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackVII.cc:51
ConstTensor5View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
xml_write_to_stream
void xml_write_to_stream(ostream &os_xml, const Index &index, bofstream *pbofs, const String &name, const Verbosity &verbosity)
Writes Index to XML output stream.
Definition: xml_io_basic_types.cc:80
RadiationVector::StokesDim
Index StokesDim() const
Get Stokes dimension.
Definition: transmissionmatrix.h:873
Sparse::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackII.cc:66
Absorption::string2normalizationtype
NormalizationType string2normalizationtype(const String &in)
Definition: absorptionlines.h:104
ARTS::Group::RadiationVector
RadiationVector RadiationVector
Definition: autoarts.h:95
xml_data_parse_error
void xml_data_parse_error(ArtsXMLTag &tag, String str_error)
Throws XML parser runtime error.
Definition: xml_io.cc:705
Time
Class to handle time in ARTS.
Definition: artstime.h:40
ConstTensor5View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:44
ConstTensor3View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:150
Absorption::Lines::LowerQuantumNumbers
String LowerQuantumNumbers() const noexcept
Lower quantum numbers string.
Definition: absorptionlines.cc:2570
Absorption::Lines::LineShapeMetaData
String LineShapeMetaData() const noexcept
Meta data for the line shape if it exists.
Definition: absorptionlines.h:839
Absorption::Lines::write
bofstream & write(bofstream &os) const
Binary write for Lines.
Definition: absorptionlines.h:1445
LineShape::shapetype2string
String shapetype2string(Type type) noexcept
Turns selected Type into a string.
Definition: lineshapemodel.h:805
Absorption::Lines::Self
bool Self() const noexcept
Returns self broadening status.
Definition: absorptionlines.h:1361
ARTS::Group::TransmissionMatrix
TransmissionMatrix TransmissionMatrix
Definition: autoarts.h:112
SpeciesTag::Isotopologue
Index Isotopologue() const
Isotopologue species index.
Definition: abs_species_tags.h:87
ArtsXMLTag
The ARTS XML tag class.
Definition: xml_io_private.h:90
file.h
This file contains basic functions to handle ASCII files.
Absorption::CutoffType
CutoffType
Describes the type of cutoff calculations.
Definition: absorptionlines.h:207
ARTS::Group::QuantumIdentifier
QuantumIdentifier QuantumIdentifier
Definition: autoarts.h:94
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Absorption::Lines::LinemixingLimit
Numeric LinemixingLimit() const noexcept
Returns line mixing limit.
Definition: absorptionlines.h:1331
ConstTensor7View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackVII.cc:57
Absorption::string2cutofftype
CutoffType string2cutofftype(const String &in)
Definition: absorptionlines.h:213
Absorption::Lines::MetaData
String MetaData() const
Returns a printable statement about the lines.
Definition: absorptionlines.cc:2580
Absorption::cutofftype2string
String cutofftype2string(CutoffType in)
Definition: absorptionlines.h:224
RadiationVector::Frequencies
Index Frequencies() const
Get frequency count.
Definition: transmissionmatrix.h:876
Tensor6
The Tensor6 class.
Definition: matpackVI.h:1088
ARTS::Var::ncols
Index ncols(Workspace &ws) noexcept
Definition: autoarts.h:4546
LineShape::string2shapetype
Type string2shapetype(const String &type)
Turns predefined strings into a Type.
Definition: lineshapemodel.h:855
Vector
The Vector class.
Definition: matpackI.h:860
Absorption::PopulationType
PopulationType
Describes the type of population level counter.
Definition: absorptionlines.h:148
TransmissionMatrix
Class to keep track of Transmission Matrices for Stokes Dim 1-4.
Definition: transmissionmatrix.h:38
ArtsXMLTag::set_name
void set_name(const String &new_name)
Definition: xml_io_private.h:98
Absorption::string2populationtype
PopulationType string2populationtype(const String &in)
Definition: absorptionlines.h:156
SpeciesTag::Species
Index Species() const
Molecular species index.
Definition: abs_species_tags.h:64
ConstTensor6View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackVI.cc:57
Absorption::Lines::BroadeningSpecies
const ArrayOfSpeciesTag & BroadeningSpecies() const noexcept
Returns the broadening species.
Definition: absorptionlines.h:1351
ARTS::Var::nbooks
Index nbooks(Workspace &ws) noexcept
Definition: autoarts.h:4539
Rational
Implements rational numbers to work with other ARTS types.
Definition: rational.h:54
Absorption::Lines::LocalQuanta
const std::vector< QuantumNumberType > & LocalQuanta() const noexcept
Returns local quantum numbers.
Definition: absorptionlines.h:1341
Tensor7
The Tensor7 class.
Definition: matpackVII.h:2382
Absorption::string2mirroringtype
MirroringType string2mirroringtype(const String &in)
Definition: absorptionlines.h:56
arts.h
The global header file for ARTS.
Absorption::Lines::read
bifstream & read(bifstream &is)
Binary read for Lines.
Definition: absorptionlines.h:1438
xml_io.h
This file contains basic functions to handle XML data files.
bofstream
Binary output file stream class.
Definition: bofstream.h:42