00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00068 #include "arts.h"
00069 #include "token.h"
00070 #include "array.h"
00071 #include "file.h"
00072 #include "auto_wsv.h"
00073 #include "methods.h"
00074 #include "wsv_aux.h"
00075
00076
00077 void align(ofstream& ofs, bool& is_first_parameter, const String& indent)
00078 {
00079
00080 if (is_first_parameter)
00081 is_first_parameter = false;
00082 else
00083 {
00084 ofs << ",\n";
00085
00086 ofs << indent;
00087 }
00088 }
00089
00090 int main()
00091 {
00092 try
00093 {
00094
00095 extern Array<MdRecord> md_data;
00096 extern const ArrayOfString wsv_group_names;
00097 extern const Array<WsvRecord> wsv_data;
00098
00099
00100 define_md_data();
00101
00102
00103 define_wsv_group_names();
00104
00105
00106 define_wsv_data();
00107
00108
00109 const Index n_md = md_data.nelem();
00110 const Index n_wsv = wsv_data.nelem();
00111
00112
00113
00114 if (N_WSV != n_wsv)
00115 {
00116 cout << "The file wsv.h is not up to date!\n";
00117 cout << "(N_WSV = " << N_WSV << ", n_wsv = " << n_wsv << ")\n";
00118 cout << "Make wsv.h first. Check if Makefile is correct.\n";
00119 return 1;
00120 }
00121
00122
00123
00124 ofstream ofs;
00125 open_output_file(ofs,"auto_md.h");
00126
00127 ofs << "// This file was generated automatically by make_auto_md_h.cc.\n";
00128 ofs << "// DO NOT EDIT !\n";
00129 ofs << "// Generated: "
00130 << __DATE__ << ", "
00131 << __TIME__ << "\n\n";
00132
00133 ofs << "#ifndef auto_md_h\n";
00134 ofs << "#define auto_md_h\n\n";
00135
00136 ofs << "#include \"matpackI.h\"\n"
00137 << "#include \"los.h\"\n"
00138 << "#include \"absorption.h\"\n"
00139 << "#include \"auto_wsv.h\"\n"
00140 << "#include \"parser.h\"\n"
00141 << "\n";
00142
00143 ofs << "// This is only used for a consistency check. You can get the\n"
00144 << "// number of workspace variables from wsv_data.nelem().\n"
00145 << "#define N_MD " << n_md << "\n\n";
00146
00147 ofs << "enum MdHandle{\n";
00148 for (Index i=0; i<n_md-1; ++i)
00149 {
00150 ofs << " " << md_data[i].Name() << "_,\n";
00151 }
00152 ofs << " " << md_data[n_md-1].Name() << "_\n";
00153 ofs << "};\n\n";
00154
00155
00156 ofs << "// Method function declarations:\n\n";
00157 for (Index i=0; i<n_md; ++i)
00158 {
00159
00160
00161
00162 bool is_first_parameter = true;
00163
00164
00165
00166 String indent(md_data[i].Name().nelem()+6,' ');
00167
00168
00169
00170 ArrayOfIndex vo=md_data[i].Output();
00171 ArrayOfIndex vi=md_data[i].Input();
00172 ArrayOfIndex vgo=md_data[i].GOutput();
00173 ArrayOfIndex vgi=md_data[i].GInput();
00174
00175
00176
00177
00178
00179
00180 for (ArrayOfIndex::const_iterator j=vo.begin(); j<vo.end(); ++j)
00181 for (ArrayOfIndex::iterator k=vi.begin(); k<vi.end(); ++k)
00182 {
00183 if ( *j == *k )
00184 {
00185
00186 k = vi.erase(k) - 1;
00187
00188
00189
00190
00191 }
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 ofs << "void " << md_data[i].Name() << "(";
00203
00204
00205 {
00206
00207 bool is_first_of_these = true;
00208
00209 for (Index j=0; j<vo.nelem(); ++j)
00210 {
00211
00212 align(ofs,is_first_parameter,indent);
00213
00214
00215 if (is_first_of_these)
00216 {
00217 ofs << "// WS Output:\n";
00218 ofs << indent;
00219 is_first_of_these = false;
00220 }
00221
00222 ofs << wsv_group_names[wsv_data[vo[j]].Group()] << "&";
00223 }
00224 }
00225
00226
00227 {
00228
00229 bool is_first_of_these = true;
00230
00231 for (Index j=0; j<vgo.nelem(); ++j)
00232 {
00233
00234 align(ofs,is_first_parameter,indent);
00235
00236
00237 if (is_first_of_these)
00238 {
00239 ofs << "// WS Generic Output:\n";
00240 ofs << indent;
00241 is_first_of_these = false;
00242 }
00243
00244 ofs << wsv_group_names[md_data[i].GOutput()[j]] << "&";
00245 }
00246 }
00247
00248
00249 {
00250
00251 bool is_first_of_these = true;
00252
00253 for (Index j=0; j<vgo.nelem(); ++j)
00254 {
00255
00256 align(ofs,is_first_parameter,indent);
00257
00258
00259 if (is_first_of_these)
00260 {
00261 ofs << "// WS Generic Output Names:\n";
00262 ofs << indent;
00263 is_first_of_these = false;
00264 }
00265
00266 ofs << "const String&";
00267 }
00268 }
00269
00270
00271 {
00272
00273 bool is_first_of_these = true;
00274
00275 for (Index j=0; j<vi.nelem(); ++j)
00276 {
00277
00278 align(ofs,is_first_parameter,indent);
00279
00280
00281 if (is_first_of_these)
00282 {
00283 ofs << "// WS Input:\n";
00284 ofs << indent;
00285 is_first_of_these = false;
00286 }
00287
00288 ofs << "const "
00289 << wsv_group_names[wsv_data[vi[j]].Group()] << "&";
00290 }
00291 }
00292
00293
00294 {
00295
00296 bool is_first_of_these = true;
00297
00298 for (Index j=0; j<vgi.nelem(); ++j)
00299 {
00300
00301 align(ofs,is_first_parameter,indent);
00302
00303
00304 if (is_first_of_these)
00305 {
00306 ofs << "// WS Generic Input:\n";
00307 ofs << indent;
00308 is_first_of_these = false;
00309 }
00310
00311 ofs << "const "
00312 << wsv_group_names[md_data[i].GInput()[j]] << "&";
00313 }
00314 }
00315
00316
00317 {
00318
00319 bool is_first_of_these = true;
00320
00321 for (Index j=0; j<vgi.nelem(); ++j)
00322 {
00323
00324 align(ofs,is_first_parameter,indent);
00325
00326
00327 if (is_first_of_these)
00328 {
00329 ofs << "// WS Generic Input Names:\n";
00330 ofs << indent;
00331 is_first_of_these = false;
00332 }
00333
00334 ofs << "const String&";
00335 }
00336 }
00337
00338
00339 {
00340
00341 bool is_first_of_these = true;
00342
00343
00344 Index n_mr = md_data[i].Keywords().nelem();
00345
00346 for (Index j=0; j!=n_mr; ++j)
00347 {
00348
00349 align(ofs,is_first_parameter,indent);
00350
00351
00352 if (is_first_of_these)
00353 {
00354 ofs << "// Control Parameters:\n";
00355 ofs << indent;
00356 is_first_of_these = false;
00357 }
00358
00359 extern String TokValTypeName[];
00360 ofs << "const " << TokValTypeName[md_data[i].Types()[j]] << "& "
00361 << md_data[i].Keywords()[j];
00362 }
00363 }
00364
00365 ofs << ");\n\n";
00366 }
00367
00368
00369 ofs << "// Get-away function declarations:\n\n";
00370 for (Index i=0; i<n_md; ++i)
00371 ofs << "void " << md_data[i].Name()
00372 << "_g(WorkSpace& ws, const MRecord& mr);\n";
00373
00374 ofs << "\n";
00375
00376 ofs << "\n#endif // auto_md_h\n";
00377
00378
00379 ofs.close();
00380
00381 }
00382 catch (exception x)
00383 {
00384 cout << "Something went wrong. Message text:\n";
00385 cout << x.what() << '\n';
00386 return 1;
00387 }
00388
00389 return 0;
00390 }