Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -1250,7 +1250,10 @@ homotopy_list : homotopy_item ...@@ -1250,7 +1250,10 @@ homotopy_list : homotopy_item
; ;
homotopy_item : NAME COMMA expression COMMA expression ';' 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 number : INT_NUMBER
| FLOAT_NUMBER | FLOAT_NUMBER
......
...@@ -179,7 +179,10 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename) const ...@@ -179,7 +179,10 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename) const
const int id = symbol_table.getID(name) + 1; const int id = symbol_table.getID(name) + 1;
output << "options_.homotopy_values = vertcat(options_.homotopy_values, [ " << type << ", " << id << ", "; output << "options_.homotopy_values = vertcat(options_.homotopy_values, [ " << type << ", " << id << ", ";
if (expression1 != NULL)
expression1->writeOutput(output); expression1->writeOutput(output);
else
output << "NaN";
output << ", "; output << ", ";
expression2->writeOutput(output); expression2->writeOutput(output);
output << "]);" << endl; output << "]);" << endl;
......
...@@ -347,10 +347,7 @@ ParsingDriver::homotopy_val(string *name, NodeID val1, NodeID val2) ...@@ -347,10 +347,7 @@ ParsingDriver::homotopy_val(string *name, NodeID val1, NodeID val2)
&& type != eExogenousDet) && type != eExogenousDet)
error("homotopy_val: " + *name + " should be a parameter or exogenous variable"); error("homotopy_val: " + *name + " should be a parameter or exogenous variable");
if (homotopy_values.find(*name) != homotopy_values.end()) homotopy_values.push_back(make_pair(*name, make_pair(val1, val2)));
error("homotopy_val: " + *name +" declared twice");
homotopy_values[*name] = make_pair(val1, val2);
delete name; delete name;
} }
......
...@@ -95,11 +95,9 @@ public: ...@@ -95,11 +95,9 @@ public:
class HomotopyStatement : public Statement class HomotopyStatement : public Statement
{ {
public: public:
/*! //! Stores the declarations of homotopy_setup
Contrary to Initval and Endval, we use a map, since it is impossible to reuse /*! Order matter so we use a vector. First NodeID can be NULL if no initial value given. */
a given initialization value in a second initialization inside the block. typedef vector<pair<string, pair<NodeID, NodeID> > > homotopy_values_type;
*/
typedef map<string,pair<NodeID,NodeID> > homotopy_values_type;
private: private:
const homotopy_values_type homotopy_values; const homotopy_values_type homotopy_values;
const SymbolTable &symbol_table; const SymbolTable &symbol_table;
......
...@@ -209,7 +209,8 @@ public: ...@@ -209,7 +209,8 @@ public:
void init_val(string *name, NodeID rhs); void init_val(string *name, NodeID rhs);
//! Writes an histval block //! Writes an histval block
void hist_val(string *name, string *lag, NodeID rhs); 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); void homotopy_val(string *name, NodeID val1, NodeID val2);
//! Writes end of an initval block //! Writes end of an initval block
void end_initval(); void end_initval();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment