ARTS  2.4.0(git:4fb77825)
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 <algorithm>
27 #include <map>
28 #include "agenda_class.h"
29 #include "agenda_record.h"
30 #include "global_data.h"
31 #include "messages.h"
32 #include "workspace_ng.h"
33 #include "wsv_aux.h"
34 
35 /* Workspace method: Doxygen documentation will be auto-generated */
37  // WS Generic Input:
38  const Agenda& this_agenda,
39  const Verbosity& verbosity) {
41  out3 << " Manual agenda execution\n";
42 
45 
46  if (!this_agenda.checked()) {
47  std::ostringstream os;
48  if (this_agenda.name().nelem() == 0)
49  os << "This agenda is uninitialized. We don't even know its name.";
50  else
51  os << "*" << this_agenda.name() << "* is uninitialized.";
52  os << " Use *AgendaSet* to add methods to it.";
53  throw std::runtime_error(os.str());
54  }
55 
56  const AgRecord& agr = agenda_data[AgendaMap.find(this_agenda.name())->second];
57 
58  // Duplicate input-only arguments of the agenda as they might be
59  // changed inside the agenda.
60  const ArrayOfIndex& ain = agr.In();
61  const ArrayOfIndex& aout = agr.Out();
62 
63  // Put the input and outputs into new sets to sort them. Otherwise
64  // set_difference screws up.
65  set<Index> sain;
66  set<Index> saout;
67  sain.insert(ain.begin(), ain.end());
68  saout.insert(aout.begin(), aout.end());
69 
70  set<Index> in_only;
71  set_difference(sain.begin(),
72  sain.end(),
73  saout.begin(),
74  saout.end(),
75  insert_iterator<set<Index> >(in_only, in_only.begin()));
76  for (set<Index>::const_iterator it = in_only.begin(); it != in_only.end();
77  it++) {
78  ws.duplicate(*it);
79  }
80 
81  const ArrayOfIndex& outputs_to_push = this_agenda.get_output2push();
82  const ArrayOfIndex& outputs_to_dup = this_agenda.get_output2dup();
83 
84  for (ArrayOfIndex::const_iterator it = outputs_to_push.begin();
85  it != outputs_to_push.end();
86  it++) {
87  if (ws.is_initialized(*it))
88  ws.duplicate(*it);
89  else
90  ws.push_uninitialized(*it, NULL);
91  }
92 
93  for (ArrayOfIndex::const_iterator it = outputs_to_dup.begin();
94  it != outputs_to_dup.end();
95  it++) {
96  ws.duplicate(*it);
97  }
98 
99  String agenda_error_msg;
100  bool agenda_failed = false;
101 
102  try {
103  this_agenda.execute(ws);
104  } catch (const std::exception& e) {
105  ostringstream os;
106  os << "Run-time error in agenda: " << this_agenda.name() << '\n'
107  << e.what();
108  agenda_failed = true;
109  agenda_error_msg = os.str();
110  }
111  for (ArrayOfIndex::const_iterator it = outputs_to_push.begin();
112  it != outputs_to_push.end();
113  it++) {
114  ws.pop_free(*it);
115  }
116 
117  for (ArrayOfIndex::const_iterator it = outputs_to_dup.begin();
118  it != outputs_to_dup.end();
119  it++) {
120  ws.pop_free(*it);
121  }
122 
123  for (set<Index>::const_iterator it = in_only.begin(); it != in_only.end();
124  it++) {
125  ws.pop_free(*it);
126  }
127 
128  if (agenda_failed) throw runtime_error(agenda_error_msg);
129 }
130 
131 /* Workspace method: Doxygen documentation will be auto-generated */
133  // WS Generic Input:
134  const Index& agenda_array_index,
135  const ArrayOfAgenda& agenda_array,
136  const Verbosity& verbosity) {
137  if (agenda_array_index < 0 || agenda_array_index >= agenda_array.nelem()) {
138  std::ostringstream os;
139  os << "Agenda index " << agenda_array_index
140  << " out of bounds. 0 <= index < " << agenda_array.nelem();
141  throw std::runtime_error(os.str());
142  }
143  AgendaExecute(ws, agenda_array[agenda_array_index], verbosity);
144 }
145 
146 /* Workspace method: Doxygen documentation will be auto-generated */
148  // WS Generic Input:
149  const Agenda& this_agenda,
150  const Verbosity& verbosity) {
151  CREATE_OUT3;
152  out3 << " Manual, exclusive agenda execution\n";
153 
154 #pragma omp critical(AgendaExecuteExclusive_region)
155  AgendaExecute(ws, this_agenda, verbosity);
156 }
157 
158 /* Workspace method: Doxygen documentation will be auto-generated */
160  // WS Generic Output:
161  Agenda& output_agenda,
162  // WS Generic Output Names:
163  const String& agenda_name,
164  // Agenda from controlfile:
165  const Agenda& input_agenda,
166  const Verbosity& verbosity) {
167  output_agenda = input_agenda;
168  output_agenda.set_name(agenda_name);
169 
170  output_agenda.check(ws, verbosity);
171 }
172 
173 /* Workspace method: Doxygen documentation will be auto-generated */
175  // WS Generic Output:
176  ArrayOfAgenda& out,
177  // WS Generic Names:
178  const String& agenda_name,
179  // Agenda from controlfile:
180  const Agenda& input_agenda,
181  const Verbosity& verbosity) {
182  out.push_back(input_agenda);
183 
184  Agenda& appended_agenda = out[out.nelem() - 1];
185  appended_agenda.set_name(agenda_name);
186 
187  appended_agenda.check(ws, verbosity);
188 }
189 
190 /* Workspace method: Doxygen documentation will be auto-generated */
192  // WS Generic Output:
193  Agenda& output_agenda,
194  // WS Generic Output Names:
195  const String& output_agenda_name,
196  // WS Generic Input:
197  const Agenda& in_agenda _U_,
198  // WS Generic Input Names:
199  const String& in_agenda_name,
200  // Agenda from controlfile:
201  const Agenda& input_agenda,
202  const Verbosity& verbosity) {
203  if (output_agenda_name != in_agenda_name) {
204  ostringstream os;
205  os << "Output and input agenda must be the same!" << endl
206  << "*" << output_agenda_name << "* and *" << in_agenda_name << "* "
207  << "are not.";
208  throw runtime_error(os.str());
209  }
210 
211  Array<MRecord> methods = output_agenda.Methods();
212  for (Index i = 0; i < input_agenda.Methods().nelem(); i++)
213  methods.push_back(input_agenda.Methods()[i]);
214 
215  output_agenda.set_methods(methods);
216  output_agenda.check(ws, verbosity);
217 }
218 
219 /* Workspace method: Doxygen documentation will be auto-generated */
221  // Agenda from controlfile:
222  const Agenda&,
223  const Verbosity& verbosity) {
224  CREATE_OUT0;
226  "The 'Arts' method is obsolete. Arts1 controlfiles are no longer supported.",
227  out0);
228 }
229 
230 /* Workspace method: Doxygen documentation will be auto-generated */
231 void Arts2(Workspace& ws,
232  // Agenda from controlfile:
233  const Agenda& input_agenda,
234  const Verbosity& verbosity) {
235  Verbosity* v = (Verbosity*)ws[get_wsv_id("verbosity")];
236 
237  // If the verbosity in the current workspace and the verbosity parameter point
238  // to the same variable in memory, that means we were called
239  // from inside a controlfile by the user. That is not permitted.
240  if (v == &verbosity) {
241  CREATE_OUT0;
242  arts_exit_with_error_message("The 'Arts2' method can't be called directly.",
243  out0);
244  }
245  (*v) = verbosity;
246  input_agenda.execute(ws);
247 }
agenda_record.h
Declarations for AgRecord, storing lookup information for one agenda.
ArrayOfAgendaExecute
void ArrayOfAgendaExecute(Workspace &ws, const Index &agenda_array_index, const ArrayOfAgenda &agenda_array, const Verbosity &verbosity)
WORKSPACE METHOD: ArrayOfAgendaExecute.
Definition: m_agenda.cc:132
Agenda::execute
void execute(Workspace &ws) const
Execute an agenda.
Definition: agenda_class.cc:148
get_wsv_id
Index get_wsv_id(const String &name)
Get index of WSV.
Definition: workspace.cc:5751
ARTS::Var::verbosity
Verbosity verbosity(Workspace &ws) noexcept
Definition: autoarts.h:7112
Agenda::set_methods
void set_methods(const Array< MRecord > &ml)
Definition: agenda_class.h:76
global_data::AgendaMap
map< String, Index > AgendaMap
The map associated with agenda_data.
Definition: agenda_record.cc:35
Agenda::get_output2dup
const ArrayOfIndex & get_output2dup() const
Definition: agenda_class.h:86
ArrayOfAgendaAppend
void ArrayOfAgendaAppend(Workspace &ws, ArrayOfAgenda &out, const String &agenda_name, const Agenda &input_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: ArrayOfAgendaAppend.
Definition: m_agenda.cc:174
Agenda
The Agenda class.
Definition: agenda_class.h:44
Agenda::checked
bool checked() const
Definition: agenda_class.h:93
Array
This can be used to make arrays out of anything.
Definition: array.h:108
methods
std::vector< Method > methods()
Definition: make_autoarts_h.cc:129
Absorption::nelem
Index nelem(const Lines &l)
Number of lines.
Definition: absorptionlines.h:1820
AgendaExecuteExclusive
void AgendaExecuteExclusive(Workspace &ws, const Agenda &this_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: AgendaExecuteExclusive.
Definition: m_agenda.cc:147
agenda_class.h
Declarations for agendas.
CREATE_OUT3
#define CREATE_OUT3
Definition: messages.h:207
CREATE_OUT0
#define CREATE_OUT0
Definition: messages.h:204
AgendaAppend
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:191
messages.h
Declarations having to do with the four output streams.
AgRecord
Lookup information for one agenda.
Definition: agenda_record.h:43
_U_
#define _U_
Definition: config.h:183
my_basic_string< char >
AgendaSet
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:159
Agenda::name
String name() const
Agenda name.
Definition: agenda_class.cc:658
Verbosity
Definition: messages.h:49
global_data.h
Arts
void Arts(Workspace &, const Agenda &, const Verbosity &verbosity)
WORKSPACE METHOD: Arts.
Definition: m_agenda.cc:220
Workspace::pop_free
void pop_free(Index i)
Remove the topmost WSV from its stack and free its memory.
Definition: workspace_ng.cc:141
Agenda::check
void check(Workspace &ws, const Verbosity &verbosity)
Checks consistency of an agenda.
Definition: agenda_class.cc:80
my_basic_string::nelem
Index nelem() const
Number of elements.
Definition: mystring.h:246
Workspace::duplicate
void duplicate(Index i)
Duplicate WSV.
Definition: workspace_ng.cc:77
AgRecord::In
const ArrayOfIndex & In() const
Definition: agenda_record.h:61
Workspace::push_uninitialized
void push_uninitialized(Index i, void *wsv)
Put a new WSV onto its stack.
Definition: workspace_ng.cc:161
workspace_ng.h
This file contains the Workspace class.
Arts2
void Arts2(Workspace &ws, const Agenda &input_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: Arts2.
Definition: m_agenda.cc:231
Workspace
Workspace class.
Definition: workspace_ng.h:40
AgendaExecute
void AgendaExecute(Workspace &ws, const Agenda &this_agenda, const Verbosity &verbosity)
WORKSPACE METHOD: AgendaExecute.
Definition: m_agenda.cc:36
Agenda::get_output2push
const ArrayOfIndex & get_output2push() const
Definition: agenda_class.h:85
Agenda::set_name
void set_name(const String &nname)
Set agenda name.
Definition: agenda_class.cc:647
global_data::agenda_data
const Array< AgRecord > agenda_data
The lookup information for the agendas.
Definition: agendas.cc:41
ARTS::Var::agenda_array_index
Index agenda_array_index(Workspace &ws) noexcept
Definition: autoarts.h:2311
Workspace::is_initialized
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:118
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Agenda::Methods
const Array< MRecord > & Methods() const
Definition: agenda_class.h:74
arts_exit_with_error_message
void arts_exit_with_error_message(const String &m, ArtsOut &out)
Print error message and exit.
Definition: arts.cc:64
AgRecord::Out
const ArrayOfIndex & Out() const
Definition: agenda_record.h:60
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:195
wsv_aux.h
Auxiliary header stuff related to workspace variable groups.