-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup_easyplot.m
127 lines (105 loc) · 3.27 KB
/
setup_easyplot.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
function setup_easyplot(strType)
% path to easyplot dir
[EPpath, name, ext] = fileparts(mfilename('fullpath'));
%easyplotDir='D:\Projects\aims-gitlab\easyplot';
if nargin == 0
strType='pc';
end
driveLetter='';
if ispc
driveLetter=EPpath(1:2);
end
% baseDIR : typically top folder containing easyplot and imos-toolbox folders
% ITBdir : folder name of imos toolbox, assumes you have set imosToolbox so that imosToolbox.m already in your path
% EPdir : foldername of easyplot
switch strType
case 'pc'
%baseDIR=[driveLetter '\AIMS'];
%AODNbaseDir=[driveLetter '\AIMS'];
ITBdir = 'imos-toolbox';
%EPdir = 'easyplot'; % easyplot folder name
thisFilepath = mfilename('fullpath');
[baseDIR, EPdir] = fileparts(EPpath);
case 'pc-dev'
baseDIR=[driveLetter '\Projects\aims-gitlab'];
AODNbaseDir=[driveLetter '\Projects\aodn'];
ITBdir = 'imos-toolbox';
EPdir = 'easyplot';
case 'hpc'
baseDIR='/export/ocean/AIMS';
AODNbaseDir='/export/ocean/AIMS';
ITBdir = 'imos-toolbox-2.5-aims';
EPdir = 'easyplot';
case 'hpc-dev'
baseDIR='/export/ocean/sspagnol/src/aims-gitlab';
AODNbaseDir='/export/ocean/sspagnol/src/github/aodn';
ITBdir = 'imos-toolbox';
EPdir = 'easyplot';
otherwise
[baseDIR, EPdir] = fileparts(EPpath);
ITBdir = 'imos-toolbox';
EPdir = 'easyplot';
end
% path to imosToolbox
ITBpath=fullfile(baseDIR, ITBdir);
% path to AIMS Easyplot
EPpath=fullfile(baseDIR, EPdir);
%%
reAddPaths(EPpath,'AIMS easyplot',true,'(snapshot)');
%% add IMOS Toolbox paths
reAddPaths(ITBpath,'IMOS toolbox',true);
end
%%
function reAddPaths(topDir,messageStr,atBeginning,excludePattern)
disp(['Adding paths for ' messageStr ', please wait...']);
try
if ~exist('excludePattern')
excludePattern = '';
end
gp=genpath_clean(topDir, excludePattern);
disp(' Removing any existing paths.')
rempath(gp);
disp(' Adding new paths');
if atBeginning
addpath(gp,'-begin');
else
addpath(gp,'-end');
end
catch
error(['Path ' topDir ' does not exist.']);
end
end
%%
function rempath(gp)
% from a genpath path string, remove on paths that are currently in the
% matlab path
ss=strsplit(gp,';');
pp=strsplit(path,';');
ii=ismember(ss,pp);
ss=ss(ii); %list with only directories that are currently on matlab path
if ~isempty(ss)
thePath=sprintf(['%s' pathsep],ss{:}); %make string seperated by pathsep
if thePath(end)==pathsep % remove last not needed pathsep
thePath(end)=[];
end
rmpath(thePath);
end
end
%%
function thePath = genpath_clean( topDir, excludePattern )
%genpath_clean generate a path without .svn, .git etc.
% generate a path without .svn, .git etc. Based on idea from OpenEarthTools
b=genpath(topDir);
s = strread(b, '%s','delimiter', pathsep); % read path as cell
rpattern='(\.svn|\.git|\.hg\private)';
ii=cellfun(@isempty,regexp(s,rpattern,'match','once'));
s=s(ii); %cell array without .git etc
if ~isempty(excludePattern)
ii=cellfun(@isempty,regexp(s,excludePattern,'match','once'));
s=s(ii);
end
thePath=sprintf(['%s' pathsep],s{:}); %make string seperated by pathsep
if thePath(end)==pathsep % remove last not needed pathsep
thePath(end)=[];
end
end