-
Notifications
You must be signed in to change notification settings - Fork 2
/
dstrysave.m
executable file
·49 lines (49 loc) · 1.13 KB
/
dstrysave.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
% Author: Carl Doersch (cdoersch at cs dot cmu dot edu)
function dstrysave(filenm,cmd,varargin)
% if(exist(filenm,'file'))
global ds;
iserror=0;
%if(dsbool(ds,'conf','checksaves'))
ofil=filenm;
filenm=[filenm '_tmp.mat'];
%end
while(iserror>=0)
if(iserror>0)
pause(2)
end
try
checkpassed=false;
while(~checkpassed)
save(filenm,'cmd',varargin{:});
iserror=-1;
checkpassed=(~dsbool(ds,'conf','checksaves'))||checksave(filenm,'''cmd''');
end
% cmd=val.cmd;
catch ex
iserror=iserror+1;
if(iserror==5)
dsprinterr;
throw(MException('dsmapreducer:cantwrite',['unable to write ' filenm]))
end
end
end
disp(['wrote ' filenm]);
%if(dsbool(ds,'conf','checksaves'))
movefile(filenm,ofil,'f');
%end
% delete(filenm);
% else
% cmd=[];
% end
end
function res=checksave(fname,vars)
res=true;
try
eval(['load(''' fname ''',' vars ');']);
disp(['checked save of ' fname]);
catch ex
dsstacktrace(ex);
res=false;
end
eval(['clear(' vars ');']);
end