forked from cpp-lln-lab/localizer_visual_motion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initEnv.m
107 lines (79 loc) · 2.62 KB
/
initEnv.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
% (C) Copyright 2020 Agah Karakuzu
% (C) Copyright 2019 CPP visual motion localizer developpers
function initEnv
% 1 - Check if version requirements
% are satisfied and the packages are
% are installed/loaded:
% Octave > 4
% - image
% - optim
% - struct
% - statistics
%
% MATLAB >= R2015b
%
% 2 - Add project to the O/M path
octaveVersion = '4.0.3';
matlabVersion = '8.6.0';
installlist = {'io', 'statistics', 'image'};
if isOctave
% Exit if min version is not satisfied
if ~compare_versions(OCTAVE_VERSION, octaveVersion, '>=')
error('Minimum required Octave version: %s', octaveVersion);
end
for ii = 1:length(installlist)
packageName = installlist{ii};
try
% Try loading Octave packages
disp(['loading ' packageName]);
pkg('load', packageName);
catch
tryInstallFromForge(packageName);
end
end
else % MATLAB ----------------------------
if verLessThan('matlab', matlabVersion)
error('Sorry, minimum required version is R2017b. :(');
end
end
% If external dir is empty throw an exception
% and ask user to update submodules.
libDirectory = fullfile(fileparts(mfilename('fullpath')), 'lib');
if numel(dir(libDirectory)) <= 2 % Means that the external is empty
error(['Git submodules are not cloned!', ...
'Try this in your terminal:', ...
' git submodule update --recursive ']);
else
addDependencies();
end
disp('Correct matlab/octave verions and added to the path!');
end
function retval = isOctave
% Return: true if the environment is Octave.
persistent cacheval % speeds up repeated calls
if isempty (cacheval)
cacheval = (exist ('OCTAVE_VERSION', 'builtin') > 0);
end
retval = cacheval;
end
function tryInstallFromForge(packageName)
errorcount = 1;
while errorcount % Attempt twice in case installation fails
try
pkg('install', '-forge', packageName);
pkg('load', packageName);
errorcount = 0;
catch err
errorcount = errorcount + 1;
if errorcount > 2
error(err.message);
end
end
end
end
function addDependencies()
pth = fileparts(mfilename('fullpath'));
addpath(genpath(fullfile(pth, 'lib', 'CPP_BIDS', 'src')));
addpath(genpath(fullfile(pth, 'lib', 'CPP_PTB', 'src')));
addpath(genpath(fullfile(pth, 'subfun')));
end