2019-09-03 11:19:46 +02:00
function dynareroot = dynare_config ( path_to_dynare)
%function dynareroot = dynare_config(path_to_dynare)
%
2008-05-16 10:18:37 +02:00
% This function tests the existence of valid mex files (for qz
% decomposition, solution to sylvester equation and kronecker
% products...) and, if needed, add paths to the matlab versions
% of these routines.
2008-08-04 15:33:57 +02:00
% Also adds other directories to the path.
2008-05-16 10:18:37 +02:00
%
% INPUTS
% none
2011-08-11 15:10:57 +02:00
%
2008-05-16 10:18:37 +02:00
% OUTPUTS
% none
2011-08-11 15:10:57 +02:00
%
2008-05-16 10:18:37 +02:00
% SPECIAL REQUIREMENTS
% none
2008-08-01 14:40:33 +02:00
2020-01-16 10:40:15 +01:00
% Copyright (C) 2001-2020 Dynare Team
2008-08-01 14:40:33 +02:00
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
2011-07-26 11:07:27 +02:00
if nargin && ~ isempty ( path_to_dynare )
2008-05-16 10:18:37 +02:00
addpath ( path_to_dynare ) ;
end
2015-03-30 14:54:14 +02:00
2009-07-03 12:36:11 +02:00
dynareroot = strrep ( which ( ' dynare' ) , ' dynare.m' , ' ' ) ;
2008-06-24 20:20:48 +02:00
2011-12-21 18:31:29 +01:00
origin = pwd ( ) ;
cd ( [ dynareroot ' /..' ] )
2016-06-16 23:55:07 +02:00
p = { ' /distributions/' ; ...
' /kalman/' ; ...
' /kalman/likelihood' ; ...
' /AIM/' ; ...
' /partial_information/' ; ...
' /perfect-foresight-models/' ; ...
' /ms-sbvar/' ; ...
' /ms-sbvar/identification/' ; ...
' /../contrib/ms-sbvar/TZcode/MatlabFiles/' ; ...
2017-06-22 16:34:52 +02:00
' /../contrib/jsonlab/' ; ...
2016-06-16 23:55:07 +02:00
' /parallel/' ; ...
' /particles/src' ; ...
' /gsa/' ; ...
' /ep/' ; ...
2017-05-18 10:46:08 +02:00
' /backward/' ; ...
2019-12-20 16:28:06 +01:00
' /convergence_diagnostics/' ; ...
2016-06-16 23:55:07 +02:00
' /cli/' ; ...
' /lmmcp/' ; ...
' /optimization/' ; ...
2020-02-12 13:13:31 +01:00
' /discretionary_policy/' ; ...
2019-12-19 17:20:38 +01:00
' /accessors/' ; ...
2016-06-16 23:55:07 +02:00
' /modules/dseries/src/' ; ...
' /utilities/doc/' ; ...
' /utilities/tests/src/' ; ...
' /utilities/dataset/' ; ...
' /utilities/general/' ; ...
2017-01-06 11:09:04 +01:00
' /utilities/graphics/' ; ...
2016-06-16 23:55:07 +02:00
' /modules/reporting/src/' ; ...
' /modules/reporting/macros/' } ;
2008-10-13 20:54:42 +02:00
2009-07-03 12:20:42 +02:00
% For functions that exist only under some Octave versions
% or some MATLAB versions, and for which we provide some replacement functions
2018-06-05 19:46:09 +02:00
% Replacements for rows(), columns(), vec() and issquare() (inexistent under MATLAB)
2013-11-04 10:54:45 +01:00
if ~ isoctave
2016-06-16 23:55:07 +02:00
p { end + 1 } = ' /missing/rows_columns' ;
p { end + 1 } = ' /missing/issquare' ;
p { end + 1 } = ' /missing/vec' ;
2008-07-28 11:46:07 +02:00
end
2019-02-25 14:56:53 +01:00
% ordeig() doesn't exist in Octave < 5
if isoctave && octave_ver_less_than ( ' 5' )
2016-06-16 23:55:07 +02:00
p { end + 1 } = ' /missing/ordeig' ;
2009-07-03 12:20:42 +02:00
end
2019-03-26 18:33:15 +01:00
%% intersect(…, 'stable') doesn't exist in Octave and in MATLAB < R2013a
if isoctave || matlab_ver_less_than ( ' 8.1' )
2019-02-15 16:31:24 +01:00
p { end + 1 } = ' /missing/intersect_stable' ;
end
2018-06-05 19:46:09 +02:00
% Replacements for functions of the MATLAB statistics toolbox
2019-02-18 17:33:52 +01:00
if isoctave
2020-01-06 14:32:22 +01:00
% Under Octave, these functions are in the statistics Forge package.
% Our replacement functions don't work under Octave (because of gamrnd, see
% #1638), hence the statistics toolbox is now a hard requirement
if ~ user_has_octave_forge_package ( ' statistics' )
2019-02-18 17:33:52 +01:00
error ( ' You must install the "statistics" package from Octave Forge, either with your distribution package manager or with "pkg install -forge statistics"' )
end
else
if ~ user_has_matlab_license ( ' statistics_toolbox' )
p { end + 1 } = ' /missing/stats/' ;
2018-06-06 13:02:42 +02:00
end
2018-06-05 19:46:09 +02:00
end
2017-03-22 15:20:13 +01:00
% Check if struct2array is available.
if ~ exist ( ' struct2array' )
p { end + 1 } = ' /missing/struct2array' ;
end
2019-02-25 14:56:53 +01:00
% isfile is missing in Octave < 5 and Matlab < R2017b
if ( isoctave && octave_ver_less_than ( ' 5' ) ) || ( ~ isoctave && matlab_ver_less_than ( ' 9.3' ) )
2017-10-10 13:33:32 +02:00
p { end + 1 } = ' /missing/isfile' ;
end
2019-05-20 12:45:54 +02:00
% strsplit and strjoin are missing in MATLAB < R2013a
2018-03-12 21:24:38 +01:00
if ~ isoctave && matlab_ver_less_than ( ' 8.1' )
p { end + 1 } = ' /missing/strsplit' ;
2019-05-20 12:45:54 +02:00
p { end + 1 } = ' /missing/strjoin' ;
2018-03-12 21:24:38 +01:00
end
2019-11-13 11:43:27 +01:00
% contains and splitlines don't exist in Octave and in MATLAB < R2016b
if isoctave || matlab_ver_less_than ( ' 9.1' )
p { end + 1 } = ' /missing/contains' ;
p { end + 1 } = ' /missing/splitlines' ;
end
2018-11-13 16:59:27 +01:00
% isrow, iscolumn and ismatrix are missing in Matlab<R2010b
2018-05-30 17:42:55 +02:00
if ~ isoctave && matlab_ver_less_than ( ' 7.11' )
2018-11-13 16:59:27 +01:00
p { end + 1 } = ' /missing/is-row-column-matrix' ;
2018-05-30 17:42:55 +02:00
end
2019-03-26 16:49:39 +01:00
%% isdiag is missing in MATLAB < R2014a
2020-01-16 10:40:15 +01:00
if ~ isoctave && matlab_ver_less_than ( ' 8.3' )
2019-03-26 16:49:39 +01:00
p { end + 1 } = ' /missing/isdiag' ;
end
2019-03-26 18:19:40 +01:00
%% narginchk is missing in MATLAB < R2011b
if ~ isoctave && matlab_ver_less_than ( ' 7.13' )
p { end + 1 } = ' /missing/narginchk' ;
end
2016-06-17 21:59:29 +02:00
P = cellfun ( @ ( c ) [ dynareroot ( 1 : end - 1 ) c ] , p , ' uni' , false ) ;
2016-06-16 23:55:07 +02:00
2016-06-17 21:59:29 +02:00
% Get mex files folder(s)
mexpaths = add_path_to_mex_files ( dynareroot , false ) ;
2016-06-16 23:55:07 +02:00
2016-06-17 21:59:29 +02:00
% Add mex files folder(s)
P ( end + 1 : end + length ( mexpaths ) ) = mexpaths ;
% Set matlab's path
2016-06-16 23:55:07 +02:00
addpath ( P { : } ) ;
2009-03-11 15:57:34 +01:00
2015-06-24 19:02:42 +02:00
% Initialization of the dates and dseries classes (recursive).
2019-02-10 00:02:05 +01:00
initialize_dseries_class ( ) ;
2014-05-14 12:36:06 +02:00
2018-03-12 21:24:38 +01:00
cd ( origin ) ;