ARTS 2.5.0 (git: 9ee3ac6c)
xml_io_partfun.cc
Go to the documentation of this file.
1#include "debug.h"
2#include "xml_io_partfun.h"
3
4#include "xml_io_base.h"
5
7
12void xml_read_from_stream(std::istream& is_xml,
14 bifstream* pbifs,
15 const Verbosity& verbosity) {
16 XMLTag tag(verbosity);
17
18 tag.read_from_stream(is_xml);
19 tag.check_name("PartitionFunctionsData");
20
22 tag.get_attribute_value("type", type);
23 data.type = PartitionFunctions::toTypeOrThrow(type);
24
25 xml_read_from_stream(is_xml, data.data, pbifs, verbosity);
26
27 tag.read_from_stream(is_xml);
28 tag.check_name("/PartitionFunctionsData");
29}
30
32
38void xml_write_to_stream(std::ostream& os_xml,
40 bofstream* pbofs,
41 const String& name,
42 const Verbosity& verbosity) {
43 XMLTag open_tag(verbosity);
44 XMLTag close_tag(verbosity);
45 std::ostringstream v;
46
47 open_tag.set_name("PartitionFunctionsData");
48 if (name not_eq "") open_tag.add_attribute("name", name);
49 open_tag.add_attribute("type", String(toString(data.type)));
50 open_tag.write_to_stream(os_xml);
51 os_xml << '\n';
52
53 xml_write_to_stream(os_xml, data.data, pbofs, "Data", verbosity);
54
55 close_tag.set_name("/PartitionFunctionsData");
56 close_tag.write_to_stream(os_xml);
57
58 os_xml << '\n';
59}
60
61namespace PartitionFunctions {
62void Data::print_data() const {
63 constexpr int cutline = 10;
64 const Index n = data.nrows();
65
66 switch (type) {
67 case PartitionFunctions::Type::Interp:
68 std::cout << "constexpr std::array<Numeric, " << n << "> data{";
69 for (Index i=0; i<n; i++) {
70 if (i % cutline == 0) {
71 std::cout << '\n';
72 }
73 std::cout << data(i, 1) << ',' << ' ';
74 }
75 std::cout << "};\n";
76
77 std::cout << "constexpr std::array<Numeric, " << n << "> grid{";
78 for (Index i=0; i<n; i++) {
79 if (i % cutline == 0) {
80 std::cout << '\n';
81 }
82 std::cout << data(i, 0) << ',' << ' ';
83 }
84 std::cout << "};\n";
85 break;
86 case PartitionFunctions::Type::Coeff:
87 std::cout << "constexpr std::array<Numeric, " << n << "> coeff{";
88 for (Index i=0; i<n; i++) {
89 if (i % cutline == 0) {
90 std::cout << '\n';
91 }
92 std::cout << data(i, 0) << ',' << ' ';
93 }
94 std::cout << "};\n";
95 break;
96 case PartitionFunctions::Type::FINAL: {/* leave last
97 */ }
98 }
99}
100
101void Data::print_method() const {
102 switch (type) {
103 case PartitionFunctions::Type::Interp:
104 std::cout << "return linterp<derivative>(grid, data, T);\n";
105 break;
106 case PartitionFunctions::Type::Coeff:
107 std::cout << "return polynom<derivative>(coeff, T);\n";
108 break;
109 case PartitionFunctions::Type::FINAL: {/* leave last
110 */ }
111 }
112}
113
114Data data_read_file(const std::filesystem::path& path) {
115 Data out;
116
117 xml_read_from_file_base(String(path.native()), out, Verbosity());
118
119 return out;
120}
121}
void * data
Index nrows() const ARTS_NOEXCEPT
Returns the number of rows.
Definition: matpackI.cc:433
The ARTS XML tag class.
Definition: xml_io_base.h:68
void add_attribute(const String &aname, const String &value)
Adds a String attribute to tag.
Definition: xml_io_base.cc:60
void write_to_stream(ostream &os)
Write XML tag.
Definition: xml_io_base.cc:300
void check_name(const String &expected_name)
Check tag name.
Definition: xml_io_base.cc:48
void read_from_stream(istream &is)
Reads next XML tag.
Definition: xml_io_base.cc:179
void get_attribute_value(const String &aname, String &value)
Returns value of attribute as String.
Definition: xml_io_base.cc:124
void set_name(const String &new_name)
Definition: xml_io_base.h:76
Binary output file stream class.
Definition: bifstream.h:42
Binary output file stream class.
Definition: bofstream.h:42
Helper macros for debugging.
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
my_basic_string< char > String
The String type for ARTS.
Definition: mystring.h:287
char Type type
Data data_read_file(const std::filesystem::path &path)
#define v
void xml_read_from_file_base(const String &filename, T &type, const Verbosity &verbosity)
Reads data from XML file.
Definition: xml_io_base.h:243
void xml_read_from_stream(std::istream &is_xml, PartitionFunctions::Data &data, bifstream *pbifs, const Verbosity &verbosity)
Reads Data from XML input stream.
void xml_write_to_stream(std::ostream &os_xml, const PartitionFunctions::Data &data, bofstream *pbofs, const String &name, const Verbosity &verbosity)
Writes PartitionFunctions::Data to XML output stream.