forked from darwinlau/CASPR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialise_CASPR.m
More file actions
231 lines (209 loc) · 9.7 KB
/
Copy pathinitialise_CASPR.m
File metadata and controls
231 lines (209 loc) · 9.7 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
% A function to temporarily add the CASPR libraries
% Author: Jonathan EDEN
% Created: 2016
% Description:
function initialise_CASPR()
clc;
scriptname = mfilename('fullpath');
[CASPR_homepath] = fileparts(scriptname);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Confirm that initialise has been called from the right folder
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
assert(exist([CASPR_homepath '/src'], 'dir') == 7 && exist([CASPR_homepath '/data'], 'dir') == 7, 'Incorrect CASPR folder structure');
cd(CASPR_homepath);
% Set the current version
CASPR_version = 20171030;
CASPR_model_config_path = [CASPR_homepath,'/data/model_config'];
CASPR_GUI_dev_model_config = 0; % Developmental models are not shown
global_model_mode = 0; % Global model mode
reuse_compiled = 0; % Flag for reusing compiled files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Determine if setup needs to be executed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(~exist([CASPR_homepath,'/data/config'],'dir'))
mkdir([CASPR_homepath,'/data/config'])
save([CASPR_homepath,'/data/config/CASPR_environment.mat'],...
'CASPR_homepath','CASPR_version','CASPR_model_config_path','CASPR_GUI_dev_model_config','global_model_mode','reuse_compiled');
setup_CASPR;
else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Determine if CASPR needs to be updated
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load the previous version information
if(~exist([CASPR_homepath,'/data/config/CASPR_environment.mat'],'file'))
save([CASPR_homepath,'/data/config/CASPR_environment.mat'],'CASPR_homepath','CASPR_version','CASPR_model_config_path','CASPR_GUI_dev_model_config','global_model_mode','reuse_compiled');
update_CASPR;
else
previous_version = load([CASPR_homepath,'/data/config/CASPR_environment.mat'],'CASPR_version');
if(isempty(fieldnames(previous_version))||(CASPR_version>previous_version.CASPR_version))
save([CASPR_homepath,'/data/config/CASPR_environment.mat'],'CASPR_homepath','CASPR_version','CASPR_model_config_path','CASPR_GUI_dev_model_config','global_model_mode','reuse_compiled');
update_CASPR;
else
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add the libraries
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
save([CASPR_homepath,'/data/config/CASPR_environment.mat'],'CASPR_homepath','CASPR_version','CASPR_model_config_path','CASPR_GUI_dev_model_config','global_model_mode','reuse_compiled','-append');
set_CASPR_environment;
fprintf('CASPR initialisation complete. Enjoy !\n')
end
end
end
end
% Function for setting up the CASPR. This first checks the system
% environment and then runs and a setup and update to create the necessary
% folders.
function setup_CASPR()
% Check the status of the dependencies
fprintf('\n----------------------------------------------------\n')
fprintf('Checking Environment and Dependency Installation \n')
fprintf('----------------------------------------------------\n')
check_system_environment;
% Run the rest of setup (setup environment and logging, then test the
% system).
num_tests_failed = setup_update_CASPR();
fprintf('\n----------------------------------------------------\n')
fprintf('CASPR Setup Complete. Enjoy!\n');
if num_tests_failed > 0
fprintf('WARNING: Some unit tests failed. Please contact the maintainers of CASPR with the test summary information\n');
end
fprintf('----------------------------------------------------\n\n')
end
function update_CASPR()
fprintf('\n----------------------------------------------------\n')
fprintf('Updating CASPR \n')
fprintf('----------------------------------------------------\n')
% Check if the old logs folder is present and remove if so
CASPR_homepath = cd;
if(exist([CASPR_homepath,'/logs'],'dir'))
fprintf('\n----------------------------------------------------\n')
fprintf('Removing outdated folder locations.\n')
fprintf('----------------------------------------------------\n')
rmdir([CASPR_homepath,'/logs'],'s');
end
% Check if the old logging level file is present and remove if so
if(exist([CASPR_homepath,'/data/config/log_level.mat'],'file'))
fprintf('\n----------------------------------------------------\n')
fprintf('Removing outdated log level file.\n')
fprintf('----------------------------------------------------\n')
delete data/config/log_level.mat
end
num_tests_failed = setup_update_CASPR();
fprintf('\n----------------------------------------------------\n')
fprintf('CASPR Update Complete. Enjoy!\n')
if num_tests_failed > 0
fprintf('NOTE: Some unit tests failed. Please contact the maintainers of CASPR with the test summary information\n');
else
fprintf('----------------------------------------------------\n\n')
fprintf(' - Logging was successfully setup.\n')
fprintf(' - All items in model config successfully build.\n')
fprintf(' - All tests of model elements pass.\n')
fprintf(' - All tests of analysis tools pass.\n')
end
fprintf('----------------------------------------------------\n\n')
end
% Check the dependencies have been correctly setup.
function old_matlab_version = check_system_environment()
% First check it is a known operating system
assert(ismac || isunix || ispc, 'Operating system platform not supported');
old_matlab_version = 0;
% Code to test the matlab version
mver = ver('MATLAB');
fprintf('- Checking MATLAB version... \n\r');
fprintf('MATLAB version: %s\n\r',mver.Release);
% Version 8.6 is 2015b
if (verLessThan('matlab', '8.6'))
old_matlab_version = 1;
fprintf('WARNING: CASPR is designed for MATLAB versions from 2015b onwards. Certain functionality may not work on this version\n\r');
end
% Optitoolbox
fprintf('- Checking OptiToolbox...\n\r');
if(~strcmp(mexext,'mexw32')&&~strcmp(mexext,'mexw64'))
fprintf('[WARNING]: OPTI Toolbox is compiled only for Windows systems. Some functionality will be lost for this version. \n\r');
else
% Test opti
if(strcmp(mexext,'mexw32'))
fprintf('MATLAB %s 32bit (Windows x86) detected\n\r',mver.Release);
else
fprintf('MATLAB %s 64bit (Windows x64) detected\n\r',mver.Release);
end
% Test if optitoolbox is in the path
p = path;
if(isempty(strfind(p,'OptiToolbox')))
fprintf('[WARNING]: OptiToolbox is not your matlab file path.\n\r');
else
fprintf('OptiToolbox found on the path.\n\r');
%opti_Install_Test(1);
end
end
% Test for qhull
fprintf('- Checking qhull...\n\r');
if(isunix)
qhull_file = '/dependencies/qhull-2012.1/bin/qconvex';
else
qhull_file = '/dependencies/qhull-2012.1/bin/qconvex.exe';
end
if(exist(qhull_file,'file'))
fprintf('qhull is built to specificiations\n\r')
else
fprintf('[WARNING]: You do not seem to have qhull installed or it is not in the expected location.\n\r');
end
end
function set_CASPR_environment()
% Workout the delimiter symbol for PATH string
if ismac || isunix
path_delimiter = ':';
elseif ispc
path_delimiter = ';';
else
error('Platform not supported');
end
fprintf('---------------------------------------------\n')
fprintf('Initialising CASPR environment\n')
fprintf('---------------------------------------------\n')
% Remove any path that contains CASPR
fprintf('Cleaning CASPR from library path\n')
p = path;
p = strsplit(p, path_delimiter);
index = false(size(p));
for i = 1:length(index)
if(~isempty(strfind(p{i},'CASPR')))
index(i) = true;
end
end
if(sum(index)>0)
temp_p = p(index);
rmpath(temp_p{ : });
end
% Store the home directory
CASPR_homepath = cd;
% Add the necessary paths
fprintf('Adding CASPR to library path\n')
path_list = genpath(CASPR_homepath);
path_list = strsplit(path_list, path_delimiter);
for i = 1:length(path_list)
if(~isempty(strfind(path_list{i},'.git')))
path_list{i} = '';
end
end
addpath(path_list{:});
rehash
fprintf('CASPR paths have been successfully set up \n')
end
function num_tests_failed = setup_update_CASPR()
% Temporarily add the CASPR libraries to the path
set_CASPR_environment;
% Setup logging
fprintf('\n----------------------------------------------------\n')
fprintf('Set up Logging\n')
fprintf('----------------------------------------------------\n')
CASPR_log.SetLoggingDetails(CASPRLogLevel.INFO);
fprintf('Logging successfully setup\n');
% Test that the models are correctly configured
fprintf('\n----------------------------------------------------\n')
fprintf('Running CASPRTestScript to make sure everything is working\n')
fprintf('----------------------------------------------------\n')
% Run unit tests to confirm that the models are correctly setup
%suite = matlab.unittest.TestSuite.fromFile('ModelConfigTest.m');
%suite.run;
num_tests_failed = CASPRTestScript();
end