/
spm_update.m
69 lines (62 loc) · 2.05 KB
/
spm_update.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
function spm_update(update)
% Check (and install) SPM8 updates from the FIL FTP server
% FORMAT spm_update
% This function will connect itself to the FIL FTP server, compare the
% version number of the updates with the one of the SPM installation
% currently in the MATLAB path and will display the outcome.
%
% FORMAT spm_update(update)
% Invoking this function with any input parameter will do the same as
% above but will also attempt to download and install the updates.
%__________________________________________________________________________
% Copyright (C) 2010-2013 Wellcome Trust Centre for Neuroimaging
% Guillaume Flandin
% $Id: spm_update.m 5235 2013-02-04 15:30:21Z guillaume $
url = 'ftp://ftp.fil.ion.ucl.ac.uk/spm/spm8_updates/';
if ~nargin
update = false;
else
update = true;
end
[s,sts] = urlread(url);
if ~sts, error('Cannot access the FIL FTP server.'); end
n = regexp(s,'spm8_updates_r(\d.*?)\.zip','tokens','once');
if isempty(n)
fprintf(' There are no updates available yet.\n');
return;
else
n = str2double(n{1});
end
try
[v,r] = spm('Ver','',1); r = str2double(r);
catch
error('SPM cannot be found in MATLAB path.');
end
if ~strcmp(v,'SPM8'), error('Your SPM version is %s and not SPM8',v); end
rs = [3042 3164 3408 3684 4010 4290 4667 5236];
if isnan(r), r = rs(1); end
if floor(r) == 8
try
r = rs(round((r-floor(r))*10)+1);
catch
r = rs(end);
end
end
if n > r
fprintf(' A new version of SPM is available on:\n');
fprintf(' %s\n',url);
fprintf(' (Your version: %d - New version: %d)\n',r,n);
if update
d = spm('Dir');
delete(get(0,'Children')); spm('clean'); evalc('spm_rmpath');
try
s = unzip([url sprintf('spm8_updates_r%d.zip',n)], d);
fprintf(' %d files have been updated.\n',numel(s));
catch
fprintf(' Update failed: check file permissions.\n');
end
addpath(d);
end
else
fprintf(' Your version of SPM is up to date.\n');
end