From c1381f1d755ef5ecbc352d7dafa0de30aa7723c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 13 Sep 2024 17:37:33 +0200
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20The=20=E2=80=9Conlyclearglobals?=
 =?UTF-8?q?=E2=80=9D=20option=20was=20not=20actually=20clearing=20global?=
 =?UTF-8?q?=20variables?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The driver was calling “clear” before “global”, hence clearing local and not
global variables (unless “global” had already been called at scope).

Rather use “clearvars -global”.
---
 src/ModFile.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ModFile.cc b/src/ModFile.cc
index 9b8211f4..6a378ecd 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -1065,9 +1065,9 @@ ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global,
     mOutputFile << "clearvars -global" << endl
                 << "clear_persistent_variables(fileparts(which('dynare')), false)" << endl;
   else if (clear_global)
-    mOutputFile
-        << "clear M_ options_ oo_ estim_params_ bayestopt_ dataset_ dataset_info estimation_info;"
-        << endl;
+    mOutputFile << "clearvars -global M_ options_ oo_ estim_params_ bayestopt_ dataset_ "
+                   "dataset_info estimation_info;"
+                << endl;
 
   if (!notime)
     mOutputFile << "tic0 = tic;" << endl;
-- 
GitLab