forked from toastpp/toastpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtoast2_install.m
executable file
·134 lines (116 loc) · 3.9 KB
/
mtoast2_install.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
% This script adds the TOAST mex and script directories to the
% Matlab path.
% To add the path permanently, you can append the contents of this
% file to your startup.m file, located in our Matlab startup
% directory, or in <matlabroot>/toolbox/local.
function mtoast_install(varargin)
nargin = length(varargin);
nogui = nargin > 0 && varargin{1} == true;
if ~nogui
fprintf(1,'\nAdding search paths for the Toast++ toolbox.\n\n')
end
% figure out path structure
toastdir = getenv('TOASTDIR');
if length(toastdir) == 0
[toastdir,name,ext] = fileparts(which('mtoast2_install.m'));
end
toastver = getenv('TOASTVER');
if length(toastver) == 0
arch = computer;
switch arch
case 'PCWIN'
toastver = [toastdir '\win\Win32\Release'];
case 'PCWIN64'
toastver = [toastdir '\win\x64\Release'];
case 'MACI64'
toastver = [toastdir '/darwin64'];
otherwise
disp('Warning: could not determine location of mex files')
disp('Please edit the matlab path manually')
end
end
% Remove current toast references from path
fprintf('Searching for existing toast path entries ...\n');
p = path;
p(find(p==' ')) = '^';
p(find(p==pathsep)) = ' ';
p = textscan(p,'%s');
p = p{1};
for i = 1:size(p,1) % restore spaces
p{i}(find(p{i}=='^')) = ' ';
end
k = strfind(p,'toast');
nfound = 0;
for i=1:length(k)
if length(k{i}) > 0
fprintf('Removing search path %s\n', p{i});
rmpath(p{i});
nfound = nfound+1;
end
end
if nfound > 0
fprintf('Removed %d existing toast path entries\n', nfound);
else
fprintf('No existing toast paths found.\n');
end
if ~nogui
fprintf ('\nTOAST root directory: %s\n', toastdir);
fprintf ('TOAST arch directory: %s\n\n', toastver);
end
% Sanity checks: assert valid file structure
assertfile([toastdir '/mtoast2_install.m']);
assertdir([toastdir '/script']);
assertdir([toastdir '/script/matlab']);
assertdir([toastdir '/script/matlab/toast2']);
assertdir([toastdir '/script/matlab/utilities']);
assertdir([toastver '/mex2']);
assertfile([toastver '/mex2/toastmex.' mexext]);
% Add all directories under the script/matlab node
p = genpath([toastdir '/script/matlab/']);
p(find(p==' ')) = '^'; % protect spaces in directory names
p(find(p==pathsep)) = ' '; % replace separators with spaces
p = textscan(p,'%s'); % split path into separate elements
p = p{1};
for i = 1:size(p,1) % restore spaces
p{i}(find(p{i}=='^')) = ' ';
end
k1=strfind(p,'CVS'); % eliminate CVS subdirs
k2=strfind(p,'.svn'); % eliminate .svn subdirs
k = [k1,k2];
pth = '';
for i=1:size(k,1)
if length(k{i,1}) == 0 && length(k{i,2}) == 0
if length(pth) > 0
pth = [pth pathsep];
end
pth = [pth cell2mat(p(i))];
if ~nogui
disp(['Adding search path ' cell2mat(p(i))])
end
end
end
addpath (pth);
% add the mex directory
mexp = [toastver '/mex2'];
addpath (mexp);
if ~nogui
disp(['Adding search path ' mexp])
end
rmpath ([toastdir '/script/matlab/toast']); % remove original toast script directory
if nargin == 0 || nogui==false
% open path tool GUI to allow user to modify and save the toast paths
fprintf(1,'\nPlease check that the toast paths are set correctly,\n')
fprintf(1,'then save to store the paths permanently.\n')
pathtool
end
function assertfile(pathstr)
if exist(pathstr,'file') ~= 2
error('\nToast toolbox file structure mismatch. Expected file not found:\n%s\n\nDetected toast root folder: %s\nDetected toast binary folder: %s\n\nPlease check your toast installation.', pathstr, toastdir, toastver);
end
end
function assertdir(pathstr)
if exist(pathstr,'dir') ~= 7
error('\nToast toolbox file structure mismatch. Expected directory not found:\n%s\n\nDetected toast root folder: %s\nDetected toast binary folder: %s\n\nPlease check your toast installation.', pathstr, toastdir, toastver);
end
end
end