From b51f122e59a881625ee4c04cc9d4558aa4992a13 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 19 Nov 2021 17:49:57 +0100
Subject: [PATCH] With nostrict, really ignore unused endogenous in
 initval/endval/histval

Closes: #82
---
 src/NumericalInitialization.cc | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/NumericalInitialization.cc b/src/NumericalInitialization.cc
index 92f0ca27..1495fa36 100644
--- a/src/NumericalInitialization.cc
+++ b/src/NumericalInitialization.cc
@@ -132,6 +132,9 @@ InitOrEndValStatement::writeInitValues(ostream &output) const
 {
   for (auto [symb_id, value] : init_values)
     {
+      if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
+        continue;
+
       SymbolType type = symbol_table.getType(symb_id);
       int tsid = symbol_table.getTypeSpecificID(symb_id) + 1;
 
@@ -167,9 +170,11 @@ InitOrEndValStatement::writeJsonInitValues(ostream &output) const
   for (auto it = init_values.begin();
        it != init_values.end(); ++it)
     {
+      auto [symb_id, value] = *it;
+      if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
+        continue;
       if (it != init_values.begin())
         output << ", ";
-      auto [symb_id, value] = *it;
       output << R"({"name": ")" << symbol_table.getName(symb_id) << R"(", )" << R"("value": ")";
       value->writeJsonOutput(output, {}, {});
       output << R"("})";
@@ -363,6 +368,8 @@ HistValStatement::writeOutput(ostream &output, const string &basename, bool mini
   for (const auto &[key, value] : hist_values)
     {
       auto [symb_id, lag] = key;
+      if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
+        continue;
 
       output << "M_.histval_dseries{'" << symbol_table.getName(symb_id) << "'}(dates('" << lag << "Y'))=";
       value->writeOutput(output);
@@ -389,6 +396,8 @@ HistValStatement::writeJsonOutput(ostream &output) const
        it != hist_values.end(); ++it)
     {
       auto [symb_id, lag] = it->first;
+      if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
+        continue;
       if (it != hist_values.begin())
         output << ", ";
       output << R"({ "name": ")" << symbol_table.getName(symb_id) << R"(")"
-- 
GitLab