ARTS 2.5.4 (git: 31ce4f0e)
agenda_set.h
Go to the documentation of this file.
1#pragma once
2
3#include "agenda_class.h"
4#include "array.h"
5#include "global_data.h"
6#include "matpack.h"
7#include "mystring.h"
8#include "workspace_ng.h"
9
10namespace AgendaManip {
17 bool input{false};
18 bool any{false};
19
21 friend std::ostream& operator<<(std::ostream& os,
22 const AgendaMethodVariable& x);
23};
24
27 const String& method_name);
28
30std::pair<ArrayOfIndex, ArrayOfIndex> split_io(
32
33struct SetWsv {
35 enum class opt : char { NameOnly, ValueOnly, NameAndValue };
36
38 std::string str{""};
40
42 SetWsv(const std::string& x, const std::string& y);
43
45 SetWsv(std::string_view x);
46
48 SetWsv(ArtsType auto&& t) : test(opt::ValueOnly), val(std::forward<decltype(t)>(t)) {}
49
51 SetWsv(std::string_view x, ArtsType auto&& t) : test(opt::NameAndValue), str(x), val(std::forward<decltype(t)>(t)) {}
52};
53
55 bool positional{false};
56
59
60 bool new_value{false};
61
62 constexpr MethodVariable() {}
63
66 const SetWsv& wsv);
67
68 void add_del(Workspace& ws, Agenda& a) const;
69
70 void add_set(Workspace& ws, Agenda& a) const;
71
72 private:
74 const std::string_view rhs);
75
76 void wsv_position(Workspace& ws, const TokVal& value);
77};
78
79template <std::size_t N>
80std::array<MethodVariable, N> input_data_array(
81 Workspace& ws,
83 const std::array<SetWsv, N>& vals) {
84 std::array<MethodVariable, N> out{};
85 if constexpr (N > 0)
86 for (std::size_t i = 0; i < N; i++)
87 out[i] = MethodVariable(ws, list, vals[i]);
88 return out;
89}
90
91template <std::size_t N>
93 const std::array<MethodVariable, N>& input_data) {
94 const static TokVal any{};
95 if constexpr (N > 0)
96 if (auto ptr = std::find_if(input_data.crbegin(),
97 input_data.crend(),
98 [](auto& mv) { return mv.new_value; });
99 ptr not_eq input_data.crend())
100 return ws.wsv_data_ptr->at(ptr->ws_pos).default_value();
101 return any;
102}
103
104template <std::size_t N>
106 Agenda& a,
107 const std::string_view method,
108 const std::array<SetWsv, N>& input) {
109 auto list = sorted_mdrecord(ws, method);
110
111 // List of all input data
112 auto input_data = input_data_array(ws, list, input);
113
114 // Adapt positional arguments
115 if constexpr (N > 0) {
116 for (Index i = 0; i < static_cast<Index>(N); i++) {
117 if (input_data[i].positional) input_data[i].method_pos = i;
118 }
119 }
120
121 for (auto& x : input_data) list[x.method_pos].ws_pos = x.ws_pos;
122
123 for (auto& io : list)
125 io.ws_pos < 0,
126 "Not setting all input, this is a developer error. Here is the data:\n",
127 list)
128
129 auto [in, out] = split_io(list);
130
131 auto ptr = std::find_if(global_data::md_data.begin(),
133 [method](auto& x) { return method == x.Name(); });
134 const auto m_id = std::distance(global_data::md_data.begin(), ptr);
135
136 if (not ptr->SetMethod())
137 for (auto& x : input_data) x.add_set(ws, a);
138 a.push_back(MRecord(m_id, out, in, to_tokval(ws, input_data), Agenda{ws}));
139 if (not ptr->SetMethod())
140 for (auto& x : input_data) x.add_del(ws, a);
141}
142
147
148 AgendaCreator(Workspace& workspace, const char* name);
149
152
154 template <typename... Input>
155 void add(const std::string_view method, Input&&... input) {
156 if constexpr (sizeof...(Input) > 0)
158 ws,
159 agenda,
160 method,
161 stdarrayify<SetWsv>(SetWsv(std::forward<Input>(input))...));
162 else
163 add_method_and_setters(ws, agenda, method, std::array<SetWsv, 0>{});
164 }
165
167 void set(const std::string_view var, const TokVal& value);
168
170 void ignore(const std::string_view var);
171};
172
204} // namespace AgendaManip
Declarations for agendas.
This file contains the definition of Array.
The Agenda class.
Definition: agenda_class.h:69
This can be used to make arrays out of anything.
Definition: array.h:48
Method runtime data.
Definition: agenda_class.h:135
Definition: tokval.h:145
Workspace class.
Definition: workspace_ng.h:53
std::shared_ptr< Array< WsvRecord > > wsv_data_ptr
Definition: workspace_ng.h:58
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
This file contains the definition of String, the ARTS string class.
Agenda get_g0_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:523
Agenda get_ppath_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:350
Agenda get_iy_surface_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:316
Agenda get_ppath_step_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:372
Agenda get_iy_loop_freqs_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:281
Agenda get_iy_independent_beam_approx_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:694
Agenda get_main_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:658
Agenda get_iy_main_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:226
Agenda get_iy_cloudbox_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:332
std::pair< ArrayOfIndex, ArrayOfIndex > split_io(Array< AgendaMethodVariable > &var_order)
Split input and output of method variables.
Definition: agenda_set.cc:70
Agenda get_water_p_eq_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:438
Agenda get_dobatch_calc_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:550
Agenda get_inversion_iterate_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:706
Agenda get_surface_rtprop_sub_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:586
Agenda get_refr_index_air_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:390
Agenda get_spt_calc_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:598
Agenda get_pha_mat_spt_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:634
Agenda get_propmat_clearsky_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:622
std::array< MethodVariable, N > input_data_array(Workspace &ws, const Array< AgendaMethodVariable > &list, const std::array< SetWsv, N > &vals)
Definition: agenda_set.h:80
Agenda get_met_profile_calc_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:646
Agenda get_test_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:574
Agenda get_doit_scat_field_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:730
Agenda get_iy_radar_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:682
Agenda get_forloop_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:718
Agenda get_doit_conv_test_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:766
Agenda get_ybatch_calc_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:562
Agenda get_gas_scattering_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:453
Agenda get_doit_rte_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:742
Agenda get_iy_space_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:301
Agenda get_doit_mono_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:754
Array< AgendaMethodVariable > sorted_mdrecord(Workspace &ws, const String &method_name)
Return a full list of all the Method Variables with defaults on the workspace.
Definition: agenda_set.cc:12
Agenda get_sensor_response_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:610
Agenda get_surface_rtprop_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:467
Agenda get_jacobian_agenda(Workspace &ws, const String &option)
Definition: agenda_set.cc:670
void add_method_and_setters(Workspace &ws, Agenda &a, const std::string_view method, const std::array< SetWsv, N > &input)
Definition: agenda_set.h:105
const TokVal & to_tokval(Workspace &ws, const std::array< MethodVariable, N > &input_data)
Definition: agenda_set.h:92
VectorView var(VectorView var, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the variance of the ranged ys.
Definition: raw.cc:159
VectorView std(VectorView std, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the standard deviation of the ranged ys.
Definition: raw.cc:205
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:113
const Array< MdRecord > md_data
Lookup information for workspace methods.
Definition: methods_aux.cc:50
#define N
Definition: rng.cc:164
Helper class to create an agenda.
Definition: agenda_set.h:144
AgendaCreator(Workspace &workspace, const char *name)
Definition: agenda_set.cc:172
void add(const std::string_view method, Input &&... input)
Add a method with as many inputs as you want. These inputs must be of type Wsv.
Definition: agenda_set.h:155
Agenda finalize()
Check the agenda and return a copy of it (ignoring/touching all agenda input/output not dealt with)
Definition: agenda_set.cc:178
void set(const std::string_view var, const TokVal &value)
Set a variable to a value.
Definition: agenda_set.cc:215
void ignore(const std::string_view var)
Ignores a variable (only call if the variable input is ignored despite being BOTH in- and output)
Definition: agenda_set.cc:224
A Complete Description of a Method Variable.
Definition: agenda_set.h:12
friend std::ostream & operator<<(std::ostream &os, const AgendaMethodVariable &x)
DEBUG.
Definition: agenda_set.cc:8
void add_del(Workspace &ws, Agenda &a) const
Definition: agenda_set.cc:131
void method_position(const Array< AgendaMethodVariable > &list, const std::string_view rhs)
Definition: agenda_set.cc:156
void add_set(Workspace &ws, Agenda &a) const
Definition: agenda_set.cc:143
void wsv_position(Workspace &ws, const TokVal &value)
Definition: agenda_set.cc:165
opt
Checks for which type of information should be used later on.
Definition: agenda_set.h:35
SetWsv(const std::string &x, const std::string &y)
For named wsv1=wsv2.
Definition: agenda_set.cc:82
SetWsv(std::string_view x, ArtsType auto &&t)
For named value.
Definition: agenda_set.h:51
SetWsv(ArtsType auto &&t)
For position value.
Definition: agenda_set.h:48
std::string str
Definition: agenda_set.h:38
#define a
This file contains the Workspace class.