-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathndr_Init.m
More file actions
75 lines (56 loc) · 2.29 KB
/
ndr_Init.m
File metadata and controls
75 lines (56 loc) · 2.29 KB
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
function ndr_Init
% NDR_INIT - initalize a global variable ndr_globals with default file paths
myndrpath = fileparts(which('ndr_Init'));
% remove any paths that have the string 'NDR-matlab' so we don't have stale paths confusing anyone
pathsnow = path;
pathsnow_cell = split(pathsnow,pathsep);
matches = contains(pathsnow_cell, 'NDR-matlab');
pathstoremove = char(strjoin(pathsnow_cell(matches),pathsep));
rmpath(pathstoremove);
% add everyelement except '.git' directories
pathstoadd = genpath(myndrpath);
pathstoadd_cell = split(pathstoadd,pathsep);
matches=(~contains(pathstoadd_cell,'.git'))&(~contains(pathstoadd_cell,'.ndr_globals'));
pathstoadd = char(strjoin(pathstoadd_cell(matches),pathsep));
addpath(pathstoadd);
ndr.globals;
% paths
ndr_globals.path = [];
ndr_globals.path.path = myndrpath;
ndr_globals.path.temppath = [tempdir filesep 'ndrtemp'];
ndr_globals.path.testpath = [tempdir filesep 'ndrtestcode'];
ndr_globals.path.filecachepath = [userpath filesep 'Documents' filesep 'NDR' filesep 'NDR-filecache'];
ndr_globals.path.preferences = [userpath filesep 'Preferences' filesep' 'NDR'];
if ~exist(ndr_globals.path.temppath,'dir'),
mkdir(ndr_globals.path.temppath);
end;
if ~exist(ndr_globals.path.testpath,'dir'),
mkdir(ndr_globals.path.testpath);
end;
if ~exist(ndr_globals.path.filecachepath,'dir'),
mkdir(ndr_globals.path.filecachepath);
end;
if ~exist(ndr_globals.path.preferences,'dir'),
mkdir(ndr_globals.path.preferences);
end;
ndr_globals.debug.verbose = 1;
% test write access to preferences, testpath, filecache, temppath
paths = {ndr_globals.path.testpath, ndr_globals.path.temppath, ndr_globals.path.filecachepath, ndr_globals.path.preferences};
pathnames = {'NDR test path', 'NDR temporary path', 'NDR filecache path', 'NDR preferences path'};
for i=1:numel(paths),
fname = [paths{i} filesep 'testfile_' int2str(fix(10000*rand)) '.txt'];
fid = fopen(fname,'wt');
if fid<0,
error(['We do not have write access to the ' pathnames{i} ' at ' paths{i} '.']);
end;
fclose(fid);
delete(fname);
end;
return;
ndr_globals.Python_available = 0;
try,
ndr_globals.Python_available = ndr.fun.python_detect;
end;
if ndr_globals.Python_available,
ndr.reader.neo.insert_python_path();
end;