30void align(ofstream& ofs,
bool& is_first_parameter,
const String& indent) {
32 if (is_first_parameter)
33 is_first_parameter =
false;
64 const Index n_md = md_data.nelem();
71 ofs <<
"// This file was generated automatically by make_auto_md_cc.cc.\n";
72 ofs <<
"// DO NOT EDIT !\n";
73 ofs <<
"// Generated: " << __DATE__ <<
", " << __TIME__ <<
"\n\n";
75 ofs <<
"#include \"arts.h\"\n"
76 <<
"#include \"auto_md.h\"\n"
77 <<
"#include \"wsv_aux.h\"\n"
78 <<
"#include \"mc_interp.h\"\n"
79 <<
"#include \"m_append.h\"\n"
80 <<
"#include \"m_delete.h\"\n"
81 <<
"#include \"m_copy.h\"\n"
82 <<
"#include \"m_conversion.h\"\n"
83 <<
"#include \"m_extract.h\"\n"
84 <<
"#include \"m_general.h\"\n"
85 <<
"#include \"m_gridded_fields.h\"\n"
86 <<
"#include \"m_ignore.h\"\n"
87 <<
"#include \"m_nc.h\"\n"
88 <<
"#include \"m_reduce.h\"\n"
89 <<
"#include \"m_select.h\"\n"
90 <<
"#include \"m_xml.h\"\n"
91 <<
"#include \"m_basic_types.h\"\n"
92 <<
"#include \"propagationmatrix.h\"\n"
93 <<
"#include \"transmissionmatrix.h\"\n"
94 <<
"#include \"agenda_record.h\"\n"
95 <<
"#include \"workspace_ng.h\"\n"
96 <<
"#include \"global_data.h\"\n"
97 <<
"#include \"absorptionlines.h\"\n"
104 for (
Index i = 0; i < n_md; ++i) {
109 bool is_first_parameter =
true;
116 bool pass_workspace =
false;
146 for (
Index j = 0; !pass_workspace && j < mdd.
In().nelem(); j++) {
148 pass_workspace =
true;
154 for (
Index j = 0; !pass_workspace && j < mdd.
GInType().nelem(); j++) {
156 pass_workspace =
true;
169 <<
"_g(Workspace&" << ws <<
", const MRecord&" << mr <<
")\n"
172 ofs <<
"void " << mdd.
Name() <<
"_g(Workspace&" << ws
173 <<
", const MRecord&" << mr <<
")\n"
184 bool output_only =
true;
185 for (ArrayOfIndex::const_iterator j = mdd.
In().begin();
193 if (output_only) voutonly.push_back(k);
198 for (
Index j = 0; j < voutonly.
nelem(); j++) {
199 ostringstream docstr;
200 docstr <<
" // " << wsv_data[vo[voutonly[j]]].Name() <<
"\n";
202 String gname = wsv_groups[wsv_data[vo[voutonly[j]]].Group()];
203 ostringstream initstr;
204 if (gname ==
"Numeric")
205 initstr <<
" = NAN;";
206 else if (gname ==
"Index")
209 initstr <<
" = " << gname <<
"();";
213 ofs <<
" if (mr.In().end() == find(mr.In().begin(), mr.In().end(),"
214 <<
" mr.Out()[" << voutonly[j] <<
"]))\n";
215 ofs <<
" (*(static_cast<" << wsv_groups[wsv_data[vo[voutonly[j]]].Group()]
216 <<
"*>(ws[mr.Out()[" << voutonly[j] <<
"]].get())))" << initstr.str();
221 ofs <<
" " << mdd.
Name() <<
"(";
225 is_first_parameter =
false;
237 align(ofs, is_first_parameter, indent);
239 ofs <<
"*(static_cast<" << wsv_groups[wsv_data[vo[j]].Group()]
240 <<
"*>(ws[mr.Out()[" << j <<
"]].get()))";
252 align(ofs, is_first_parameter, indent);
254 ofs <<
"*(static_cast<" << wsv_groups[vgo[j]] <<
"*>(ws[mr.Out()["
255 << j + vo.
nelem() <<
"]].get()))";
262 align(ofs, is_first_parameter, indent);
264 ofs <<
"(*ws.wsv_data_ptr)[mr.Out()[" << j + vo.
nelem()
272 align(ofs, is_first_parameter, indent);
275 ofs <<
"*(static_cast<" << wsv_groups[wsv_data[vi[j]].Group()]
276 <<
"*>(ws[mr.In()[" << j <<
"]].get()))";
278 ofs <<
"*(static_cast<" << wsv_groups[wsv_data[vi[j]].Group()]
279 <<
"*>(ws[mr.In()[" << j <<
"]].get()))";
287 align(ofs, is_first_parameter, indent);
289 ofs <<
"mr.SetValue()";
300 align(ofs, is_first_parameter, indent);
302 ofs <<
"*(static_cast<" << wsv_groups[vgi[j]] <<
"*>(ws[mr.In()["
303 << j + vi.
nelem() <<
"]].get()))";
310 align(ofs, is_first_parameter, indent);
312 ofs <<
"(*ws.wsv_data_ptr)[mr.In()[" << j + vi.
nelem()
321 align(ofs, is_first_parameter, indent);
327 bool pass_verbosity =
true;
330 for (
Index j = 0; pass_verbosity && j < mdd.
In().nelem(); j++) {
331 if (wsv_data[mdd.
In()[j]].Name() ==
"verbosity") {
332 pass_verbosity =
false;
337 for (
Index j = 0; pass_verbosity && j < mdd.
Out().nelem(); j++) {
338 if (wsv_data[mdd.
Out()[j]].Name() ==
"verbosity") {
339 pass_verbosity =
false;
343 if (pass_verbosity) {
346 align(ofs, is_first_parameter, indent);
347 ofs <<
"*(static_cast<" << wsv_groups[verbosity_group_id] <<
"*>(ws["
348 << verbosity_wsv_id <<
"].get()))";
358 bool is_first_parameter =
true;
360 ofs <<
"// The array holding the pointers to the getaway functions.\n"
361 <<
"void (*getaways[])(Workspace&, const MRecord&)\n"
363 for (
Index i = 0; i < n_md; ++i) {
367 align(ofs, is_first_parameter, indent);
372 ofs << mdd.
Name() <<
"_g";
376 ofs <<
", nullptr};\n\n";
381 ofs <<
"void auto_md_agenda_execute_helper(bool& agenda_failed, String& agenda_error_msg, Workspace& ws, const Agenda& input_agenda)\n";
383 ofs <<
" const ArrayOfIndex& outputs_to_push = input_agenda.get_output2push();\n";
384 ofs <<
" const ArrayOfIndex& outputs_to_dup = input_agenda.get_output2dup();\n";
386 ofs <<
" for (auto&& i : outputs_to_push)\n";
388 ofs <<
" // Even if a variable is only used as WSM output inside this agenda,\n";
389 ofs <<
" // It is possible that it is used as input further down by another agenda,\n";
390 ofs <<
" // which we can't see here. Therefore initialized variables have to be\n";
391 ofs <<
" // duplicated.\n";
392 ofs <<
" if (ws.is_initialized(i))\n";
393 ofs <<
" ws.duplicate(i);\n";
395 ofs <<
" ws.emplace(i);\n";
398 ofs <<
" for (auto&& i : outputs_to_dup)\n";
399 ofs <<
" ws.duplicate(i);\n";
401 ofs <<
" agenda_failed = false;\n";
404 ofs <<
" input_agenda.execute(ws);\n";
406 ofs <<
" catch (const std::exception &e)\n";
408 ofs <<
" ostringstream os;\n";
409 ofs <<
" os << \"Run-time error in agenda: \"\n";
410 ofs <<
" << input_agenda.name() << \'\\n\' << e.what();\n";
411 ofs <<
" agenda_failed = true;\n";
412 ofs <<
" agenda_error_msg = os.str();\n";
415 ofs <<
" for (auto&& i : outputs_to_push)\n";
416 ofs <<
" ws.pop(i);\n";
418 ofs <<
" for (auto&& i : outputs_to_dup)\n";
419 ofs <<
" ws.pop(i);\n";
429 for (
Index i = 0; i < agenda_data.nelem(); i++) {
430 const AgRecord& agr = agenda_data[i];
433 ostringstream ain_push_os, ain_pop_os;
434 ostringstream aout_push_os, aout_pop_os;
438 bool is_agenda_array = wsv_data[wsv_ptr->second].Group() ==
get_wsv_group_id(
"ArrayOfAgenda");
445 if (is_agenda_array) {
446 ofs <<
" if (agenda_array_index < 0 || agenda_array_index >= input_agenda_array.nelem())\n"
448 <<
" std::ostringstream os;\n"
449 <<
" os << \"Agenda index \" << agenda_array_index\n"
450 <<
" << \" out of bounds. 0 <= index < \" << input_agenda_array.nelem();\n"
451 <<
" throw std::runtime_error(os.str());\n"
453 <<
" const Agenda& input_agenda = input_agenda_array[agenda_array_index];\n\n";
455 ofs <<
" using global_data::AgendaMap;\n"
456 <<
" using global_data::agenda_data;\n"
458 <<
" if (!input_agenda.checked())\n"
459 <<
" throw std::runtime_error(\"" << agr.
Name()
460 <<
" is uninitialized. Use *AgendaSet* to add methods to it.\\n"
461 <<
"Agenda variables defined in the controlfile cannot be executed.\\nThe agenda must "
462 <<
"be copied to a workspace variable for execution.\");\n"
464 <<
" const AgRecord& agr =\n"
465 <<
" agenda_data[AgendaMap.find (input_agenda.name ())->second];\n"
471 auto it = agi.begin();
472 while (it != agi.end() && *it != ago[j]) it++;
473 if (it == agi.end()) {
474 aout_push_os <<
" auto borrowed_out_"<<j<<
"{ws.borrow_uninitialized (aout[" << j <<
"], "
475 << wsv_data[ago[j]].Name() <<
")};\n";
477 aout_push_os <<
" auto borrowed_out_"<<j<<
"{ws.borrow (aout[" << j <<
"], "
478 << wsv_data[ago[j]].Name() <<
")};\n";
485 auto it = ago.begin();
486 while (it != ago.end() && *it != agi[j]) it++;
487 if (it == ago.end()) {
488 ain_push_os <<
" auto borrowed_in_"<<j<<
"{ws.borrow (ain[" << j <<
"], "
489 << wsv_data[agi[j]].Name() <<
")};\n";
494 if (aout_push_os.str().length()) {
495 ofs <<
" const ArrayOfIndex& aout = agr.Out();\n";
496 ofs << aout_push_os.str() <<
"\n";
498 if (ain_push_os.str().length()) {
499 ofs <<
" const ArrayOfIndex& ain = agr.In();\n";
500 ofs << ain_push_os.str() <<
"\n";
503 ofs <<
" bool agenda_failed;\n";
504 ofs <<
" String agenda_error_msg;\n";
505 ofs <<
" auto_md_agenda_execute_helper(agenda_failed, agenda_error_msg, ws, input_agenda);\n\n";
507 if (aout_pop_os.str().length()) {
508 ofs << aout_pop_os.str() <<
"\n";
510 if (ain_pop_os.str().length()) {
511 ofs << ain_pop_os.str() <<
"\n";
514 ofs <<
" if (agenda_failed) throw runtime_error (agenda_error_msg);\n";
520 for (
auto&& it : wsv_groups) {
521 if (it ==
"Any")
continue;
522 ofs <<
"/* Workspace method: Doxygen documentation will be auto-generated */\n"
523 <<
"void " << it <<
"Create(";
525 if (it ==
"Agenda") ofs <<
"Workspace& ws, ";
527 ofs << it <<
"& var, const Verbosity&)\n"
534 else if (it ==
"Numeric")
537 ofs <<
"var = " << it <<
'(';
538 if (it ==
"Agenda") ofs <<
"ws";
544 if (it not_eq
"Agenda" and it not_eq
"ArrayOfAgenda") {
545 ofs <<
"/* Workspace method: Doxygen documentation will be auto-generated */\n"
546 <<
"void " << it <<
"Set(" << it <<
"& out, const " << it
547 <<
"& value, const Verbosity&) { out = value; }\n\n";
550 }
catch (
const std::runtime_error& x) {
551 cout <<
"Something went wrong. Message text:\n";
552 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)
INDEX Index
The type to use for all integer numbers and indices.
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.