From d0131f3652d5e477691b4b52028b6ec4debc0622 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Thu, 11 May 2017 12:14:45 +0200
Subject: [PATCH] var_estimation: add datafile option

---
 ComputingTasks.cc | 18 +++++++++++++++---
 ComputingTasks.hh |  5 +++--
 DynareBison.yy    | 13 +++++++++++--
 ParsingDriver.cc  |  4 ++--
 ParsingDriver.hh  |  2 +-
 5 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/ComputingTasks.cc b/ComputingTasks.cc
index 40e7a86f..f60fd7c8 100644
--- a/ComputingTasks.cc
+++ b/ComputingTasks.cc
@@ -236,15 +236,27 @@ VarModelStatement::createVarModelMFunction(ostream &output, const map<string, se
   output << ");" << endl;
 }
 
-VarEstimationStatement::VarEstimationStatement(const string &var_model_name_arg) :
-  var_model_name(var_model_name_arg)
+VarEstimationStatement::VarEstimationStatement(const OptionsList &options_list_arg) :
+  options_list(options_list_arg)
 {
 }
 
+void
+VarEstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
+{
+  OptionsList::string_options_t::const_iterator it = options_list.string_options.find("var_estimation.model_name");
+  if (it == options_list.string_options.end())
+    {
+      cerr << "ERROR: You must provide the model name to the var_estimation statement." << endl;
+      exit(EXIT_FAILURE);
+    }
+}
+
 void
 VarEstimationStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
 {
-  output << "oo_ = var_estimation('" << var_model_name << "', M_, options_, oo_);" << endl;
+  options_list.writeOutput(output);
+  output << "oo_ = var_estimation(M_, options_, oo_);" << endl;
 }
 
 VarRestrictionsStatement::VarRestrictionsStatement(const string &var_model_name_arg,
diff --git a/ComputingTasks.hh b/ComputingTasks.hh
index ea4228b7..e4a219c6 100644
--- a/ComputingTasks.hh
+++ b/ComputingTasks.hh
@@ -151,9 +151,10 @@ public:
 class VarEstimationStatement : public Statement
 {
 private:
-  const string &var_model_name;
+  const OptionsList options_list;
 public:
-  VarEstimationStatement(const string &var_model_name_arg);
+  VarEstimationStatement(const OptionsList &options_list_arg);
+  virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
   virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
 };
 
diff --git a/DynareBison.yy b/DynareBison.yy
index 298764f9..b9757d96 100644
--- a/DynareBison.yy
+++ b/DynareBison.yy
@@ -452,10 +452,17 @@ restriction_exclusion_equation : EQUATION '(' symbol ')' symbol_list ';'
                                  { driver.add_VAR_restriction_exclusion_equation($3); }
                                ;
 
-var_estimation : VAR_ESTIMATION '(' symbol ')' ';'
-                 { driver.run_var_estimation($3); }
+var_estimation : VAR_ESTIMATION '(' var_estimation_options_list ')' ';'
+                 { driver.run_var_estimation(); }
                ;
 
+var_estimation_options_list : var_estimation_options_list COMMA var_estimation_options
+                            | var_estimation_options
+                            ;
+
+var_estimation_options : o_var_datafile
+                       | o_var_model_name
+                       ;
 
 nonstationary_var_list : nonstationary_var_list symbol
                          { driver.declare_nonstationary_var($2); }
@@ -2995,6 +3002,8 @@ o_var_nobs : NOBS EQUAL INT_NUMBER { driver.option_num("var.nobs", $3); };
 o_var_method : METHOD EQUAL symbol { driver.option_num("var.method", $3); };
 o_series : SERIES EQUAL symbol { driver.option_str("series", $3); };
 o_datafile : DATAFILE EQUAL filename { driver.option_str("datafile", $3); };
+o_var_datafile : DATAFILE EQUAL filename { driver.option_str("var_estimation.datafile", $3); };
+o_var_model_name : symbol { driver.option_str("var_estimation.model_name", $1); };
 o_dirname : DIRNAME EQUAL filename { driver.option_str("dirname", $3); };
 o_huge_number : HUGE_NUMBER EQUAL non_negative_number { driver.option_num("huge_number", $3); };
 o_nobs : NOBS EQUAL vec_int
diff --git a/ParsingDriver.cc b/ParsingDriver.cc
index 49a6bd39..d718732b 100644
--- a/ParsingDriver.cc
+++ b/ParsingDriver.cc
@@ -625,9 +625,9 @@ ParsingDriver::add_VAR_covariance_pair_restriction(string *name11, string *name1
 }
 
 void
-ParsingDriver::run_var_estimation(string *model_name)
+ParsingDriver::run_var_estimation()
 {
-  mod_file->addStatement(new VarEstimationStatement(*model_name));
+  mod_file->addStatement(new VarEstimationStatement(options_list));
 }
 
 void
diff --git a/ParsingDriver.hh b/ParsingDriver.hh
index 16193c74..c6ff4cfd 100644
--- a/ParsingDriver.hh
+++ b/ParsingDriver.hh
@@ -793,7 +793,7 @@ public:
   void add_VAR_covariance_number_restriction(string *name1, string *name2, string *valuestr);
   void add_VAR_covariance_pair_restriction(string *name11, string *name12, string *name21, string *name22);
   //! Runs VAR estimation process
-  void run_var_estimation(string *model_name);
+  void run_var_estimation();
 };
 
 #endif // ! PARSING_DRIVER_HH
-- 
GitLab