ARTS  2.0.49
agenda_record.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008 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 <map>
27 #include <iostream>
28 #include "messages.h"
29 #include "agenda_record.h"
30 #include "wsv_aux.h"
31 #include "workspace_ng.h"
32 
34 
44 AgRecord::AgRecord( const char name[],
45  const char description[],
46  const MakeArray<String>& output,
47  const MakeArray<String>& input ) :
48  mname( name ),
49  mdescription( description ),
50  moutput( 0 ),
51  minput( 0 )
52 {
53  // We must check that this agenda exists in the workspace
54 
55  // Find returns end() if the name is not found in the map. If
56  // this assertion fails, it means that we are trying to set the
57  // lookup data for an agenda that has not been defined in
58  // wsv_data (i.e., in workspace.cc). First make a record entry
59  // in workspace.cc for your agenda. If you have done so and
60  // still get an assertion failure, then check that you spelled
61  // the name in exactly the same way in both places.
62  assert( Workspace::WsvMap.end() !=
63  Workspace::WsvMap.find(mname) );
64 
65  moutput.resize(output.nelem());
66  for ( Index j=0; j<output.nelem(); ++j )
67  {
68  moutput[j] = get_wsv_id (output[j]);
69  if (moutput[j] == -1)
70  {
71  ostringstream os;
72 
73  os << "Unknown output WSV " << output[j] << " in WSM " << mname;
74  throw runtime_error( os.str() );
75  }
76  }
77 
78  minput.resize(input.nelem());
79  for ( Index j=0; j<input.nelem(); ++j )
80  {
81  minput[j] = get_wsv_id (input[j]);
82  if (minput[j] == -1)
83  {
84  ostringstream os;
85 
86  os << "Unknown input WSV " << input[j] << " in WSM " << mname;
87  throw runtime_error( os.str() );
88  }
89  }
90 
91 }
92 
94 {
95  extern const Array<AgRecord> agenda_data;
96  extern map<String, Index> AgendaMap;
97 
98  for ( Index i=0 ; i<agenda_data.nelem() ; ++i )
99  {
100  AgendaMap[agenda_data[i].Name()] = i;
101  }
102 }
103 
105 
116 {
117  // Make external data visible
118  extern const Array<AgRecord> agenda_data;
119  DEBUG_ONLY (extern map<String, Index> AgendaMap);
120 
121  Index i,j,k;
122 
123  k = 0;
124 
125  // Check, that each agenda from agenda_data occurs in wsv_data:
126  for ( i=0; i<agenda_data.nelem(); ++i )
127  {
128  // cout << "Checking wsv_data for " << agenda_data[i].Name() << ".\n";
129 
130  // Find returns end() if the name is not found in the map. If
131  // this assertion fails, it means that wsv_data does not contain
132  // this agenda.
133  // You have to add a record for your agenda in both files:
134  // workspace.cc and agendas.cc. The name has to be spelled
135  // exactly the same in both places.
136  // Uncomment the cout statement above and recompile to see which
137  // agenda causes the trouble.
138  assert( Workspace::WsvMap.end() !=
139  Workspace::WsvMap.find(agenda_data[i].Name()) );
140  }
141 
142  // Check, that each agenda from wsv_data occurs in agenda_data:
143  for ( j=0; j<Workspace::wsv_data.nelem(); ++j )
144  {
145  // Is this an agenda WSV?
146  if ( get_wsv_group_id ("Agenda") == Workspace::wsv_data[j].Group() )
147  {
148  // cout << "Checking agenda_data for " << Workspace::wsv_data[j].Name() << ".\n";
149 
150  // Find returns end() if the name is not found in the map. If
151  // this assertion fails, it means that agenda_data does not contain
152  // this agenda.
153  // You have to add a record for your agenda in both files:
154  // workspace.cc and agendas.cc. The name has to be spelled
155  // exactly the same in both places.
156  // Uncomment the cout statement above and recompile to see which
157  // agenda causes the trouble.
158  assert( AgendaMap.end() !=
159  AgendaMap.find(Workspace::wsv_data[j].Name()) );
160 
161  // Counts the number of agenda WSVs in Workspace::wsv_data:
162  ++k;
163  }
164  }
165 
166  // As a last check we make sure that both lists contain the same
167  // number of agendas:
168  assert( i==k );
169 
170  return true;
171 }
172 
174 
181 ostream& operator<<(ostream& os, const AgRecord& agr)
182 {
183  // extern const ArrayOfString wsv_group_names;
184  // extern const String TokValTypeName[];
185  bool first;
186 
187  os << "\n*-------------------------------------------------------------------*\n"
188  << "Workspace variable = " << agr.Name()
189  << "\n---------------------------------------------------------------------\n"
190  << "\n" << agr.Description() << "\n"
191  << "\n---------------------------------------------------------------------\n";
192 
193  // os << "\n-----\nName = " << agr.Name() << '\n\n'
194  // << "Description =\n" << agr.Description() << "\n\n";
195 
196  os << "Group = Agenda\n";
197 
198  // Output:
199  first = true;
200  os << "Output = ";
201  for ( Index i=0; i<agr.Out().nelem(); ++i )
202  {
203  if (first) first=false;
204  else os << ", ";
205 
206  os << Workspace::wsv_data[agr.Out()[i]].Name();
207  }
208  os << "\n";
209 
210  // Input:
211  first = true;
212  os << "Input = ";
213  for ( Index i=0; i<agr.In().nelem(); ++i )
214  {
215  if (first) first=false;
216  else os << ", ";
217 
218  os << Workspace::wsv_data[agr.In()[i]].Name();
219  }
220 
221  os << "\n*-------------------------------------------------------------------*\n";
222 
223  return os;
224 }
225 
227 
236 ostream& operator<<(ostream& os, const WsvRecord& wr)
237 {
238  extern const ArrayOfString wsv_group_names;
239 
240  // We need a special treatment for the case that the WSV is an agenda.
241 
242  if ( get_wsv_group_id("Agenda") != wr.Group() )
243  {
244  // No agenda.
245 
246  os << "\n*-------------------------------------------------------------------*\n"
247  << "Workspace variable = " << wr.Name()
248  << "\n---------------------------------------------------------------------\n"
249  << "\n" << wr.Description() << "\n"
250  << "\n---------------------------------------------------------------------\n"
251  << "Group = " << wsv_group_names[wr.Group()]
252  << "\n*-------------------------------------------------------------------*\n";
253  }
254  else
255  {
256  // Agenda.
257 
258  extern const Array<AgRecord> agenda_data;
259  // AgendaMap is constant here and should never be changed
260  extern map<String, Index> AgendaMap;
261 
262  map<String, Index>::const_iterator j =
263  AgendaMap.find( wr.Name() );
264 
265  // Just for added safety, check that we really found something:
266  assert( j != AgendaMap.end() );
267 
268  cout << agenda_data[j->second] << "\n";
269  }
270 
271  return os;
272 }
273 
275 
279 void write_agenda_wrapper_header( ofstream& ofs,
280  const AgRecord& agr)
281 {
282  extern const ArrayOfString wsv_group_names;
283 
284  // Wrapper function
285  ofs << "void " << agr.Name () << "Execute(\n";
286 
287  // Wrapper function Workspace parameters
288  ofs << " // Workspace\n";
289  ofs << " Workspace& ws,\n";
290  // Wrapper function output parameters
291  const ArrayOfIndex& ago = agr.Out();
292  ofs << " // Output\n";
293  for (ArrayOfIndex::const_iterator j = ago.begin (); j != ago.end (); j++)
294  {
295  ofs << " ";
296  ofs << wsv_group_names[Workspace::wsv_data[*j].Group()] << "& ";
297  ofs << Workspace::wsv_data[*j].Name() << ",\n";
298  }
299 
300  // Wrapper function input parameters
301  const ArrayOfIndex& agi = agr.In();
302  ofs << " // Input\n";
303  for (ArrayOfIndex::const_iterator j = agi.begin (); j != agi.end (); j++)
304  {
305  // Ignore Input parameters that are also output
306  ArrayOfIndex::const_iterator it = ago.begin ();
307  while (it != ago.end () && *it != *j) it++;
308  if (it == ago.end ())
309  {
310  String group_name = wsv_group_names[Workspace::wsv_data[*j].Group()];
311 
312  ofs << " const ";
313  ofs << group_name;
314 
315  // Don't pass by reference for elementary types
316  if ( group_name != "Index" && group_name != "Numeric")
317  {
318  ofs << "&";
319  }
320  ofs << " " << Workspace::wsv_data[*j].Name() << ",\n";
321  }
322  }
323 
324  // Wrapper function agenda and silent parameters
325  ofs << " // Wrapper Input\n";
326  ofs << " const Agenda& input_agenda)";
327 }
328 
agenda_record.h
Declarations for AgRecord, storing lookup information for one agenda.
Workspace::wsv_data
static Array< WsvRecord > wsv_data
Definition: workspace_ng.h:59
AgRecord::minput
ArrayOfIndex minput
Workspace Input.
Definition: agenda_record.h:88
AgendaMap
map< String, Index > AgendaMap
The map assiciated with agenda_data.
Definition: globals_2.cc:71
AgRecord::AgRecord
AgRecord()
Default constructor.
Definition: agenda_record.h:48
get_wsv_id
Index get_wsv_id(const String &name)
Get index of WSV.
Definition: workspace.cc:4555
DEBUG_ONLY
#define DEBUG_ONLY(...)
Definition: arts.h:146
Array
This can be used to make arrays out of anything.
Definition: array.h:103
WsvRecord::Group
Index Group() const
The wsv group to which this variable belongs.
Definition: wsv_aux.h:102
agenda_data
Array< AgRecord > agenda_data
Definition: agendas.cc:40
messages.h
Declarations having to do with the four output streams.
write_agenda_wrapper_header
void write_agenda_wrapper_header(ofstream &ofs, const AgRecord &agr)
Write a agenda wrapper header.
Definition: agenda_record.cc:279
AgRecord
Lookup information for one agenda.
Definition: agenda_record.h:44
my_basic_string
The implementation for String, the ARTS string class.
Definition: mystring.h:62
AgRecord::moutput
ArrayOfIndex moutput
Workspace Output.
Definition: agenda_record.h:85
WsvRecord::Name
const String & Name() const
Name of this workspace variable.
Definition: wsv_aux.h:98
AgRecord::Name
const String & Name() const
Definition: agenda_record.h:63
wsv_group_names
ArrayOfString wsv_group_names
Definition: groups.cc:40
AgRecord::mname
String mname
The name of this agenda.
Definition: agenda_record.h:79
check_agenda_data
bool check_agenda_data()
Check that agendas.cc and workspace.cc are consistent.
Definition: agenda_record.cc:115
AgRecord::In
const ArrayOfIndex & In() const
Definition: agenda_record.h:66
define_agenda_map
void define_agenda_map()
Definition: agenda_record.cc:93
WsvRecord
This class contains all static information for one workspace variable.
Definition: wsv_aux.h:49
workspace_ng.h
This file contains the declaration and partly the implementation of the workspace class.
WsvRecord::Description
const String & Description() const
A text describing this workspace variable.
Definition: wsv_aux.h:100
Workspace::WsvMap
static map< String, Index > WsvMap
Definition: workspace_ng.h:62
operator<<
ostream & operator<<(ostream &os, const AgRecord &agr)
Output operator for AgRecord.
Definition: agenda_record.cc:181
MakeArray
Explicit construction of Arrays.
Definition: make_array.h:52
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
AgRecord::Description
const String & Description() const
Definition: agenda_record.h:64
get_wsv_group_id
Index get_wsv_group_id(const String &name)
Definition: groups.cc:192
AgRecord::Out
const ArrayOfIndex & Out() const
Definition: agenda_record.h:65
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
wsv_aux.h
Auxiliary header stuff related to workspace variable groups.