Commit 6726a958 authored by sebastien's avatar sebastien
Browse files

v4 matlab+preprocessor: allow syntax of homotopy_setup without initial value


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1779 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 924e3406
......@@ -1250,7 +1250,10 @@ homotopy_list : homotopy_item
;
homotopy_item : NAME COMMA expression COMMA expression ';'
{ driver.homotopy_val($1,$3,$5);};
{ driver.homotopy_val($1, $3, $5);}
| NAME COMMA expression ';'
{ driver.homotopy_val($1, NULL, $3);}
;
number : INT_NUMBER
| FLOAT_NUMBER
......
......@@ -179,7 +179,10 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename) const
const int id = symbol_table.getID(name) + 1;
output << "options_.homotopy_values = vertcat(options_.homotopy_values, [ " << type << ", " << id << ", ";
expression1->writeOutput(output);
if (expression1 != NULL)
expression1->writeOutput(output);
else
output << "NaN";
output << ", ";
expression2->writeOutput(output);
output << "]);" << endl;
......
......@@ -347,10 +347,7 @@ ParsingDriver::homotopy_val(string *name, NodeID val1, NodeID val2)
&& type != eExogenousDet)
error("homotopy_val: " + *name + " should be a parameter or exogenous variable");
if (homotopy_values.find(*name) != homotopy_values.end())
error("homotopy_val: " + *name +" declared twice");
homotopy_values[*name] = make_pair(val1, val2);
homotopy_values.push_back(make_pair(*name, make_pair(val1, val2)));
delete name;
}
......
......@@ -95,11 +95,9 @@ public:
class HomotopyStatement : public Statement
{
public:
/*!
Contrary to Initval and Endval, we use a map, since it is impossible to reuse
a given initialization value in a second initialization inside the block.
*/
typedef map<string,pair<NodeID,NodeID> > homotopy_values_type;
//! Stores the declarations of homotopy_setup
/*! Order matter so we use a vector. First NodeID can be NULL if no initial value given. */
typedef vector<pair<string, pair<NodeID, NodeID> > > homotopy_values_type;
private:
const homotopy_values_type homotopy_values;
const SymbolTable &symbol_table;
......
......@@ -209,7 +209,8 @@ public:
void init_val(string *name, NodeID rhs);
//! Writes an histval block
void hist_val(string *name, string *lag, NodeID rhs);
//! Writes an homotopy_setup block
//! Adds an entry in a homotopy_setup block
/*! Second argument "val1" can be NULL if no initial value provided */
void homotopy_val(string *name, NodeID val1, NodeID val2);
//! Writes end of an initval block
void end_initval();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment