-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdp_node_copy.m
executable file
·79 lines (52 loc) · 1.78 KB
/
dp_node_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
classdef dp_node_copy < dp_node
% this node will copy files to input.op
%
% it will select all input files, identified as fields ending with '_fn'
% alternatively, use the constructor to specify desired fields
properties
field_names
end
methods
function obj = dp_node_copy(field_names)
if (nargin > 0)
obj.field_names = field_names;
end
end
function output = i2o(obj, input)
f = obj.get_fieldnames_to_copy(input);
for c = 1:numel(f)
tmp = f{c};
output.(tmp) = msf_fn_new_path(input.op, input.(tmp));
end
end
function output = execute(obj, input, output)
f = obj.get_fieldnames_to_copy(input);
for c = 1:numel(f)
tmp = f{c};
% possibly one should throw a warning here
if (~isfield(output, tmp))
error('bad output structure');
end
obj.log(3, 'Copying file %s', output.(tmp));
msf_mkdir(fileparts(output.(tmp)));
copyfile(input.(tmp), output.(tmp));
end
end
function f = get_fieldnames_to_copy(obj, input)
if (isempty(obj.field_names))
f_tmp = fieldnames(input);
% copy fields with _fn
f = {};
for c = 1:numel(f_tmp)
tmp = f_tmp{c};
if (~strcmp('_fn', tmp( max(1,(end-2)):(end))))
continue;
end
f{end+1} = f_tmp{c};
end
else
f = obj.field_names;
end
end
end
end