Go to the documentation of this file.
37 : mtasklist (tasklist), mcfile (controlfile), mcfile_version (1), verbosity (rverbosity)
79 out3 <<
"\nParsing control text:\n";
87 if (
"Arts" !=
md_data[
id].Name() &&
"Arts2" !=
md_data[
id].Name() )
89 out0 <<
"The outermost agenda must be Arts2!\n"
90 <<
"(But it seems to be " <<
md_data[id].Name() <<
".)\n";
108 out0 <<
"Unexpected character(s) at the end of the control file\n";
109 out0 <<
"after the main agenda was already closed.\n";
110 out0 <<
"File: " << x.
file() <<
'\n';
111 out0 <<
"Line: " << x.
line() <<
'\n';
112 out0 <<
"Column: " << x.
column() <<
'\n';
119 out0 <<
"Unexpected end of control script.\n";
120 out0 <<
"File: " << x.
file() <<
'\n';
121 out0 <<
"Line: " << x.
line() <<
'\n';
127 out0 <<
"Unexpected character:\n";
128 out0 << x.what() <<
'\n';
129 out0 <<
"File: " << x.
file() <<
'\n';
130 out0 <<
"Line: " << x.
line() <<
'\n';
131 out0 <<
"Column: " << x.
column() <<
'\n';
137 out0 <<
"Illegal Line break:\n";
138 out0 << x.what() <<
'\n';
139 out0 <<
"File: " << x.
file() <<
'\n';
140 out0 <<
"Line: " << x.
line() <<
'\n';
148 out0 <<
"Unknown Method:\n";
149 out0 << x.what() <<
'\n';
150 out0 <<
"File: " << x.
file() <<
'\n';
151 out0 <<
"Line: " << x.
line() <<
'\n';
152 out0 <<
"Column: " << x.
column() <<
'\n';
160 out0 <<
"Unknown workspace variable:\n";
161 out0 << x.what() <<
'\n';
162 out0 <<
"File: " << x.
file() <<
'\n';
163 out0 <<
"Line: " << x.
line() <<
'\n';
164 out0 <<
"Column: " << x.
column() <<
'\n';
170 out0 <<
"Attempt to create a workspace variable that already exists:\n";
171 out0 << x.what() <<
'\n';
172 out0 <<
"File: " << x.
file() <<
'\n';
173 out0 <<
"Line: " << x.
line() <<
'\n';
174 out0 <<
"Column: " << x.
column() <<
'\n';
182 out0 <<
"Workspace variable belongs to the wrong group:\n";
183 out0 << x.what() <<
'\n';
184 out0 <<
"File: " << x.
file() <<
'\n';
185 out0 <<
"Line: " << x.
line() <<
'\n';
186 out0 <<
"Column: " << x.
column() <<
'\n';
192 out0 <<
"Parse error:\n";
193 out0 << x.what() <<
'\n';
194 out0 <<
"File: " << x.
file() <<
'\n';
195 out0 <<
"Line: " << x.
line() <<
'\n';
196 out0 <<
"Column: " << x.
column() <<
'\n';
241 auto_vars,auto_vars_values,include_file);
253 os <<
"Cannot find include file " << include_file
258 throw runtime_error (os.str());
261 out2 <<
"- Including control file " << include_file <<
"\n";
275 auto_vars_values[0],tasks));
293 out3 <<
"- " <<
md_data[id].Name() <<
"\n";
296 if ( 0 <
md_data[
id].GOutType().nelem()
297 +
md_data[
id].GInType().nelem() )
369 bool found_curly_brace =
false;
376 auto_vars.resize( 0 );
377 auto_vars_values.resize( 0 );
382 if (methodname ==
"INCLUDE")
393 if (methodname ==
"Arts2")
397 else if (methodname ==
"Arts")
399 throw runtime_error(
"Arts version 1 controlfiles are no longer supported.");
405 auto_vars, auto_vars_values);
414 found_curly_brace =
true;
422 out3 <<
"- " << mdd->
Name() <<
"\n";
432 os <<
"Expected method name , but got `" <<
msource.
Current() <<
"'.";
443 if (found_curly_brace)
452 if (!no_eot)
throw Eot(x);
493 istringstream is(mdd->
GInDefault()[gin_index]);
496 if (is.bad () || is.fail ())
502 istringstream is(mdd->
GInDefault()[gin_index]);
505 if (is.bad () || is.fail ())
533 <<
"Default values for generic inputs with type "
535 <<
"Either remove the default value for generic input '"
536 << mdd->
GIn()[gin_index] <<
"' in workspace method\n"
537 <<
"*" << mdd->
Name() <<
"* in methods.cc or discuss this "
538 <<
"issue on the arts-dev mailing list.\n";
551 name =
"auto_" + mdd->
Name() +
"_" +
"gin" + os.str() +
"_"
552 + mdd->
GIn()[gin_index];
555 map<String, Index>::const_iterator wsvit =
561 "Automatically allocated variable.",
567 wsvid = wsvit->second;
570 auto_vars.push_back(wsvid);
571 auto_vars_values.push_back(tv);
576 os <<
"Failed to assign default value for generic '"
577 << mdd->
GIn()[gin_index] <<
"'.\n"
578 <<
"Check the documentation of workspace method *"
579 << mdd->
Name() <<
"*.\n";
589 os <<
"Generic input '" << mdd->
GIn()[gin_index]
590 <<
"' omitted but no default value found.\n"
591 <<
"Check the documentation of workspace method *"
592 << mdd->
Name() <<
"*.\n";
625 extern const map<String, Index>
MdRawMap;
628 extern const map<String, Index>
MdMap;
630 bool still_supergeneric=
true;
635 const map<String, Index>::const_iterator i =
MdRawMap.find(methodname);
654 const map<String, Index>::const_iterator i2 =
MdMap.find(methodname);
655 assert ( i2 !=
MdMap.end() );
660 still_supergeneric =
false;
667 Index supergeneric_index = -1;
675 first, still_supergeneric, supergeneric_args,
681 auto_vars, auto_vars_values,
682 first, still_supergeneric, supergeneric_args,
685 assert(!still_supergeneric);
693 for (ArrayOfIndex::const_iterator outs=vo.begin();
694 outs<vo.end(); ++outs)
696 output.push_back (*outs);
700 for (ArrayOfIndex::const_iterator ins=vi.begin(); ins<vi.end(); ++ins)
702 input.push_back (*ins);
708 bool all_gin_have_defaults =
true;
710 all_gin_have_defaults && gin < mdd->
GIn().nelem();
717 all_gin_have_defaults =
false;
722 auto_vars_values, gin);
725 const map<String, Index>::const_iterator wsvit =
735 wsvid = wsvit->second;
737 input.push_back(wsvid);
741 if (!all_gin_have_defaults)
744 os <<
"Not all generic inputs of this method have default "
745 <<
"values, you have to specify them!";
779 bool& still_supergeneric,
780 String& supergeneric_args,
787 extern const map<String, Index>
MdMap;
814 "generic" + os.str(),
818 throw ParseError(
"Only constants can be passed to Set methods.\n"
819 "You might want to use the *Copy* here.",
828 const map<String, Index>::const_iterator wsvit =
838 wsvid = wsvit->second;
844 if ( still_supergeneric )
850 os << mdd->
Name() <<
"_sg_" << supergeneric_args;
851 methodname = os.str();
854 const map<String, Index>::const_iterator mdit =
855 MdMap.find(methodname);
856 if (mdit !=
MdMap.end())
862 still_supergeneric =
false;
874 if (supergeneric_index == -1)
876 bool wrong_group_id =
true;
882 wrong_group_id =
false;
883 supergeneric_index = i;
890 bool firsttype =
true;
893 if (!firsttype) os <<
", ";
else firsttype =
false;
899 +
" input. Check the online docs.",
931 input.push_back(wsvid);
958 bool& still_supergeneric,
959 String& supergeneric_args,
960 Index& supergeneric_index)
966 extern const map<String, Index>
MdMap;
969 for (
Index j=0 ; j<mdd->
GOut().nelem() ; ++j )
984 map<String, Index>::const_iterator wsvit =
988 if (still_supergeneric)
991 os <<
"This might be either a typo or you have to create "
992 <<
"the variable\nby calling TYPECreate(" << wsvname
993 <<
") first. Replace TYPE with the\n"
994 <<
"WSV group your variable should belong to.";
1003 if (mdd->
Name().length() > 6
1004 && mdd->
Name().substr (mdd->
Name().length() - 6)
1008 os <<
"This might be either a typo or you have to create "
1009 <<
"the variable\nby calling "
1011 <<
"Create( " << wsvname
1023 "Automatically allocated variable.",
1032 if (mdd->
Name().length() > 6 &&
1033 mdd->
Name().find (
"Create") == mdd->
Name().length() - 6)
1036 os << wsvname <<
" already exists. A variable can only be created once.\n";
1042 wsvid = wsvit->second;
1050 if ( still_supergeneric )
1054 supergeneric_args +=
1056 os << mdd->
Name() <<
"_sg_" << supergeneric_args;
1057 methodname = os.str();
1060 const map<String, Index>::const_iterator mdit =
MdMap.find(methodname);
1061 if (mdit !=
MdMap.end() )
1067 still_supergeneric =
false;
1079 if (supergeneric_index == -1)
1081 bool wrong_group_id =
true;
1087 wrong_group_id =
false;
1088 supergeneric_index = i;
1095 bool firsttype =
true;
1098 if (!firsttype) os <<
", ";
else firsttype =
false;
1104 +
" output. Check the online docs.",
1136 output.push_back(wsvid);
1170 for (ArrayOfIndex::const_iterator ins=vi.begin(); ins<vi.end(); ++ins)
1196 const map<String, Index>::const_iterator wsvit =
1204 wsvid = wsvit->second;
1218 input.push_back(wsvid);
1246 for (ArrayOfIndex::const_iterator outs=vo.begin(); outs<vo.end(); ++outs)
1275 map<String, Index>::const_iterator wsvit =
1279 if (mdd->
Name().length() > 6
1280 && mdd->
Name().substr (mdd->
Name().length() - 6)
1284 os <<
"This might be either a typo or you have to create "
1285 <<
"the variable\nby calling "
1287 <<
"Create( " << wsvname
1299 "Automatically allocated variable.",
1306 wsvid = wsvit->second;
1320 output.push_back(wsvid);
1342 const Index method_type,
1345 extern const map<String, Index>
MdMap;
1350 map<String, Index>::const_iterator mdit;
1352 TokVal auto_keyword_value;
1369 <<
" constant to a WSM is not supported!";
1377 switch (method_type)
1380 auto_keyword_value = auto_vars_values[i];
1381 auto_output_var.push_back(auto_vars[i]);
1386 auto_input_var.push_back(auto_vars[i]);
1390 throw runtime_error(
"Invalid method_type");
1393 mdit =
MdMap.find(method_name);
1394 assert ( mdit !=
MdMap.end() );
1395 init_mdid = mdit->second;
1398 auto_output_var, auto_input_var,
1459 os <<
"Expected whitespace, but got `" << dummy <<
"'.";
1502 os <<
"Workspace variable names must start with a letter!";
1513 if ( isalnum(dummy) ||
'_'==dummy )
1551 const String& default_name,
1566 os <<
"Passing constants as supergeneric parameters is not supported.";
1579 name =
"auto_" + mdd->
Name() +
"_" + default_name;
1584 "Automatically allocated variable.",
1590 wsvid = wsvit->second;
1593 auto_vars.push_back(wsvid);
1601 auto_vars_values.push_back(dummy);
1607 auto_vars_values.push_back(n);
1613 auto_vars_values.push_back(n);
1619 auto_vars_values.push_back(dummy);
1625 auto_vars_values.push_back(dummy);
1631 auto_vars_values.push_back(dummy);
1637 auto_vars_values.push_back(dummy);
1644 throw runtime_error (os.str());
1662 os <<
"Expected '" << c <<
"', but got '" <<
msource.
Current() <<
"'.";
1739 if (
'+' == dummy ||
'-' == dummy )
1753 os <<
"Expected digit or variable name, but got `" <<
msource.
Current()
1764 if ( isdigit(chtmp) )
1801 bool found_digit =
false;
1805 if (
'+' == dummy ||
'-' == dummy )
1821 if ( isdigit(chtmp) )
1861 if ( isdigit(chtmp) )
1877 throw ParseError(
"Expected at least one digit.",
1884 if (
'e' == dummy ||
'E' == dummy )
1912 istringstream is(res);
1925 istringstream is(res);
1970 res.push_back(dummy);
2015 res.push_back(dummy);
2064 tres.push_back(dummy);
2070 for (
int i = 0; i < tres.
nelem (); i++)
2106 Index cur_ncols = 1;
2120 if (ncols != -1 && cur_ncols > ncols)
2123 os <<
"Expected ';', but got '" <<
msource.
Current() <<
"'. Check Matrix dimensions.";
2138 else if (ncols != cur_ncols)
2141 os <<
"Expected ',', but got '" <<
msource.
Current() <<
"'. Check Matrix dimensions.";
2154 if (ncols > cur_ncols)
2157 os <<
"Expected '" << c <<
"', but got '" <<
msource.
Current() <<
"'. Check Matrix dimensions.";
2166 tres.push_back(dummy);
2170 if (ncols == -1) ncols = cur_ncols;
2171 if (ncols != cur_ncols)
2173 throw ParseError(
"Missing element(s) in last row of matrix",
2182 res.
resize(nrows, ncols);
2183 for (
Index i = 0; i < nrows; i++)
2184 for (
Index j = 0; j < ncols; j++)
2185 res(i, j) = tres[i*ncols+j];
2210 if (str[pos] !=
'[')
2212 throw runtime_error (
"No opening bracket\n");
2221 while ( pos < str.length() && str[pos] !=
']' )
2227 if (str[pos] !=
',')
2236 istringstream is (str.substr(pos));
2238 if (is.bad () || is.fail ())
2240 tres.push_back(dummy);
2241 while (pos < str.length()
2242 && (isdigit(str[pos]) || str[pos] ==
'-' || str[pos] ==
'.'
2243 || str[pos] ==
'e'))
2250 for (
int i = 0; i < tres.
nelem (); i++)
2279 if (str[pos] !=
'[')
2281 throw runtime_error (
"No opening bracket\n");
2290 while ( pos < str.length() && str[pos] !=
']' )
2296 if (str[pos] !=
',')
2304 if (str[pos] !=
'"')
2306 throw runtime_error (
"Expected quotes\n");
2312 while ( pos < str.length() && str[pos] !=
'"' )
2318 if (pos == str.length() || str[pos] !=
'"')
2321 tres.push_back(dummy);
2327 res.resize(tres.
nelem());
2328 for (
int i = 0; i < tres.
nelem (); i++)
const ArrayOfString & GOut() const
void parse_specific_output(const MdRecord *mdd, ArrayOfIndex &output, bool &first)
Parse the output WSVs for current method from the controlfile.
static Array< WsvRecord > wsv_data
bool Supergeneric() const
const ArrayOfArrayOfIndex & GOutSpecType() const
void AppendFile(const String &name)
Appends contents of file to the source text.
const ArrayOfIndex & GOutType() const
The declarations of all the exception classes.
void parse_generic_output(const MdRecord *&mdd, Index &id, String &methodname, ArrayOfIndex &output, bool &first, bool &still_supergeneric, String &supergeneric_args, Index &supergeneric_index)
Parse the generic output WSVs for current method from the controlfile.
void eat_whitespace_from_string(String &str, size_t &pos)
Eats whitespace from a String.
void parse_method(Index &id, ArrayOfIndex &output, ArrayOfIndex &input, Agenda &tasks, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, String &include_file, bool no_eot=false)
Parse the Contents of text as ARTS control input.
void Init()
This sets the pointer to the first existing character in the text.
This stores arbitrary token values and remembers the type.
void read_integer(String &res)
Reads an integer.
void parse_generic_input(const MdRecord *&mdd, Index &id, String &methodname, ArrayOfIndex &input, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, bool &first, bool &still_supergeneric, String &supergeneric_args, Index &supergeneric_index)
Parse the generic input WSVs for current method from the controlfile.
Array< MdRecord > md_data_raw
Lookup information for workspace methods.
const ArrayOfIndex & GInType() const
bool is_whitespace(const char c)
Returns true if this character is considered whitespace.
Structure to hold all command line Parameters.
Index nelem() const
Return the number of agenda elements.
void eat_whitespace()
Eats whitespace.
void parse_specific_input(const MdRecord *mdd, ArrayOfIndex &input, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, bool &first)
Parse the specific input WSVs for current method from the controlfile.
bool & LineBreak()
Read the line break flag.
void parse_matrix(Matrix &res)
Read a Matrix.
void resize(Index n)
Resize function.
void read_name(String &name)
Reads name of method, keyword, or workspace variable.
bool reachedEot()
Check if the current position reached the end.
void assertain_character(char c)
Make sure that the current character is equal to c and go to the next character.
bool find_file(String &filename, const char *extension)
Find the given file.
void parse_intvector(ArrayOfIndex &res)
Read a vector of integers.
virtual String file() const
virtual Index column() const
This can be used to make arrays out of anything.
Index Line()
Return the line number, but for the file that is associated with the current position.
const Verbosity & verbosity
String set_gin_to_default(const MdRecord *mdd, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, Index keyword_index)
Set generic input to default value.
void AdvanceLine()
Advances position pointer by one line.
virtual Index line() const
Index Column()
Return the current column.
bool parse_numvector_from_string(Vector &res, String &str)
Read a vector of Numerics from a String.
void parse_Stringvector(ArrayOfString &res)
Read a vector of Strings.
bool parse_stringarray_from_string(ArrayOfString &res, String &str)
Read an Array of Strings from a String.
void parse_agenda(Agenda &tasklist)
Parse the Contents of text as ARTS control input.
void parse_method_args(const MdRecord *&mdd, Index &id, String &methodname, ArrayOfIndex &output, ArrayOfIndex &input, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values)
Parse method's argument list.
bool AgendaMethod() const
ArrayOfString wsv_group_names
const String & File()
Return the filename associated with the current position.
void parse_tasklist()
Public interface to the main function of the parser.
NUMERIC Numeric
The type to use for all floating point numbers.
map< String, Index > MdRawMap
The map associated with md_data_raw.
const String & Name() const
void read_numeric(String &res)
Reads a floating point number.
void resize(Index r, Index c)
Resize function.
const ArrayOfIndex & InOnly() const
This file contains header information for the dealing with command line parameters.
const Array< String > & GInDefault() const
Index read_name_or_value(String &name, ArrayOfIndex &auto_vars, Array< TokVal > &auto_vars_values, const String &default_name, const MdRecord *mdd, const Index group)
Reads name of a workspace variable or a value.
Array< MdRecord > md_data
Lookup information for workspace methods.
ArtsParser(Agenda &tasklist, String controlfile, const Verbosity &verbosity)
Constructs a new parser.
const ArrayOfString & GIn() const
This class contains all static information for one workspace variable.
This file contains the declaration and partly the implementation of the workspace class.
All information for one workspace method.
Parameters parameters
Holds the command line parameters.
static map< String, Index > WsvMap
char Current()
Return the current character.
void parse_numeric(Numeric &n)
Use a String stream to parse a floating point number.
const ArrayOfArrayOfIndex & GInSpecType() const
map< String, Index > MdMap
The map associated with md_data.
static Index add_wsv(const WsvRecord &wsv)
void parse_main()
The main function of the parser.
void resize(Index n)
Resize the method list.
void parse_numvector(Vector &res)
Read a vector of Numerics.
void parse_integer(Index &n)
Use a String stream to parse an integer number.
This file contains basic functions to handle ASCII files.
void AdvanceChar()
Advance position pointer by one character.
INDEX Index
The type to use for all integer numbers and indices.
const ArrayOfIndex & Out() const
const Array< MRecord > & Methods() const
void arts_exit(int status)
This is the exit function of ARTS.
ArrayOfString includepath
List of paths to search for include files.
void parse_String(String &res)
Reads a String, complete with quotation marks.
Index get_wsv_group_id(const String &name)
void push_back(MRecord n)
Append a new method to end of list.
Index nelem() const
Number of elements.
Declaration of the class MdRecord.
Auxiliary header stuff related to workspace variable groups.
The global header file for ARTS.
void tasklist_insert_set_delete(const ArrayOfIndex &auto_vars, const Array< TokVal > &auto_vars_values, const Index method_type, Agenda &tasklist)
Insert Set and Delete methods for automatically allocated output WSVs.