-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspm_extract_files.m
72 lines (61 loc) · 1.93 KB
/
spm_extract_files.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
function spm_extract_files(P,cwd)
% FORMAT spm_extract_files(P,cwd)
% forints files (and their subroutines) and expect them to the current
% directory
%__________________________________________________________________________
% Copyright (C) 2013 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_extract_files.m 5175 2013-01-04 12:50:44Z guillaume $
if nargin == 1; cwd = pwd; end
% deal with cell arrays
%--------------------------------------------------------------------------
if iscell(P)
for i = 1:length(P)
spm_extract_files(P{i},cwd)
end
return
end
% get file
%--------------------------------------------------------------------------
if isempty(dir(P))
try
% check for subroutines
%------------------------------------------------------------------
copyfile(which(P),cwd);
end
else
return
end
% check for subroutines
%--------------------------------------------------------------------------
try
fid = fopen(P);
Q = textscan(fid,'%s');
fclose(fid);
Q = Q{1};
for i = 1:length(Q)
s = strfind(Q{i},'spm_');
for k = 1:length(s)
% calls: spm_???(
%--------------------------------------------------------------
j = strfind(Q{i},'(');
j = j(find(j > s(k),1));
if ~isempty(j)
q = [Q{i}(s(k):(j - 1)) '.m'];
if ~strcmp(P,q)
spm_extract_files(q,cwd);
end
end
% functions: 'spm_???'
%--------------------------------------------------------------
j = strfind(Q{i},'''');
j = j(find(j > s(k),1));
if ~isempty(j)
q = [Q{i}(s(k):(j - 1)) '.m'];
if ~strcmp(P,q)
spm_extract_files(q,cwd);
end
end
end
end
end