From 1d5a442fe5b12d0f114b0ad5671ed7646c16f901 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 22 Nov 2023 17:17:34 +0100
Subject: [PATCH] Bump minimal required version of Octave to 7.1.0

Incidentally, this means that the JSONlab submodule is no longer needed, so it
is removed in the present commit.

Closes: #1907
---
 .gitmodules                                          | 3 ---
 contrib/jsonlab                                      | 1 -
 doc/manual/source/installation-and-configuration.rst | 2 +-
 macOS/build.sh                                       | 1 -
 matlab/+estimate/nls.m                               | 8 +-------
 matlab/+pac/+estimate/nls.m                          | 8 +-------
 matlab/dynare.m                                      | 4 ++--
 matlab/dynare_estimation_1.m                         | 5 -----
 matlab/loadjson_.m                                   | 7 +------
 matlab/missing/mex/mjdgges/mjdgges.m                 | 4 ----
 matlab/modules/dseries                               | 2 +-
 matlab/ols/pooled_ols.m                              | 6 +-----
 matlab/ols/sur.m                                     | 6 +-----
 meson.build                                          | 2 +-
 tests/run_all_unit_tests.m                           | 8 +-------
 windows/build.sh                                     | 2 --
 16 files changed, 11 insertions(+), 58 deletions(-)
 delete mode 160000 contrib/jsonlab

diff --git a/.gitmodules b/.gitmodules
index c1b148f57a..1bb00333ba 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -14,9 +14,6 @@
 	path = matlab/modules/dseries
 	url = ../../Dynare/dseries.git
 	branch = master
-[submodule "contrib/jsonlab"]
-	path = contrib/jsonlab
-	url = https://github.com/fangq/jsonlab.git
 [submodule "preprocessor"]
 	path = preprocessor
 	url = ../../Dynare/preprocessor.git
diff --git a/contrib/jsonlab b/contrib/jsonlab
deleted file mode 160000
index 5a58fafdca..0000000000
--- a/contrib/jsonlab
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 5a58fafdca239e61be4d7b2270307b2445bb571a
diff --git a/doc/manual/source/installation-and-configuration.rst b/doc/manual/source/installation-and-configuration.rst
index 7c0bcf5f6c..08315de1eb 100644
--- a/doc/manual/source/installation-and-configuration.rst
+++ b/doc/manual/source/installation-and-configuration.rst
@@ -15,7 +15,7 @@ compilation steps are necessary in that case.
 In order to run Dynare, you need one of the following:
 
 * MATLAB, any version ranging from 9.5 (R2018b) to 23.2 (R2023b);
-* GNU Octave, any version ranging from 6.2.0 to 8.4.0, with the statistics package
+* GNU Octave, any version ranging from 7.1.0 to 8.4.0, with the statistics package
   from `Octave-Forge`_. Note however that the Dynare installer for Windows
   requires a more specific version of Octave, as indicated on the download
   page.
diff --git a/macOS/build.sh b/macOS/build.sh
index e94d70d2f7..18c6fbc9e6 100755
--- a/macOS/build.sh
+++ b/macOS/build.sh
@@ -145,7 +145,6 @@ fi
 
 cp -p  "$ROOTDIR"/scripts/dynare.el                                  "$PKGFILES"/scripts
 cp -pr "$ROOTDIR"/contrib/ms-sbvar/TZcode/MatlabFiles                "$PKGFILES"/contrib/ms-sbvar/TZcode
