ARTS 2.5.11 (git: 6827797f)
agenda_record.cc
Go to the documentation of this file.
1
9#include "agenda_record.h"
10#include <iostream>
11#include <map>
12
13#include "debug.h"
14#include "groups.h"
15#include "messages.h"
17#include "workspace_ng.h"
18#include "wsv_aux.h"
19
20namespace global_data {
22map<String, Index> AgendaMap;
23
24extern const Array<AgRecord> agenda_data;
26} // namespace global_data
27
29
39AgRecord::AgRecord(const char* name,
40 const char* description,
41 const ArrayOfString& output,
42 const ArrayOfString& input)
43 : mname(name), mdescription(description), moutput(0), minput(0) {
44 // We must check that this agenda exists in the workspace
45
46 // Find returns end() if the name is not found in the map. If
47 // this assertion fails, it means that we are trying to set the
48 // lookup data for an agenda that has not been defined in
49 // wsv_data (i.e., in workspace.cc). First make a record entry
50 // in workspace.cc for your agenda. If you have done so and
51 // still get an assertion failure, then check that you spelled
52 // the name in exactly the same way in both places.
54 std::ostringstream os;
55 os << "Agenda *" << mname << "* not found in WSV data.";
56 throw std::runtime_error(os.str());
57 }
58
59 moutput.resize(output.nelem());
60 for (Index j = 0; j < output.nelem(); ++j) {
61 auto wsv_ptr = global_data::WsvMap.find(output[j]);
62 ARTS_USER_ERROR_IF(wsv_ptr == global_data::WsvMap.end(), "The ", mname,
63 " agenda fails.\nOutput #", j + 1, " named ", output[j],
64 " is not a WSV")
65 moutput[j] = wsv_ptr->second;
66 if (moutput[j] == -1) {
67 ostringstream os;
68
69 os << "Unknown output WSV " << output[j] << " in WSM " << mname;
70 throw runtime_error(os.str());
71 }
72 }
73
74 minput.resize(input.nelem());
75 for (Index j = 0; j < input.nelem(); ++j) {
76 auto wsv_ptr = global_data::WsvMap.find(input[j]);
77 ARTS_USER_ERROR_IF(wsv_ptr == global_data::WsvMap.end(), "The ", mname,
78 " agenda fails.\nInput #", j + 1, " named ", input[j],
79 " is not a WSV")
80 minput[j] = wsv_ptr->second;
81 if (minput[j] == -1) {
82 ostringstream os;
83
84 os << "Unknown input WSV " << input[j] << " in WSM " << mname;
85 throw runtime_error(os.str());
86 }
87 }
88}
89
93
94 for (Index i = 0; i < agenda_data.nelem(); ++i) {
95 AgendaMap[agenda_data[i].Name()] = i;
96 }
97}
98
100
111 // Make external data visible
114
115 Index i, j;
116 DEBUG_ONLY(Index k=0;)
117
118 // Check, that each agenda from agenda_data occurs in wsv_data:
119 for (i = 0; i < agenda_data.nelem(); ++i) {
120 // cout << "Checking wsv_data for " << agenda_data[i].Name() << ".\n";
121
122 // Find returns end() if the name is not found in the map. If
123 // this assertion fails, it means that wsv_data does not contain
124 // this agenda.
125 // You have to add a record for your agenda in both files:
126 // workspace.cc and agendas.cc. The name has to be spelled
127 // exactly the same in both places.
128 // Uncomment the cout statement above and recompile to see which
129 // agenda causes the trouble.
131 global_data::WsvMap.find(agenda_data[i].Name()));
132 }
133
134 // Check, that each agenda from wsv_data occurs in agenda_data:
135 for (j = 0; j < global_data::wsv_data.nelem(); ++j) {
136 // Is this an agenda WSV?
137 if (get_wsv_group_id("Agenda") == global_data::wsv_data[j].Group() ||
138 get_wsv_group_id("ArrayOfAgenda") == global_data::wsv_data[j].Group()) {
139 // cout << "Checking agenda_data for " << Workspace::wsv_data[j].Name() << ".\n";
140
141 // Find returns end() if the name is not found in the map. If
142 // this assertion fails, it means that agenda_data does not contain
143 // this agenda.
144 // You have to add a record for your agenda in both files:
145 // workspace.cc and agendas.cc. The name has to be spelled
146 // exactly the same in both places.
147 // Uncomment the cout statement above and recompile to see which
148 // agenda causes the trouble.
149 ARTS_ASSERT(AgendaMap.end() != AgendaMap.find(global_data::wsv_data[j].Name()));
150
151 // Counts the number of agenda WSVs in Workspace::wsv_data:
152 DEBUG_ONLY(++k;)
153 }
154 }
155
156 // As a last check we make sure that both lists contain the same
157 // number of agendas:
158 ARTS_ASSERT(i == k);
159
160 return true;
161}
162
164
171ostream& operator<<(ostream& os, const AgRecord& agr) {
172 bool first;
173
174 os << "\n*-------------------------------------------------------------------*\n"
175 << "Workspace variable = " << agr.Name()
176 << "\n---------------------------------------------------------------------\n"
177 << "\n"
178 << agr.Description() << "\n"
179 << "\n---------------------------------------------------------------------\n";
180
181 os << "Group = Agenda\n";
182
183 // Output:
184 first = true;
185 os << "Output = ";
186 for (Index i = 0; i < agr.Out().nelem(); ++i) {
187 if (first)
188 first = false;
189 else
190 os << ", ";
191
192 os << global_data::wsv_data[agr.Out()[i]].Name();
193 }
194 os << "\n";
195
196 // Input:
197 first = true;
198 os << "Input = ";
199 for (Index i = 0; i < agr.In().nelem(); ++i) {
200 if (first)
201 first = false;
202 else
203 os << ", ";
204
205 os << global_data::wsv_data[agr.In()[i]].Name();
206 }
207
208 os << "\n*-------------------------------------------------------------------*\n";
209
210 return os;
211}
212
214
219 const AgRecord& agr,
220 bool is_agenda_array) {
222
223 // Wrapper function
224 ofs << "void " << agr.Name() << "Execute(\n";
225
226 // Wrapper function Workspace parameters
227 ofs << " // Workspace\n";
228 ofs << " Workspace& ws,\n";
229 // Wrapper function output parameters
230 const ArrayOfIndex& ago = agr.Out();
231 ofs << " // Output\n";
232 for (auto j : ago) {
233 ofs << " ";
234 ofs << wsv_groups[global_data::wsv_data[j].Group()] << "& ";
235 ofs << global_data::wsv_data[j].Name() << ",\n";
236 }
237
238 // Wrapper function input parameters
239 const ArrayOfIndex& agi = agr.In();
240 ofs << " // Input\n";
241 for (auto j : agi) {
242 // Ignore Input parameters that are also output
243 auto it = ago.begin();
244 while (it != ago.end() && *it != j) it++;
245
246 if (it == ago.end()) {
247 String group_name = wsv_groups[global_data::wsv_data[j].Group()].name;
248
249 ofs << " const ";
250 ofs << group_name;
251
252 // Don't pass by reference for elementary types
253 if (group_name != "Index" && group_name != "Numeric") {
254 ofs << "&";
255 }
256 ofs << " " << global_data::wsv_data[j].Name() << ",\n";
257 }
258 }
259
260 // Wrapper function agenda and silent parameters
261 ofs << " // Wrapper Input\n";
262 if (is_agenda_array) {
263 ofs << " const ArrayOfAgenda& input_agenda_array)";
264 } else {
265 ofs << " const Agenda& input_agenda)";
266 }
267}
void define_agenda_map()
ostream & operator<<(ostream &os, const AgRecord &agr)
Output operator for AgRecord.
bool check_agenda_data()
Check that agendas.cc and workspace.cc are consistent.
void write_agenda_wrapper_header(ofstream &ofs, const AgRecord &agr, bool is_agenda_array)
Write a agenda wrapper header.
Declarations for AgRecord, storing lookup information for one agenda.
Lookup information for one agenda.
Definition: agenda_record.h:26
const ArrayOfIndex & Out() const
Definition: agenda_record.h:44
ArrayOfIndex moutput
Workspace Output.
Definition: agenda_record.h:57
const ArrayOfIndex & In() const
Definition: agenda_record.h:45
AgRecord()
Default constructor.
Definition: agenda_record.h:29
ArrayOfIndex minput
Workspace Input.
Definition: agenda_record.h:60
const String & Description() const
Definition: agenda_record.h:43
String mname
The name of this agenda.
Definition: agenda_record.h:51
const String & Name() const
Definition: agenda_record.h:42
This can be used to make arrays out of anything.
Definition: array.h:31
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:75
Helper macros for debugging.
#define DEBUG_ONLY(...)
Definition: debug.h:53
#define ARTS_ASSERT(condition,...)
Definition: debug.h:84
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:135
Index get_wsv_group_id(const String &name)
Returns the id of the given group.
Definition: groups.cc:346
Declarations having to do with the four output streams.
const ArrayOfGroupRecord wsv_groups
The names associated with Wsv groups as Strings.
Definition: global_data.h:74
Array< WsvRecord > wsv_data
Definition: workspace.cc:22
std::map< String, Index > WsvMap
Definition: workspace.cc:24
const Array< AgRecord > agenda_data
The lookup information for the agendas.
Definition: agendas.cc:24
map< String, Index > AgendaMap
The map associated with agenda_data.
This file contains the Workspace class.
Auxiliary header stuff related to workspace variable groups.