From 60ef6bbdbd2f95b7f8d52b1c10cf6bb9aa7773cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 14 Dec 2021 17:46:02 +0100
Subject: [PATCH] Allow multiple estimated_params statements

---
 src/ComputingTasks.cc | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc
index c332510d..73fc5ca8 100644
--- a/src/ComputingTasks.cc
+++ b/src/ComputingTasks.cc
@@ -1361,11 +1361,15 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo
 void
 EstimatedParamsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
 {
-  output << "estim_params_.var_exo = zeros(0, 10);" << endl
-         << "estim_params_.var_endo = zeros(0, 10);" << endl
-         << "estim_params_.corrx = zeros(0, 11);" << endl
-         << "estim_params_.corrn = zeros(0, 11);" << endl
-         << "estim_params_.param_vals = zeros(0, 10);" << endl;
+  /* Multiple estimated_params statements are allowed, so make sure we don’t
+     overwrite previous ones. */
+  output << "if isempty(estim_params_)" << endl
+         << "    estim_params_.var_exo = zeros(0, 10);" << endl
+         << "    estim_params_.var_endo = zeros(0, 10);" << endl
+         << "    estim_params_.corrx = zeros(0, 11);" << endl
+         << "    estim_params_.corrn = zeros(0, 11);" << endl
+         << "    estim_params_.param_vals = zeros(0, 10);" << endl
+         << "end" << endl;
 
   for (const auto &it : estim_params_list)
     {
-- 
GitLab