diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 473087c00..a7cd3c705 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -165,7 +165,7 @@ StochSimulStatement::StochSimulStatement(const SymbolList &symbol_list_arg, void 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 OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); @@ -191,7 +191,7 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, void 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 OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); @@ -217,7 +217,7 @@ RamseyPolicyStatement::RamseyPolicyStatement(const SymbolList &symbol_list_arg, void 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 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, void 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 OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); @@ -718,7 +718,7 @@ OsrStatement::OsrStatement(const SymbolList &symbol_list_arg, void 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 OptionsList::num_options_type::const_iterator it = options_list.num_options.find("order"); diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index d90a704d7..38e10562d 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -53,20 +53,32 @@ ModFile::checkPass() if (!mod_file_struct.order_option) 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 if (model_tree.equation_number() == 0 && (mod_file_struct.check_present || mod_file_struct.simul_present - || mod_file_struct.stoch_simul_or_similar_present)) + || stochastic_statement_present)) { - cerr << "Error: you must declare at least one model equation!" << endl; + cerr << "ERROR: At least one model equation must be declared!" << endl; exit(-1); } - if (mod_file_struct.simul_present - && mod_file_struct.stoch_simul_or_similar_present) + if (mod_file_struct.simul_present && stochastic_statement_present) { - cerr << "Error: a mod file cannot contain both a simul command and one of {stoch_simul, estimation, osr, ramsey_policy}" << 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); + } + + // Enforce the same number of equations and endogenous if ramsey_policy not present + if (!mod_file_struct.ramsey_policy_present && (model_tree.equation_number() != symbol_table.endo_nbr)) + { + cerr << "ERROR: There are " << model_tree.equation_number() << " equations but " << symbol_table.endo_nbr << " endogenous variables!" << endl; exit(-1); } } @@ -114,14 +126,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const mOutputFile.open(fname.c_str(), ios::out | ios::binary); if (!mOutputFile.is_open()) { - cerr << "Error: Can't open file " << fname + cerr << "ERROR: Can't open file " << fname << " for writing" << endl; exit(-1); } } else { - cerr << "Error: Missing file name" << endl; + cerr << "ERROR: Missing file name" << endl; exit(-1); } diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc index dc629b49f..eff107c2b 100644 --- a/preprocessor/Statement.cc +++ b/preprocessor/Statement.cc @@ -22,7 +22,11 @@ ModFileStructure::ModFileStructure() : check_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) { } diff --git a/preprocessor/include/ModFile.hh b/preprocessor/include/ModFile.hh index aecd9c1ec..6dde14522 100644 --- a/preprocessor/include/ModFile.hh +++ b/preprocessor/include/ModFile.hh @@ -60,6 +60,7 @@ public: //! Add a statement void addStatement(Statement *st); //! Do some checking and fills mod_file_struct + /*! \todo add check for number of equations and endogenous if ramsey_policy is present */ void checkPass(); //! Execute computations void computingPass(); diff --git a/preprocessor/include/Statement.hh b/preprocessor/include/Statement.hh index 77dd87449..9a6f990a7 100644 --- a/preprocessor/include/Statement.hh +++ b/preprocessor/include/Statement.hh @@ -36,9 +36,17 @@ public: bool check_present; //! Whether a simul statement is present bool simul_present; - //! Whether a stoch_simul, estimation, osr, ramsey_policy statement is present - bool stoch_simul_or_similar_present; - //! The value of the "order" option of stoch_simul, estimation, osr, ramsey_policy + //! Whether a stoch_simul statement is present + bool stoch_simul_present; + //! 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 /*! 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;