-
Notifications
You must be signed in to change notification settings - Fork 70
/
checkTiming.m
86 lines (83 loc) · 2.91 KB
/
checkTiming.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
function [ is_ok, text_error, total_dur ] = checkTiming( system, varargin )
%checkTiming(sys, objects, ...)
% Function checks whether timing of the specified evets are aligned to
% the corresponding raster
if (isempty(varargin))
text_error=['empty or damaged block detected' ];
is_ok=false;
return;
end
total_dur=mr.calcDuration(varargin{:});
is_ok=div_check(total_dur,system.gradRasterTime);
if (is_ok)
text_error=[];
else
text_error=['total duration:' num2str(total_dur*1e6) 'us' ];
end
for i=1:length(varargin)
e=varargin{i};
assert(isstruct(e), 'wrong format of the variable aguments, list of structures is expected');
ok=true;
if length(e)>1
% for now this is only the case for arrays of extensions, but
% we actually cannot check extensons anyway...
continue;
end
if isfield(e, 'type') && (strcmp(e.type,'adc') || strcmp(e.type,'rf'))
raster=system.rfRasterTime;
else
raster=system.gradRasterTime;
end
if isfield(e, 'delay')
if e.delay<-eps
ok=false;
end
if ~div_check(e.delay,raster)
ok=false;
end
end
if isfield(e, 'duration')
if ~div_check(e.duration,raster)
ok=false;
end
end
if isfield(e, 'dwell')
if e.dwell<raster
ok=false;
end
end
if isfield(e, 'type') && strcmp(e.type,'trap')
if ~div_check(e.riseTime, system.gradRasterTime) || ~div_check(e.flatTime, system.gradRasterTime) || ~div_check(e.fallTime, system.gradRasterTime)
ok=false;
end
end
if ~ok
is_ok=false;
if ~isempty(text_error)
text_error = [text_error ' '];
end
text_error = [text_error '[ '];
if isfield(e, 'type')
text_error = [text_error 'type:' e.type ' ' ];
end
if isfield(e, 'delay')
text_error = [text_error 'delay:' num2str(e.delay*1e6) 'us ' ];
end
if isfield(e, 'duration')
text_error = [text_error 'duration:' num2str(e.duration*1e6) 'us ' ];
end
if isfield(e, 'dwell')
text_error = [text_error 'dwell:' num2str(e.dwell*1e9) 'ns ' ];
end
if isfield(e, 'type') && strcmp(e.type,'trap')
text_error = [text_error 'riseTime:' num2str(e.riseTime*1e6) 'us flatTime:' num2str(e.flatTime*1e6) 'us fallTime:' num2str(e.fallTime*1e6) 'us '];
end
text_error = [text_error ']'];
end
end
end
function out = div_check(a, b)
% checks wheher a can be divided by b to an accuracy of 1e-9
c = a / b;
out = (abs( c - round(c) ) < 1e-9);
end