ARTS 2.5.9 (git: 825fa5f2)
agenda_record.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_record.h"
27#include <iostream>
28#include <map>
29
30#include "debug.h"
31#include "groups.h"
32#include "messages.h"
34#include "workspace_ng.h"
35#include "wsv_aux.h"
36
37namespace global_data {
39map<String, Index> AgendaMap;
40
41extern const Array<AgRecord> agenda_data;
43} // namespace global_data
44
46
56AgRecord::AgRecord(const char* name,
57 const char* description,
58 const ArrayOfString& output,
59 const ArrayOfString& input)
60 : mname(name), mdescription(description), moutput(0), minput(0) {
61 // We must check that this agenda exists in the workspace
62
63 // Find returns end() if the name is not found in the map. If
64 // this assertion fails, it means that we are trying to set the
65 // lookup data for an agenda that has not been defined in
66 // wsv_data (i.e., in workspace.cc). First make a record entry
67 // in workspace.cc for your agenda. If you have done so and
68 // still get an assertion failure, then check that you spelled
69 // the name in exactly the same way in both places.
71 std::ostringstream os;
72 os << "Agenda *" << mname << "* not found in WSV data.";
73 throw std::runtime_error(os.str());
74 }
75
76 moutput.resize(output.nelem());
77 for (Index j = 0; j < output.nelem(); ++j) {
78 auto wsv_ptr = global_data::WsvMap.find(output[j]);
79 ARTS_USER_ERROR_IF(wsv_ptr == global_data::WsvMap.end(), "The ", mname,
80 " agenda fails.\nOutput #", j + 1, " named ", output[j],
81 " is not a WSV")
82 moutput[j] = wsv_ptr->second;
83 if (moutput[j] == -1) {
84 ostringstream os;
85
86 os << "Unknown output WSV " << output[j] << " in WSM " << mname;
87 throw runtime_error(os.str());
88 }
89 }
90
91 minput.resize(input.nelem());
92 for (Index j = 0; j < input.nelem(); ++j) {
93 auto wsv_ptr = global_data::WsvMap.find(input[j]);
94 ARTS_USER_ERROR_IF(wsv_ptr == global_data::WsvMap.end(), "The ", mname,
95 " agenda fails.\nInput #", j + 1, " named ", input[j],
96 " is not a WSV")
97 minput[j] = wsv_ptr->second;
98 if (minput[j] == -1) {
99 ostringstream os;
100
101 os << "Unknown input WSV " << input[j] << " in WSM " << mname;
102 throw runtime_error(os.str());
103 }
104 }
105}
106
110
111 for (Index i = 0; i < agenda_data.nelem(); ++i) {
112 AgendaMap[agenda_data[i].Name()] = i;
113 }
114}
115
117
128 // Make external data visible
131
132 Index i, j;
133 DEBUG_ONLY(Index k=0;)
134
135 // Check, that each agenda from agenda_data occurs in wsv_data:
136 for (i = 0; i < agenda_data.nelem(); ++i) {
137 // cout << "Checking wsv_data for " << agenda_data[i].Name() << ".\n";
138
139 // Find returns end() if the name is not found in the map. If
140 // this assertion fails, it means that wsv_data does not contain
141 // this agenda.
142 // You have to add a record for your agenda in both files:
143 // workspace.cc and agendas.cc. The name has to be spelled
144 // exactly the same in both places.
145 // Uncomment the cout statement above and recompile to see which
146 // agenda causes the trouble.
148 global_data::WsvMap.find(agenda_data[i].Name()));
149 }
150
151 // Check, that each agenda from wsv_data occurs in agenda_data:
152 for (j = 0; j < global_data::wsv_data.nelem(); ++j) {
153 // Is this an agenda WSV?
154 if (get_wsv_group_id("Agenda") == global_data::wsv_data[j].Group() ||
155 get_wsv_group_id("ArrayOfAgenda") == global_data::wsv_data[j].Group()) {
156 // cout << "Checking agenda_data for " << Workspace::wsv_data[j].Name() << ".\n";
157
158 // Find returns end() if the name is not found in the map. If
159 // this assertion fails, it means that agenda_data does not contain
160 // this agenda.
161 // You have to add a record for your agenda in both files:
162 // workspace.cc and agendas.cc. The name has to be spelled
163 // exactly the same in both places.
164 // Uncomment the cout statement above and recompile to see which
165 // agenda causes the trouble.
166 ARTS_ASSERT(AgendaMap.end() != AgendaMap.find(global_data::wsv_data[j].Name()));
167
168 // Counts the number of agenda WSVs in Workspace::wsv_data:
169 DEBUG_ONLY(++k;)
170 }
171 }
172
173 // As a last check we make sure that both lists contain the same
174 // number of agendas:
175 ARTS_ASSERT(i == k);
176
177 return true;
178}
179
181
188ostream& operator<<(ostream& os, const AgRecord& agr) {
189 bool first;
190
191 os << "\n*-------------------------------------------------------------------*\n"
192 << "Workspace variable = " << agr.Name()
193 << "\n---------------------------------------------------------------------\n"
194 << "\n"
195 << agr.Description() << "\n"
196 << "\n---------------------------------------------------------------------\n";
197
198 os << "Group = Agenda\n";
199
200 // Output:
201 first = true;
202 os << "Output = ";
203 for (Index i = 0; i < agr.Out().nelem(); ++i) {
204 if (first)
205 first = false;
206 else
207 os << ", ";
208
209 os << global_data::wsv_data[agr.Out()[i]].Name();
210 }
211 os << "\n";
212
213 // Input:
214 first = true;
215 os << "Input = ";
216 for (Index i = 0; i < agr.In().nelem(); ++i) {
217 if (first)
218 first = false;
219 else
220 os << ", ";
221
222 os << global_data::wsv_data[agr.In()[i]].Name();
223 }
224
225 os << "\n*-------------------------------------------------------------------*\n";
226
227 return os;
228}
229
231
236 const AgRecord& agr,
237 bool is_agenda_array) {
239
240 // Wrapper function
241 ofs << "void " << agr.Name() << "Execute(\n";
242
243 // Wrapper function Workspace parameters
244 ofs << " // Workspace\n";
245 ofs << " Workspace& ws,\n";
246 // Wrapper function output parameters
247 const ArrayOfIndex& ago = agr.Out();
248 ofs << " // Output\n";
249 for (auto j : ago) {
250 ofs << " ";
251 ofs << wsv_groups[global_data::wsv_data[j].Group()] << "& ";
252 ofs << global_data::wsv_data[j].Name() << ",\n";
253 }
254
255 // Wrapper function input parameters
256 const ArrayOfIndex& agi = agr.In();
257 ofs << " // Input\n";
258 for (auto j : agi) {
259 // Ignore Input parameters that are also output
260 auto it = ago.begin();
261 while (it != ago.end() && *it != j) it++;
262
263 if (it == ago.end()) {
264 String group_name = wsv_groups[global_data::wsv_data[j].Group()].name;
265
266 ofs << " const ";
267 ofs << group_name;
268
269 // Don't pass by reference for elementary types
270 if (group_name != "Index" && group_name != "Numeric") {
271 ofs << "&";
272 }
273 ofs << " " << global_data::wsv_data[j].Name() << ",\n";
274 }
275 }
276
277 // Wrapper function agenda and silent parameters
278 ofs << " // Wrapper Input\n";
279 if (is_agenda_array) {
280 ofs << " const ArrayOfAgenda& input_agenda_array)";
281 } else {
282 ofs << " const Agenda& input_agenda)";
283 }
284}
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:43
const ArrayOfIndex & Out() const
Definition: agenda_record.h:61
ArrayOfIndex moutput
Workspace Output.
Definition: agenda_record.h:74
const ArrayOfIndex & In() const
Definition: agenda_record.h:62
AgRecord()
Default constructor.
Definition: agenda_record.h:46
ArrayOfIndex minput
Workspace Input.
Definition: agenda_record.h:77
const String & Description() const
Definition: agenda_record.h:60
String mname
The name of this agenda.
Definition: agenda_record.h:68
const String & Name() const
Definition: agenda_record.h:59
This can be used to make arrays out of anything.
Definition: array.h:48
Index nelem() const ARTS_NOEXCEPT
Definition: array.h:92
Helper macros for debugging.
#define DEBUG_ONLY(...)
Definition: debug.h:51
#define ARTS_ASSERT(condition,...)
Definition: debug.h:82
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
Index get_wsv_group_id(const String &name)
Returns the id of the given group.
Definition: groups.cc:360
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.
const ArrayOfGroupRecord wsv_groups
The names associated with Wsv groups as Strings.
Definition: global_data.h:91
Array< WsvRecord > wsv_data
Definition: workspace.cc:41
std::map< String, Index > WsvMap
Definition: workspace.cc:43
const Array< AgRecord > agenda_data
The lookup information for the agendas.
Definition: agendas.cc:41
map< String, Index > AgendaMap
The map associated with agenda_data.
This file contains the Workspace class.
Auxiliary header stuff related to workspace variable groups.