00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "arts.h"
00019 #include "token.h"
00020 #include "array.h"
00021 #include "file.h"
00022 #include "auto_wsv.h"
00023 #include "methods.h"
00024 #include "wsv_aux.h"
00025
00026
00027 void align(ofstream& ofs, bool& is_first_parameter, const String& indent)
00028 {
00029
00030 if (is_first_parameter)
00031 is_first_parameter = false;
00032 else
00033 {
00034 ofs << ",\n";
00035
00036 ofs << indent;
00037 }
00038 }
00039
00040 int main()
00041 {
00042 try
00043 {
00044
00045 extern Array<MdRecord> md_data;
00046 extern const ArrayOfString wsv_group_names;
00047 extern const Array<WsvRecord> wsv_data;
00048
00049
00050 define_md_data();
00051
00052
00053 define_wsv_group_names();
00054
00055
00056 define_wsv_data();
00057
00058
00059 const Index n_md = md_data.nelem();
00060 const Index n_wsv = wsv_data.nelem();
00061
00062
00063
00064 if (N_WSV != n_wsv)
00065 {
00066 cout << "The file wsv.h is not up to date!\n";
00067 cout << "(N_WSV = " << N_WSV << ", n_wsv = " << n_wsv << ")\n";
00068 cout << "Make wsv.h first. Check if Makefile is correct.\n";
00069 return 1;
00070 }
00071
00072
00073
00074 ofstream ofs;
00075 open_output_file(ofs,"auto_md.cc");
00076
00077 ofs << "// This file was generated automatically by make_auto_md_cc.cc.\n";
00078 ofs << "// DO NOT EDIT !\n";
00079 ofs << "// Generated: "
00080 << __DATE__ << ", "
00081 << __TIME__ << "\n\n";
00082
00083 ofs << "#include \"arts.h\"\n"
00084 << "#include \"make_array.h\"\n"
00085 << "#include \"auto_md.h\"\n"
00086 << "#include \"auto_wsv_groups.h\"\n"
00087 << "#include \"wsv_aux.h\"\n"
00088 << "\n";
00089
00090
00091 ofs << "// The workspace variable pointers:\n"
00092 << "extern const Array<WsvP*> wsv_pointers;\n\n"
00093
00094 << "// Other wsv data:\n"
00095 << "extern const Array<WsvRecord> wsv_data;\n\n";
00096
00097
00098
00099
00100 for (Index i=0; i<n_md; ++i)
00101 {
00102
00103
00104 bool is_first_parameter = true;
00105
00106
00107 String indent = String(md_data[i].Name().nelem()+3,' ');;
00108
00109
00110
00111 ArrayOfIndex vo=md_data[i].Output();
00112 ArrayOfIndex vi=md_data[i].Input();
00113 ArrayOfIndex vgo=md_data[i].GOutput();
00114 ArrayOfIndex vgi=md_data[i].GInput();
00115
00116
00117
00118
00119
00120
00121 for (ArrayOfIndex::const_iterator j=vo.begin(); j<vo.end(); ++j)
00122 for (ArrayOfIndex::iterator k=vi.begin(); k<vi.end(); ++k)
00123 if ( *j == *k )
00124 {
00125
00126 k = vi.erase(k) - 1;
00127
00128
00129
00130
00131 }
00132
00133
00134
00135
00136
00137
00138
00139 {
00140
00141 String ws, mr;
00142
00143
00144
00145 if (vo.nelem () || vi.nelem ())
00146 {
00147 ws = " ws";
00148 }
00149
00150
00151
00152 if ( vgo.nelem () || vgi.nelem ()
00153 || md_data[i].Keywords().nelem())
00154 {
00155 mr = " mr";
00156 }
00157
00158 ofs << "void " << md_data[i].Name()
00159 << "_g(WorkSpace&" << ws
00160 << ", const MRecord&" << mr << ")\n"
00161 << "{\n";
00162 }
00163
00164
00165
00166
00167 for (Index j=0; j<vgo.nelem(); ++j)
00168 {
00169 ofs << " " << wsv_group_names[md_data[i].GOutput()[j]]
00170 << " *GO" << j << " = *wsv_pointers[mr.Output()[" << j
00171 << "]];\n";
00172 }
00173
00174
00175 for (Index j=0; j<vgi.nelem(); ++j)
00176 {
00177 ofs << " " << wsv_group_names[md_data[i].GInput()[j]]
00178 << " *GI" << j << " = *wsv_pointers[mr.Input()[" << j
00179 << "]];\n";
00180 }
00181
00182 ofs << " " << md_data[i].Name() << "(";
00183
00184
00185 for (Index j=0; j<vo.nelem(); ++j)
00186 {
00187
00188 align(ofs,is_first_parameter,indent);
00189
00190 ofs << "ws." << wsv_data[vo[j]].Name();
00191 }
00192
00193
00194 for (Index j=0; j<vgo.nelem(); ++j)
00195 {
00196
00197 align(ofs,is_first_parameter,indent);
00198
00199 ofs << "*GO" << j;
00200 }
00201
00202
00203 for (Index j=0; j<vgo.nelem(); ++j)
00204 {
00205
00206 align(ofs,is_first_parameter,indent);
00207
00208 ofs << "wsv_data[mr.Output()["
00209 << j
00210 << "]].Name()";
00211 }
00212
00213
00214 for (Index j=0; j<vi.nelem(); ++j)
00215 {
00216
00217 align(ofs,is_first_parameter,indent);
00218
00219 ofs << "ws." << wsv_data[vi[j]].Name();
00220 }
00221
00222
00223 for (Index j=0; j<vgi.nelem(); ++j)
00224 {
00225
00226 align(ofs,is_first_parameter,indent);
00227
00228 ofs << "*GI" << j;
00229 }
00230
00231
00232 for (Index j=0; j<vgi.nelem(); ++j)
00233 {
00234
00235 align(ofs,is_first_parameter,indent);
00236
00237 ofs << "wsv_data[mr.Input()["
00238 << j
00239 << "]].Name()";
00240 }
00241
00242
00243 {
00244
00245
00246 Index n_mr = md_data[i].Keywords().nelem();
00247
00248 for (Index j=0; j!=n_mr; ++j)
00249 {
00250
00251 align(ofs,is_first_parameter,indent);
00252
00253 ofs << "mr.Values()[" << j << "]";
00254 }
00255 }
00256
00257 ofs << ");\n";
00258 ofs << "}\n\n";
00259 }
00260
00261
00262 {
00263 String indent = " ";
00264 bool is_first_parameter = true;
00265
00266 ofs << "// The array holding the pointers to the getaway functions.\n"
00267 << "void (*getaways[])(WorkSpace&, const MRecord&)\n"
00268 << " = {";
00269 for (Index i=0; i<n_md; ++i)
00270 {
00271
00272 align(ofs,is_first_parameter,indent);
00273
00274 ofs << md_data[i].Name() << "_g";
00275 }
00276 ofs << "};\n\n";
00277 }
00278
00279 }
00280 catch (exception x)
00281 {
00282 cout << "Something went wrong. Message text:\n";
00283 cout << x.what() << '\n';
00284 return 1;
00285 }
00286
00287 return 0;
00288 }