Commit 74fb2cb0 authored by sebastien's avatar sebastien
Browse files

trunk preprocessor:

* fail if no. of equations is different from no. of endogenous (unless ramsey_policy is used)
* more fields in the ModFileStructure class
* cosmetic changes


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2121 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 81ada88d
...@@ -165,7 +165,7 @@ StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg, ...@@ -165,7 +165,7 @@ StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg,
void void
StochSimulStatement::checkPass(ModFileStructure &mod_file_struct) StochSimulStatement::checkPass(ModFileStructure &mod_file_struct)
{ {
mod_file_struct.stoch_simul_or_similar_present = true; mod_file_struct.stoch_simul_present = true;
// Fill in option_order of mod_file_struct // Fill in option_order of mod_file_struct
OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order");
...@@ -191,7 +191,7 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, ...@@ -191,7 +191,7 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg,
void void
ForecastStatement::checkPass(ModFileStructure &mod_file_struct) ForecastStatement::checkPass(ModFileStructure &mod_file_struct)
{ {
mod_file_struct.stoch_simul_or_similar_present = true; mod_file_struct.forecast_present = true;
// Fill in option_order of mod_file_struct // Fill in option_order of mod_file_struct
OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order");
...@@ -217,7 +217,7 @@ RamseyPolicyStatement::RamseyPolicyStatement(const SymbolList &symbol_list_arg, ...@@ -217,7 +217,7 @@ RamseyPolicyStatement::RamseyPolicyStatement(const SymbolList &symbol_list_arg,
void void
RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct) RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct)
{ {
mod_file_struct.stoch_simul_or_similar_present = true; mod_file_struct.ramsey_policy_present = true;
/* Fill in option_order of mod_file_struct /* Fill in option_order of mod_file_struct
Since ramsey policy needs one further order of derivation (for example, for 1st order Since ramsey policy needs one further order of derivation (for example, for 1st order
...@@ -245,7 +245,7 @@ EstimationStatement::EstimationStatement(const SymbolList &symbol_list_arg, ...@@ -245,7 +245,7 @@ EstimationStatement::EstimationStatement(const SymbolList &symbol_list_arg,
void void
EstimationStatement::checkPass(ModFileStructure &mod_file_struct) EstimationStatement::checkPass(ModFileStructure &mod_file_struct)
{ {
mod_file_struct.stoch_simul_or_similar_present = true; mod_file_struct.estimation_present = true;
// Fill in option_order of mod_file_struct // Fill in option_order of mod_file_struct
OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order");
...@@ -718,7 +718,7 @@ OsrStatement::OsrStatement(const SymbolList &symbol_list_arg, ...@@ -718,7 +718,7 @@ OsrStatement::OsrStatement(const SymbolList &symbol_list_arg,
void void
OsrStatement::checkPass(ModFileStructure &mod_file_struct) OsrStatement::checkPass(ModFileStructure &mod_file_struct)
{ {
mod_file_struct.stoch_simul_or_similar_present = true; mod_file_struct.osr_present = true;
// Fill in option_order of mod_file_struct // Fill in option_order of mod_file_struct
OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order");
......
...@@ -53,20 +53,32 @@ ModFile::checkPass() ...@@ -53,20 +53,32 @@ ModFile::checkPass()
if (!mod_file_struct.order_option) if (!mod_file_struct.order_option)
mod_file_struct.order_option = 2; mod_file_struct.order_option = 2;
bool stochastic_statement_present = mod_file_struct.stoch_simul_present
|| mod_file_struct.estimation_present
|| mod_file_struct.forecast_present
|| mod_file_struct.osr_present
|| mod_file_struct.ramsey_policy_present;
// Allow empty model only when doing a standalone BVAR estimation // Allow empty model only when doing a standalone BVAR estimation
if (model_tree.equation_number() == 0 if (model_tree.equation_number() == 0
&& (mod_file_struct.check_present && (mod_file_struct.check_present
|| mod_file_struct.simul_present || mod_file_struct.simul_present
|| mod_file_struct.stoch_simul_or_similar_present)) || stochastic_statement_present))
{
cerr << "ERROR: At least one model equation must be declared!" << endl;
exit(-1);
}
if (mod_file_struct.simul_present && stochastic_statement_present)
{ {
cerr << "Error: you must declare at least one model equation!" << endl; cerr << "ERROR: A .mod file cannot contain both a simul command and one of {stoch_simul, estimation, forecast, osr, ramsey_policy}" << endl;
exit(-1); exit(-1);
} }
if (mod_file_struct.simul_present // Enforce the same number of equations and endogenous if ramsey_policy not present
&& mod_file_struct.stoch_simul_or_similar_present) if (!mod_file_struct.ramsey_policy_present && (model_tree.equation_number() != symbol_table.endo_nbr))
{ {
cerr << "Error: a mod file cannot contain both a simul command and one of {stoch_simul, estimation, osr, ramsey_policy}" << endl; cerr << "ERROR: There are " << model_tree.equation_number() << " equations but " << symbol_table.endo_nbr << " endogenous variables!" << endl;
exit(-1); exit(-1);
} }
} }
...@@ -114,14 +126,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const ...@@ -114,14 +126,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
mOutputFile.open(fname.c_str(), ios::out | ios::binary); mOutputFile.open(fname.c_str(), ios::out | ios::binary);
if (!mOutputFile.is_open()) if (!mOutputFile.is_open())
{ {
cerr << "Error: Can't open file " << fname cerr << "ERROR: Can't open file " << fname
<< " for writing" << endl; << " for writing" << endl;
exit(-1); exit(-1);
} }
} }
else else
{ {
cerr << "Error: Missing file name" << endl; cerr << "ERROR: Missing file name" << endl;
exit(-1); exit(-1);
} }
......
...@@ -22,7 +22,11 @@ ...@@ -22,7 +22,11 @@
ModFileStructure::ModFileStructure() : ModFileStructure::ModFileStructure() :
check_present(false), check_present(false),
simul_present(false), simul_present(false),
stoch_simul_or_similar_present(false), stoch_simul_present(false),
estimation_present(false),
forecast_present(false),
osr_present(false),
ramsey_policy_present(false),
order_option(0) order_option(0)
{ {
} }
......
...@@ -60,6 +60,7 @@ public: ...@@ -60,6 +60,7 @@ public:
//! Add a statement //! Add a statement
void addStatement(Statement *st); void addStatement(Statement *st);
//! Do some checking and fills mod_file_struct //! Do some checking and fills mod_file_struct
/*! \todo add check for number of equations and endogenous if ramsey_policy is present */
void checkPass(); void checkPass();
//! Execute computations //! Execute computations
void computingPass(); void computingPass();
......
...@@ -36,9 +36,17 @@ public: ...@@ -36,9 +36,17 @@ public:
bool check_present; bool check_present;
//! Whether a simul statement is present //! Whether a simul statement is present
bool simul_present; bool simul_present;
//! Whether a stoch_simul, estimation, osr, ramsey_policy statement is present //! Whether a stoch_simul statement is present
bool stoch_simul_or_similar_present; bool stoch_simul_present;
//! The value of the "order" option of stoch_simul, estimation, osr, ramsey_policy //! Whether an estimation statement is present
bool estimation_present;
//! Whether a forecast statement is present
bool forecast_present;
//! Whether an osr statement is present
bool osr_present;
//! Whether a ramsey_policy statement is present
bool ramsey_policy_present;
//! The value of the "order" option of stoch_simul, estimation, forecast, osr, ramsey_policy
//! Derivation order //! Derivation order
/*! First initialized to zero. If user sets order option somewhere in the MOD file, it will be equal to the maximum of order options. Otherwise will default to 2 */ /*! First initialized to zero. If user sets order option somewhere in the MOD file, it will be equal to the maximum of order options. Otherwise will default to 2 */
int order_option; int order_option;
......
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