-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdstryload.m
executable file
·55 lines (55 loc) · 973 Bytes
/
dstryload.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
% Author: Carl Doersch (cdoersch at cs dot cmu dot edu)
function cmd=dstryload(filenm,conf)
myretry=0;
mydelete=1;
dowait=1;
if(nargin>1)
if(isfield(conf,'delete'))
mydelete=conf.delete;
end
if(isfield(conf,'retry'))
myretry=conf.retry;
end
if(isfield(conf,'nowait'))
dowait=~(conf.nowait);
end
end
nretries=0;
while(~exist(filenm,'file'))
if(myretry)
if(nretries>5)
throw(MException('tryload:notexist','too many retries'));
end
pause(2)
else
cmd=[];
return;
end
end
iserror=0;
while(iserror>=0)
if(iserror>0)
pause(2)
end
try
val=load(filenm);
iserror=-1;
cmd=val.cmd;
catch ex
if(~dowait)
cmd=[];
return;
end
iserror=iserror+1;
if(iserror==10)
rethrow(ex);
end
end
end
if(mydelete)
delete(filenm);
end
%if(~exist(cmd,'var'))
% cmd=[];
%end
end