00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026 #include <map>
00027 #include <iostream>
00028 #include "messages.h"
00029 #include "agenda_record.h"
00030 #include "wsv_aux.h"
00031 #include "workspace_ng.h"
00032
00034
00044 AgRecord::AgRecord( const char name[],
00045 const char description[],
00046 const MakeArray<String>& output,
00047 const MakeArray<String>& input ) :
00048 mname( name ),
00049 mdescription( description ),
00050 moutput( 0 ),
00051 minput( 0 )
00052 {
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 assert( Workspace::WsvMap.end() !=
00063 Workspace::WsvMap.find(mname) );
00064
00065 moutput.resize(output.nelem());
00066 for ( Index j=0; j<output.nelem(); ++j )
00067 {
00068 moutput[j] = get_wsv_id (output[j]);
00069 if (moutput[j] == -1)
00070 {
00071 ostringstream os;
00072
00073 os << "Unknown output WSV " << output[j] << " in WSM " << mname;
00074 throw runtime_error( os.str() );
00075 }
00076 }
00077
00078 minput.resize(input.nelem());
00079 for ( Index j=0; j<input.nelem(); ++j )
00080 {
00081 minput[j] = get_wsv_id (input[j]);
00082 if (minput[j] == -1)
00083 {
00084 ostringstream os;
00085
00086 os << "Unknown input WSV " << input[j] << " in WSM " << mname;
00087 throw runtime_error( os.str() );
00088 }
00089 }
00090
00091 }
00092
00093 void define_agenda_map()
00094 {
00095 extern const Array<AgRecord> agenda_data;
00096 extern map<String, Index> AgendaMap;
00097
00098 for ( Index i=0 ; i<agenda_data.nelem() ; ++i )
00099 {
00100 AgendaMap[agenda_data[i].Name()] = i;
00101 }
00102 }
00103
00105
00115 bool check_agenda_data()
00116 {
00117
00118 extern const Array<AgRecord> agenda_data;
00119 DEBUG_ONLY (extern map<String, Index> AgendaMap);
00120
00121 Index i,j,k;
00122
00123 k = 0;
00124
00125
00126 for ( i=0; i<agenda_data.nelem(); ++i )
00127 {
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 assert( Workspace::WsvMap.end() !=
00139 Workspace::WsvMap.find(agenda_data[i].Name()) );
00140 }
00141
00142
00143 for ( j=0; j<Workspace::wsv_data.nelem(); ++j )
00144 {
00145
00146 if ( get_wsv_group_id ("Agenda") == Workspace::wsv_data[j].Group() )
00147 {
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 assert( AgendaMap.end() !=
00159 AgendaMap.find(Workspace::wsv_data[j].Name()) );
00160
00161
00162 ++k;
00163 }
00164 }
00165
00166
00167
00168 assert( i==k );
00169
00170 return true;
00171 }
00172
00174
00181 ostream& operator<<(ostream& os, const AgRecord& agr)
00182 {
00183
00184
00185 bool first;
00186
00187 os << "\n*-------------------------------------------------------------------*\n"
00188 << "Workspace variable = " << agr.Name()
00189 << "\n---------------------------------------------------------------------\n"
00190 << "\n" << agr.Description() << "\n"
00191 << "\n---------------------------------------------------------------------\n";
00192
00193
00194
00195
00196 os << "Group = Agenda\n";
00197
00198
00199 first = true;
00200 os << "Output = ";
00201 for ( Index i=0; i<agr.Out().nelem(); ++i )
00202 {
00203 if (first) first=false;
00204 else os << ", ";
00205
00206 os << Workspace::wsv_data[agr.Out()[i]].Name();
00207 }
00208 os << "\n";
00209
00210
00211 first = true;
00212 os << "Input = ";
00213 for ( Index i=0; i<agr.In().nelem(); ++i )
00214 {
00215 if (first) first=false;
00216 else os << ", ";
00217
00218 os << Workspace::wsv_data[agr.In()[i]].Name();
00219 }
00220
00221 os << "\n*-------------------------------------------------------------------*\n";
00222
00223 return os;
00224 }
00225
00227
00236 ostream& operator<<(ostream& os, const WsvRecord& wr)
00237 {
00238 extern const ArrayOfString wsv_group_names;
00239
00240
00241
00242 if ( get_wsv_group_id("Agenda") != wr.Group() )
00243 {
00244
00245
00246 os << "\n*-------------------------------------------------------------------*\n"
00247 << "Workspace variable = " << wr.Name()
00248 << "\n---------------------------------------------------------------------\n"
00249 << "\n" << wr.Description() << "\n"
00250 << "\n---------------------------------------------------------------------\n"
00251 << "Group = " << wsv_group_names[wr.Group()]
00252 << "\n*-------------------------------------------------------------------*\n";
00253 }
00254 else
00255 {
00256
00257
00258 extern const Array<AgRecord> agenda_data;
00259
00260 extern map<String, Index> AgendaMap;
00261
00262 map<String, Index>::const_iterator j =
00263 AgendaMap.find( wr.Name() );
00264
00265
00266 assert( j != AgendaMap.end() );
00267
00268 cout << agenda_data[j->second] << "\n";
00269 }
00270
00271 return os;
00272 }
00273
00275
00279 void write_agenda_wrapper_header( ofstream& ofs,
00280 const AgRecord& agr)
00281 {
00282 extern const ArrayOfString wsv_group_names;
00283
00284
00285 ofs << "void " << agr.Name () << "Execute(\n";
00286
00287
00288 ofs << " // Workspace\n";
00289 ofs << " Workspace& ws,\n";
00290
00291 const ArrayOfIndex& ago = agr.Out();
00292 ofs << " // Output\n";
00293 for (ArrayOfIndex::const_iterator j = ago.begin (); j != ago.end (); j++)
00294 {
00295 ofs << " ";
00296 ofs << wsv_group_names[Workspace::wsv_data[*j].Group()] << "& ";
00297 ofs << Workspace::wsv_data[*j].Name() << ",\n";
00298 }
00299
00300
00301 const ArrayOfIndex& agi = agr.In();
00302 ofs << " // Input\n";
00303 for (ArrayOfIndex::const_iterator j = agi.begin (); j != agi.end (); j++)
00304 {
00305
00306 ArrayOfIndex::const_iterator it = ago.begin ();
00307 while (it != ago.end () && *it != *j) it++;
00308 if (it == ago.end ())
00309 {
00310 String group_name = wsv_group_names[Workspace::wsv_data[*j].Group()];
00311
00312 ofs << " const ";
00313 ofs << group_name;
00314
00315
00316 if ( group_name != "Index" && group_name != "Numeric")
00317 {
00318 ofs << "&";
00319 }
00320 ofs << " " << Workspace::wsv_data[*j].Name() << ",\n";
00321 }
00322 }
00323
00324
00325 ofs << " // Wrapper Input\n";
00326 ofs << " const Agenda& input_agenda)";
00327 }
00328