From 113d7e1140d4abeccfad71bd9918681a33d9f48e Mon Sep 17 00:00:00 2001
From: sebastien <sebastien@ac1d8469-bf42-47a9-8791-bf33cf982152>
Date: Fri, 17 Oct 2008 12:52:08 +0000
Subject: [PATCH] trunk preprocessor: allow zero equation if standalone BVAR
 estimation

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2170 ac1d8469-bf42-47a9-8791-bf33cf982152
---
 ComputingTasks.cc         | 14 +++++++++++++-
 ModFile.cc                | 11 +++++++++--
 Statement.cc              |  4 +++-
 include/ComputingTasks.hh |  3 ++-
 include/Statement.hh      |  4 ++++
 5 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/ComputingTasks.cc b/ComputingTasks.cc
index b755a3ad..c357d32f 100644
--- a/ComputingTasks.cc
+++ b/ComputingTasks.cc
@@ -848,7 +848,7 @@ PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct)
 {
   if (model_tree->equation_number() != 1)
     {
-      cerr << "Error: planer_objective: should have only one equation!" << endl;
+      cerr << "ERROR: planer_objective: should have only one equation!" << endl;
       exit(-1);
     }
 }
@@ -872,6 +872,12 @@ BVARDensityStatement::BVARDensityStatement(int maxnlags_arg, const OptionsList &
 {
 }
 
+void
+BVARDensityStatement::checkPass(ModFileStructure &mod_file_struct)
+{
+  mod_file_struct.bvar_density_present = true;
+}
+
 void
 BVARDensityStatement::writeOutput(ostream &output, const string &basename) const
 {
@@ -885,6 +891,12 @@ BVARForecastStatement::BVARForecastStatement(int nlags_arg, const OptionsList &o
 {
 }
 
+void
+BVARForecastStatement::checkPass(ModFileStructure &mod_file_struct)
+{
+  mod_file_struct.bvar_forecast_present = true;
+}
+
 void
 BVARForecastStatement::writeOutput(ostream &output, const string &basename) const
 {
diff --git a/ModFile.cc b/ModFile.cc
index 38e10562..6b832720 100644
--- a/ModFile.cc
+++ b/ModFile.cc
@@ -75,8 +75,15 @@ ModFile::checkPass()
       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))
+  /*
+    Enforce the same number of equations and endogenous, except in two cases:
+    - ramsey_policy is used
+    - a BVAR command is used and there is no equation (standalone BVAR estimation)
+  */
+  if (!mod_file_struct.ramsey_policy_present
+      && !((mod_file_struct.bvar_density_present || mod_file_struct.bvar_forecast_present)
+           && model_tree.equation_number() == 0)
+      && (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);
diff --git a/Statement.cc b/Statement.cc
index eff107c2..17adf591 100644
--- a/Statement.cc
+++ b/Statement.cc
@@ -27,7 +27,9 @@ ModFileStructure::ModFileStructure() :
   forecast_present(false),
   osr_present(false),
   ramsey_policy_present(false),
-  order_option(0)
+  order_option(0),
+  bvar_density_present(false),
+  bvar_forecast_present(false)
 {
 }
 
diff --git a/include/ComputingTasks.hh b/include/ComputingTasks.hh
index eaa5703b..08d24a1d 100644
--- a/include/ComputingTasks.hh
+++ b/include/ComputingTasks.hh
@@ -445,6 +445,7 @@ private:
   const OptionsList options_list;
 public:
   BVARDensityStatement(int maxnlags_arg, const OptionsList &options_list_arg);
+  virtual void checkPass(ModFileStructure &mod_file_struct);
   virtual void writeOutput(ostream &output, const string &basename) const;
 };
 
@@ -455,8 +456,8 @@ private:
   const OptionsList options_list;
 public:
   BVARForecastStatement(int nlags_arg, const OptionsList &options_list_arg);
+  virtual void checkPass(ModFileStructure &mod_file_struct);
   virtual void writeOutput(ostream &output, const string &basename) const;
 };
 
-
 #endif
diff --git a/include/Statement.hh b/include/Statement.hh
index 9a6f990a..d86129f7 100644
--- a/include/Statement.hh
+++ b/include/Statement.hh
@@ -50,6 +50,10 @@ public:
   //! 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;
+  //! Whether a bvar_density statement is present
+  bool bvar_density_present;
+  //! Whether a bvar_forecast statement is present
+  bool bvar_forecast_present;
 };
 
 class Statement
-- 
GitLab