select_x13_binary.m 2.61 KB
Newer Older
1
function x13_binary = select_x13_binary(warn_only)
Stéphane Adjemian's avatar
Stéphane Adjemian committed
2

3 4 5 6 7
% Returns the path to the X13 binary. If no X13 binary can be found, raises an
% error (unless warn_only=true, in which case it returns an empty string and
% displays a warning).

% Copyright (C) 2017-2019 Dynare Team
8 9 10 11 12 13
%
% This code 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.
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
14
% Dynare dseries submodule is distributed in the hope that it will be useful,
15 16 17 18 19 20 21
% 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/>.

22 23 24 25
if nargin < 1
    warn_only = false;
end

26
dseries_src_root = strrep(which('initialize_dseries_class'),'initialize_dseries_class.m','');
27 28
dseries_x13_root = sprintf('%s%s%s%s%s%s%s', dseries_src_root, '..', filesep(), 'externals', filesep(), 'x13', filesep());

29 30 31
if ismac()
    x13_binary = sprintf('%s%s%s', dseries_x13_root, 'osx', filesep());
    if is64bit()
32
        x13_binary = sprintf('%s%s%s%s', x13_binary, '64', filesep(), 'x13as');
33
    else
34
        x13_binary = sprintf('%s%s%s%s', x13_binary, '32', filesep(), 'x13as');
35 36
    end
elseif isunix()
37 38 39
    x13_binary = sprintf('%s%s%s', dseries_x13_root, 'linux', filesep());
    if is64bit()
        x13_binary = sprintf('%s%s%s%s', x13_binary, '64', filesep(), 'x13as');
40
    else
41 42 43 44 45 46
        x13_binary = sprintf('%s%s%s%s', x13_binary, '32', filesep(), 'x13as');
    end
    if ~exist(x13_binary, 'file')
        [status, x13_binary] = system('which x13as');
        if ~status
            x13_binary = deblank(x13_binary);
47
        end
48 49 50 51
    end
elseif ispc()
    x13_binary = sprintf('%s%s%s', dseries_x13_root, 'windows', filesep());
    if is64bit()
52
        x13_binary = sprintf('%s%s%s%s', x13_binary, '64', filesep(), 'x13as.exe');
53
    else
54
        x13_binary = sprintf('%s%s%s%s', x13_binary, '32', filesep(), 'x13as.exe');
Stéphane Adjemian's avatar
Stéphane Adjemian committed
55
    end
56
else
57 58 59 60 61 62 63 64 65 66 67
    error('Unsupported platform')
end

if ~exist(x13_binary, 'file')
    if warn_only
        warning('X13 binary is not available.\nIf you are under Debian or Ubuntu, you can install it through your package manager, with ''apt install x13as''.\nIf you are under Windows or macOS, this probably means that you did not install the dseries toolbox through an official package.\n');
        x13_binary = '';
    else
        error('Can''t find X13 binary');
    end
end