-
Notifications
You must be signed in to change notification settings - Fork 4
/
pdapply.m
executable file
·70 lines (65 loc) · 2.08 KB
/
pdapply.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
function [pulse changedout]=pdapply(pd,pulse,time)
%function [pulse changed]=pdapply(pd, pulse,time)
% Apply a pulse dictionary to a pulse. Return the new pulse. Changed is
% true if the application was non-trivial
% (c) 2010 Hendrik Bluhm. Please see LICENSE and COPYRIGHT information in plssetup.m.
if ~exist('time','var')
time=[];
end
if ~strcmp(pulse.format,'elem')
changedout=0;
return;
end
% If pd is a cell array, apply each dictionary in sequence. This allows
% for some *neat* effects. :p
if iscell(pd)
changed = 0;
for i=1:length(pd)
[pulse c2] = pdapply(pd{i},pulse,time);
changed = changed || c2;
end
changedout = changed;
return;
end
if ischar(pd)
pd=pdload(pd,time);
end
changedout=0;
changed = 1;
while changed
changed=0;
for i=1:length(pulse.data)
if (pulse.data(i).type(1) == '@') && isfield(pd,pulse.data(i).type(2:end))
nels=getfield(pd,pulse.data(i).type(2:end));
if ischar(nels)
nels={nels};
end
if iscell(nels)
nels=struct('type',nels,'time',[],'val',[]);
end
template=pulse.data(i);
pulse.data(i)=[];
ot = ~isnan(template.time);
ov = ~isnan(template.val);
for j=1:length(nels)
if ischar(nels(j))
nels(j) = struct('type',nels(j),'time',[],'val',[]);
end
nels(j).time(ot)=template.time(ot);
nels(j).val(ov)=template.val(ov);
end
pulse.data = [pulse.data(1:i-1) orderfields(nels,pulse.data(1)) pulse.data(i:end)];
changed=1;
changedout=1;
if isfield(pulse,'pardef') && ~isempty(pulse.pardef)
pulse.pardef = bump_pardef(pulse.pardef,i,length(nels)-1);
end
break;
end
end
end
return
function pardef = bump_pardef(pardef, from, by)
tobump=find(pardef(:,1) > from);
pardef(tobump,1)=pardef(tobump,1)+by;
return;