Home > matlab > dynare_config.m

dynare_config

PURPOSE ^

function dynareroot = dynare_config(path_to_dynare)

SYNOPSIS ^

function dynareroot = dynare_config(path_to_dynare,verbose)

DESCRIPTION ^

function dynareroot = dynare_config(path_to_dynare)
 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.
 Also adds other directories to the path.

 INPUTS
   none

 OUTPUTS
   none

 SPECIAL REQUIREMENTS
   none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dynareroot = dynare_config(path_to_dynare,verbose)
0002 %function dynareroot = dynare_config(path_to_dynare)
0003 % This function tests the existence of valid mex files (for qz
0004 % decomposition, solution to sylvester equation and kronecker
0005 % products...) and, if needed, add paths to the matlab versions
0006 % of these routines.
0007 % Also adds other directories to the path.
0008 %
0009 % INPUTS
0010 %   none
0011 %
0012 % OUTPUTS
0013 %   none
0014 %
0015 % SPECIAL REQUIREMENTS
0016 %   none
0017 
0018 % Copyright (C) 2001-2012 Dynare Team
0019 %
0020 % This file is part of Dynare.
0021 %
0022 % Dynare is free software: you can redistribute it and/or modify
0023 % it under the terms of the GNU General Public License as published by
0024 % the Free Software Foundation, either version 3 of the License, or
0025 % (at your option) any later version.
0026 %
0027 % Dynare is distributed in the hope that it will be useful,
0028 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0029 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0030 % GNU General Public License for more details.
0031 %
0032 % You should have received a copy of the GNU General Public License
0033 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0034 
0035 if nargin && ~isempty(path_to_dynare)
0036     addpath(path_to_dynare);
0037 end
0038 dynareroot = strrep(which('dynare'),'dynare.m','');
0039 
0040 origin = pwd();
0041 cd([dynareroot '/..'])
0042 
0043 if ~nargin || nargin==1
0044     verbose = 1;
0045 end
0046 
0047 
0048 addpath([dynareroot '/distributions/'])
0049 addpath([dynareroot '/kalman/'])
0050 addpath([dynareroot '/kalman/likelihood'])
0051 addpath([dynareroot '/AIM/'])
0052 addpath([dynareroot '/partial_information/'])
0053 addpath([dynareroot '/ms-sbvar/'])
0054 addpath([dynareroot '/ms-sbvar/identification/'])
0055 addpath([dynareroot '../contrib/ms-sbvar/TZcode/MatlabFiles/'])
0056 addpath([dynareroot '/parallel/'])
0057 addpath([dynareroot '/particle/'])
0058 addpath([dynareroot '/gsa/'])
0059 addpath([dynareroot '/ep/'])
0060 addpath([dynareroot '/utilities/doc/'])
0061 addpath([dynareroot '/utilities/tests/'])
0062 addpath([dynareroot '/utilities/dataset/'])
0063 addpath([dynareroot '/utilities/general/'])
0064 
0065 % For functions that exist only under some Octave versions
0066 % or some MATLAB versions, and for which we provide some replacement functions
0067 
0068 if ~exist('OCTAVE_VERSION')
0069     % Replacements for rows() and columns() (inexistent under MATLAB)
0070     addpath([dynareroot '/missing/rows_columns'])
0071     % Replacement for vec() (inexistent under MATLAB)
0072     addpath([dynareroot '/missing/vec'])
0073     if ~user_has_matlab_license('statistics_toolbox')
0074         % Replacements for functions of the stats toolbox
0075         addpath([dynareroot '/missing/stats/'])
0076     end
0077 end
0078 
0079 % ordeig() was introducted in MATLAB 7.0.1, and doesn't exist in Octave
0080 if exist('OCTAVE_VERSION') || matlab_ver_less_than('7.0.1')
0081     addpath([dynareroot '/missing/ordeig'])
0082 end
0083 
0084 % bsxfun is missing in old versions of MATLAB (and exists in Octave)
0085 if ~exist('OCTAVE_VERSION') && matlab_ver_less_than('7.4')
0086     addpath([dynareroot '/missing/bsxfun'])
0087 end
0088 
0089 % nanmean is in Octave Forge Statistics package and in MATLAB Statistics
0090 % toolbox
0091 if (exist('OCTAVE_VERSION') && ~user_has_octave_forge_package('statistics')) ...
0092     || (~exist('OCTAVE_VERSION') && ~user_has_matlab_license('statistics_toolbox'))
0093     addpath([dynareroot '/missing/nanmean'])
0094 end
0095 
0096 % Add path to MEX files
0097 if exist('OCTAVE_VERSION')
0098     addpath([dynareroot '../mex/octave/']);
0099 else
0100     % Add win32 specific paths for Dynare Windows package
0101     if strcmp(computer, 'PCWIN')
0102         if matlab_ver_less_than('7.1')
0103             mexpath = [dynareroot '../mex/matlab/win32-7.0-7.0.4'];
0104             if exist(mexpath, 'dir')
0105                 addpath(mexpath)
0106             end
0107         elseif matlab_ver_less_than('7.5')
0108             mexpath = [dynareroot '../mex/matlab/win32-7.1-7.4'];
0109             if exist(mexpath, 'dir')
0110                 addpath(mexpath)
0111             end
0112         else
0113             mexpath = [dynareroot '../mex/matlab/win32-7.5-7.14'];
0114             if exist(mexpath, 'dir')
0115                 addpath(mexpath)
0116             end
0117         end
0118     end
0119 
0120     % Add win64 specific paths for Dynare Windows package
0121     if strcmp(computer, 'PCWIN64')
0122         if matlab_ver_less_than('7.3')
0123             mexpath = [dynareroot '../mex/matlab/win64-7.2'];
0124             if exist(mexpath, 'dir')
0125                 addpath(mexpath)
0126             end
0127         elseif matlab_ver_less_than('7.5')
0128             mexpath = [dynareroot '../mex/matlab/win64-7.3-7.4'];
0129             if exist(mexpath, 'dir')
0130                 addpath(mexpath)
0131             end
0132         elseif matlab_ver_less_than('7.8')
0133             mexpath = [dynareroot '../mex/matlab/win64-7.5-7.7'];
0134             if exist(mexpath, 'dir')
0135                 addpath(mexpath)
0136             end
0137         else
0138             mexpath = [dynareroot '../mex/matlab/win64-7.8-7.14'];
0139             if exist(mexpath, 'dir')
0140                 addpath(mexpath)
0141             end
0142         end
0143     end
0144 
0145     if strcmp(computer, 'MACI')
0146         if matlab_ver_less_than('7.5')
0147             mexpath = [dynareroot '../mex/matlab/osx32-7.4'];
0148             if exist(mexpath, 'dir')
0149                 addpath(mexpath)
0150             end
0151         else
0152             mexpath = [dynareroot '../mex/matlab/osx32-7.5-7.14'];
0153             if exist(mexpath, 'dir')
0154                 addpath(mexpath)
0155             end
0156         end
0157     end
0158 
0159     if strcmp(computer, 'MACI64')
0160         mexpath = [dynareroot '../mex/matlab/osx64'];
0161         if exist(mexpath, 'dir')
0162             addpath(mexpath)
0163         end
0164     end
0165 
0166     % Add generic MATLAB path (with higher priority than the previous ones)
0167     addpath([dynareroot '../mex/matlab/']);
0168 end
0169 
0170 %% Set mex routine names
0171 mex_status = cell(1,3);
0172 mex_status(1,1) = {'mjdgges'};
0173 mex_status(1,2) = {'qz'};
0174 mex_status(1,3) = {'Generalized QZ'};
0175 mex_status(2,1) = {'gensylv'};
0176 mex_status(2,2) = {'gensylv'};
0177 mex_status(2,3) = {'Sylvester equation solution'};
0178 mex_status(3,1) = {'A_times_B_kronecker_C'};
0179 mex_status(3,2) = {'kronecker'};
0180 mex_status(3,3) = {'Kronecker products'};
0181 mex_status(4,1) = {'sparse_hessian_times_B_kronecker_C'};
0182 mex_status(4,2) = {'kronecker'};
0183 mex_status(4,3) = {'Sparse kronecker products'};
0184 mex_status(5,1) = {'local_state_space_iteration_2'};
0185 mex_status(5,2) = {'particle/local_state_space_iteration'};
0186 mex_status(5,3) = {'Local state space iteraton (second order)'};
0187 number_of_mex_files = size(mex_status,1);
0188 %% Remove some directories from matlab's path. This is necessary if the user has
0189 %% added dynare_v4/matlab with the subfolders. Matlab has to ignore these
0190 %% subfolders if valid mex files exist.
0191 matlab_path = path;
0192 for i=1:number_of_mex_files
0193     test = strfind(matlab_path,[dynareroot mex_status{i,2}]);
0194     action = length(test);
0195     if action
0196         rmpath([dynareroot mex_status{i,2}]);
0197         matlab_path = path;
0198     end
0199 end
0200 %% Test if valid mex files are available, if a mex file is not available
0201 %% a matlab version of the routine is included in the path.
0202 if verbose
0203     disp(' ')
0204     disp('Configuring Dynare ...')
0205 end
0206 
0207 for i=1:number_of_mex_files
0208     test = (exist(mex_status{i,1},'file') == 3);
0209     if ~test
0210         addpath([dynareroot mex_status{i,2}]);
0211         message = '[m]   ';
0212     else
0213         message = '[mex] ';
0214     end
0215     if verbose
0216         disp([ message mex_status{i,3} '.' ])
0217     end
0218 end
0219 
0220 % Test if bytecode DLL is present
0221 if exist('bytecode', 'file') == 3
0222     message = '[mex] ';
0223 else
0224     message = '[no]  ';
0225 end
0226 if verbose
0227     disp([ message 'Bytecode evaluation.' ])
0228 end
0229 
0230 % Test if k-order perturbation DLL is present
0231 if exist('k_order_perturbation', 'file') == 3
0232     message = '[mex] ';
0233 else
0234     message = '[no]  ';
0235 end
0236 if verbose
0237     disp([ message 'k-order perturbation solver.' ])
0238 end
0239 
0240 % Test if dynare_simul_ DLL is present
0241 if exist('dynare_simul_', 'file') == 3
0242     message = '[mex] ';
0243 else
0244     message = '[no]  ';
0245 end
0246 if verbose
0247     disp([ message 'k-order solution simulation.' ])
0248 end
0249 
0250 % Test if qmc_sequence DLL is present
0251 if exist('qmc_sequence', 'file') == 3
0252     message = '[mex] ';
0253 else
0254     message = '[no]  ';
0255 end
0256 if verbose
0257     disp([ message 'Quasi Monte-Carlo sequence (Sobol).' ])
0258     disp(' ')
0259 end
0260 
0261 cd(origin);

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005