From ff17a871dd76560f3ed37cbba3cdf07254f4ab1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 9 Apr 2014 15:23:20 +0200
Subject: [PATCH] Multiple "shocks" block are cumulative.

This was the default behavior before commit 82b31156. This commit reintroduces
this behavior.
---
 ModFile.cc |  3 +++
 Shocks.cc  | 20 +++++++-------------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/ModFile.cc b/ModFile.cc
index 7e73f550..f5c20837 100644
--- a/ModFile.cc
+++ b/ModFile.cc
@@ -585,6 +585,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
               << "M_.Correlation_matrix = eye(" << symbol_table.exo_nbr() << ", "
               << symbol_table.exo_nbr() << ");" << endl;
 
+  // Initialize M_.det_shocks
+  mOutputFile << "M_.det_shocks = [];" << endl;
+
   if (mod_file_struct.calibrated_measurement_errors)
     mOutputFile << "M_.H = zeros(" << symbol_table.observedVariablesNbr() << ", "
                 << symbol_table.observedVariablesNbr() << ");" << endl
diff --git a/Shocks.cc b/Shocks.cc
index fef8bda4..25adbdee 100644
--- a/Shocks.cc
+++ b/Shocks.cc
@@ -36,7 +36,6 @@ void
 AbstractShocksStatement::writeDetShocks(ostream &output) const
 {
   int exo_det_length = 0;
-  int counter = 1;
 
   for (det_shocks_t::const_iterator it = det_shocks.begin();
        it != det_shocks.end(); it++)
@@ -50,19 +49,14 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
           const int &period2 = it->second[i].period2;
           const expr_t value = it->second[i].value;
 
-          output << "M_.det_shocks(" << counter << ").exo_det=" << (int) exo_det
-                 << ";" << endl
-                 << "M_.det_shocks(" << counter << ").exo_id=" << id
-                 << ";" << endl
-                 << "M_.det_shocks(" << counter << ").multiplicative=" << (int) mshocks
-                 << ";" << endl
-                 << "M_.det_shocks(" << counter << ").periods=" << period1
-                 << ":" << period2 << ";" << endl
-                 << "M_.det_shocks(" << counter << ").value=(";
+          output << "M_.det_shocks = [ M_.det_shocks;" << endl
+                 << "struct('exo_det'," << (int) exo_det
+                 << ",'exo_id'," << id
+                 << ",'multiplicative'," << (int) mshocks
+                 << ",'periods'," << period1 << ":" << period2
+                 << ",'value',";
           value->writeOutput(output);
-          output << ");" << endl;
-
-          counter++;
+          output << ") ];" << endl;
 
           if (exo_det && (period2 > exo_det_length))
             exo_det_length = period2;
-- 
GitLab