ARTS 2.5.4 (git: 31ce4f0e)
xml_io_compound_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
29#include "arts.h"
30#include "cloudbox.h"
31#include "debug.h"
32#include "global_data.h"
33#include "predefined/predef_data.h"
34#include "xml_io.h"
35#include <sstream>
36
38// Overloaded functions for reading/writing data from/to XML stream
40
41//=== CIARecord ================================================
42
44
49void xml_read_from_stream(istream& is_xml,
50 CIARecord& cr,
51 bifstream* pbifs,
52 const Verbosity& verbosity) {
53 ArtsXMLTag tag(verbosity);
54 String name;
55 String molecule1;
56 String molecule2;
57 Species::Species species1;
58 Species::Species species2;
59
60 tag.read_from_stream(is_xml);
61 tag.check_name("CIARecord");
62 tag.get_attribute_value("molecule1", molecule1);
63 tag.get_attribute_value("molecule2", molecule2);
64
65 species1 = Species::fromShortName(molecule1);
66 species2 = Species::fromShortName(molecule2);
67
68 if (not good_enum(species1)) {
69 ostringstream os;
70 os << "Unknown species (1st molecule) in CIARecord: " << molecule1;
71 throw runtime_error(os.str());
72 }
73 if (not good_enum(species2)) {
74 ostringstream os;
75 os << "Unknown species (2nd molecule) in CIARecord: " << molecule2;
76 throw runtime_error(os.str());
77 }
78
79 cr.SetSpecies(species1, species2);
80
81 xml_read_from_stream(is_xml, cr.mdata, pbifs, verbosity);
82
83 tag.read_from_stream(is_xml);
84 tag.check_name("/CIARecord");
85}
86
88
94void xml_write_to_stream(ostream& os_xml,
95 const CIARecord& cr,
96 bofstream* pbofs,
97 const String& name _U_,
98 const Verbosity& verbosity) {
99 ArtsXMLTag open_tag(verbosity);
100 ArtsXMLTag close_tag(verbosity);
101
102 open_tag.set_name("CIARecord");
103 open_tag.add_attribute("molecule1", cr.MoleculeName(0));
104 open_tag.add_attribute("molecule2", cr.MoleculeName(1));
105 open_tag.write_to_stream(os_xml);
106 os_xml << '\n';
107
108 xml_write_to_stream(os_xml, cr.Data(), pbofs, "", verbosity);
109
110 close_tag.set_name("/CIARecord");
111 close_tag.write_to_stream(os_xml);
112 os_xml << '\n';
113}
114
116
122void xml_read_from_stream(istream& is_xml,
123 CovarianceMatrix& covmat,
124 bifstream* pbifs,
125 const Verbosity& verbosity) {
126 ArtsXMLTag tag(verbosity);
127 String name, type;
128 Index n_blocks, row_start, row_extent, column_start, column_extent, row_index,
129 column_index, is_inverse;
130
131 tag.read_from_stream(is_xml);
132 tag.check_name("CovarianceMatrix");
133 tag.get_attribute_value("n_blocks", n_blocks);
134
135 covmat = CovarianceMatrix();
136 for (Index i = 0; i < n_blocks; i++) {
137 tag.read_from_stream(is_xml);
138 tag.check_name("Block");
139
140 tag.get_attribute_value("row_index", row_index);
141 tag.get_attribute_value("column_index", column_index);
142 tag.get_attribute_value("row_start", row_start);
143 tag.get_attribute_value("row_extent", row_extent);
144 tag.get_attribute_value("column_start", column_start);
145 tag.get_attribute_value("column_extent", column_extent);
146 tag.get_attribute_value("type", type);
147 tag.get_attribute_value("is_inverse", is_inverse);
148
149 Range row_range(row_start, row_extent);
150 Range column_range(column_start, column_extent);
151 if (type == "Matrix") {
152 std::shared_ptr<Matrix> M =
153 std::make_shared<Matrix>(row_extent, column_extent);
154 xml_read_from_stream(is_xml, *M, pbifs, verbosity);
155 if (!is_inverse) {
156 covmat.correlations_.emplace_back(
157 row_range,
158 column_range,
159 std::make_pair(row_index, column_index),
160 M);
161 } else {
162 covmat.inverses_.emplace_back(row_range,
163 column_range,
164 std::make_pair(row_index, column_index),
165 M);
166 }
167 } else if (type == "Sparse") {
168 std::shared_ptr<Sparse> M =
169 std::make_shared<Sparse>(row_extent, column_extent);
170 xml_read_from_stream(is_xml, *M, pbifs, verbosity);
171 if (!is_inverse) {
172 covmat.correlations_.emplace_back(
173 row_range,
174 column_range,
175 std::make_pair(row_index, column_index),
176 M);
177 } else {
178 covmat.inverses_.emplace_back(row_range,
179 column_range,
180 std::make_pair(row_index, column_index),
181 M);
182 }
183 }
184 tag.read_from_stream(is_xml);
185 tag.check_name("/Block");
186 }
187 tag.read_from_stream(is_xml);
188 tag.check_name("/CovarianceMatrix");
189}
190
191//=== CovarianceMatrix =========================================================
192
194
201void xml_write_to_stream(ostream& os_xml,
202 const CovarianceMatrix& covmat,
203 bofstream* pbofs,
204 const String& name _U_,
205 const Verbosity& verbosity) {
206 ArtsXMLTag covmat_tag(verbosity);
207 ArtsXMLTag close_tag(verbosity);
208
209 covmat_tag.set_name("CovarianceMatrix");
210 covmat_tag.add_attribute(
211 "n_blocks", Index(covmat.correlations_.size() + covmat.inverses_.size()));
212 covmat_tag.write_to_stream(os_xml);
213 os_xml << '\n';
214 for (const Block& c : covmat.correlations_) {
215 ArtsXMLTag block_tag(verbosity);
216 block_tag.set_name("Block");
217
218 Index i, j;
219 std::tie(i, j) = c.get_indices();
220 block_tag.add_attribute("row_index", i);
221 block_tag.add_attribute("column_index", j);
222
223 Range row_range = c.get_row_range();
224 Range column_range = c.get_column_range();
225 block_tag.add_attribute("row_start", row_range.get_start());
226 block_tag.add_attribute("row_extent", row_range.get_extent());
227 block_tag.add_attribute("column_start", column_range.get_start());
228 block_tag.add_attribute("column_extent", column_range.get_extent());
229 block_tag.add_attribute("is_inverse", Index(0));
230 if (c.get_matrix_type() == Block::MatrixType::dense) {
231 block_tag.add_attribute("type", "Matrix");
232 block_tag.write_to_stream(os_xml);
233 os_xml << '\n';
234 xml_write_to_stream(os_xml, c.get_dense(), pbofs, name, verbosity);
235 } else {
236 block_tag.add_attribute("type", "Sparse");
237 block_tag.write_to_stream(os_xml);
238 os_xml << '\n';
239 xml_write_to_stream(os_xml, c.get_sparse(), pbofs, name, verbosity);
240 }
241 close_tag.set_name("/Block");
242 close_tag.write_to_stream(os_xml);
243 os_xml << '\n';
244 }
245 for (const Block& c : covmat.inverses_) {
246 ArtsXMLTag block_tag(verbosity);
247 block_tag.set_name("Block");
248
249 Index i, j;
250 std::tie(i, j) = c.get_indices();
251 block_tag.add_attribute("row_index", i);
252 block_tag.add_attribute("column_index", j);
253
254 Range row_range = c.get_row_range();
255 Range column_range = c.get_column_range();
256 block_tag.add_attribute("row_start", row_range.get_start());
257 block_tag.add_attribute("row_extent", row_range.get_extent());
258 block_tag.add_attribute("column_start", column_range.get_start());
259 block_tag.add_attribute("column_extent", column_range.get_extent());
260 block_tag.add_attribute("is_inverse", Index(1));
261 if (c.get_matrix_type() == Block::MatrixType::dense) {
262 block_tag.add_attribute("type", "Matrix");
263 block_tag.write_to_stream(os_xml);
264 os_xml << '\n';
265 xml_write_to_stream(os_xml, c.get_dense(), pbofs, name, verbosity);
266 } else {
267 block_tag.add_attribute("type", "Sparse");
268 block_tag.write_to_stream(os_xml);
269 os_xml << '\n';
270 xml_write_to_stream(os_xml, c.get_sparse(), pbofs, name, verbosity);
271 }
272 close_tag.set_name("/Block");
273 close_tag.write_to_stream(os_xml);
274 os_xml << '\n';
275 }
276 os_xml << '\n';
277 close_tag.set_name("/CovarianceMatrix");
278 close_tag.write_to_stream(os_xml);
279}
280
281//=== EnergyLevelMap ===========================================================
282
284
289void xml_read_from_stream(istream& is_xml,
290 EnergyLevelMap& elm,
291 bifstream* pbifs,
292 const Verbosity& verbosity) {
293 ArtsXMLTag tag(verbosity);
294
295 tag.read_from_stream(is_xml);
296
297 tag.check_name("EnergyLevelMap");
298 String type;
299 tag.get_attribute_value("type", type);
301
302 xml_read_from_stream(is_xml, elm.levels, pbifs, verbosity);
303 xml_read_from_stream(is_xml, elm.value, pbifs, verbosity);
304 xml_read_from_stream(is_xml, elm.vib_energy, pbifs, verbosity);
305
306 tag.read_from_stream(is_xml);
307 tag.check_name("/EnergyLevelMap");
308
309 elm.ThrowIfNotOK();
310}
311
313
319void xml_write_to_stream(ostream& os_xml,
320 const EnergyLevelMap& elm,
321 bofstream* pbofs,
322 const String& name,
323 const Verbosity& verbosity) {
324 ArtsXMLTag open_tag(verbosity);
325 ArtsXMLTag close_tag(verbosity);
326
327 open_tag.set_name("EnergyLevelMap");
328 if (name.length()) open_tag.add_attribute("name", name);
329 open_tag.add_attribute("type", toString(elm.type));
330 open_tag.write_to_stream(os_xml);
331
332 xml_write_to_stream(os_xml, elm.levels, pbofs, "Energy Levels", verbosity);
333 xml_write_to_stream(os_xml, elm.value, pbofs, "Level Data", verbosity);
334 xml_write_to_stream(os_xml, elm.vib_energy, pbofs, "Level Energy", verbosity);
335
336 close_tag.set_name("/EnergyLevelMap");
337 close_tag.write_to_stream(os_xml);
338 os_xml << '\n';
339}
340
341//=== GasAbsLookup ===========================================================
342
344
349void xml_read_from_stream(istream& is_xml,
350 GasAbsLookup& gal,
351 bifstream* pbifs,
352 const Verbosity& verbosity) {
353 ArtsXMLTag tag(verbosity);
354
355 tag.read_from_stream(is_xml);
356 tag.check_name("GasAbsLookup");
357
358 xml_read_from_stream(is_xml, gal.species, pbifs, verbosity);
359 xml_read_from_stream(is_xml, gal.nonlinear_species, pbifs, verbosity);
360 xml_read_from_stream(is_xml, gal.f_grid, pbifs, verbosity);
361 xml_read_from_stream(is_xml, gal.p_grid, pbifs, verbosity);
362 xml_read_from_stream(is_xml, gal.vmrs_ref, pbifs, verbosity);
363 xml_read_from_stream(is_xml, gal.t_ref, pbifs, verbosity);
364 xml_read_from_stream(is_xml, gal.t_pert, pbifs, verbosity);
365 xml_read_from_stream(is_xml, gal.nls_pert, pbifs, verbosity);
366 xml_read_from_stream(is_xml, gal.xsec, pbifs, verbosity);
367
368 tag.read_from_stream(is_xml);
369 tag.check_name("/GasAbsLookup");
370}
371
373
379void xml_write_to_stream(ostream& os_xml,
380 const GasAbsLookup& gal,
381 bofstream* pbofs,
382 const String& name,
383 const Verbosity& verbosity) {
384 ArtsXMLTag open_tag(verbosity);
385 ArtsXMLTag close_tag(verbosity);
386
387 open_tag.set_name("GasAbsLookup");
388 if (name.length()) open_tag.add_attribute("name", name);
389 open_tag.write_to_stream(os_xml);
390
391 xml_write_to_stream(os_xml, gal.species, pbofs, "", verbosity);
393 os_xml, gal.nonlinear_species, pbofs, "NonlinearSpecies", verbosity);
394 xml_write_to_stream(os_xml, gal.f_grid, pbofs, "FrequencyGrid", verbosity);
395 xml_write_to_stream(os_xml, gal.p_grid, pbofs, "PressureGrid", verbosity);
397 os_xml, gal.vmrs_ref, pbofs, "ReferenceVmrProfiles", verbosity);
399 os_xml, gal.t_ref, pbofs, "ReferenceTemperatureProfile", verbosity);
401 os_xml, gal.t_pert, pbofs, "TemperaturePerturbations", verbosity);
402 xml_write_to_stream(os_xml,
403 gal.nls_pert,
404 pbofs,
405 "NonlinearSpeciesVmrPerturbations",
406 verbosity);
408 os_xml, gal.xsec, pbofs, "AbsorptionCrossSections", verbosity);
409
410 close_tag.set_name("/GasAbsLookup");
411 close_tag.write_to_stream(os_xml);
412 os_xml << '\n';
413}
414
415//=== GriddedField ===========================================================
416
418
423void xml_read_from_stream(istream& is_xml,
424 GriddedField& gfield,
425 bifstream* pbifs,
426 const Verbosity& verbosity) {
427 XMLTag tag(verbosity);
428
429 for (Index i = 0; i < gfield.get_dim(); i++) {
430 tag.read_from_stream(is_xml);
431 if (tag.get_name() == "Vector") {
432 String s;
433 tag.get_attribute_value("name", s);
434 if (s.length()) gfield.set_grid_name(i, s);
435
436 Vector v;
437 xml_parse_from_stream(is_xml, v, pbifs, tag, verbosity);
438 gfield.set_grid(i, v);
439 tag.read_from_stream(is_xml);
440 tag.check_name("/Vector");
441 } else if (tag.get_name() == "Array") {
442 String s;
443 tag.get_attribute_value("name", s);
444 if (s.length()) gfield.set_grid_name(i, s);
445
446 tag.get_attribute_value("type", s);
447 if (s == "String") {
448 ArrayOfString as;
449 xml_parse_from_stream(is_xml, as, pbifs, tag, verbosity);
450 gfield.set_grid(i, as);
451 tag.read_from_stream(is_xml);
452 tag.check_name("/Array");
453
454 } else {
456 "Grids must be of type *Vector* or *ArrayOfString*\n"
457 "but *ArrayOf" +
458 s + "* found.");
459 }
460 } else {
461 ostringstream os;
462 os << "Grids must be of type *Vector* or *ArrayOfString*\n"
463 << "but tag <" + tag.get_name() + "> found.";
464 if (tag.get_name() == "ArrayOfString")
465 os << "\nCorrect XML tag for *ArrayOfString* is <Array type=\"String\" ...>.";
466 xml_parse_error(os.str());
467 }
468 }
469}
470
472
477void xml_write_to_stream(ostream& os_xml,
478 const GriddedField& gfield,
479 bofstream* pbofs,
480 const String& /* name */,
481 const Verbosity& verbosity) {
482 for (Index i = 0; i < gfield.get_dim(); i++) {
483 switch (gfield.get_grid_type(i)) {
485 xml_write_to_stream(os_xml,
486 gfield.get_numeric_grid(i),
487 pbofs,
488 gfield.get_grid_name(i),
489 verbosity);
490 break;
491 case GRID_TYPE_STRING:
492 xml_write_to_stream(os_xml,
493 gfield.get_string_grid(i),
494 pbofs,
495 gfield.get_grid_name(i),
496 verbosity);
497 break;
498 }
499 }
500}
501
502//=== GriddedField1 ===========================================================
503
505
510void xml_read_from_stream(istream& is_xml,
511 GriddedField1& gfield,
512 bifstream* pbifs,
513 const Verbosity& verbosity) {
514 ArtsXMLTag tag(verbosity);
515
516 tag.read_from_stream(is_xml);
517 tag.check_name("GriddedField1");
518
519 String s;
520 tag.get_attribute_value("name", s);
521 if (s.length()) gfield.set_name(s);
522
523 xml_read_from_stream(is_xml, *((GriddedField*)&gfield), pbifs, verbosity);
524 xml_read_from_stream(is_xml, gfield.data, pbifs, verbosity);
525
526 tag.read_from_stream(is_xml);
527 tag.check_name("/GriddedField1");
528
529 gfield.checksize_strict();
530}
531
533
539void xml_write_to_stream(ostream& os_xml,
540 const GriddedField1& gfield,
541 bofstream* pbofs,
542 const String& name,
543 const Verbosity& verbosity) {
544 ArtsXMLTag open_tag(verbosity);
545 ArtsXMLTag close_tag(verbosity);
546
547 open_tag.set_name("GriddedField1");
548 if (!name.length() && (gfield.get_name().length()))
549 open_tag.add_attribute("name", gfield.get_name());
550 else if (name.length())
551 open_tag.add_attribute("name", name);
552
553 open_tag.write_to_stream(os_xml);
554 os_xml << '\n';
555
556 xml_write_to_stream(os_xml, *((GriddedField*)&gfield), pbofs, "", verbosity);
557 xml_write_to_stream(os_xml, gfield.data, pbofs, "Data", verbosity);
558
559 close_tag.set_name("/GriddedField1");
560 close_tag.write_to_stream(os_xml);
561 os_xml << '\n';
562}
563
564//=== GriddedField2 ===========================================================
565
567
572void xml_read_from_stream(istream& is_xml,
573 GriddedField2& gfield,
574 bifstream* pbifs,
575 const Verbosity& verbosity) {
576 ArtsXMLTag tag(verbosity);
577
578 tag.read_from_stream(is_xml);
579 tag.check_name("GriddedField2");
580
581 String s;
582 tag.get_attribute_value("name", s);
583 if (s.length()) gfield.set_name(s);
584
585 xml_read_from_stream(is_xml, *((GriddedField*)&gfield), pbifs, verbosity);
586 xml_read_from_stream(is_xml, gfield.data, pbifs, verbosity);
587
588 tag.read_from_stream(is_xml);
589 tag.check_name("/GriddedField2");
590
591 gfield.checksize_strict();
592}
593
595
601void xml_write_to_stream(ostream& os_xml,
602 const GriddedField2& gfield,
603 bofstream* pbofs,
604 const String& name,
605 const Verbosity& verbosity) {
606 ArtsXMLTag open_tag(verbosity);
607 ArtsXMLTag close_tag(verbosity);
608
609 open_tag.set_name("GriddedField2");
610 if (!name.length() && (gfield.get_name().length()))
611 open_tag.add_attribute("name", gfield.get_name());
612 else if (name.length())
613 open_tag.add_attribute("name", name);
614
615 open_tag.write_to_stream(os_xml);
616 os_xml << '\n';
617
618 xml_write_to_stream(os_xml, *((GriddedField*)&gfield), pbofs, "", verbosity);
619 xml_write_to_stream(os_xml, gfield.data, pbofs, "Data", verbosity);
620
621 close_tag.set_name("/GriddedField2");
622 close_tag.write_to_stream(os_xml);
623 os_xml << '\n';
624}
625
626//=== GriddedField3 ===========================================================
627
629
634void xml_read_from_stream(istream& is_xml,
635 GriddedField3& gfield,
636 bifstream* pbifs,
637 const Verbosity& verbosity) {
638 ArtsXMLTag tag(verbosity);
639
640 tag.read_from_stream(is_xml);
641 tag.check_name("GriddedField3");
642
643 String s;
644 tag.get_attribute_value("name", s);
645 if (s.length()) gfield.set_name(s);
646
647 xml_read_from_stream(is_xml, *((GriddedField*)&gfield), pbifs, verbosity);
648 xml_read_from_stream(is_xml, gfield.data, pbifs, verbosity);
649
650 tag.read_from_stream(is_xml);
651 tag.check_name("/GriddedField3");
652
653 gfield.checksize_strict();
654}
655
657
663void xml_write_to_stream(ostream& os_xml,
664 const GriddedField3& gfield,
665 bofstream* pbofs,
666 const String& name,
667 const Verbosity& verbosity) {
668 ArtsXMLTag open_tag(verbosity);
669 ArtsXMLTag close_tag(verbosity);
670
671 open_tag.set_name("GriddedField3");
672 if (!name.length() && (gfield.get_name().length()))
673 open_tag.add_attribute("name", gfield.get_name());
674 else if (name.length())
675 open_tag.add_attribute("name", name);
676
677 open_tag.write_to_stream(os_xml);
678 os_xml << '\n';
679
680 xml_write_to_stream(os_xml, *((GriddedField*)&gfield), pbofs, "", verbosity);
681 xml_write_to_stream(os_xml, gfield.data, pbofs, "Data", verbosity);
682
683 close_tag.set_name("/GriddedField3");
684 close_tag.write_to_stream(os_xml);
685 os_xml << '\n';
686}
687
688//=== GriddedField4 ===========================================================
689
691
696void xml_read_from_stream(istream& is_xml,
697 GriddedField4& gfield,
698 bifstream* pbifs,
699 const Verbosity& verbosity) {
700 ArtsXMLTag tag(verbosity);
701
702 tag.read_from_stream(is_xml);
703 tag.check_name("GriddedField4");
704
705 String s;
706 tag.get_attribute_value("name", s);
707 if (s.length()) gfield.set_name(s);
708
709 xml_read_from_stream(is_xml, *((GriddedField*)&gfield), pbifs, verbosity);
710 xml_read_from_stream(is_xml, gfield.data, pbifs, verbosity);
711
712 tag.read_from_stream(is_xml);
713 tag.check_name("/GriddedField4");
714
715 gfield.checksize_strict();
716}
717
719
725void xml_write_to_stream(ostream& os_xml,
726 const GriddedField4& gfield,
727 bofstream* pbofs,
728 const String& name,
729 const Verbosity& verbosity) {
730 ArtsXMLTag open_tag(verbosity);
731 ArtsXMLTag close_tag(verbosity);
732
733 open_tag.set_name("GriddedField4");
734 if (!name.length() && (gfield.get_name().length()))
735 open_tag.add_attribute("name", gfield.get_name());
736 else if (name.length())
737 open_tag.add_attribute("name", name);
738
739 open_tag.write_to_stream(os_xml);
740 os_xml << '\n';
741
742 xml_write_to_stream(os_xml, *((GriddedField*)&gfield), pbofs, "", verbosity);
743 xml_write_to_stream(os_xml, gfield.data, pbofs, "Data", verbosity);
744
745 close_tag.set_name("/GriddedField4");
746 close_tag.write_to_stream(os_xml);
747 os_xml << '\n';
748}
749
750//=== GriddedField5 ===========================================================
751
753
758void xml_read_from_stream(istream& is_xml,
759 GriddedField5& gfield,
760 bifstream* pbifs,
761 const Verbosity& verbosity) {
762 ArtsXMLTag tag(verbosity);
763
764 tag.read_from_stream(is_xml);
765 tag.check_name("GriddedField5");
766
767 String s;
768 tag.get_attribute_value("name", s);
769 if (s.length()) gfield.set_name(s);
770
771 xml_read_from_stream(is_xml, *((GriddedField*)&gfield), pbifs, verbosity);
772 xml_read_from_stream(is_xml, gfield.data, pbifs, verbosity);
773
774 tag.read_from_stream(is_xml);
775 tag.check_name("/GriddedField5");
776
777 gfield.checksize_strict();
778}
779
781
787void xml_write_to_stream(ostream& os_xml,
788 const GriddedField5& gfield,
789 bofstream* pbofs,
790 const String& name,
791 const Verbosity& verbosity) {
792 ArtsXMLTag open_tag(verbosity);
793 ArtsXMLTag close_tag(verbosity);
794
795 open_tag.set_name("GriddedField5");
796 if (!name.length() && (gfield.get_name().length()))
797 open_tag.add_attribute("name", gfield.get_name());
798 else if (name.length())
799 open_tag.add_attribute("name", name);
800
801 open_tag.write_to_stream(os_xml);
802 os_xml << '\n';
803
804 xml_write_to_stream(os_xml, *((GriddedField*)&gfield), pbofs, "", verbosity);
805 xml_write_to_stream(os_xml, gfield.data, pbofs, "Data", verbosity);
806
807 close_tag.set_name("/GriddedField5");
808 close_tag.write_to_stream(os_xml);
809 os_xml << '\n';
810}
811
812//=== GriddedField6 ===========================================================
813
815
820void xml_read_from_stream(istream& is_xml,
821 GriddedField6& gfield,
822 bifstream* pbifs,
823 const Verbosity& verbosity) {
824 ArtsXMLTag tag(verbosity);
825
826 tag.read_from_stream(is_xml);
827 tag.check_name("GriddedField6");
828
829 String s;
830 tag.get_attribute_value("name", s);
831 if (s.length()) gfield.set_name(s);
832
833 xml_read_from_stream(is_xml, *((GriddedField*)&gfield), pbifs, verbosity);
834 xml_read_from_stream(is_xml, gfield.data, pbifs, verbosity);
835
836 tag.read_from_stream(is_xml);
837 tag.check_name("/GriddedField6");
838
839 gfield.checksize_strict();
840}
841
843
849void xml_write_to_stream(ostream& os_xml,
850 const GriddedField6& gfield,
851 bofstream* pbofs,
852 const String& name,
853 const Verbosity& verbosity) {
854 ArtsXMLTag open_tag(verbosity);
855 ArtsXMLTag close_tag(verbosity);
856
857 open_tag.set_name("GriddedField6");
858 if (!name.length() && (gfield.get_name().length()))
859 open_tag.add_attribute("name", gfield.get_name());
860 else if (name.length())
861 open_tag.add_attribute("name", name);
862
863 open_tag.write_to_stream(os_xml);
864 os_xml << '\n';
865
866 xml_write_to_stream(os_xml, *((GriddedField*)&gfield), pbofs, "", verbosity);
867 xml_write_to_stream(os_xml, gfield.data, pbofs, "Data", verbosity);
868
869 close_tag.set_name("/GriddedField6");
870 close_tag.write_to_stream(os_xml);
871 os_xml << '\n';
872}
873
874//=== GridPos =====================================================
875
877
882void xml_read_from_stream(istream& is_xml,
883 GridPos& gpos,
884 bifstream* pbifs,
885 const Verbosity& verbosity) {
886 ArtsXMLTag tag(verbosity);
887
888 tag.read_from_stream(is_xml);
889 tag.check_name("GridPos");
890
891 xml_read_from_stream(is_xml, gpos.idx, pbifs, verbosity);
892 xml_read_from_stream(is_xml, gpos.fd[0], pbifs, verbosity);
893 xml_read_from_stream(is_xml, gpos.fd[1], pbifs, verbosity);
894
895 tag.read_from_stream(is_xml);
896 tag.check_name("/GridPos");
897}
898
900
906void xml_write_to_stream(ostream& os_xml,
907 const GridPos& gpos,
908 bofstream* pbofs,
909 const String& name,
910 const Verbosity& verbosity) {
911 ArtsXMLTag open_tag(verbosity);
912 ArtsXMLTag close_tag(verbosity);
913
914 open_tag.set_name("GridPos");
915 if (name.length()) open_tag.add_attribute("name", name);
916 open_tag.write_to_stream(os_xml);
917
918 xml_write_to_stream(os_xml,
919 gpos.idx,
920 pbofs,
921 "OriginalGridIndexBelowInterpolationPoint",
922 verbosity);
924 os_xml, gpos.fd[0], pbofs, "FractionalDistanceToNextPoint_1", verbosity);
926 os_xml, gpos.fd[1], pbofs, "FractionalDistanceToNextPoint_2", verbosity);
927
928 close_tag.set_name("/GridPos");
929 close_tag.write_to_stream(os_xml);
930 os_xml << '\n';
931}
932
933//=== HitranRelaxationMatrixData ================================================
934
936
941void xml_read_from_stream(istream& is_xml,
943 bifstream* pbifs,
944 const Verbosity& verbosity) {
945 ArtsXMLTag tag(verbosity);
946
947 tag.read_from_stream(is_xml);
948 tag.check_name("HitranRelaxationMatrixData");
949
950 xml_read_from_stream(is_xml, hitran.W0pp, pbifs, verbosity);
951 xml_read_from_stream(is_xml, hitran.B0pp, pbifs, verbosity);
952 xml_read_from_stream(is_xml, hitran.W0rp, pbifs, verbosity);
953 xml_read_from_stream(is_xml, hitran.B0rp, pbifs, verbosity);
954 xml_read_from_stream(is_xml, hitran.W0qp, pbifs, verbosity);
955 xml_read_from_stream(is_xml, hitran.B0qp, pbifs, verbosity);
956 xml_read_from_stream(is_xml, hitran.W0pr, pbifs, verbosity);
957 xml_read_from_stream(is_xml, hitran.B0pr, pbifs, verbosity);
958 xml_read_from_stream(is_xml, hitran.W0rr, pbifs, verbosity);
959 xml_read_from_stream(is_xml, hitran.B0rr, pbifs, verbosity);
960 xml_read_from_stream(is_xml, hitran.W0qr, pbifs, verbosity);
961 xml_read_from_stream(is_xml, hitran.B0qr, pbifs, verbosity);
962 xml_read_from_stream(is_xml, hitran.W0pq, pbifs, verbosity);
963 xml_read_from_stream(is_xml, hitran.B0pq, pbifs, verbosity);
964 xml_read_from_stream(is_xml, hitran.W0rq, pbifs, verbosity);
965 xml_read_from_stream(is_xml, hitran.B0rq, pbifs, verbosity);
966 xml_read_from_stream(is_xml, hitran.W0qq, pbifs, verbosity);
967 xml_read_from_stream(is_xml, hitran.B0qq, pbifs, verbosity);
968
969 tag.read_from_stream(is_xml);
970 tag.check_name("/HitranRelaxationMatrixData");
971}
972
974
980void xml_write_to_stream(ostream& os_xml,
981 const HitranRelaxationMatrixData& hitran,
982 bofstream* pbofs,
983 const String& name,
984 const Verbosity& verbosity) {
985 ArtsXMLTag open_tag(verbosity);
986 ArtsXMLTag close_tag(verbosity);
987
988 open_tag.set_name("HitranRelaxationMatrixData");
989 if (name.length()) open_tag.add_attribute("name", name);
990 open_tag.write_to_stream(os_xml);
991 os_xml << '\n';
992
993 xml_write_to_stream(os_xml, hitran.W0pp, pbofs, "W0pp", verbosity);
994 xml_write_to_stream(os_xml, hitran.B0pp, pbofs, "B0pp", verbosity);
995 xml_write_to_stream(os_xml, hitran.W0rp, pbofs, "W0rp", verbosity);
996 xml_write_to_stream(os_xml, hitran.B0rp, pbofs, "B0rp", verbosity);
997 xml_write_to_stream(os_xml, hitran.W0qp, pbofs, "W0qp", verbosity);
998 xml_write_to_stream(os_xml, hitran.B0qp, pbofs, "B0qp", verbosity);
999 xml_write_to_stream(os_xml, hitran.W0pr, pbofs, "W0pr", verbosity);
1000 xml_write_to_stream(os_xml, hitran.B0pr, pbofs, "B0pr", verbosity);
1001 xml_write_to_stream(os_xml, hitran.W0rr, pbofs, "W0rr", verbosity);
1002 xml_write_to_stream(os_xml, hitran.B0rr, pbofs, "B0rr", verbosity);
1003 xml_write_to_stream(os_xml, hitran.W0qr, pbofs, "W0qr", verbosity);
1004 xml_write_to_stream(os_xml, hitran.B0qr, pbofs, "B0qr", verbosity);
1005 xml_write_to_stream(os_xml, hitran.W0pq, pbofs, "W0pq", verbosity);
1006 xml_write_to_stream(os_xml, hitran.B0pq, pbofs, "B0pq", verbosity);
1007 xml_write_to_stream(os_xml, hitran.W0rq, pbofs, "W0rq", verbosity);
1008 xml_write_to_stream(os_xml, hitran.B0rq, pbofs, "B0rq", verbosity);
1009 xml_write_to_stream(os_xml, hitran.W0qq, pbofs, "W0qq", verbosity);
1010 xml_write_to_stream(os_xml, hitran.B0qq, pbofs, "B0qq", verbosity);
1011
1012 close_tag.set_name("/HitranRelaxationMatrixData");
1013 close_tag.write_to_stream(os_xml);
1014 os_xml << '\n';
1015}
1016
1017//=== Ppath =====================================================
1018
1020
1025void xml_read_from_stream(istream& is_xml,
1026 Ppath& ppath,
1027 bifstream* pbifs,
1028 const Verbosity& verbosity) {
1029 ArtsXMLTag tag(verbosity);
1030
1031 tag.read_from_stream(is_xml);
1032 tag.check_name("Ppath");
1033
1034 xml_read_from_stream(is_xml, ppath.dim, pbifs, verbosity);
1035 xml_read_from_stream(is_xml, ppath.np, pbifs, verbosity);
1036 xml_read_from_stream(is_xml, ppath.constant, pbifs, verbosity);
1037 xml_read_from_stream(is_xml, ppath.background, pbifs, verbosity);
1038 xml_read_from_stream(is_xml, ppath.start_pos, pbifs, verbosity);
1039 xml_read_from_stream(is_xml, ppath.start_los, pbifs, verbosity);
1040 xml_read_from_stream(is_xml, ppath.start_lstep, pbifs, verbosity);
1041 xml_read_from_stream(is_xml, ppath.pos, pbifs, verbosity);
1042 xml_read_from_stream(is_xml, ppath.los, pbifs, verbosity);
1043 xml_read_from_stream(is_xml, ppath.r, pbifs, verbosity);
1044 xml_read_from_stream(is_xml, ppath.lstep, pbifs, verbosity);
1045 xml_read_from_stream(is_xml, ppath.end_pos, pbifs, verbosity);
1046 xml_read_from_stream(is_xml, ppath.end_los, pbifs, verbosity);
1047 xml_read_from_stream(is_xml, ppath.end_lstep, pbifs, verbosity);
1048 xml_read_from_stream(is_xml, ppath.nreal, pbifs, verbosity);
1049 xml_read_from_stream(is_xml, ppath.ngroup, pbifs, verbosity);
1050 xml_read_from_stream(is_xml, ppath.gp_p, pbifs, verbosity);
1051 xml_read_from_stream(is_xml, ppath.gp_lat, pbifs, verbosity);
1052 xml_read_from_stream(is_xml, ppath.gp_lon, pbifs, verbosity);
1053
1054 tag.read_from_stream(is_xml);
1055 tag.check_name("/Ppath");
1056}
1057
1059
1065void xml_write_to_stream(ostream& os_xml,
1066 const Ppath& ppath,
1067 bofstream* pbofs,
1068 const String& name,
1069 const Verbosity& verbosity) {
1070 ArtsXMLTag open_tag(verbosity);
1071 ArtsXMLTag close_tag(verbosity);
1072
1073 open_tag.set_name("Ppath");
1074 if (name.length()) open_tag.add_attribute("name", name);
1075 open_tag.write_to_stream(os_xml);
1076
1078 os_xml, ppath.dim, pbofs, "AtmosphericDimensionality", verbosity);
1080 os_xml, ppath.np, pbofs, "NumberOfPositionInPropagationPath", verbosity);
1082 os_xml, ppath.constant, pbofs, "PropagationPathConstant", verbosity);
1084 os_xml, ppath.background, pbofs, "RadiativeBackground", verbosity);
1085 xml_write_to_stream(os_xml,
1086 ppath.start_pos,
1087 pbofs,
1088 "StartPositionOfPropagationPath",
1089 verbosity);
1091 os_xml, ppath.start_los, pbofs, "StartLOSOfPropagationPath", verbosity);
1092 xml_write_to_stream(os_xml,
1093 ppath.start_lstep,
1094 pbofs,
1095 "StartLstepOfPropagationPath",
1096 verbosity);
1098 os_xml, ppath.pos, pbofs, "PropagationPathPointPositions", verbosity);
1099 xml_write_to_stream(os_xml, ppath.los, pbofs, "LineOfSight", verbosity);
1101 os_xml, ppath.r, pbofs, "PropagationPathPointRadii", verbosity);
1103 os_xml, ppath.lstep, pbofs, "PropagationPathPositionLength", verbosity);
1105 os_xml, ppath.end_pos, pbofs, "EndPositionOfPropagationPath", verbosity);
1107 os_xml, ppath.end_los, pbofs, "EndLOSOfPropagationPath", verbosity);
1109 os_xml, ppath.end_lstep, pbofs, "EndLstepPropagationPath", verbosity);
1111 os_xml, ppath.nreal, pbofs, "RefractiveIndexRealPart", verbosity);
1113 os_xml, ppath.ngroup, pbofs, "GroupRefractiveIndex", verbosity);
1115 os_xml, ppath.gp_p, pbofs, "PressureGridIndexPosition", verbosity);
1117 os_xml, ppath.gp_lat, pbofs, "LatitudeGridIndexPosition", verbosity);
1119 os_xml, ppath.gp_lon, pbofs, "LongitudeGridIndexPosition", verbosity);
1120
1121 close_tag.set_name("/Ppath");
1122 close_tag.write_to_stream(os_xml);
1123 os_xml << '\n';
1124}
1125
1126//=== PropagationMatrix ======================================================
1127
1129
1134void xml_read_from_stream(istream& is_xml,
1136 bifstream* pbifs,
1137 const Verbosity& verbosity) {
1138 ArtsXMLTag tag(verbosity);
1139
1140 tag.read_from_stream(is_xml);
1141 tag.check_name("PropagationMatrix");
1142
1143 try {
1144 Tensor4 d;
1145 xml_read_from_stream(is_xml, d, pbifs, verbosity);
1146 Index naa = d.nbooks();
1147 Index nza = d.npages();
1148 Index nf = d.nrows();
1149 Index nstokes_needed = d.ncols();
1150 pm = PropagationMatrix(nf, need2stokes<true>(nstokes_needed), nza, naa);
1151 pm.Data() = std::move(d); // destructive takeover
1152 } catch (const std::runtime_error& e) {
1153 ostringstream os;
1154 os << "Error reading PropagationMatrix: "
1155 << "\n"
1156 << e.what();
1157 throw runtime_error(os.str());
1158 }
1159
1160 tag.read_from_stream(is_xml);
1161 tag.check_name("/PropagationMatrix");
1162}
1163
1165
1171void xml_write_to_stream(ostream& os_xml,
1172 const PropagationMatrix& pm,
1173 bofstream* pbofs,
1174 const String& name,
1175 const Verbosity& verbosity) {
1176 ArtsXMLTag open_tag(verbosity);
1177 ArtsXMLTag close_tag(verbosity);
1178
1179 open_tag.set_name("PropagationMatrix");
1180 if (name.length()) open_tag.add_attribute("name", name);
1181
1182 open_tag.write_to_stream(os_xml);
1183 os_xml << '\n';
1184
1185 xml_write_to_stream(os_xml, pm.Data(), pbofs, "", verbosity);
1186
1187 close_tag.set_name("/PropagationMatrix");
1188 close_tag.write_to_stream(os_xml);
1189
1190 os_xml << '\n';
1191}
1192
1193//=== QuantumIdentifier =========================================
1194
1196
1201void xml_read_from_stream(istream& is_xml,
1203 bifstream* pbifs _U_,
1204 const Verbosity& verbosity) {
1205 static_assert(QuantumIdentifier::version == 1);
1206
1207 ArtsXMLTag tag(verbosity);
1208
1209 tag.read_from_stream(is_xml);
1210 tag.check_name("QuantumIdentifier");
1211
1212 Index version;
1213 if (tag.has_attribute("version")) {
1214 tag.get_attribute_value("version", version);
1215 } else {
1216 version = 0;
1217 }
1220 "The version of this quantum identifier is too new. You need to upgrade ARTS to use it.")
1221
1222 try {
1223 String qi_str;
1224 parse_xml_tag_content_as_string(is_xml, qi_str);
1225 qi = QuantumIdentifier(qi_str, version);
1226 } catch (const std::runtime_error& e) {
1227 ostringstream os;
1228 os << "Error reading QuantumIdentifier: "
1229 << "\n"
1230 << e.what();
1231 throw runtime_error(os.str());
1232 }
1233
1234 tag.read_from_stream(is_xml);
1235 tag.check_name("/QuantumIdentifier");
1236}
1237
1239
1245void xml_write_to_stream(ostream& os_xml,
1246 const QuantumIdentifier& qi,
1247 bofstream* pbofs _U_,
1248 const String& name,
1249 const Verbosity& verbosity) {
1250 ArtsXMLTag open_tag(verbosity);
1251 ArtsXMLTag close_tag(verbosity);
1252
1253 static_assert(QuantumIdentifier::version == 1);
1254
1255 open_tag.set_name("QuantumIdentifier");
1256 open_tag.add_attribute("version", QuantumIdentifier::version);
1257 if (name.length()) open_tag.add_attribute("name", name);
1258 open_tag.write_to_stream(os_xml);
1259
1260 os_xml << qi;
1261
1262 close_tag.set_name("/QuantumIdentifier");
1263 close_tag.write_to_stream(os_xml);
1264 os_xml << endl;
1265}
1266
1267//=== RetrievalQuantity =========================================
1268
1270
1275void xml_read_from_stream(istream& is_xml,
1277 bifstream* pbifs,
1278 const Verbosity& verbosity) {
1279 ArtsXMLTag tag(verbosity);
1280 Jacobian::Target target;
1281 String subtag;
1282 String subsubtag;
1283 String mode;
1284 ArrayOfVector grids;
1285
1286 tag.read_from_stream(is_xml);
1287 tag.check_name("RetrievalQuantity");
1288
1289 xml_read_from_stream(is_xml, target, pbifs, verbosity);
1290 xml_read_from_stream(is_xml, subtag, pbifs, verbosity);
1291 xml_read_from_stream(is_xml, subsubtag, pbifs, verbosity);
1292 xml_read_from_stream(is_xml, mode, pbifs, verbosity);
1293 xml_read_from_stream(is_xml, grids, pbifs, verbosity);
1294
1295 tag.read_from_stream(is_xml);
1296 tag.check_name("/RetrievalQuantity");
1297
1298 rq = RetrievalQuantity(
1299 target, subtag, subsubtag, mode, target.perturbation, grids);
1300}
1301
1303
1309void xml_write_to_stream(ostream& os_xml,
1310 const RetrievalQuantity& rq,
1311 bofstream* pbofs,
1312 const String& name,
1313 const Verbosity& verbosity) {
1314 ArtsXMLTag open_tag(verbosity);
1315 ArtsXMLTag close_tag(verbosity);
1316
1317 open_tag.set_name("RetrievalQuantity");
1318 if (name.length()) open_tag.add_attribute("name", name);
1319 open_tag.write_to_stream(os_xml);
1320
1321 xml_write_to_stream(os_xml, rq.Target(), pbofs, "", verbosity);
1322 xml_write_to_stream(os_xml, rq.Subtag(), pbofs, "Subtag", verbosity);
1323 xml_write_to_stream(os_xml, rq.SubSubtag(), pbofs, "SubSubtag", verbosity);
1324 xml_write_to_stream(os_xml, rq.Mode(), pbofs, "Mode", verbosity);
1325 xml_write_to_stream(os_xml, rq.Grids(), pbofs, "Grids", verbosity);
1326
1327 close_tag.set_name("/RetrievalQuantity");
1328 close_tag.write_to_stream(os_xml);
1329 os_xml << '\n';
1330}
1331
1332//=== SingleScatteringData ======================================
1333
1335
1340void xml_read_from_stream(istream& is_xml,
1341 SingleScatteringData& ssdata,
1342 bifstream* pbifs,
1343 const Verbosity& verbosity) {
1344 ArtsXMLTag tag(verbosity);
1345 String version;
1346
1347 tag.read_from_stream(is_xml);
1348 tag.check_name("SingleScatteringData");
1349 tag.get_attribute_value("version", version);
1350
1351 if (version == "3") {
1352 String ptype_string;
1353 xml_read_from_stream(is_xml, ptype_string, pbifs, verbosity);
1354 ssdata.ptype = PTypeFromString(ptype_string);
1355 } else if (version == "2") {
1356 String ptype_string;
1357 xml_read_from_stream(is_xml, ptype_string, pbifs, verbosity);
1358 ssdata.ptype = PType2FromString(ptype_string);
1359 } else {
1360 Index ptype;
1361 xml_read_from_stream(is_xml, ptype, pbifs, verbosity);
1362 if (ptype != PTYPE_GENERAL && ptype != PTYPE_TOTAL_RND &&
1363 ptype != PTYPE_AZIMUTH_RND) {
1364 ostringstream os;
1365 os << "Ptype value (" << ptype << ") is wrong."
1366 << "It must be \n"
1367 << PTYPE_TOTAL_RND << " - totally randomly oriented particles,\n"
1369 << " - azimuthally randomly oriented particles, or\n"
1370 << PTYPE_GENERAL << " - arbitrary oriented particles.\n";
1371 throw runtime_error(os.str());
1372 }
1373 ssdata.ptype = PType(ptype);
1374 }
1375 xml_read_from_stream(is_xml, ssdata.description, pbifs, verbosity);
1376 xml_read_from_stream(is_xml, ssdata.f_grid, pbifs, verbosity);
1377 xml_read_from_stream(is_xml, ssdata.T_grid, pbifs, verbosity);
1378 xml_read_from_stream(is_xml, ssdata.za_grid, pbifs, verbosity);
1379 /* Verify that we have a good coverage for the za grid */
1380 if ((ssdata.za_grid[0] > 1) ||
1381 ssdata.za_grid[ssdata.za_grid.nelem() - 1] < 179) {
1382 ostringstream os;
1383 os << "Missing data in xml-stream. Expected za_grid: [0, 180]. "
1384 << "Found za_grid: [" << ssdata.za_grid[0] << ", "
1385 << ssdata.za_grid[ssdata.za_grid.nelem() - 1] << "]";
1386 throw runtime_error(os.str());
1387 }
1388 xml_read_from_stream(is_xml, ssdata.aa_grid, pbifs, verbosity);
1389
1390 xml_read_from_stream(is_xml, ssdata.pha_mat_data, pbifs, verbosity);
1391 if (ssdata.pha_mat_data.nlibraries() != ssdata.f_grid.nelem()) {
1392 throw runtime_error(
1393 "Number of frequencies in f_grid and pha_mat_data "
1394 "not matching!!!");
1395 }
1396
1397 xml_read_from_stream(is_xml, ssdata.ext_mat_data, pbifs, verbosity);
1398 xml_read_from_stream(is_xml, ssdata.abs_vec_data, pbifs, verbosity);
1399
1400 tag.read_from_stream(is_xml);
1401 tag.check_name("/SingleScatteringData");
1402
1403 if (version != "3" && ssdata.ptype == PTYPE_AZIMUTH_RND) {
1405 }
1406
1407 chk_scat_data(ssdata, verbosity);
1408}
1409
1411
1417void xml_write_to_stream(ostream& os_xml,
1418 const SingleScatteringData& ssdata,
1419 bofstream* pbofs,
1420 const String& name,
1421 const Verbosity& verbosity) {
1422 ArtsXMLTag open_tag(verbosity);
1423 ArtsXMLTag close_tag(verbosity);
1424
1425 open_tag.set_name("SingleScatteringData");
1426 if (name.length()) open_tag.add_attribute("name", name);
1427 open_tag.add_attribute("version", "3");
1428 open_tag.write_to_stream(os_xml);
1429
1430 os_xml << '\n';
1432 os_xml, PTypeToString(ssdata.ptype), pbofs, "", verbosity);
1433 xml_write_to_stream(os_xml, ssdata.description, pbofs, "", verbosity);
1434 xml_write_to_stream(os_xml, ssdata.f_grid, pbofs, "", verbosity);
1435 xml_write_to_stream(os_xml, ssdata.T_grid, pbofs, "", verbosity);
1436 xml_write_to_stream(os_xml, ssdata.za_grid, pbofs, "", verbosity);
1437 xml_write_to_stream(os_xml, ssdata.aa_grid, pbofs, "", verbosity);
1438 xml_write_to_stream(os_xml, ssdata.pha_mat_data, pbofs, "", verbosity);
1439 xml_write_to_stream(os_xml, ssdata.ext_mat_data, pbofs, "", verbosity);
1440 xml_write_to_stream(os_xml, ssdata.abs_vec_data, pbofs, "", verbosity);
1441
1442 close_tag.set_name("/SingleScatteringData");
1443 close_tag.write_to_stream(os_xml);
1444 os_xml << '\n';
1445}
1446
1447//=== ScatteringMetaData ======================================
1448
1450
1455void xml_read_from_stream(istream& is_xml,
1456 ScatteringMetaData& smdata,
1457 bifstream* pbifs,
1458 const Verbosity& verbosity) {
1459 ArtsXMLTag tag(verbosity);
1460 String version;
1461
1462 tag.read_from_stream(is_xml);
1463 tag.check_name("ScatteringMetaData");
1464 tag.get_attribute_value("version", version);
1465
1466 if (version != "3") {
1467 ostringstream os;
1468 os << "Only ScatteringMetaData version 3 can be handled. "
1469 << "Versions 1 and 2 are obsolete.";
1470 throw runtime_error(os.str());
1471 }
1472
1473 xml_read_from_stream(is_xml, smdata.description, pbifs, verbosity);
1474 xml_read_from_stream(is_xml, smdata.source, pbifs, verbosity);
1475 xml_read_from_stream(is_xml, smdata.refr_index, pbifs, verbosity);
1476 xml_read_from_stream(is_xml, smdata.mass, pbifs, verbosity);
1477 xml_read_from_stream(is_xml, smdata.diameter_max, pbifs, verbosity);
1478 xml_read_from_stream(is_xml, smdata.diameter_volume_equ, pbifs, verbosity);
1480 is_xml, smdata.diameter_area_equ_aerodynamical, pbifs, verbosity);
1481
1482 tag.read_from_stream(is_xml);
1483 tag.check_name("/ScatteringMetaData");
1484}
1485
1487
1493void xml_write_to_stream(ostream& os_xml,
1494 const ScatteringMetaData& smdata,
1495 bofstream* pbofs,
1496 const String& name,
1497 const Verbosity& verbosity) {
1498 ArtsXMLTag open_tag(verbosity);
1499 ArtsXMLTag close_tag(verbosity);
1500
1501 open_tag.set_name("ScatteringMetaData");
1502 if (name.length()) open_tag.add_attribute("name", name);
1503 open_tag.add_attribute("version", "3");
1504 open_tag.write_to_stream(os_xml);
1505
1506 xml_write_to_stream(os_xml, smdata.description, pbofs, "", verbosity);
1507 xml_write_to_stream(os_xml, smdata.source, pbofs, "", verbosity);
1508 xml_write_to_stream(os_xml, smdata.refr_index, pbofs, "", verbosity);
1509 xml_write_to_stream(os_xml, smdata.mass, pbofs, "", verbosity);
1510 xml_write_to_stream(os_xml, smdata.diameter_max, pbofs, "", verbosity);
1511 xml_write_to_stream(os_xml, smdata.diameter_volume_equ, pbofs, "", verbosity);
1513 os_xml, smdata.diameter_area_equ_aerodynamical, pbofs, "", verbosity);
1514
1515 close_tag.set_name("/ScatteringMetaData");
1516 close_tag.write_to_stream(os_xml);
1517 os_xml << '\n';
1518}
1519
1520//=== SLIData2 =====================================================
1522
1528void xml_read_from_stream(istream& is_xml,
1529 SLIData2& slidata,
1530 bifstream* pbifs,
1531 const Verbosity& verbosity) {
1532 ArtsXMLTag tag(verbosity);
1533
1534 tag.read_from_stream(is_xml);
1535 tag.check_name("SLIData2");
1536
1537 xml_read_from_stream(is_xml, slidata.x1a, pbifs, verbosity);
1538 xml_read_from_stream(is_xml, slidata.x2a, pbifs, verbosity);
1539 xml_read_from_stream(is_xml, slidata.ya, pbifs, verbosity);
1540
1541 tag.read_from_stream(is_xml);
1542 tag.check_name("/SLIData2");
1543}
1544
1545void xml_write_to_stream(ostream& os_xml,
1546 const SLIData2& slidata,
1547 bofstream* pbofs,
1548 const String& name,
1549 const Verbosity& verbosity) {
1550 ArtsXMLTag open_tag(verbosity);
1551 ArtsXMLTag close_tag(verbosity);
1552
1553 open_tag.set_name("SLIData2");
1554 if (name.length()) open_tag.add_attribute("name", name);
1555 open_tag.write_to_stream(os_xml);
1556
1557 xml_write_to_stream(os_xml, slidata.x1a, pbofs, "", verbosity);
1558 xml_write_to_stream(os_xml, slidata.x2a, pbofs, "", verbosity);
1559 xml_write_to_stream(os_xml, slidata.ya, pbofs, "", verbosity);
1560
1561 close_tag.set_name("/SLIData2");
1562 close_tag.write_to_stream(os_xml);
1563 os_xml << '\n';
1564}
1565
1566//=== SpeciesIsotopologueRatios ===========================================
1567
1569
1574void xml_read_from_stream(istream& is_xml,
1576 bifstream* pbifs,
1577 const Verbosity& verbosity) {
1578 ARTS_USER_ERROR_IF(pbifs, "No support for binary IO for (SpeciesIsotopologueRatios)")
1579
1581
1582 iso_rat = SpeciesIsotopologueRatios{};
1583
1584 ArtsXMLTag tag(verbosity);
1585
1586 tag.read_from_stream(is_xml);
1587 tag.check_name("SpeciesIsotopologueRatios");
1588
1589 Index nelem;
1590 tag.get_attribute_value("nelem", nelem);
1591
1592 String name;
1593 Numeric val;
1594 for (Index n = 0; n < nelem; n++) {
1595 is_xml >> name >> double_imanip() >> val;
1596
1597 if (is_xml.fail()) {
1598 ostringstream os;
1599 os << " near "
1600 << "\n Element: " << n;
1601 xml_data_parse_error(tag, os.str());
1602 }
1603
1604 const Index i = Species::find_species_index(Species::Tag(name).Isotopologue());
1605 ARTS_USER_ERROR_IF(i < 0 or i >= iso_rat.maxsize,
1606 "Species: ", name, " cannot be understood as a species by your compiled version of ARTS")
1607
1608 iso_rat.data[i] = val;
1609 }
1610
1611 tag.read_from_stream(is_xml);
1612 tag.check_name("/SpeciesIsotopologueRatios");
1613}
1614
1616
1622void xml_write_to_stream(ostream& os_xml,
1623 const SpeciesIsotopologueRatios& iso_rat,
1624 bofstream* pbofs,
1625 const String& name,
1626 const Verbosity& verbosity)
1627
1628{
1629 ARTS_USER_ERROR_IF(pbofs, "No support for binary IO for (SpeciesIsotopologueRatios)")
1630
1631 ArtsXMLTag open_tag(verbosity);
1632 ArtsXMLTag close_tag(verbosity);
1633
1634 open_tag.set_name("SpeciesIsotopologueRatios");
1635 if (name.length()) open_tag.add_attribute("name", name);
1636 open_tag.add_attribute("nelem", iso_rat.maxsize);
1637
1638 open_tag.write_to_stream(os_xml);
1639 os_xml << '\n';
1640
1642 os_xml << iso_rat << '\n';
1643
1644 close_tag.set_name("/SpeciesIsotopologueRatios");
1645 close_tag.write_to_stream(os_xml);
1646
1647 os_xml << '\n';
1648}
1649
1650//=== SpeciesTag ================================================
1651
1653
1657/* param pbifs Pointer to binary input stream. NULL in case of ASCII file.
1658 Ignored because SpeciesTag is always stored in ASCII format.*/
1659void xml_read_from_stream(istream& is_xml,
1660 SpeciesTag& stag,
1661 bifstream* /* pbifs */,
1662 const Verbosity& verbosity) {
1663 ArtsXMLTag tag(verbosity);
1664 stringbuf strbuf;
1665 char dummy;
1666
1667 tag.read_from_stream(is_xml);
1668 tag.check_name("SpeciesTag");
1669
1670 // Skip whitespaces
1671 bool string_starts_with_quotes = true;
1672 do {
1673 is_xml >> dummy;
1674 switch (dummy) {
1675 case ' ':
1676 case '\"':
1677 case '\n':
1678 case '\r':
1679 case '\t':
1680 break;
1681 default:
1682 string_starts_with_quotes = false;
1683 }
1684 } while (is_xml.good() && dummy != '"' && string_starts_with_quotes);
1685
1686 // Throw exception if first char after whitespaces is not a quote
1687 if (!string_starts_with_quotes) {
1688 xml_parse_error("SpeciesTag must begin with \"");
1689 }
1690
1691 is_xml.get(strbuf, '"');
1692 if (is_xml.fail()) {
1693 xml_parse_error("SpeciesTag must end with \"");
1694 }
1695
1696 stag = SpeciesTag(strbuf.str());
1697
1698 // Ignore quote
1699 is_xml >> dummy;
1700
1701 tag.read_from_stream(is_xml);
1702 tag.check_name("/SpeciesTag");
1703}
1704
1706
1711/* param pbofs Pointer to binary file stream. NULL for ASCII output.
1712 Ignore because SpeciesTag is always stored in ASCII format. */
1713void xml_write_to_stream(ostream& os_xml,
1714 const SpeciesTag& stag,
1715 bofstream* /* pbofs */,
1716 const String& name,
1717 const Verbosity& verbosity) {
1718 ArtsXMLTag open_tag(verbosity);
1719 ArtsXMLTag close_tag(verbosity);
1720
1721 open_tag.set_name("SpeciesTag");
1722 if (name.length()) open_tag.add_attribute("name", name);
1723 open_tag.write_to_stream(os_xml);
1724
1725 os_xml << '\"' << stag.Name() << '\"';
1726
1727 close_tag.set_name("/SpeciesTag");
1728 close_tag.write_to_stream(os_xml);
1729 os_xml << '\n';
1730}
1731
1732//=== Star =====================================================
1733
1735
1740void xml_read_from_stream(istream& is_xml,
1741 Star& star,
1742 bifstream* pbifs,
1743 const Verbosity& verbosity) {
1744 ArtsXMLTag tag(verbosity);
1745
1746 tag.read_from_stream(is_xml);
1747 tag.check_name("Star");
1748
1749 xml_read_from_stream(is_xml, star.description, pbifs, verbosity);
1750 xml_read_from_stream(is_xml, star.spectrum, pbifs, verbosity);
1751 xml_read_from_stream(is_xml, star.radius, pbifs, verbosity);
1752 xml_read_from_stream(is_xml, star.distance, pbifs, verbosity);
1753 xml_read_from_stream(is_xml, star.latitude, pbifs, verbosity);
1754 xml_read_from_stream(is_xml, star.longitude, pbifs, verbosity);
1755
1756 tag.read_from_stream(is_xml);
1757 tag.check_name("/Star");
1758}
1759
1761
1767void xml_write_to_stream(ostream& os_xml,
1768 const Star& star,
1769 bofstream* pbofs,
1770 const String& name,
1771 const Verbosity& verbosity) {
1772 ArtsXMLTag open_tag(verbosity);
1773 ArtsXMLTag close_tag(verbosity);
1774
1775 open_tag.set_name("Star");
1776 if (name.length()) open_tag.add_attribute("name", name);
1777 open_tag.write_to_stream(os_xml);
1778
1779 xml_write_to_stream(os_xml, star.description, pbofs, "StarType", verbosity);
1780 xml_write_to_stream(os_xml, star.spectrum, pbofs, "StarSpectrum", verbosity);
1781 xml_write_to_stream(os_xml, star.radius, pbofs, "StarRadius", verbosity);
1782 xml_write_to_stream(os_xml, star.distance, pbofs, "StarDistance", verbosity);
1783 xml_write_to_stream(os_xml, star.latitude, pbofs, "StarLatitude", verbosity);
1785 os_xml, star.longitude, pbofs, "StarLongitude", verbosity);
1786
1787 close_tag.set_name("/Star");
1788 close_tag.write_to_stream(os_xml);
1789 os_xml << '\n';
1790}
1791
1792//=== StokesVector ======================================================
1793
1795
1800void xml_read_from_stream(istream& is_xml,
1801 StokesVector& sv,
1802 bifstream* pbifs,
1803 const Verbosity& verbosity) {
1804 ArtsXMLTag tag(verbosity);
1805
1806 tag.read_from_stream(is_xml);
1807 tag.check_name("StokesVector");
1808
1809 try {
1810 Tensor4 d;
1811 xml_read_from_stream(is_xml, d, pbifs, verbosity);
1812 Index naa = d.nbooks();
1813 Index nza = d.npages();
1814 Index nf = d.nrows();
1815 Index nstokes_needed = d.ncols();
1816 sv = StokesVector(nf, need2stokes<false>(nstokes_needed), nza, naa);
1817 sv.Data() = std::move(d); // destructive takeover
1818 } catch (const std::runtime_error& e) {
1819 ostringstream os;
1820 os << "Error reading StokesVector: "
1821 << "\n"
1822 << e.what();
1823 throw runtime_error(os.str());
1824 }
1825
1826 tag.read_from_stream(is_xml);
1827 tag.check_name("/StokesVector");
1828}
1829
1831
1837void xml_write_to_stream(ostream& os_xml,
1838 const StokesVector& sv,
1839 bofstream* pbofs,
1840 const String& name,
1841 const Verbosity& verbosity) {
1842 ArtsXMLTag open_tag(verbosity);
1843 ArtsXMLTag close_tag(verbosity);
1844
1845 open_tag.set_name("StokesVector");
1846 if (name.length()) open_tag.add_attribute("name", name);
1847
1848 open_tag.write_to_stream(os_xml);
1849 os_xml << '\n';
1850
1851 xml_write_to_stream(os_xml, sv.Data(), pbofs, "", verbosity);
1852
1853 close_tag.set_name("/StokesVector");
1854 close_tag.write_to_stream(os_xml);
1855
1856 os_xml << '\n';
1857}
1858
1859//=== TelsemAtlas ======================================================
1860
1862
1867void xml_read_from_stream(istream& is_xml,
1868 TelsemAtlas& ta,
1869 bifstream* pbifs,
1870 const Verbosity& verbosity) {
1871 ArtsXMLTag tag(verbosity);
1872
1873 tag.read_from_stream(is_xml);
1874 tag.check_name("TelsemAtlas");
1875
1876 xml_read_from_stream(is_xml, ta.ndat, pbifs, verbosity);
1877 xml_read_from_stream(is_xml, ta.nchan, pbifs, verbosity);
1878 xml_read_from_stream(is_xml, ta.name, pbifs, verbosity);
1879 xml_read_from_stream(is_xml, ta.month, pbifs, verbosity);
1880 xml_read_from_stream(is_xml, ta.dlat, pbifs, verbosity);
1881 xml_read_from_stream(is_xml, ta.emis, pbifs, verbosity);
1882 xml_read_from_stream(is_xml, ta.correl, pbifs, verbosity);
1883 xml_read_from_stream(is_xml, ta.emis_err, pbifs, verbosity);
1884 xml_read_from_stream(is_xml, ta.classes1, pbifs, verbosity);
1885 xml_read_from_stream(is_xml, ta.classes2, pbifs, verbosity);
1886 xml_read_from_stream(is_xml, ta.cellnums, pbifs, verbosity);
1888 tag.read_from_stream(is_xml);
1889 tag.check_name("/TelsemAtlas");
1890}
1891
1893
1899void xml_write_to_stream(ostream& os_xml,
1900 const TelsemAtlas& ta,
1901 bofstream* pbofs,
1902 const String& name,
1903 const Verbosity& verbosity) {
1904 ArtsXMLTag open_tag(verbosity);
1905 ArtsXMLTag close_tag(verbosity);
1906
1907 open_tag.set_name("TelsemAtlas");
1908 if (name.length()) open_tag.add_attribute("name", name);
1909
1910 open_tag.write_to_stream(os_xml);
1911 os_xml << '\n';
1912 xml_write_to_stream(os_xml, ta.ndat, pbofs, "ndat", verbosity);
1913 xml_write_to_stream(os_xml, ta.nchan, pbofs, "nchan", verbosity);
1914 xml_write_to_stream(os_xml, ta.name, pbofs, "name", verbosity);
1915 xml_write_to_stream(os_xml, ta.month, pbofs, "month", verbosity);
1916 xml_write_to_stream(os_xml, ta.dlat, pbofs, "dlat", verbosity);
1917 xml_write_to_stream(os_xml, ta.emis, pbofs, "emis", verbosity);
1918 xml_write_to_stream(os_xml, ta.correl, pbofs, "correl", verbosity);
1919 xml_write_to_stream(os_xml, ta.emis_err, pbofs, "emis_err", verbosity);
1920 xml_write_to_stream(os_xml, ta.classes1, pbofs, "class1", verbosity);
1921 xml_write_to_stream(os_xml, ta.classes2, pbofs, "class2", verbosity);
1922 xml_write_to_stream(os_xml, ta.cellnums, pbofs, "cellnum", verbosity);
1923 close_tag.set_name("/TelsemAtlas");
1924 close_tag.write_to_stream(os_xml);
1925
1926 os_xml << '\n';
1927}
1928
1929//=== XsecRecord ======================================================
1930
1932
1937void xml_read_from_stream(istream& is_xml,
1938 XsecRecord& xd,
1939 bifstream* pbifs,
1940 const Verbosity& verbosity) {
1942 ArtsXMLTag tag(verbosity);
1943 Index version;
1944
1945 tag.read_from_stream(is_xml);
1946 tag.check_name("XsecRecord");
1947 tag.get_attribute_value("version", version);
1948 xd.SetVersion(version);
1949
1950 String species_name;
1951 xml_read_from_stream(is_xml, species_name, pbifs, verbosity);
1952
1953 const Species::Species species = Species::fromShortName(species_name);
1954 if (not good_enum(species)) {
1955 ostringstream os;
1956 os << " Unknown species in XsecRecord: " << species_name;
1957 throw std::runtime_error(os.str());
1958 }
1959 xd.SetSpecies(species);
1960
1961 ARTS_USER_ERROR_IF(version != 2, "Only XsecRecord version 2 is supported")
1962
1963 xml_read_from_stream(is_xml, xd.FitMinPressures(), pbifs, verbosity);
1964 xml_read_from_stream(is_xml, xd.FitMaxPressures(), pbifs, verbosity);
1965 xml_read_from_stream(is_xml, xd.FitMinTemperatures(), pbifs, verbosity);
1966 xml_read_from_stream(is_xml, xd.FitMaxTemperatures(), pbifs, verbosity);
1967 xml_read_from_stream(is_xml, xd.FitCoeffs(), pbifs, verbosity);
1968
1969 for (const auto& fitcoeffs : xd.FitCoeffs()) {
1970 const Index ncoeff = fitcoeffs.data.ncols();
1972 ncoeff != 4, "Wrong number of coefficients, expected 4, found ", ncoeff)
1973 }
1974
1975 tag.read_from_stream(is_xml);
1976 tag.check_name("/XsecRecord");
1977}
1978
1980
1986void xml_write_to_stream(ostream& os_xml,
1987 const XsecRecord& xd,
1988 bofstream* pbofs,
1989 const String& name,
1990 const Verbosity& verbosity) {
1991 ArtsXMLTag open_tag(verbosity);
1992 ArtsXMLTag close_tag(verbosity);
1993
1994 open_tag.set_name("XsecRecord");
1995 if (name.length()) open_tag.add_attribute("name", name);
1996 open_tag.add_attribute("version", xd.Version());
1997
1998 open_tag.write_to_stream(os_xml);
1999 os_xml << '\n';
2000 xml_write_to_stream(os_xml, xd.SpeciesName(), pbofs, "species", verbosity);
2001
2002 xml_write_to_stream(os_xml,
2003 xd.FitMinPressures(),
2004 pbofs,
2005 "Mininum pressures from fit",
2006 verbosity);
2007 xml_write_to_stream(os_xml,
2008 xd.FitMaxPressures(),
2009 pbofs,
2010 "Maximum pressures from fit",
2011 verbosity);
2012 xml_write_to_stream(os_xml,
2013 xd.FitMinTemperatures(),
2014 pbofs,
2015 "Mininum temperatures from fit",
2016 verbosity);
2017 xml_write_to_stream(os_xml,
2018 xd.FitMaxTemperatures(),
2019 pbofs,
2020 "Maximum temperatures from fit",
2021 verbosity);
2023 os_xml, xd.FitCoeffs(), pbofs, "Fit coefficients", verbosity);
2024
2025 close_tag.set_name("/XsecRecord");
2026 close_tag.write_to_stream(os_xml);
2027
2028 os_xml << '\n';
2029}
2030
2031//=== MapOfErrorCorrectedSuddenData ======================================================
2032
2034
2039void xml_read_from_stream(istream& is_xml,
2041 bifstream* pbifs,
2042 const Verbosity& verbosity) {
2043 ARTS_USER_ERROR_IF(pbifs not_eq nullptr, "No binary data")
2044
2046 ArtsXMLTag open_tag(verbosity);
2047 open_tag.read_from_stream(is_xml);
2048 open_tag.check_name("MapOfErrorCorrectedSuddenData");
2049
2050 Index nelem;
2051 open_tag.get_attribute_value("nelem", nelem);
2052
2053 for (Index i=0; i<nelem; i++) {
2054 ArtsXMLTag internal_open_tag(verbosity);
2055 internal_open_tag.read_from_stream(is_xml);
2056 internal_open_tag.check_name("ErrorCorrectedSuddenData");
2057
2058 // Get key
2059 String val;
2060 internal_open_tag.get_attribute_value("key", val);
2061 auto& data = rvb[QuantumIdentifier(val)];
2062
2063 // Get size
2064 Index nelem_specs;
2065 internal_open_tag.get_attribute_value("nelem", nelem_specs);
2066
2067 // Get values
2068 for (Index j=0; j<nelem_specs; j++) {
2070 is_xml >> secds;
2071 data[secds.spec] = secds;
2072 }
2073
2074 ArtsXMLTag internal_close_tag(verbosity);
2075 internal_close_tag.read_from_stream(is_xml);
2076 internal_close_tag.check_name("/ErrorCorrectedSuddenData");
2077
2078 }
2079
2080 ArtsXMLTag close_tag(verbosity);
2081 close_tag.read_from_stream(is_xml);
2082 close_tag.check_name("/MapOfErrorCorrectedSuddenData");
2083
2084 // Sanity check, it is not OK to not have AIR as catch-all broadener
2085 for (auto& x: rvb) {
2086 bool found_air=false;
2087 for (auto& y: x.data) {
2088 found_air = found_air or (y.spec == Species::Species::Bath);
2089 }
2090 ARTS_USER_ERROR_IF(not found_air,
2091 "Incomplete ErrorCorrectedSuddenData, must contain air, contains:\n",
2092 x)
2093 }
2094}
2095
2097
2103void xml_write_to_stream(ostream& os_xml,
2105 bofstream* pbofs,
2106 const String& name,
2107 const Verbosity& verbosity) {
2108 ARTS_USER_ERROR_IF(pbofs not_eq nullptr, "No binary data")
2109
2110 ArtsXMLTag open_tag(verbosity);
2111 ArtsXMLTag close_tag(verbosity);
2112
2113 open_tag.set_name("MapOfErrorCorrectedSuddenData");
2114 if (name.length()) open_tag.add_attribute("name", name);
2115 open_tag.add_attribute("nelem", rvb.nelem());
2116 open_tag.write_to_stream(os_xml);
2117 os_xml << '\n';
2118
2120
2121 for (auto& r: rvb) {
2122 ArtsXMLTag internal_open_tag(verbosity);
2123 internal_open_tag.set_name("ErrorCorrectedSuddenData");
2124 internal_open_tag.add_attribute("key", var_string(r.id));
2125 internal_open_tag.add_attribute("nelem", r.data.nelem());
2126 internal_open_tag.write_to_stream(os_xml);
2127 os_xml << '\n';
2128
2129 // Set values
2130 os_xml << r << '\n';
2131
2132 ArtsXMLTag internal_close_tag(verbosity);
2133 internal_close_tag.set_name("/ErrorCorrectedSuddenData");
2134 internal_close_tag.write_to_stream(os_xml);
2135 os_xml << '\n';
2136 }
2137
2138 close_tag.set_name("/MapOfErrorCorrectedSuddenData");
2139 close_tag.write_to_stream(os_xml);
2140
2141 os_xml << '\n';
2142}
2143
2144
2145
2146//=== PredefinedModelData =========================================
2152void xml_read_from_stream(istream& is_xml,
2153 PredefinedModelData& pmd,
2154 bifstream* pbifs,
2155 const Verbosity& verbosity) {
2156 ARTS_USER_ERROR_IF(pbifs, "No binary data")
2157
2158 pmd = PredefinedModelData{}; // overwrite
2159
2161 ArtsXMLTag open_tag(verbosity);
2162 open_tag.read_from_stream(is_xml);
2163 open_tag.check_name("PredefinedModelData");
2164
2165 Index nelem;
2166 open_tag.get_attribute_value("nelem", nelem);
2167
2168 for (Index i = 0; i < nelem; i++) {
2169 ArtsXMLTag internal_open_tag(verbosity);
2170 internal_open_tag.read_from_stream(is_xml);
2171 internal_open_tag.check_name("Data");
2172
2173 // Get key
2174 String key_str;
2175 internal_open_tag.get_attribute_value("key", key_str);
2176 auto key =
2177 Absorption::PredefinedModel::toDataKeyOrThrow(key_str);
2178
2179 String sizes_str;
2180 internal_open_tag.get_attribute_value("sizes", sizes_str);
2181
2182 Index sizes_len;
2183 internal_open_tag.get_attribute_value("sizes_nelem", sizes_len);
2184
2185 std::vector<std::size_t> sizes(sizes_len);
2186 std::istringstream values(sizes_str);
2187 for (auto& sz : sizes) values >> sz;
2188
2189 pmd.resize(sizes, key);
2190 pmd.set_data_from_stream(is_xml, key);
2191
2192 ArtsXMLTag internal_close_tag(verbosity);
2193 internal_close_tag.read_from_stream(is_xml);
2194 internal_close_tag.check_name("/Data");
2195 }
2196
2197 ArtsXMLTag close_tag(verbosity);
2198 close_tag.read_from_stream(is_xml);
2199 close_tag.check_name("/PredefinedModelData");
2200}
2201
2208void xml_write_to_stream(ostream& os_xml,
2209 const PredefinedModelData& pmd,
2210 bofstream* pbofs,
2211 const String& name,
2212 const Verbosity& verbosity) {
2213 ARTS_USER_ERROR_IF(pbofs, "No binary data")
2214
2215 ArtsXMLTag open_tag(verbosity);
2216 ArtsXMLTag close_tag(verbosity);
2217
2218 open_tag.set_name("PredefinedModelData");
2219 if (name.length()) open_tag.add_attribute("name", name);
2220 open_tag.add_attribute("nelem", Index(pmd.size()));
2221 open_tag.write_to_stream(os_xml);
2222 os_xml << '\n';
2223
2225 const auto keys = pmd.keys();
2226
2227 for (auto& key : keys) {
2228 ArtsXMLTag internal_open_tag(verbosity);
2229 internal_open_tag.set_name("Data");
2230 internal_open_tag.add_attribute("key", toString(key));
2231
2232 auto sizes = pmd.data_size(key);
2233 internal_open_tag.add_attribute("sizes_nelem", Index(sizes.size()));
2234
2235 String sizes_str = "";
2236 for (std::size_t i = 0; i < sizes.size(); i++) {
2237 if (i > 0) sizes_str += " ";
2238 sizes_str += var_string(sizes[i]);
2239 }
2240 internal_open_tag.add_attribute("sizes", sizes_str);
2241
2242 internal_open_tag.write_to_stream(os_xml);
2243 os_xml << '\n';
2244
2245 // Set values
2246 pmd.output_data_to_stream(os_xml, key);
2247 os_xml << '\n';
2248
2249 ArtsXMLTag internal_close_tag(verbosity);
2250 internal_close_tag.set_name("/Data");
2251 internal_close_tag.write_to_stream(os_xml);
2252 os_xml << '\n';
2253 }
2254
2255 close_tag.set_name("/PredefinedModelData");
2256 close_tag.write_to_stream(os_xml);
2257
2258 os_xml << '\n';
2259}
2260
2261
2263// Dummy funtion for groups for which
2264// IO function have not yet been implemented
2266
2267// FIXME: These should be implemented, sooner or later...
2268
2270 Agenda&,
2271 bifstream* /* pbifs */,
2272 const Verbosity&) {
2273 ARTS_USER_ERROR("Method not implemented!");
2274}
2275
2277 const Agenda&,
2278 bofstream* /* pbofs */,
2279 const String& /* name */,
2280 const Verbosity&) {
2281 ARTS_USER_ERROR("Method not implemented!");
2282}
2283
2284//=== MCAntenna ================================================
2285
2287 MCAntenna&,
2288 bifstream* /* pbifs */,
2289 const Verbosity&) {
2290 ARTS_USER_ERROR("Method not implemented!");
2291}
2292
2294 const MCAntenna&,
2295 bofstream* /* pbofs */,
2296 const String& /* name */,
2297 const Verbosity&) {
2298 ARTS_USER_ERROR("Method not implemented!");
2299}
2300
2301//=== TessemNN ================================================
2302
2304 TessemNN&,
2305 bifstream* /* pbifs */,
2306 const Verbosity&) {
2307 ARTS_USER_ERROR("Method not implemented!");
2308}
2309
2311 const TessemNN&,
2312 bofstream* /* pbofs */,
2313 const String& /* name */,
2314 const Verbosity&) {
2315 ARTS_USER_ERROR("Method not implemented!");
2316}
2317
2318//=== Verbosity ================================================
2319
2321 Verbosity&,
2322 bifstream* /* pbifs */,
2323 const Verbosity&) {
2324 ARTS_USER_ERROR("Method not implemented!");
2325}
2326
2328 const Verbosity&,
2329 bofstream* /* pbofs */,
2330 const String& /* name */,
2331 const Verbosity&) {
2332 ARTS_USER_ERROR("Method not implemented!");
2333}
2334
2335//=== CallbackFunction =========================================
2336
2339 bifstream* /* pbifs */,
2340 const Verbosity&) {
2341 ARTS_USER_ERROR("Method not implemented!");
2342}
2343
2345 const CallbackFunction&,
2346 bofstream* /* pbofs */,
2347 const String& /* name */,
2348 const Verbosity&) {
2349 ARTS_USER_ERROR("Method not implemented!");
2350}
The global header file for ARTS.
The Agenda class.
Definition: agenda_class.h:69
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:92
The ARTS XML tag class.
Definition: xml_io.h:45
void add_attribute(const String &aname, const std::vector< QuantumNumberType > &value)
Adds value of attribute as type std::vector<QuantumNumberType> to tag.
Definition: xml_io.cc:42
void get_attribute_value(const String &aname, SpeciesTag &value)
Returns value of attribute as type SpeciesTag.
Definition: xml_io.cc:70
CIA data for a single pair of molecules.
Definition: cia.h:68
void SetSpecies(const Species::Species first, const Species::Species second)
Set CIA species.
Definition: cia.h:148
ArrayOfGriddedField2 mdata
The data itself, directly from the HITRAN file.
Definition: cia.h:247
const ArrayOfGriddedField2 & Data() const
Return CIA data.
Definition: cia.h:138
String MoleculeName(const Index i) const
Return each molecule name (as a string) that is associated with this CIARecord.
Definition: cia.cc:267
Index nlibraries() const noexcept
Definition: matpackVII.h:153
Index nelem() const noexcept
Returns the number of elements.
Definition: matpackI.h:536
std::vector< Block > correlations_
std::vector< Block > inverses_
An absorption lookup table.
Vector p_grid
The pressure grid for the table [Pa].
Tensor4 xsec
Absorption cross sections.
Vector t_pert
The vector of temperature perturbations [K].
Vector f_grid
The frequency grid [Hz].
Matrix vmrs_ref
The reference VMR profiles.
Vector nls_pert
The vector of perturbations for the VMRs of the nonlinear species.
Vector t_ref
The reference temperature profile [K].
ArrayOfIndex nonlinear_species
The species tags with non-linear treatment.
ArrayOfArrayOfSpeciesTag species
The species tags for which the table is valid.
void checksize_strict() const final
Strict consistency check.
void checksize_strict() const final
Strict consistency check.
void checksize_strict() const final
Strict consistency check.
void checksize_strict() const final
Strict consistency check.
void checksize_strict() const final
Strict consistency check.
void checksize_strict() const final
Strict consistency check.
const String & get_name() const
Get the name of this gridded field.
void set_name(const String &s)
Set name of this gridded field.
const ArrayOfString & get_string_grid(Index i) const
Get a string grid.
Index get_dim() const
Get the dimension of this gridded field.
void set_grid_name(Index i, const String &s)
Set grid name.
void set_grid(Index i, const Vector &g)
Set a numeric grid.
GridType get_grid_type(Index i) const
Get grid type.
const Vector & get_numeric_grid(Index i) const
Get a numeric grid.
const String & get_grid_name(Index i) const
Get grid name.
Tensor4 & Data()
Get full view to data.
The range class.
Definition: matpackI.h:159
constexpr Index get_extent() const noexcept
Returns the extent of the range.
Definition: matpackI.h:342
constexpr Index get_start() const noexcept
Returns the start index of the range.
Definition: matpackI.h:340
Deals with internal derivatives, Jacobian definition, and OEM calculations.
Definition: jacobian.h:325
const String & Mode() const
Returns the mode.
Definition: jacobian.h:394
Jacobian::Target & Target()
Get the Jacobian Target.
Definition: jacobian.h:431
const String & SubSubtag() const
Returns the sub-sub-tag.
Definition: jacobian.h:379
const ArrayOfVector & Grids() const
Returns the grids of the retrieval.
Definition: jacobian.h:408
const String & Subtag() const
Returns the sub-tag.
Definition: jacobian.h:365
A 2D sequential linear interpolation (SLI) lookup table This class holds the gridded for 2D SLI as we...
Definition: mc_interp.h:52
ArrayOfVector x2a
Definition: mc_interp.h:57
ArrayOfVector ya
Definition: mc_interp.h:59
Vector x1a
Definition: mc_interp.h:55
Stokes vector is as Propagation matrix but only has 4 possible values.
A telsem atlas.
Definition: telsem.h:59
Matrix emis
Definition: telsem.h:367
Tensor3 correl
Definition: telsem.h:371
ArrayOfIndex classes2
Definition: telsem.h:374
Index nchan
Definition: telsem.h:355
Numeric dlat
Definition: telsem.h:361
Matrix emis_err
Definition: telsem.h:369
ArrayOfIndex cellnums
Definition: telsem.h:376
ArrayOfIndex classes1
Definition: telsem.h:373
Index month
Definition: telsem.h:359
void telsem_calc_correspondence()
Definition: telsem.cc:136
Index ndat
Definition: telsem.h:353
String name
Definition: telsem.h:357
The Tensor4 class.
Definition: matpackIV.h:429
The Vector class.
Definition: matpackI.h:899
The ARTS XML tag class.
Definition: xml_io_base.h:70
bool has_attribute(const String &aname) const
Returns if the attribute exists or not.
Definition: xml_io_base.cc:125
void write_to_stream(ostream &os)
Write XML tag.
Definition: xml_io_base.cc:322
void check_name(const String &expected_name)
Check tag name.
Definition: xml_io_base.cc:54
void read_from_stream(istream &is)
Reads next XML tag.
Definition: xml_io_base.cc:201
void get_attribute_value(const String &aname, String &value)
Definition: xml_io_base.cc:140
void set_name(const String &new_name)
Definition: xml_io_base.h:78
String & get_name()
Definition: xml_io_base.h:74
Hitran crosssection class.
Definition: xsec_fit.h:43
const Vector & FitMinPressures() const
Get mininum pressures from fit.
Definition: xsec_fit.h:79
const Vector & FitMinTemperatures() const
Get mininum temperatures from fit.
Definition: xsec_fit.h:89
String SpeciesName() const
Return species name.
Definition: xsec_fit.cc:38
void SetVersion(Index version)
Set species name.
Definition: xsec_fit.cc:44
Index Version() const
Return species index.
Definition: xsec_fit.h:55
const Vector & FitMaxPressures() const
Get maximum pressures from fit.
Definition: xsec_fit.h:84
const Vector & FitMaxTemperatures() const
Get maximum temperatures.
Definition: xsec_fit.h:94
void SetSpecies(const Species::Species species)
Set species name.
Definition: xsec_fit.h:52
const ArrayOfGriddedField2 & FitCoeffs() const
Get coefficients.
Definition: xsec_fit.h:99
Binary output file stream class.
Definition: bifstream.h:43
Binary output file stream class.
Definition: bofstream.h:42
Input manipulator class for doubles to enable nan and inf parsing.
Definition: double_imanip.h:42
void chk_scat_data(const SingleScatteringData &scat_data_single, const Verbosity &verbosity)
Check single scattering data.
Definition: cloudbox.cc:293
Internal cloudbox functions.
#define _U_
Definition: config.h:180
Helper macros for debugging.
#define ARTS_USER_ERROR(...)
Definition: debug.h:150
std::string var_string(Args &&... args)
Definition: debug.h:36
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
EnergyLevelMapType toEnergyLevelMapTypeOrThrow(std::string_view s)
constexpr std::string_view toString(EnergyLevelMapType x) noexcept
constexpr bool good_enum(EnumType x) noexcept
Checks if the enum number is good.
Definition: enums.h:22
@ GRID_TYPE_NUMERIC
@ GRID_TYPE_STRING
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
#define CREATE_OUT2
Definition: messages.h:205
Index nelem(const Lines &l)
Number of lines.
constexpr Numeric e
Elementary charge convenience name [C].
constexpr Index find_species_index(const Species spec, const std::string_view isot) noexcept
invlib::Matrix< ArtsCovarianceMatrixWrapper > CovarianceMatrix
invlib wrapper type for ARTS the ARTS covariance class.
Definition: oem.h:37
PType PType2FromString(const String &ptype_string)
Convert ptype name to enum value.
PType PTypeFromString(const String &ptype_string)
Convert ptype name to enum value.
void ConvertAzimuthallyRandomSingleScatteringData(SingleScatteringData &ssd)
Convert azimuthally-random oriented SingleScatteringData to latest version.
String PTypeToString(const PType &ptype)
Convert particle type enum value to String.
PType
An attribute to classify the particle type (ptype) of a SingleScatteringData.
Definition: optproperties.h:52
@ PTYPE_GENERAL
Definition: optproperties.h:53
@ PTYPE_AZIMUTH_RND
Definition: optproperties.h:54
@ PTYPE_TOTAL_RND
Definition: optproperties.h:55
Quantum::Number::GlobalState QuantumIdentifier
#define M
Definition: rng.cc:165
Species::Tag SpeciesTag
Definition: species_tags.h:101
ArrayOfQuantumIdentifier levels
EnergyLevelMapType type
void ThrowIfNotOK() const ARTS_NOEXCEPT
Structure to store a grid position.
Definition: interpolation.h:73
std::array< Numeric, 2 > fd
Definition: interpolation.h:75
Index idx
Definition: interpolation.h:74
Holds all information required for individual partial derivatives.
Definition: jacobian.h:108
Numeric perturbation
Perturbations for methods where theoretical computations are impossible or plain slow.
Definition: jacobian.h:125
An Antenna object used by MCGeneral.
Definition: mc_antenna.h:50
The structure to describe a propagation path and releated quantities.
Definition: ppath_struct.h:17
Matrix los
Line-of-sight at each ppath point.
Definition: ppath_struct.h:35
ArrayOfGridPos gp_lon
Index position with respect to the longitude grid.
Definition: ppath_struct.h:55
String background
Radiative background.
Definition: ppath_struct.h:25
Index np
Number of points describing the ppath.
Definition: ppath_struct.h:21
Matrix pos
The distance between start pos and the last position in pos.
Definition: ppath_struct.h:33
ArrayOfGridPos gp_lat
Index position with respect to the latitude grid.
Definition: ppath_struct.h:53
Numeric end_lstep
The distance between end pos and the first position in pos.
Definition: ppath_struct.h:45
Vector start_pos
Start position.
Definition: ppath_struct.h:27
Vector lstep
The length between ppath points.
Definition: ppath_struct.h:39
Numeric start_lstep
Length between sensor and atmospheric boundary.
Definition: ppath_struct.h:31
Numeric constant
The propagation path constant (only used for 1D)
Definition: ppath_struct.h:23
Vector r
Radius of each ppath point.
Definition: ppath_struct.h:37
ArrayOfGridPos gp_p
Index position with respect to the pressure grid.
Definition: ppath_struct.h:51
Vector ngroup
The group index of refraction.
Definition: ppath_struct.h:49
Index dim
Atmospheric dimensionality.
Definition: ppath_struct.h:19
Vector end_pos
End position.
Definition: ppath_struct.h:41
Vector start_los
Start line-of-sight.
Definition: ppath_struct.h:29
Vector nreal
The real part of the refractive index at each path position.
Definition: ppath_struct.h:47
Vector end_los
End line-of-sight.
Definition: ppath_struct.h:43
A logical struct for global quantum numbers with species identifiers.
static constexpr Index version
Numeric diameter_area_equ_aerodynamical
Numeric diameter_volume_equ
std::array< Numeric, maxsize > data
static constexpr Index maxsize
The structure to describe a propagation path and releated quantities.
Definition: star.h:58
Numeric latitude
latitude of the star in the sky of the planet
Definition: star.h:68
String description
star description
Definition: star.h:60
Numeric radius
Star radius.
Definition: star.h:64
Matrix spectrum
Star spectrum, monochrmatic radiance spectrum at the surface of the star.
Definition: star.h:62
Numeric distance
star distance from center of planet to center of star
Definition: star.h:66
Numeric longitude
longitude of the star in the sky of the planet
Definition: star.h:70
#define d
#define v
#define c
void xml_data_parse_error(ArtsXMLTag &tag, String str_error)
Throws XML parser runtime error.
Definition: xml_io.cc:179
This file contains basic functions to handle XML data files.
void xml_parse_from_stream(istream &, Vector &, bifstream *, ArtsXMLTag &, const Verbosity &verbosity)
void parse_xml_tag_content_as_string(std::istream &is_xml, String &content)
Get the content of an xml tag as a string.
Definition: xml_io_base.cc:723
void xml_set_stream_precision(ostream &os)
Definition: xml_io_base.cc:705
void xml_parse_error(const String &str_error)
Throws XML parser runtime error.
Definition: xml_io_base.cc:539
void xml_read_from_stream(istream &is_xml, CIARecord &cr, bifstream *pbifs, const Verbosity &verbosity)
Reads CIARecord from XML input stream.
void xml_write_to_stream(ostream &os_xml, const CIARecord &cr, bofstream *pbofs, const String &name, const Verbosity &verbosity)
Writes CIARecord to XML output stream.