ARTS  2.2.66
agenda_class.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-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 #ifndef agenda_class_h
27 #define agenda_class_h
28 
29 #include <set>
30 #include "token.h"
31 #include "messages.h"
32 
33 class MRecord;
34 
35 class Workspace;
36 
38 
44 class Agenda {
45 public:
46 
48  mchecked(false)
49  { /* Nothing to do here */ }
50 
54  Agenda(const Agenda& x) : mname(x.mname),
55  mml(x.mml),
60  { /* Nothing to do here */ }
61 
62 
63  void append(const String& methodname, const TokVal& keywordvalue);
64  void check(Workspace& ws, const Verbosity& verbosity);
65  void push_back(const MRecord& n);
66  void execute(Workspace& ws) const;
67  inline void resize(Index n);
68  inline Index nelem() const;
69  inline Agenda& operator=(const Agenda& x);
70  const Array<MRecord>& Methods() const { return mml; }
71  bool has_method(const String& methodname) const;
72  void set_methods(const Array<MRecord>& ml) { mml = ml; mchecked = false; }
73  void set_outputs_to_push_and_dup(const Verbosity& verbosity);
74  bool is_input(Workspace& ws, Index var) const;
75  bool is_output(Index var) const;
76  void set_name(const String& nname);
77  String name() const;
78  const ArrayOfIndex& get_output2push() const { return moutput_push; }
79  const ArrayOfIndex& get_output2dup() const { return moutput_dup; }
80  void print(ostream& os, const String& indent) const;
81  void set_main_agenda() { main_agenda = true; mchecked = true; }
82  bool is_main_agenda() const { return main_agenda; }
83  void find_unused_variables();
84  bool checked() const { return mchecked; }
85 
86 private:
91 
93 
96 
98  bool mchecked;
99 };
100 
101 // Documentation with implementation.
102 ostream& operator<<(ostream& os, const Agenda& a);
103 
104 
113 class MRecord {
114 public:
115  MRecord() : mid(-1),
116  moutput(),
117  minput(),
118  msetvalue(),
119  mtasks(),
120  minternal(false)
121  { /* Nothing to do here. */ }
122 
123  MRecord(const MRecord& x) : mid(x.mid),
124  moutput(x.moutput),
125  minput(x.minput),
126  msetvalue(x.msetvalue),
127  mtasks(x.mtasks),
128  minternal(x.minternal)
129  { /* Nothing to do here */ }
130 
131  MRecord(const Index id,
132  const ArrayOfIndex& output,
133  const ArrayOfIndex& input,
134  const TokVal& setvalue,
135  const Agenda& tasks,
136  bool internal = false) : mid(id),
137  moutput(output),
138  minput(input),
139  msetvalue(setvalue),
140  mtasks(tasks),
141  minternal(internal)
142  { /* Nothing to do here */ }
143 
144  Index Id() const { return mid; }
145  const ArrayOfIndex& Out() const { return moutput; }
146  const ArrayOfIndex& In() const { return minput; }
147  const TokVal& SetValue() const { return msetvalue; }
148  const Agenda& Tasks() const { return mtasks; }
149 
151 
158  bool isInternal() const { return minternal; }
159 
161 
182  {
183  mid = x.mid;
184 
185  msetvalue = x.msetvalue;
186 
187  moutput.resize(x.moutput.nelem());
188  moutput = x.moutput;
189 
190  minput.resize(x.minput.nelem());
191  minput = x.minput;
192 
193  mtasks.resize(x.mtasks.nelem());
194  mtasks = x.mtasks;
195 
196  return *this;
197  }
198 
200 
209  void ginput_only(ArrayOfIndex& ginonly) const
210  {
211  ginonly = minput; // Input
212  for (ArrayOfIndex::const_iterator j = moutput.begin(); j < moutput.end(); ++j)
213  for (ArrayOfIndex::iterator k = ginonly.begin(); k < ginonly.end(); ++k)
214  if (*j == *k)
215  {
216  // erase_vector_element(vi,k);
217  k = ginonly.erase(k) - 1;
218  // We need the -1 here, otherwise due to the
219  // following increment we would miss the element
220  // behind the erased one, which is now at the
221  // position of the erased one.
222  }
223  }
224 
225  // Output operator:
226  void print(ostream& os, const String& indent) const;
227 
228 private:
241  bool minternal;
242 };
243 
245 
248 inline void Agenda::resize(Index n)
249 {
250  mml.resize(n);
251 }
252 
254 
260 inline Index Agenda::nelem() const
261 {
262  return mml.nelem();
263 }
264 
265 
267 
272 inline void Agenda::push_back(const MRecord& n)
273 {
274  mml.push_back(n);
275  mchecked = false;
276 }
277 
278 
280 
283 inline Agenda& Agenda::operator=(const Agenda& x)
284 {
285  mml = x.mml;
286  mname = x.mname;
289  mchecked = x.mchecked;
290  return *this;
291 }
292 
293 // Documentation is with implementation.
294 ostream& operator<<(ostream& os, const MRecord& a);
295 
296 #endif
297 
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
void set_outputs_to_push_and_dup(const Verbosity &verbosity)
Retrieve indexes of all input and output WSVs.
bool main_agenda
Is set to true if this is the main agenda.
Definition: agenda_class.h:95
void find_unused_variables()
The Agenda class.
Definition: agenda_class.h:44
String name() const
Agenda name.
Index nelem() const
Number of elements.
Definition: array.h:176
void check(Workspace &ws, const Verbosity &verbosity)
Checks consistency of an agenda.
Definition: agenda_class.cc:84
Declarations having to do with the four output streams.
const ArrayOfIndex & In() const
Definition: agenda_class.h:146
ArrayOfIndex minput
Input workspace variables.
Definition: agenda_class.h:234
void ginput_only(ArrayOfIndex &ginonly) const
Get list of generic input only WSVs.
Definition: agenda_class.h:209
Agenda(const Agenda &x)
Definition: agenda_class.h:54
void resize(Index n)
Resize the method list.
Definition: agenda_class.h:248
Index Id() const
Definition: agenda_class.h:144
const ArrayOfIndex & Out() const
Definition: agenda_class.h:145
ArrayOfIndex moutput_dup
Definition: agenda_class.h:92
bool mchecked
Flag indicating that the agenda was checked for consistency.
Definition: agenda_class.h:98
bool has_method(const String &methodname) const
Check if method is in Agenda.
TokVal msetvalue
Keyword value for Set methods.
Definition: agenda_class.h:236
bool is_main_agenda() const
Definition: agenda_class.h:82
ArrayOfIndex moutput_push
Definition: agenda_class.h:90
Method runtime data.
Definition: agenda_class.h:113
bool is_input(Workspace &ws, Index var) const
Check if given variable is agenda input.
bool minternal
Flag if this method is called internally by the engine.
Definition: agenda_class.h:241
void execute(Workspace &ws) const
Execute an agenda.
MRecord(const Index id, const ArrayOfIndex &output, const ArrayOfIndex &input, const TokVal &setvalue, const Agenda &tasks, bool internal=false)
Definition: agenda_class.h:131
Index nelem() const
Return the number of agenda elements.
Definition: agenda_class.h:260
void set_methods(const Array< MRecord > &ml)
Definition: agenda_class.h:72
String mname
Definition: agenda_class.h:87
const ArrayOfIndex & get_output2push() const
Definition: agenda_class.h:78
const ArrayOfIndex & get_output2dup() const
Definition: agenda_class.h:79
MRecord & operator=(const MRecord &x)
Assignment operator for MRecord.
Definition: agenda_class.h:181
bool isInternal() const
Indicates the origin of this method.
Definition: agenda_class.h:158
void print(ostream &os, const String &indent) const
Print an agenda.
void set_name(const String &nname)
Set agenda name.
const Array< MRecord > & Methods() const
Definition: agenda_class.h:70
Agenda mtasks
An agenda, which can be given in the controlfile instead of keywords.
Definition: agenda_class.h:239
const TokVal & SetValue() const
Definition: agenda_class.h:147
void set_main_agenda()
Definition: agenda_class.h:81
bool is_output(Index var) const
Check if given variable is agenda output.
Workspace class.
Definition: workspace_ng.h:47
ArrayOfIndex moutput
Output workspace variables.
Definition: agenda_class.h:232
const Agenda & Tasks() const
Definition: agenda_class.h:148
Array< MRecord > mml
Definition: agenda_class.h:88
bool checked() const
Definition: agenda_class.h:84
Agenda & operator=(const Agenda &x)
Assignment operator.
Definition: agenda_class.h:283
MRecord(const MRecord &x)
Definition: agenda_class.h:123
This stores arbitrary token values and remembers the type.
Definition: token.h:33
Index mid
Method id.
Definition: agenda_class.h:230
ostream & operator<<(ostream &os, const Agenda &a)
Output operator for Agenda.
void append(const String &methodname, const TokVal &keywordvalue)
Appends methods to an agenda.
Definition: agenda_class.cc:59
void push_back(const MRecord &n)
Append a new method to end of list.
Definition: agenda_class.h:272