-
Notifications
You must be signed in to change notification settings - Fork 6
/
INSTALL_DTQP.m
430 lines (338 loc) · 11.3 KB
/
INSTALL_DTQP.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
%--------------------------------------------------------------------------
% INSTALL_DTQP
% Project link: https://github.com/danielrherber/dt-qp-project
% This scripts helps you get the DT QP Project up and running
%--------------------------------------------------------------------------
% Automatically adds project files to your MATLAB path, downloads the
% required files, and opens an example
%--------------------------------------------------------------------------
% Install script based on MFX Submission Install Utilities
% https://github.com/danielrherber/mfx-submission-install-utilities
% https://www.mathworks.com/matlabcentral/fileexchange/62651
%--------------------------------------------------------------------------
% Primary contributor: Daniel R. Herber (danielrherber)
% Additional contributors:
% - Yong Hoon Lee (yonghoonlee)
% - Athul K. Sundarrajan (AthulKrishnaSundarrajan)
%--------------------------------------------------------------------------
function INSTALL_DTQP(varargin)
% initialize
silentflag = 0; % don't be silent
% parse inputs
if ~isempty(varargin)
if any(strcmpi(varargin,'silent'))
silentflag = 1; % be silent
end
end
% add contents to path
RunSilent('AddSubmissionContents(mfilename)',silentflag)
% display banner text
RunSilent('DisplayBanner',silentflag)
% Check toolboxes and versions
RunSilent('MinimumVersionChecks',silentflag)
% download required web files
RunSilent('RequiredWebFiles',silentflag)
% download required web zips
RunSilent('RequiredWebZips',silentflag)
% add contents to path (files have been downloaded)
RunSilent('AddSubmissionContents(mfilename)',silentflag)
% open an example
if ~silentflag, OpenThisFile('BrysonHo166'); end
% close this file
RunSilent('CloseThisFile(mfilename)',silentflag)
% display banner text
RunSilent('DisplayBanner',silentflag)
end
%--------------------------------------------------------------------------
function RequiredWebFiles %#ok<DEFNU>
disp('-> Obtaining required web files')
% initialize index
ind = 0;
% initialize structure
files = struct('url','','folder','');
% file 1
ind = ind + 1; % increment
files(ind).url = 'http://www1.spms.ntu.edu.sg/~lilian/bookcodes/legen/legslbdiff.m';
files(ind).folder = 'legslbdiff';
% file 2
ind = ind + 1; % increment
files(ind).url = 'http://www1.spms.ntu.edu.sg/~lilian/bookcodes/legen/lepoly.m';
files(ind).folder = 'lepoly';
% obtain full function path
full_fun_path = which(mfilename('fullpath'));
outputdir = fullfile(fileparts(full_fun_path),'include');
% download
DownloadWebFiles(files,outputdir)
disp(' ')
end
%--------------------------------------------------------------------------
function RequiredWebZips %#ok<DEFNU>
disp('-> Obtaining required web zips')
% initialize index
ind = 0;
% initialize structure
zips = struct('url','','folder','','test','');
% zip 1
ind = ind + 1; % increment
zips(ind).url = 'https://github.com/chebfun/chebfun/archive/master.zip';
zips(ind).folder = 'MFX 47023';
zips(ind).test = 'chebfun';
% zip 2
ind = ind + 1; % increment
zips(ind).url = 'https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/8773/versions/38/download/zip/Multiprod_2009.zip';
zips(ind).folder = 'MFX 8773';
zips(ind).test = 'multiprod';
% zip 3
ind = ind + 1; % increment
zips(ind).url = 'https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/31272/versions/10/download/zip/DataHash_20160618.zip';
zips(ind).folder = 'MFX 31272';
zips(ind).test = 'DataHash';
% zip 4
ind = ind + 1; % increment
zips(ind).url = 'http://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/40397/versions/7/download/zip/mfoldername_v2.zip';
zips(ind).folder = 'MFX 40397';
zips(ind).test = 'mfoldername';
% zip 5
ind = ind + 1; % increment
zips(ind).url = 'https://github.com/altmany/export_fig/archive/master.zip';
zips(ind).folder = 'MFX 23629';
zips(ind).test = 'export_fig';
% zip 6
ind = ind + 1; % increment
zips(ind).url = 'https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/28944/versions/1/download/zip/pchipd.zip';
zips(ind).folder = 'MFX 28944';
zips(ind).test = 'pchipd';
% obtain full function path
full_fun_path = which(mfilename('fullpath'));
outputdir = fullfile(fileparts(full_fun_path),'include');
% download and unzip
DownloadWebZips(zips,outputdir)
disp(' ')
end
%--------------------------------------------------------------------------
function MinimumVersionChecks %#ok<DEFNU>
disp('-> Checking toolbox versions')
% initialize index
ind = 0;
% initialize structure
test = struct('toolbox','','version','','required','');
% test 1: MATLAB
ind = ind + 1; % increment
test(ind).toolbox = 'matlab';
test(ind).name = 'MATLAB';
test(ind).version = '0'; % any?
test(ind).required = true;
% test 2: Optimization Toolbox
ind = ind + 1; % increment
test(ind).toolbox = 'optim';
test(ind).name = 'Optimization Toolbox';
test(ind).version = '0'; % any?
test(ind).required = false;
% test 3: Parallel Computing Toolbox
ind = ind + 1; % increment
test(ind).toolbox = 'parallel';
test(ind).name = 'Parallel Computing Toolbox';
test(ind).version = '0'; % any?
test(ind).required = false;
% test 4: Symbolic Math Toolbox
ind = ind + 1; % increment
test(ind).toolbox = 'symbolic';
test(ind).name = 'Symbolic Math Toolbox';
test(ind).version = '0'; % any?
test(ind).required = false;
% test 5: Control System Toolbox
ind = ind + 1; % increment
test(ind).toolbox = 'control';
test(ind).name = 'Control System Toolbox';
test(ind).version = '0'; % any?
test(ind).required = false;
% download and unzip
VersionChecks(test)
disp(' ')
end
%--------------------------------------------------------------------------
function DisplayBanner %#ok<DEFNU>
flag = 'line'; DTQP_commandWindowTasks %#ok<NASGU>
flag = 'banner'; DTQP_commandWindowTasks %#ok<NASGU>
flag = 'link'; DTQP_commandWindowTasks %#ok<NASGU>
flag = 'contributor'; DTQP_commandWindowTasks %#ok<NASGU>
flag = 'line'; DTQP_commandWindowTasks %#ok<NASGU>
end
%--------------------------------------------------------------------------
function AddSubmissionContents(name) %#ok<DEFNU>
disp('-> Adding submission contents to path')
disp(' ')
% turn off potential warning
warning('off','MATLAB:dispatcher:nameConflict')
% current file
fullfuncdir = which(name);
% current folder
submissiondir = fullfile(fileparts(fullfuncdir));
% add folders and subfolders to path
addpath(genpath(submissiondir))
% turn warning back on
warning('on','MATLAB:dispatcher:nameConflict')
end
%--------------------------------------------------------------------------
function CloseThisFile(name) %#ok<DEFNU>
disp(['-> Closing ', name])
disp(' ')
% get editor information
h = matlab.desktop.editor.getAll;
% go through all open files in the editor
for k = 1:numel(h)
% check if this is the file
if ~isempty(strfind(h(k).Filename,name))
% close this file
h(k).close
end
end
end
%--------------------------------------------------------------------------
function OpenThisFile(name)
disp(['-> Opening ', name])
try
% open the file
open(name);
catch % error
disp(['Could not open ', name])
end
disp(' ')
end
%--------------------------------------------------------------------------
function DownloadWebFiles(files,outputdir)
% store the current directory
olddir = pwd;
% create a folder for outputdir
if ~exist(outputdir, 'dir')
mkdir(outputdir); % create the folder
else
addpath(genpath(outputdir)); % add folders and subfolders to path
end
% change to the output directory
cd(outputdir)
% go through each file
for k = 1:length(files)
% get data
url = files(k).url;
folder = files(k).folder;
[~,nameurl,exturl] = fileparts(url);
name = [nameurl,exturl];
% first check if the test file is in the path
if exist(name,'file') == 0
try
% download file
outfilename = websave(name,url);
% create a folder utilizing name as the foldername name
if ~exist(fullfile(outputdir,folder), 'dir')
mkdir(fullfile(outputdir,folder));
end
% move the file
movefile(outfilename,fullfile(outputdir,folder))
% output to the command window
disp(['Downloaded ',folder,'/',name])
catch % failed to download
% output to the command window
disp(['Failed to download ',folder,'/',name])
% remove the html file
delete([name,'.html'])
end
else
% output to the command window
disp(['Already available ',name])
end
end
% change back to the original directory
cd(olddir)
end
%--------------------------------------------------------------------------
function DownloadWebZips(zips,outputdir)
% store the current directory
olddir = pwd;
% create a folder for outputdir
if ~exist(outputdir, 'dir')
mkdir(outputdir); % create the folder
else
addpath(genpath(outputdir)); % add folders and subfolders to path
end
% change to the output directory
cd(outputdir)
% go through each zip
for k = 1:length(zips)
% get data
url = zips(k).url;
folder = zips(k).folder;
test = zips(k).test;
% first check if the test file is in the path
if exist(test,'file') == 0
try
% download zip file
zipname = websave(folder,url);
% save location
outputdirname = fullfile(outputdir,folder);
% create a folder utilizing name as the foldername name
if ~exist(outputdirname, 'dir')
mkdir(outputdirname);
end
% unzip the zip
unzip(zipname,outputdirname);
% delete the zip file
delete([folder,'.zip'])
% output to the command window
disp(['Downloaded and unzipped ',folder])
catch % failed to download
% output to the command window
disp(['Failed to download ',folder])
% remove the html file
delete([folder,'.html'])
end
else
% output to the command window
disp(['Already available ',folder])
end
end
% change back to the original directory
cd(olddir)
end
%--------------------------------------------------------------------------
function RunSilent(str,silentflag)
% if silent, capture the output
if silentflag
O = evalc(str); %#ok<NASGU>
else
eval(str);
end
end
%--------------------------------------------------------------------------
function VersionChecks(test)
% initialize counter
counter = 0;
% go through each file
for k = 1:length(test)
try
if verLessThan(test(k).toolbox,test(k).version) % failed
if test(k).required % required
str = ['Failed (REQUIRED): ',test(k).name];
else % recommended
str = ['Failed (optional): ',test(k).name];
end
else % passed
str = ['Passed: ',test(k).name];
counter = counter + 1;
end
catch % failed to check the toolbox
str = ['Failed to check toolbox: ', test(k).name];
end
if ~strcmpi(test(k).version,'0')
str = [str,' -v', test(k).version]; %#ok<AGROW>
end
% display to command window
disp(str)
end
% check if all tests were passed
if counter == length(test) % successful
disp('All toolbox and version checks passed')
else % failure
warning('Not all toolbox and version checks were successful')
end
end