-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathreport.m
executable file
·98 lines (94 loc) · 3.06 KB
/
report.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
86
87
88
89
90
91
92
93
94
95
96
97
98
function status = report(t,title,s,varargin)
%REPORT Report progress of solver.
% The function REPORT is designed to report progress of any type of solver
% and for Matlab's ODE-solvers in particular.
%
% Only one reporter may be active at any given time. Use WAITBAR
% directly to achieve multiple reporters.
%
% STATUS = REPORT([T0 Tend],TITLE,'init',...) sets up the progress
% reporter. T0 is the initial time/initial accuracy and Tend the final
% time/requested accuracy. The character array TITLE is the title of the
% reporter; if TITLE is a non-character array or empty, the default used
% is 'Solution progress'. This somewhat singular behavior is due to
% considerations of compatibility with Matlab's ODE-solvers.
%
% STATUS = REPORT([T0 Tend],'timeleft','init',...) continuously
% measures time and reports an estimate of the time until
% completion.
%
% STATUS = REPORT([],[],'none') causes the reporter to be inactive until
% reinitialized again. This is useful for avoiding if-clauses before
% calling REPORT.
%
% STATUS = REPORT(T,[],'',...) reports the progress T, where T0 <= T <=
% Tend.
%
% STATUS = REPORT([],[],'',...) relies on the 'timeleft'-syntax and
% updates the estimated time without computing a new estimate. This
% is useful when the number of tasks are limited, but each task
% takes a considerable amount of time.
%
% STATUS = REPORT([],[],'done',...) finishes the reporter.
%
% STATUS = 0 is returned in all syntaxes.
%
% See also WAITBAR.
% S. Engblom 2009-03-06 (Minor revision)
% S. Engblom 2007-04-05
persistent T0 Tend percent hwait t0 est lastupdate;
if isempty(s) && ~isempty(hwait)
if isempty(t)
if ~isempty(est) && ~isempty(lastupdate)
% blind update (relying on est and lastupdate being properly initiated)
est = est-toc(lastupdate);
hrs = floor(est/3600);
mins = floor(est/60)-60*hrs;
waitbar(percent/100,hwait, ...
sprintf('Estimated time left: %d hour(s), %d minute(s).', ...
hrs,mins));
lastupdate = tic;
end
% call ignored otherwise
else
% main use
now = round((t(end)-T0)/(Tend-T0)*100);
if now > percent
percent = now;
if isempty(t0) || percent < eps
waitbar(percent/100,hwait);
else
t1 = toc(t0);
est = (100-percent)/percent*t1;
hrs = floor(est/3600);
mins = floor(est/60)-60*hrs;
waitbar(percent/100,hwait, ...
sprintf('Estimated time left: %d hour(s), %d minute(s).', ...
hrs,mins));
end
end
lastupdate = tic;
end
elseif strcmp(s,'init')
T0 = t(1);
Tend = t(end);
t0 = [];
est = [];
lastupdate = [];
percent = 0;
try, close(hwait); catch, end
if isempty(title) || ~isa(title,'char')
title = 'Solution progress';
elseif strcmp(title,'timeleft')
title = 'Estimated time left: ';
t0 = tic;
end
hwait = waitbar(0.0,title);
else % 'none' and 'done' empties hwait
try, close(hwait); catch, end
hwait = [];
t0 = [];
est = [];
lastupdate = [];
end
status = 0;