initialize_dseries_toolbox.m 2.98 KB
Newer Older
1
2
function initialize_dseries_toolbox(installdependencies)

Stéphane Adjemian's avatar
Stéphane Adjemian committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
% Copyright (C) 2015-2017 Dynare Team
%
% 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.
%
% Dynare dseries submodule 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/>.

18
19
20
21
if ~nargin
    installdependencies = false;
end

22
% Check that the dates module is available.
23
24
25
try
    initialize_dates_toolbox;
catch
26
    if installdependencies
27
        urlwrite('https://git.dynare.org/Dynare/dates/-/archive/master/dates-master.zip','master.zip');
28
29
30
31
32
33
34
35
36
37
        warning('off','MATLAB:MKDIR:DirectoryExists')
        mkdir('../externals')
        warning('on','MATLAB:MKDIR:DirectoryExists')
        unzip('master.zip','../externals')
        delete('master.zip')
        addpath([pwd() '/../externals/dates-master/src'])
        initialize_dates_toolbox;
    else
        error('Missing dependency: dates module is not available.')
    end
38
39
40
41
42
end

% Get the path to the dseries toolbox.
dseries_src_root = strrep(which('initialize_dseries_toolbox'),'initialize_dseries_toolbox.m','');

43
44
45
46
47
48
49
50
51
52
% Set the subfolders to be added in the path.
p = {'/read'; ...
     '/utilities/is'; ...
     '/utilities/str'; ...
     '/utilities/x13'; ...
     '/utilities/insert'; ...
     '/utilities/file'; ...
     '/utilities/from'; ...
     '/utilities/print'; ...
     '/utilities/variables'; ...
53
54
     '/utilities/cumulate'; ...
     '/utilities/struct'};
55
56
57

% Add missing routines if dynare is not in the path
if ~exist('demean','file')
58
    p{end+1} = '/utilities/missing/demean';
59
60
61
end

if ~exist('ndim','file')
62
    p{end+1} = '/utilities/missing/ndim';
63
64
65
end

if ~exist('sample_hp_filter','file')
66
    p{end+1} = '/utilities/missing/sample_hp_filter';
Stéphane Adjemian's avatar
Stéphane Adjemian committed
67
68
end

Stéphane Adjemian's avatar
Stéphane Adjemian committed
69
if ~exist('get_file_extension','file')
70
    p{end+1} = '/utilities/missing/get_file_extension';
Stéphane Adjemian's avatar
Stéphane Adjemian committed
71
72
end

Stéphane Adjemian's avatar
Stéphane Adjemian committed
73
if isoctave && ~exist('user_has_octave_forge_package','file')
74
    p{end+1} = '/utilities/missing/user_has_octave_forge_package';
75
end
76
77

if ~exist('get_cells_id','file')
78
    p{end+1} = '/utilities/missing/get_cells_id';
79
80
end

81
if ~exist('randomstring','file')
82
    p{end+1} = '/utilities/missing/randomstring';
83
84
end

85
86
87
88
if ~exist('one_sided_hp_filter','file')
    p{end+1} = '/utilities/missing/one_sided_hp_filter';
end

89
90
% Install X13 binaries
opath = pwd();
91
92
93
94
95
96
97
try
    cd([dseries_src_root '/../externals/x13'])
    installx13();
catch
    warning('X13 is not available!')
    p(strmatch('/utilities/x13', p, 'exact')) = [];
end
98
99
100
101
cd(opath);

% Set path
P = cellfun(@(c)[dseries_src_root(1:end-1) c], p, 'uni', false);
102
103
104
addpath(P{:});

assignin('caller', 'dseries_src_root', dseries_src_root);