-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbf_copy.m
88 lines (74 loc) · 2.23 KB
/
bf_copy.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
function out = bf_copy
% Sets up a new analysis by copying an existing one
% Copyright (C) 2012 Wellcome Trust Centre for Neuroimaging
% Vladimir Litvak
% $Id$
% dir Directory
% ---------------------------------------------------------------------
BF = cfg_files;
BF.tag = 'BF';
BF.name = 'BF.mat file';
BF.filter = '^BF.mat$';
BF.num = [1 1];
BF.help = {'Select BF.mat file.'};
dir = cfg_files;
dir.tag = 'dir';
dir.name = 'Output directory';
dir.help = {'Select a directory where the copied BF.mat file will be written.'};
dir.filter = 'dir';
dir.ufilter = '.*';
dir.num = [1 1];
steps = cfg_menu;
steps.tag = 'steps';
steps.name = 'Steps to copy';
steps.help = {'Select ''all'' or the last step to copy'};
steps.labels = ['all'; bf_std_fields];
steps.values = ['all'; bf_std_fields];
steps.val = {'all'};
out = cfg_exbranch;
out.tag = 'copy';
out.name = 'Copy analysis';
out.val = {BF, dir, steps};
out.help = {'Make a copy of existing anallysis'};
out.prog = @bf_copy_run;
out.vout = @bf_copy_vout;
out.modality = {'EEG'};
end
function out = bf_copy_run(job)
BF = job.BF{1};
outdir = job.dir{1};
cd(outdir);
%-Ask about overwriting files from previous analyses
%--------------------------------------------------------------------------
if exist(fullfile(pwd,'BF.mat'),'file')
str = {'Current directory contains existing BF file:',...
'Continuing will overwrite existing file!'};
if spm_input(str,1,'bd','stop|continue',[1,0],1,mfilename);
fprintf('%-40s: %30s\n\n',...
'Abort... (existing BF file)',spm('time'));
out = []; return
end
end
if isequal(job.steps, 'all')
[r, msg] = copyfile(BF, ...
fullfile(outdir, 'BF.mat'), 'f');
if ~r
error(msg);
end
else
fields = bf_std_fields;
ind = strmatch(job.steps, fields);
BF = bf_load(BF, fields(1:ind));
bf_save(BF, 1);
end
out.BF{1} = fullfile(outdir, 'BF.mat');
end
function dep = bf_copy_vout(job)
% Output is always in field "BF", no matter how job is structured
dep = cfg_dep;
dep.sname = 'BF.mat file';
% reference field "B" from output
dep.src_output = substruct('.','BF');
% this can be entered into any evaluated input
dep.tgt_spec = cfg_findspec({{'filter','mat','strtype','e'}});
end