-cp -pr "$ROOTDIR"/contrib/jsonlab                                    "$PKGFILES"/contrib
 
 cp     "$ROOTDIR"/build-doc/*.pdf                                    "$PKGFILES"/doc
 cp     "$ROOTDIR"/build-doc/preprocessor/doc/*.pdf                   "$PKGFILES"/doc
diff --git a/matlab/+estimate/nls.m b/matlab/+estimate/nls.m
index 46c18c848f..a7673004ae 100644
--- a/matlab/+estimate/nls.m
+++ b/matlab/+estimate/nls.m
@@ -28,7 +28,7 @@ function nls(eqname, params, data, range, optimizer, varargin)
 %     equation must have NaN values in the object.
 % [4] It is assumed that the residual is additive.
 
-% Copyright © 2021-2022 Dynare Team
+% Copyright © 2021-2023 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -179,12 +179,6 @@ write_residuals_routine(lhs, rhs, eqname, ipnames_, M_);
 % Create a routine for evaluating the sum of squared residuals of the nonlinear model
 write_ssr_routine(lhs, rhs, eqname, ipnames_, M_);
 
-% Workaround for Octave bug https://savannah.gnu.org/bugs/?46282
-% Octave will randomly fail to read the ssr_* file generated in the +folder
-if isoctave && octave_ver_less_than('7')
-    path(path)
-end
-
 % Create a function handle returning the sum of square residuals for a given vector of parameters.
 ssrfun = @(p) feval([M_.fname '.ssr_' eqname], p, DATA, M_, oo_);
 
diff --git a/matlab/+pac/+estimate/nls.m b/matlab/+pac/+estimate/nls.m
index 5f0d89b3c8..5fa8a626ec 100644
--- a/matlab/+pac/+estimate/nls.m
+++ b/matlab/+pac/+estimate/nls.m
@@ -42,7 +42,7 @@ function nls(eqname, params, data, range, optimizer, varargin)
 % is available only if the matylab optimization toolbox is installed), the
 % remaining inputs are the options (key/value) passed to the optimizers.
 
-% Copyright © 2018-2022 Dynare Team
+% Copyright © 2018-2023 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -96,12 +96,6 @@ write_residuals_routine(lhs, rhs, eqname, ipnames_, M_, pacmodl);
 % Create a routine for evaluating the sum of squared residuals of the nonlinear model
 write_ssr_routine(lhs, rhs, eqname, ipnames_, M_, pacmodl);
 
-% Workaround for Octave bug https://savannah.gnu.org/bugs/?46282
-% Octave will randomly fail to read the ssr_* file generated in the +folder
-if isoctave && octave_ver_less_than('7')
-    path(path)
-end
-
 % Copy (sub)sample data in a matrix.
 DATA = data([range(1)-1, range]).data;
 
diff --git a/matlab/dynare.m b/matlab/dynare.m
index 68db17156b..84ff83a087 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -81,9 +81,9 @@ if isoctave
                  'of precompiled mex files and some\nfeatures, like solution ' ...
                  'of models approximated at third order, will not be available.'], supported_octave_version())
         skipline()
-    elseif octave_ver_less_than('6.2.0') % Should match the test in meson.build, and also the one in matlab/modules/dseries/src/initialize_dseries_class.m
+    elseif octave_ver_less_than('7.1.0') % Should match the test in meson.build, and also the one in matlab/modules/dseries/src/initialize_dseries_class.m
         skipline()
-        warning(['This version of Dynare has only been tested on Octave 6.2.0 and above. Dynare may fail to run or give unexpected result. Consider upgrading your version of Octave.'])
+        warning(['This version of Dynare has only been tested on Octave 7.1.0 and above. Dynare may fail to run or give unexpected result. Consider upgrading your version of Octave.'])
         skipline()
     end
 else
diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m
index 368ddb7cf7..f1d41fed09 100644
--- a/matlab/dynare_estimation_1.m
+++ b/matlab/dynare_estimation_1.m
@@ -34,11 +34,6 @@ global M_ options_ oo_ estim_params_ bayestopt_ dataset_ dataset_info
 dispString = 'Estimation::mcmc';
 
 if ~exist([M_.dname filesep 'Output'],'dir')
-    if isoctave && octave_ver_less_than('7') && ~exist(M_.dname)
-        % See https://savannah.gnu.org/bugs/index.php?61166
-        % This workaround is needed for recursive estimation.
-        mkdir(M_.dname)
-    end
     mkdir(M_.dname,'Output');
 end
 
diff --git a/matlab/loadjson_.m b/matlab/loadjson_.m
index 70c61b2868..6cbf10806e 100644
--- a/matlab/loadjson_.m
+++ b/matlab/loadjson_.m
@@ -1,6 +1,6 @@
 function o = loadjson_(jsonfilename)
 
-% Reads a json file using jsonlab toolbox or jsondecode builtin if available.
+% Reads a json file using jsondecode builtin.
 %
 % INPUTS
 % - jsonfilename   [char]      1×n char array, name of the JSON file.
@@ -28,11 +28,6 @@ function o = loadjson_(jsonfilename)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
-if isoctave && octave_ver_less_than('7')
-    o = loadjson(jsonfilename);
-    return
-end
-
 json = fileread(jsonfilename);
 
 o = jsondecode(json); clear('json');
diff --git a/matlab/missing/mex/mjdgges/mjdgges.m b/matlab/missing/mex/mjdgges/mjdgges.m
index b28214e923..4b1ef0648c 100644
--- a/matlab/missing/mex/mjdgges/mjdgges.m
+++ b/matlab/missing/mex/mjdgges/mjdgges.m
@@ -39,10 +39,6 @@ if nargin > 5 || nargin < 2 || nargout > 7 || nargout == 0
     error('MJDGGES: takes 2, 3 or 4 input arguments and between 1 and 7 output arguments.')
 end
 
-if isoctave && octave_ver_less_than('7')
-    error('Octave version 7 or higher is required (Octave 6 lacks the ordqz function)')
-end
-
 [me, ne] = size(e);
 [md, nd] = size(d);
 if ~isreal(e) || ~isreal(d) || me ~= ne || md ~= nd || me ~= nd
diff --git a/matlab/modules/dseries b/matlab/modules/dseries
index 99b6f167e7..80446e7cdc 160000
--- a/matlab/modules/dseries
+++ b/matlab/modules/dseries
@@ -1 +1 @@
-Subproject commit 99b6f167e71945a45249dbc6b5100d2ca6b1474f
+Subproject commit 80446e7cdcf392167e91b428b61d77e028e47674
diff --git a/matlab/ols/pooled_ols.m b/matlab/ols/pooled_ols.m
index 15569b1249..41b714e588 100644
--- a/matlab/ols/pooled_ols.m
+++ b/matlab/ols/pooled_ols.m
@@ -27,7 +27,7 @@ function varargout = pooled_ols(ds, param_common, param_regex, overlapping_dates
 % SPECIAL REQUIREMENTS
 %   dynare must have been run with the option: json=compute
 
-% Copyright © 2017-2019 Dynare Team
+% Copyright © 2017-2023 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -76,10 +76,6 @@ else
 end
 
 st = dbstack(1);
-if isoctave && octave_ver_less_than('6.3.0')
-    % Workaround for https://savannah.gnu.org/bugs/?60531, fixed in 6.3.0
-    st = st(2:end);
-end
 if ~isempty(st) && strcmp(st(1).name, 'pooled_fgls')
     save_structure_name = 'pooled_fgls';
 else
diff --git a/matlab/ols/sur.m b/matlab/ols/sur.m
index c1dfb17305..208969f92e 100644
--- a/matlab/ols/sur.m
+++ b/matlab/ols/sur.m
@@ -18,7 +18,7 @@ function varargout = sur(ds, param_names, eqtags, model_name, noniterative, ds_r
 % SPECIAL REQUIREMENTS
 %   dynare must have been run with the option: json=compute
 
-% Copyright © 2017-2021 Dynare Team
+% Copyright © 2017-2023 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -121,10 +121,6 @@ end
 %
 
 st = dbstack(1);
-if isoctave && octave_ver_less_than('6.3.0')
-    % Workaround for https://savannah.gnu.org/bugs/?60531, fixed in 6.3.0
-    st = st(2:end);
-end
 if ~isempty(st) && strcmp(st(1).name, 'surgibbs')
     varargout{1} = nobs;
     varargout{2} = X{param_names{:}}.data;
diff --git a/meson.build b/meson.build
index 3a6ac503db..ff248b79fb 100644
--- a/meson.build
+++ b/meson.build
@@ -163,7 +163,7 @@ if get_option('build_for') == 'matlab'
 else # Octave build
   octave_exe = find_program('octave', required : not meson.is_cross_build(), disabler : true)
   mkoctfile_exe = find_program('mkoctfile')
-  octave_minimal_version = '6.2.0'
+  octave_minimal_version = '7.1.0'
   octave_version = run_command(mkoctfile_exe, '-v', check : true).stdout().replace('mkoctfile, version ', '').strip()
 
   if octave_version.version_compare('<' + octave_minimal_version)
diff --git a/tests/run_all_unit_tests.m b/tests/run_all_unit_tests.m
index d346a1ba00..0bdffdb295 100644
--- a/tests/run_all_unit_tests.m
+++ b/tests/run_all_unit_tests.m
@@ -36,13 +36,7 @@ if isoctave
     mlist = mlist(find(~strcmp([matlab_dir filesep 'load_m_file_data_legacy.m'], mlist)));
 end
 
-% Set random seed, for reproducibility
-if isoctave && octave_ver_less_than('7')
-    randn('state',1);
-    rand('state',1);
-else
-    rng(1);
-end
+rng(1);
 
 failedtests = {};
 
diff --git a/windows/build.sh b/windows/build.sh
index b6909e4cfe..9c1c854de1 100755
--- a/windows/build.sh
+++ b/windows/build.sh
@@ -119,8 +119,6 @@ cp -p windows/README.txt "$ZIPDIR"
 cp -pr windows/deps/mingw64 "$ZIPDIR"
 mkdir -p "$ZIPDIR"/contrib/ms-sbvar/TZcode
 cp -pr contrib/ms-sbvar/TZcode/MatlabFiles "$ZIPDIR"/contrib/ms-sbvar/TZcode
-mkdir -p "$ZIPDIR"/contrib/jsonlab
-cp -pr contrib/jsonlab/* "$ZIPDIR"/contrib/jsonlab
 mkdir -p "$ZIPDIR"/mex/matlab/win64-9.5-23.2
 cp -p build-win-matlab/*.mexw64 "$ZIPDIR"/mex/matlab/win64-9.5-23.2
 mkdir -p "$ZIPDIR"/mex/octave/win64
-- 
GitLab