13void align(ofstream& ofs,
bool& is_first_parameter,
const String& indent) {
15 if (is_first_parameter)
16 is_first_parameter =
false;
47 const Index n_md = md_data.nelem();
54 ofs <<
"// This file was generated automatically by make_auto_md_cc.cc.\n";
55 ofs <<
"// DO NOT EDIT !\n";
56 ofs <<
"// Generated: " << __DATE__ <<
", " << __TIME__ <<
"\n\n";
58 ofs <<
"#include \"arts.h\"\n"
59 <<
"#include \"auto_md.h\"\n"
60 <<
"#include \"wsv_aux.h\"\n"
61 <<
"#include \"mc_interp.h\"\n"
62 <<
"#include \"m_append.h\"\n"
63 <<
"#include \"m_delete.h\"\n"
64 <<
"#include \"m_copy.h\"\n"
65 <<
"#include \"m_conversion.h\"\n"
66 <<
"#include \"m_extract.h\"\n"
67 <<
"#include \"m_general.h\"\n"
68 <<
"#include \"m_gridded_fields.h\"\n"
69 <<
"#include \"m_ignore.h\"\n"
70 <<
"#include \"m_nc.h\"\n"
71 <<
"#include \"m_reduce.h\"\n"
72 <<
"#include \"m_select.h\"\n"
73 <<
"#include \"m_xml.h\"\n"
74 <<
"#include \"m_basic_types.h\"\n"
75 <<
"#include \"propagationmatrix.h\"\n"
76 <<
"#include \"transmissionmatrix.h\"\n"
77 <<
"#include \"agenda_record.h\"\n"
78 <<
"#include \"workspace_ng.h\"\n"
79 <<
"#include \"global_data.h\"\n"
80 <<
"#include \"absorptionlines.h\"\n"
87 for (Index i = 0; i < n_md; ++i) {
92 bool is_first_parameter =
true;
99 bool pass_workspace =
false;
129 for (Index j = 0; !pass_workspace && j < mdd.
In().nelem(); j++) {
131 pass_workspace =
true;
137 for (Index j = 0; !pass_workspace && j < mdd.
GInType().nelem(); j++) {
139 pass_workspace =
true;
152 <<
"_g(Workspace&" << ws <<
", const MRecord&" << mr <<
")\n"
155 ofs <<
"void " << mdd.
Name() <<
"_g(Workspace&" << ws
156 <<
", const MRecord&" << mr <<
")\n"
166 for (Index k = 0; k < vo.
nelem(); ++k) {
167 bool output_only =
true;
168 for (ArrayOfIndex::const_iterator j = mdd.
In().begin();
176 if (output_only) voutonly.push_back(k);
181 for (Index j = 0; j < voutonly.
nelem(); j++) {
182 ostringstream docstr;
183 docstr <<
" // " << wsv_data[vo[voutonly[j]]].Name() <<
"\n";
185 String gname = wsv_groups[wsv_data[vo[voutonly[j]]].Group()];
186 ostringstream initstr;
187 if (gname ==
"Numeric")
188 initstr <<
" = NAN;";
189 else if (gname ==
"Index")
192 initstr <<
" = " << gname <<
"();";
196 ofs <<
" if (mr.In().end() == find(mr.In().begin(), mr.In().end(),"
197 <<
" mr.Out()[" << voutonly[j] <<
"]))\n";
198 ofs <<
" (*(static_cast<" << wsv_groups[wsv_data[vo[voutonly[j]]].Group()]
199 <<
"*>(ws[mr.Out()[" << voutonly[j] <<
"]].get())))" << initstr.str();
204 ofs <<
" " << mdd.
Name() <<
"(";
208 is_first_parameter =
false;
212 for (Index j = 0; j < vo.
nelem(); ++j) {
220 align(ofs, is_first_parameter, indent);
222 ofs <<
"*(static_cast<" << wsv_groups[wsv_data[vo[j]].Group()]
223 <<
"*>(ws[mr.Out()[" << j <<
"]].get()))";
227 for (Index j = 0; j < vgo.
nelem(); ++j) {
235 align(ofs, is_first_parameter, indent);
237 ofs <<
"*(static_cast<" << wsv_groups[vgo[j]] <<
"*>(ws[mr.Out()["
238 << j + vo.
nelem() <<
"]].get()))";
243 for (Index j = 0; j < vgo.
nelem(); ++j) {
245 align(ofs, is_first_parameter, indent);
247 ofs <<
"(*ws.wsv_data_ptr)[mr.Out()[" << j + vo.
nelem()
253 for (Index j = 0; j < vi.
nelem(); ++j) {
255 align(ofs, is_first_parameter, indent);
258 ofs <<
"*(static_cast<" << wsv_groups[wsv_data[vi[j]].Group()]
259 <<
"*>(ws[mr.In()[" << j <<
"]].get()))";
261 ofs <<
"*(static_cast<" << wsv_groups[wsv_data[vi[j]].Group()]
262 <<
"*>(ws[mr.In()[" << j <<
"]].get()))";
270 align(ofs, is_first_parameter, indent);
272 ofs <<
"mr.SetValue()";
275 for (Index j = 0; j < vgi.
nelem(); ++j) {
283 align(ofs, is_first_parameter, indent);
285 ofs <<
"*(static_cast<" << wsv_groups[vgi[j]] <<
"*>(ws[mr.In()["
286 << j + vi.
nelem() <<
"]].get()))";
291 for (Index j = 0; j < vgi.
nelem(); ++j) {
293 align(ofs, is_first_parameter, indent);
295 ofs <<
"(*ws.wsv_data_ptr)[mr.In()[" << j + vi.
nelem()
304 align(ofs, is_first_parameter, indent);
310 bool pass_verbosity =
true;
313 for (Index j = 0; pass_verbosity && j < mdd.
In().nelem(); j++) {
314 if (wsv_data[mdd.
In()[j]].Name() ==
"verbosity") {
315 pass_verbosity =
false;
320 for (Index j = 0; pass_verbosity && j < mdd.
Out().nelem(); j++) {
321 if (wsv_data[mdd.
Out()[j]].Name() ==
"verbosity") {
322 pass_verbosity =
false;
326 if (pass_verbosity) {
329 align(ofs, is_first_parameter, indent);
330 ofs <<
"*(static_cast<" << wsv_groups[verbosity_group_id] <<
"*>(ws["
331 << verbosity_wsv_id <<
"].get()))";
341 bool is_first_parameter =
true;
343 ofs <<
"// The array holding the pointers to the getaway functions.\n"
344 <<
"void (*getaways[])(Workspace&, const MRecord&)\n"
346 for (Index i = 0; i < n_md; ++i) {
350 align(ofs, is_first_parameter, indent);
355 ofs << mdd.
Name() <<
"_g";
359 ofs <<
", nullptr};\n\n";
364 ofs <<
"void auto_md_agenda_execute_helper(bool& agenda_failed, String& agenda_error_msg, Workspace& ws, const Agenda& input_agenda)\n";
366 ofs <<
" const ArrayOfIndex& outputs_to_push = input_agenda.get_output2push();\n";
367 ofs <<
" const ArrayOfIndex& outputs_to_dup = input_agenda.get_output2dup();\n";
369 ofs <<
" for (auto&& i : outputs_to_push)\n";
371 ofs <<
" // Even if a variable is only used as WSM output inside this agenda,\n";
372 ofs <<
" // It is possible that it is used as input further down by another agenda,\n";
373 ofs <<
" // which we can't see here. Therefore initialized variables have to be\n";
374 ofs <<
" // duplicated.\n";
375 ofs <<
" if (ws.is_initialized(i))\n";
376 ofs <<
" ws.duplicate(i);\n";
378 ofs <<
" ws.emplace(i);\n";
381 ofs <<
" for (auto&& i : outputs_to_dup)\n";
382 ofs <<
" ws.duplicate(i);\n";
384 ofs <<
" agenda_failed = false;\n";
387 ofs <<
" input_agenda.execute(ws);\n";
389 ofs <<
" catch (const std::exception &e)\n";
391 ofs <<
" ostringstream os;\n";
392 ofs <<
" os << \"Run-time error in agenda: \"\n";
393 ofs <<
" << input_agenda.name() << \'\\n\' << e.what();\n";
394 ofs <<
" agenda_failed = true;\n";
395 ofs <<
" agenda_error_msg = os.str();\n";
398 ofs <<
" for (auto&& i : outputs_to_push)\n";
399 ofs <<
" ws.pop(i);\n";
401 ofs <<
" for (auto&& i : outputs_to_dup)\n";
402 ofs <<
" ws.pop(i);\n";
412 for (Index i = 0; i < agenda_data.nelem(); i++) {
413 const AgRecord& agr = agenda_data[i];
416 ostringstream ain_push_os, ain_pop_os;
417 ostringstream aout_push_os, aout_pop_os;
421 bool is_agenda_array = wsv_data[wsv_ptr->second].Group() ==
get_wsv_group_id(
"ArrayOfAgenda");
428 if (is_agenda_array) {
429 ofs <<
" if (agenda_array_index < 0 || agenda_array_index >= input_agenda_array.nelem())\n"
431 <<
" std::ostringstream os;\n"
432 <<
" os << \"Agenda index \" << agenda_array_index\n"
433 <<
" << \" out of bounds. 0 <= index < \" << input_agenda_array.nelem();\n"
434 <<
" throw std::runtime_error(os.str());\n"
436 <<
" const Agenda& input_agenda = input_agenda_array[agenda_array_index];\n\n";
438 ofs <<
" using global_data::AgendaMap;\n"
439 <<
" using global_data::agenda_data;\n"
441 <<
" if (!input_agenda.checked())\n"
442 <<
" throw std::runtime_error(\"" << agr.
Name()
443 <<
" is uninitialized. Use *AgendaSet* to add methods to it.\\n"
444 <<
"Agenda variables defined in the controlfile cannot be executed.\\nThe agenda must "
445 <<
"be copied to a workspace variable for execution.\");\n"
447 <<
" const AgRecord& agr =\n"
448 <<
" agenda_data[AgendaMap.find (input_agenda.name ())->second];\n"
452 for (Index j = 0; j < ago.
nelem(); j++) {
454 auto it = agi.begin();
455 while (it != agi.end() && *it != ago[j]) it++;
456 if (it == agi.end()) {
457 aout_push_os <<
" auto borrowed_out_"<<j<<
"{ws.borrow_uninitialized (aout[" << j <<
"], "
458 << wsv_data[ago[j]].Name() <<
")};\n";
460 aout_push_os <<
" auto borrowed_out_"<<j<<
"{ws.borrow (aout[" << j <<
"], "
461 << wsv_data[ago[j]].Name() <<
")};\n";
466 for (Index j = 0; j < agi.
nelem(); j++) {
468 auto it = ago.begin();
469 while (it != ago.end() && *it != agi[j]) it++;
470 if (it == ago.end()) {
471 ain_push_os <<
" auto borrowed_in_"<<j<<
"{ws.borrow (ain[" << j <<
"], "
472 << wsv_data[agi[j]].Name() <<
")};\n";
477 if (aout_push_os.str().length()) {
478 ofs <<
" const ArrayOfIndex& aout = agr.Out();\n";
479 ofs << aout_push_os.str() <<
"\n";
481 if (ain_push_os.str().length()) {
482 ofs <<
" const ArrayOfIndex& ain = agr.In();\n";
483 ofs << ain_push_os.str() <<
"\n";
486 ofs <<
" bool agenda_failed;\n";
487 ofs <<
" String agenda_error_msg;\n";
488 ofs <<
" auto_md_agenda_execute_helper(agenda_failed, agenda_error_msg, ws, input_agenda);\n\n";
490 if (aout_pop_os.str().length()) {
491 ofs << aout_pop_os.str() <<
"\n";
493 if (ain_pop_os.str().length()) {
494 ofs << ain_pop_os.str() <<
"\n";
497 ofs <<
" if (agenda_failed) throw runtime_error (agenda_error_msg);\n";
503 for (
auto&& it : wsv_groups) {
504 if (it ==
"Any")
continue;
505 ofs <<
"/* Workspace method: Doxygen documentation will be auto-generated */\n"
506 <<
"void " << it <<
"Create(";
508 if (it ==
"Agenda") ofs <<
"Workspace& ws, ";
510 ofs << it <<
"& var, const Verbosity&)\n"
517 else if (it ==
"Numeric")
520 ofs <<
"var = " << it <<
'(';
521 if (it ==
"Agenda") ofs <<
"ws";
527 if (it not_eq
"Agenda" and it not_eq
"ArrayOfAgenda") {
528 ofs <<
"/* Workspace method: Doxygen documentation will be auto-generated */\n"
529 <<
"void " << it <<
"Set(" << it <<
"& out, const " << it
530 <<
"& value, const Verbosity&) { out = value; }\n\n";
533 }
catch (
const std::runtime_error& x) {
534 cout <<
"Something went wrong. Message text:\n";
535 cout << x.what() <<
'\n';
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.
void define_agenda_data()
This file contains the definition of Array.
The global header file for ARTS.
void define_wsv_groups()
Define the array of workspace variable group names.
Lookup information for one agenda.
const ArrayOfIndex & Out() const
const ArrayOfIndex & In() const
const String & Name() const
This can be used to make arrays out of anything.
Index nelem() const ARTS_NOEXCEPT
All information for one workspace method.
const ArrayOfIndex & In() const
const String & Name() const
const ArrayOfIndex & InOnly() const
bool PassWorkspace() const
const ArrayOfIndex & GOutType() const
const String & ActualGroups() const
bool PassWsvNames() const
bool AgendaMethod() const
bool Supergeneric() const
const ArrayOfIndex & Out() const
const ArrayOfIndex & GInType() const
Helper macros for debugging.
#define ARTS_ASSERT(condition,...)
#define ARTS_USER_ERROR_IF(condition,...)
void open_output_file(ofstream &file, const std::string_view name)
Open a file for writing.
This file contains basic functions to handle ASCII files.
Index get_wsv_group_id(const String &name)
Returns the id of the given group.
bool is_agenda_group_id(const Index group)
Check if group is an agenda group.
void align(ofstream &ofs, bool &is_first_parameter, const String &indent)
void define_md_data_raw()
Declaration of the class MdRecord.
void expand_md_data_raw_to_md_data()
Expand supergeneric methods.
my_basic_string< char > String
The String type for ARTS.
const ArrayOfGroupRecord wsv_groups
The names associated with Wsv groups as Strings.
Array< WsvRecord > wsv_data
const Array< MdRecord > md_data
Lookup information for workspace methods.
std::map< String, Index > WsvMap
const Array< AgRecord > agenda_data
The lookup information for the agendas.
This file contains the Workspace class.