From ddaaf9e1e30b93f2910d431a4ad639a666009a18 Mon Sep 17 00:00:00 2001 From: sebastien Date: Mon, 7 Jul 2008 17:08:55 +0000 Subject: [PATCH] v4 matlab: * added a function matlab_ver_less_than() for testing Matlab version * updated dynare_config.m and build_matlab.m accordingly * removed tests to check whether we are older than Matlab 6.5 (R13), since we don't support those old versions anymore * removed a few unnecessary uses of eval() git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1936 ac1d8469-bf42-47a9-8791-bf33cf982152 --- matlab/UnivariateSpectralDensity.m | 8 ++----- matlab/dynare_config.m | 9 +------- matlab/dynare_solve.m | 2 +- matlab/matlab_ver_less_than.m | 35 ++++++++++++++++++++++++++++++ matlab/set_default_option.m | 6 +---- matlab/th_autocovariances.m | 8 ++----- mex/sources/build_matlab.m | 21 ++++++------------ 7 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 matlab/matlab_ver_less_than.m diff --git a/matlab/UnivariateSpectralDensity.m b/matlab/UnivariateSpectralDensity.m index 0d6f7edc1..6986fd86f 100644 --- a/matlab/UnivariateSpectralDensity.m +++ b/matlab/UnivariateSpectralDensity.m @@ -25,10 +25,8 @@ GridSize = length(omega); exo_names_orig_ord = M_.exo_names_orig_ord; if exist('OCTAVE_VERSION') warning('off', 'Octave:divide-by-zero') -elseif sscanf(version('-release'),'%d') < 13 - warning off else - eval('warning off MATLAB:dividebyzero') + warning off MATLAB:dividebyzero end if nargin<2 var_list = []; @@ -150,10 +148,8 @@ end if exist('OCTAVE_VERSION') warning('on', 'Octave:divide-by-zero') -elseif sscanf(version('-release'),'%d') < 13 - warning_config else - eval('warning on MATLAB:dividebyzero') + warning on MATLAB:dividebyzero end if pltinfo diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m index c1f2ff84b..9692b9159 100644 --- a/matlab/dynare_config.m +++ b/matlab/dynare_config.m @@ -24,14 +24,7 @@ dynareroot = strrep(which('dynare.m'),'dynare.m',''); if exist('OCTAVE_VERSION') addpath([dynareroot '../mex/octave/']) else - MATLAB = ver('matlab'); - %% FIXME: - %% It's not satisfactory to convert string versions into numbers, and to - %% compare these numbers: - %% - conversion will fail if version = 1.2.3 - %% - it will give 7.10 < 7.9 - VERSION = str2num(MATLAB.Version); - if (VERSION <= 7.4) + if matlab_ver_less_than('7.5') addpath([dynareroot '../mex/2007a/']) else addpath([dynareroot '../mex/2007b/']) diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m index 9acb10dfd..23382c6b2 100644 --- a/matlab/dynare_solve.m +++ b/matlab/dynare_solve.m @@ -26,7 +26,7 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin) options_ = set_default_option(options_,'solve_algo',2); info = 0; if options_.solve_algo == 0 - if ~isempty(which('fsolve')) & sscanf(version('-release'),'%d') >= 13; + if ~isempty(which('fsolve')) options=optimset('fsolve'); options.MaxFunEvals = 50000; options.MaxIter = 2000; diff --git a/matlab/matlab_ver_less_than.m b/matlab/matlab_ver_less_than.m new file mode 100644 index 000000000..4b83843f8 --- /dev/null +++ b/matlab/matlab_ver_less_than.m @@ -0,0 +1,35 @@ +function r = matlab_ver_less_than(verstr) +% function r = matlab_ver_less_than(verstr) +% +% Returns 1 if current Matlab version is strictly older than +% the one given in argument. +% +% It basically does the same job than verLessThan(), which is +% only available since Matlab 7.4. +% +% Note that this function will fail under Octave. +% +% INPUTS +% verstr: a string of the format 'x.y' or 'x.y.z' +% +% OUTPUTS +% r: 0 or 1 +% +% SPECIAL REQUIREMENTS +% none +% +% part of DYNARE, copyright Dynare Team (2008) +% Gnu Public License. + + ver_struct = ver('matlab'); + cur_verstr = ver_struct.Version; + + r = get_ver_numeric(cur_verstr) < get_ver_numeric(verstr); + + +function x = get_ver_numeric(verstr) + nums = sscanf(verstr, '%d.%d.%d')'; + if length(nums) < 3 + nums(3) = 0; + end + x = nums * [1; 0.01; 0.0001 ]; diff --git a/matlab/set_default_option.m b/matlab/set_default_option.m index 55fcbec22..c7e355eb3 100644 --- a/matlab/set_default_option.m +++ b/matlab/set_default_option.m @@ -18,11 +18,7 @@ function options=set_default_option(options,field,default) % Gnu Public License. if ~isfield(options,field) - if ~exist('OCTAVE_VERSION') && sscanf(version('-release'),'%d') < 13 - options = setfield(options,field,default); - else - eval('options.(field) = default;'); - end + options.(field) = default; end % 06/07/03 MJ added ; to eval expression \ No newline at end of file diff --git a/matlab/th_autocovariances.m b/matlab/th_autocovariances.m index 013fff054..86a9c5d7e 100644 --- a/matlab/th_autocovariances.m +++ b/matlab/th_autocovariances.m @@ -22,10 +22,8 @@ function [Gamma_y,ivar]=th_autocovariances(dr,ivar,M_,options_) exo_names_orig_ord = M_.exo_names_orig_ord; if exist('OCTAVE_VERSION') warning('off', 'Octave:divide-by-zero') - elseif sscanf(version('-release'),'%d') < 13 - warning off else - eval('warning off MATLAB:dividebyzero') + warning off MATLAB:dividebyzero end nar = options_.ar; Gamma_y = cell(nar+1,1); @@ -202,9 +200,7 @@ function [Gamma_y,ivar]=th_autocovariances(dr,ivar,M_,options_) end if exist('OCTAVE_VERSION') warning('on', 'Octave:divide-by-zero') - elseif sscanf(version('-release'),'%d') < 13 - warning_config else - eval('warning on MATLAB:dividebyzero') + warning on MATLAB:dividebyzero end \ No newline at end of file diff --git a/mex/sources/build_matlab.m b/mex/sources/build_matlab.m index f214cc2f3..d127e8e96 100644 --- a/mex/sources/build_matlab.m +++ b/mex/sources/build_matlab.m @@ -2,14 +2,7 @@ % Copyright Dynare Team (2007-2008) % GNU Public License -% Get Matlab version number in numeric format -% FIXME: -% It's not satisfactory to convert string versions into numbers, and to -% compare these numbers: -% - conversion will fail if version = 1.2.3 -% - it will give 7.10 < 7.9 -MATLAB = ver('matlab'); -VERSION = str2num(MATLAB.Version); +addpath '../../matlab'; % For matlab_ver_less_than MATLAB_PATH = matlabroot; @@ -19,7 +12,7 @@ if strcmpi('GLNX86', computer) || strcmpi('GLNXA64', computer) ... || strcmpi('MACI', computer) || strcmpi('MAC', computer) % GNU/Linux (x86-32 or x86-64) or MacOS (Intel or PPC) LAPACK_PATH = '-lmwlapack'; - if VERSION <= 7.4 + if matlab_ver_less_than('7.5') BLAS_PATH = LAPACK_PATH; % On <= 7.4, BLAS in included in LAPACK else BLAS_PATH = '-lmwblas'; @@ -28,7 +21,7 @@ elseif strcmpi('PCWIN', computer) % Windows (x86-32) with Microsoft or gcc compiler LIBRARY_PATH = [MATLAB_PATH '/extern/lib/win32/microsoft/']; LAPACK_PATH = ['"' LIBRARY_PATH 'libmwlapack.lib"']; - if VERSION <= 7.4 + if matlab_ver_less_than('7.5') BLAS_PATH = LAPACK_PATH; % On <= 7.4, BLAS in included in LAPACK else BLAS_PATH = ['"' LIBRARY_PATH 'libmwblas.lib"']; @@ -38,21 +31,21 @@ else end % mwSize and mwIndex appeared in Matlab 7.3 -if VERSION < 7.3 +if matlab_ver_less_than('7.3') COMPILE_OPTIONS = [ COMPILE_OPTIONS ' -DMWTYPES_NOT_DEFINED' ]; end % Large array dims for 64 bits platforms appeared in Matlab 7.3 -if strcmpi('GLNXA64', computer) && VERSION >= 7.3 +if strcmpi('GLNXA64', computer) && ~matlab_ver_less_than('7.3') COMPILE_OPTIONS = [ COMPILE_OPTIONS ' -largeArrayDims' ]; end % blas.h and lapack.h appeared in Matlab 7.5 -if VERSION < 7.5 +if matlab_ver_less_than('7.5') COMPILE_OPTIONS = [ COMPILE_OPTIONS ' -DNO_BLAS_H -DNO_LAPACK_H' ]; end -if VERSION <= 7.4 +if matlab_ver_less_than('7.5') OUTPUT_DIR = '../2007a'; else OUTPUT_DIR = '../2007b';