ARTS 2.5.9 (git: 825fa5f2)
m_agenda.cc
Go to the documentation of this file.
1/* Copyright (C) 2002-2012 Stefan Buehler <sbuehler@ltu.se>
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
26#include "agenda_class.h"
27#include "agenda_record.h"
28#include "debug.h"
29#include "global_data.h"
30#include "messages.h"
31#include "workspace_ng.h"
32#include "wsv_aux.h"
33
34#include <algorithm>
35#include <map>
36
37/* Workspace method: Doxygen documentation will be auto-generated */
38void AgendaExecute(Workspace& ws [[maybe_unused]],
39 // WS Generic Input:
40 const Agenda& this_agenda,
41 const Verbosity& verbosity) {
43 out3 << " Manual agenda execution\n";
44
45 if (!this_agenda.checked()) {
46 std::ostringstream os;
47 if (this_agenda.name().nelem() == 0)
48 os << "This agenda is uninitialized. We don't even know its name.";
49 else
50 os << "*" << this_agenda.name() << "* is uninitialized.";
51 os << " Use *AgendaSet* or *@arts_agenda* to add methods to it.";
52 throw std::runtime_error(os.str());
53 }
54
55 const auto [ain, aout] = this_agenda.get_global_inout();
56
57 // Put the input and outputs into new sets to sort them. Otherwise
58 // set_difference screws up.
59 set<Index> sain;
60 set<Index> saout;
61 sain.insert(ain.begin(), ain.end());
62 saout.insert(aout.begin(), aout.end());
63
64 set<Index> in_only;
65 set_difference(sain.begin(),
66 sain.end(),
67 saout.begin(),
68 saout.end(),
69 insert_iterator<set<Index> >(in_only, in_only.begin()));
70 for (Index it : in_only) {
71 ws.duplicate(it);
72 }
73
74 const ArrayOfIndex& outputs_to_push = this_agenda.get_output2push();
75 const ArrayOfIndex& outputs_to_dup = this_agenda.get_output2dup();
76
77 for (Index it : outputs_to_push) {
78 if (ws.is_initialized(it))
79 ws.duplicate(it);
80 else
81 ws.emplace(it);
82 }
83
84 for (auto it : outputs_to_dup) ws.duplicate(it);
85
86 String msg;
87 bool agenda_failed = false;
88
89 try {
90 this_agenda.execute(ws);
91 } catch (const std::exception& e) {
92 agenda_failed = true;
93 msg = e.what();
94 }
95
96 for (auto it : outputs_to_push) ws.pop(it);
97
98 for (auto it : outputs_to_dup) ws.pop(it);
99
100 for (auto it : in_only) ws.pop(it);
101
102 ARTS_USER_ERROR_IF(agenda_failed,
103 "Run-time error in agenda: ",
104 this_agenda.name(),
105 '\n',
106 msg);
107}
108
109/* Workspace method: Doxygen documentation will be auto-generated */
111 // WS Generic Input:
112 const Index& agenda_array_index,
113 const ArrayOfAgenda& agenda_array,
114 const Verbosity& verbosity) {
115 if (agenda_array_index < 0 || agenda_array_index >= agenda_array.nelem()) {
116 std::ostringstream os;
117 os << "Agenda index " << agenda_array_index
118 << " out of bounds. 0 <= index < " << agenda_array.nelem();
119 throw std::runtime_error(os.str());
120 }
121 AgendaExecute(ws, agenda_array[agenda_array_index], verbosity);
122}
123
124/* Workspace method: Doxygen documentation will be auto-generated */
126 // WS Generic Input:
127 const Agenda& this_agenda,
128 const Verbosity& verbosity) {
130 out3 << " Manual, exclusive agenda execution\n";
131
132#pragma omp critical(AgendaExecuteExclusive_region)
133 AgendaExecute(ws, this_agenda, verbosity);
134}
135
136/* Workspace method: Doxygen documentation will be auto-generated */
138 // WS Generic Output:
139 Agenda& output_agenda,
140 // WS Generic Output Names:
141 const String& agenda_name,
142 // Agenda from controlfile:
143 const Agenda& input_agenda,
144 const Verbosity& verbosity) {
145 output_agenda = input_agenda;
146
147 output_agenda.set_name(agenda_name);
148
149 output_agenda.check(ws, verbosity);
150}
151
152/* Workspace method: Doxygen documentation will be auto-generated */
154 // WS Generic Output:
155 ArrayOfAgenda& out,
156 // WS Generic Names:
157 const String& agenda_name,
158 // Agenda from controlfile:
159 const Agenda& input_agenda,
160 const Verbosity& verbosity) {
161 out.push_back(input_agenda);
162
163 Agenda& appended_agenda = out[out.nelem() - 1];
164 appended_agenda.set_name(agenda_name);
165
166 appended_agenda.check(ws, verbosity);
167}
168
169/* Workspace method: Doxygen documentation will be auto-generated */
170void AgendaAppend(Workspace& ws [[maybe_unused]],
171 // WS Generic Output:
172 Agenda& output_agenda,
173 // WS Generic Output Names:
174 const String& output_agenda_name,
175 // WS Generic Input:
176 const Agenda& in_agenda [[maybe_unused]],
177 // WS Generic Input Names:
178 const String& in_agenda_name,
179 // Agenda from controlfile:
180 const Agenda& input_agenda,
181 const Verbosity& verbosity) {
182 if (output_agenda_name != in_agenda_name) {
183 ostringstream os;
184 os << "Output and input agenda must be the same!" << endl
185 << "*" << output_agenda_name << "* and *" << in_agenda_name << "* "
186 << "are not.";
187 throw runtime_error(os.str());
188 }
189
190 Array<MRecord> methods = output_agenda.Methods();
191 for (Index i = 0; i < input_agenda.Methods().nelem(); i++)
192 methods.push_back(input_agenda.Methods()[i]);
193
194 output_agenda.set_methods(methods);
195 output_agenda.check(ws, verbosity);
196}
197
198/* Workspace method: Doxygen documentation will be auto-generated */
200 // Agenda from controlfile:
201 const Agenda&,
202 const Verbosity& verbosity) {
205 "The 'Arts' method is obsolete. Arts1 controlfiles are no longer supported.",
206 out0);
207}
208
209/* Workspace method: Doxygen documentation will be auto-generated */
211 // Agenda from controlfile:
212 const Agenda& input_agenda,
213 const Verbosity& verbosity) {
214 Verbosity* v = static_cast<Verbosity*>(ws[ws.WsvMap_ptr->find("verbosity") -> second].get());
215
216 // If the verbosity in the current workspace and the verbosity parameter point
217 // to the same variable in memory, that means we were called
218 // from inside a controlfile by the user. That is not permitted.
219 if (v == &verbosity) {
221 arts_exit_with_error_message("The 'Arts2' method can't be called directly.",
222 out0);
223 }
224 (*v) = verbosity;
225 input_agenda.execute(ws);
226}
Declarations for agendas.
Declarations for AgRecord, storing lookup information for one agenda.
void arts_exit_with_error_message(const String &m, ArtsOut &out)
Print error message and exit.
Definition: arts.cc:64
The Agenda class.
Definition: agenda_class.h:69
const ArrayOfIndex & get_output2push() const
Definition: agenda_class.h:94
String name() const
Agenda name.
void execute(Workspace &ws_in) const
Execute an agenda.
void set_methods(const Array< MRecord > &ml)
void check(Workspace &ws_in, const Verbosity &verbosity)
Checks consistency of an agenda.
const ArrayOfIndex & get_output2dup() const
Definition: agenda_class.h:95
std::pair< ArrayOfIndex, ArrayOfIndex > get_global_inout() const
Get index lists of global input and output variables from agenda_data of this agenda.
bool checked() const
Definition: agenda_class.h:102
void set_name(const String &nname)
Set agenda name.
const Array< MRecord > & Methods() const
Definition: agenda_class.h:86
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:92
Workspace class.
Definition: workspace_ng.h:53
T * get(const char *name)
Retrieve a value ptr if it exist (FIXME: C++20 allows const char* as template argument)
Definition: workspace_ng.h:188
std::shared_ptr< WsvMap_type > WsvMap_ptr
Definition: workspace_ng.h:79
Index nelem() const
Definition: mystring.h:189
Helper macros for debugging.
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
void AgendaAppend(Workspace &ws, Agenda &output_agenda, const String &output_agenda_name, const Agenda &in_agenda, const String &in_agenda_name, const Agenda &input_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: AgendaAppend.
Definition: m_agenda.cc:170
void ArrayOfAgendaAppend(Workspace &ws, ArrayOfAgenda &out, const String &agenda_name, const Agenda &input_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: ArrayOfAgendaAppend.
Definition: m_agenda.cc:153
void AgendaSet(Workspace &ws, Agenda &output_agenda, const String &agenda_name, const Agenda &input_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: AgendaSet.
Definition: m_agenda.cc:137
void AgendaExecute(Workspace &ws, const Agenda &this_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: AgendaExecute.
Definition: m_agenda.cc:38
void ArrayOfAgendaExecute(Workspace &ws, const Index &agenda_array_index, const ArrayOfAgenda &agenda_array, const Verbosity &verbosity)
WORKSPACE METHOD: ArrayOfAgendaExecute.
Definition: m_agenda.cc:110
void Arts(Workspace &, const Agenda &, const Verbosity &verbosity)
WORKSPACE METHOD: Arts.
Definition: m_agenda.cc:199
void AgendaExecuteExclusive(Workspace &ws, const Agenda &this_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: AgendaExecuteExclusive.
Definition: m_agenda.cc:125
void Arts2(Workspace &ws, const Agenda &input_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: Arts2.
Definition: m_agenda.cc:210
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Declarations having to do with the four output streams.
#define CREATE_OUT3
Definition: messages.h:206
#define CREATE_OUT0
Definition: messages.h:203
#define v
This file contains the Workspace class.
Auxiliary header stuff related to workspace variable groups.