Select Git revision
check_matlab_path.m
Forked from
Dynare / dynare
Source project has a limited visibility.
check_matlab_path.m 5.67 KiB
function check_matlab_path(change_path_flag)
% Copyright © 2015-2023 Dynare Team
%
% 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 <https://www.gnu.org/licenses/>.
if ~nargin || isempty(change_path_flag)
change_path_flag = true;
end
% Get path to dynare/matlab folder.
DYNARE_PATH = strrep(which('dynare'),'dynare.m','');
if isempty(DYNARE_PATH)
% Nothing to do here (this case should not happen)
disp('dynare.m is not in the Matlab''s path.')
return
else
% Removes trailing slash.
DYNARE_PATH = DYNARE_PATH(1:end-1);
end
% Get matlab path
MATLAB_PATH = path();
if isoctave
% Octave always has '.' at the top of the path, so remove '.:'
MATLAB_PATH = MATLAB_PATH(3:end);
end
% Position of DYNARE_PATH in MATLAB_PATH
idDYNARE = strfind(MATLAB_PATH,DYNARE_PATH);
if isempty(idDYNARE)
disp('dynare.m is not in the Matlab''s path.')
return
else
if isequal(length(idDYNARE),1)
if isequal(idDYNARE, 1)
% Dynare is on top of matlab's path! Nothing to do here...
return
else
str0 = sprintf('Dynare is not on top of the Matlab/Octave path!');
% Check that this will not create a problem
MATLAB_PATH_ = path2cell(MATLAB_PATH);
DYNARE_ROUTINES = getallroutinenames(DYNARE_PATH, getalldirectories(DYNARE_PATH));
MATLAB_ROUTINES = {};
for i=1:position(idDYNARE, MATLAB_PATH)
TMP_MATLAB_ROUTINES = getallroutinenames(MATLAB_PATH_{i});
MATLAB_ROUTINES = { MATLAB_ROUTINES{:} TMP_MATLAB_ROUTINES{:} };
end
COMMON_ROUTINES = intersect(MATLAB_ROUTINES, DYNARE_ROUTINES);
if ~isempty(COMMON_ROUTINES)
warning off backtrace
skipline()
if length(COMMON_ROUTINES)==1
warning(sprintf('%s This can cause problems because the Dynare implementation of %s will be overriden.', str0, COMMON_ROUTINES{1}));
else