idamnjanovic@70
|
1 function varargout = timereta(tid,iter,delay)
|
idamnjanovic@70
|
2 %TIMERETA Estimated remaining time.
|
idamnjanovic@70
|
3 % S = TIMERETA(TID,ITER) returns the estimated remaining time (in
|
idamnjanovic@70
|
4 % seconds) for the process associated with timer TID, assuming the
|
idamnjanovic@70
|
5 % process has completed ITER iterations. Note: the function will exit
|
idamnjanovic@70
|
6 % with an error if the timer TID does not have an associated number of
|
idamnjanovic@70
|
7 % iterations (see function TIMERINIT).
|
idamnjanovic@70
|
8 %
|
idamnjanovic@70
|
9 % [H,M,S] = TIMERETA(TID,ITER) returns the estimated remaining time in
|
idamnjanovic@70
|
10 % hours, minutes and seconds.
|
idamnjanovic@70
|
11 %
|
idamnjanovic@70
|
12 % TIMERETA(TID,ITER), with no output arguments, prints the estimated
|
idamnjanovic@70
|
13 % remaining time to the screen. The time is displayed in the format
|
idamnjanovic@70
|
14 %
|
idamnjanovic@70
|
15 % TIMERNAME: iteration ITER / ITERNUM, estimated remaining time: HH:MM:SS.SS
|
idamnjanovic@70
|
16 %
|
idamnjanovic@70
|
17 % If the timer has no assigned name, the display format changes to
|
idamnjanovic@70
|
18 %
|
idamnjanovic@70
|
19 % Iteration ITER / ITERNUM, estimated remaining time: HH:MM:SS.SS
|
idamnjanovic@70
|
20 %
|
idamnjanovic@70
|
21 % TIMERETA(TID,ITER,DELAY) only displays the remaining time if the
|
idamnjanovic@70
|
22 % time elapsed since the previous printout is at least DELAY seconds.
|
idamnjanovic@70
|
23 %
|
idamnjanovic@70
|
24 % See also TIMERINIT, TIMERCLEAR.
|
idamnjanovic@70
|
25
|
idamnjanovic@70
|
26
|
idamnjanovic@70
|
27 % Ron Rubinstein
|
idamnjanovic@70
|
28 % Computer Science Department
|
idamnjanovic@70
|
29 % Technion, Haifa 32000 Israel
|
idamnjanovic@70
|
30 % ronrubin@cs
|
idamnjanovic@70
|
31 %
|
idamnjanovic@70
|
32 % June 2008
|
idamnjanovic@70
|
33
|
idamnjanovic@70
|
34
|
idamnjanovic@70
|
35 global utiltbx_timer_start_times
|
idamnjanovic@70
|
36 global utiltbx_timer_iternums
|
idamnjanovic@70
|
37 global utiltbx_timer_lastiter
|
idamnjanovic@70
|
38 global utiltbx_time_lastdisp
|
idamnjanovic@70
|
39 global utiltbx_timer_name
|
idamnjanovic@70
|
40
|
idamnjanovic@70
|
41
|
idamnjanovic@70
|
42 if (tid<1 || tid>length(utiltbx_timer_iternums))
|
idamnjanovic@70
|
43 error('Unknown timer id');
|
idamnjanovic@70
|
44 end
|
idamnjanovic@70
|
45
|
idamnjanovic@70
|
46 if (utiltbx_timer_iternums(tid) < 0)
|
idamnjanovic@70
|
47 error('Specified timer does not have an associated number of iterations');
|
idamnjanovic@70
|
48 end
|
idamnjanovic@70
|
49
|
idamnjanovic@70
|
50 % update last reported iteration number
|
idamnjanovic@70
|
51 utiltbx_timer_lastiter(tid) = iter;
|
idamnjanovic@70
|
52
|
idamnjanovic@70
|
53 % compute elapsed time
|
idamnjanovic@70
|
54 starttime = utiltbx_timer_start_times(tid,:);
|
idamnjanovic@70
|
55 currtime = clock;
|
idamnjanovic@70
|
56 timediff = etime(currtime, starttime);
|
idamnjanovic@70
|
57
|
idamnjanovic@70
|
58 % total iteration number
|
idamnjanovic@70
|
59 iternum = utiltbx_timer_iternums(tid);
|
idamnjanovic@70
|
60
|
idamnjanovic@70
|
61 % compute eta
|
idamnjanovic@70
|
62 timeremain = (iternum-iter)*timediff/iter;
|
idamnjanovic@70
|
63
|
idamnjanovic@70
|
64 % return eta in seconds
|
idamnjanovic@70
|
65 if (nargout==1)
|
idamnjanovic@70
|
66 varargout{1} = timeremain;
|
idamnjanovic@70
|
67
|
idamnjanovic@70
|
68 % return eta in hms
|
idamnjanovic@70
|
69 elseif (nargout==3)
|
idamnjanovic@70
|
70 [varargout{1}, varargout{2}, varargout{3}] = secs2hms(timeremain);
|
idamnjanovic@70
|
71
|
idamnjanovic@70
|
72
|
idamnjanovic@70
|
73 % print eta
|
idamnjanovic@70
|
74 elseif (nargout==0)
|
idamnjanovic@70
|
75
|
idamnjanovic@70
|
76 % check last display time
|
idamnjanovic@70
|
77 lastdisptime = utiltbx_time_lastdisp(tid,:);
|
idamnjanovic@70
|
78 if (nargin>2 && etime(currtime,lastdisptime) < delay)
|
idamnjanovic@70
|
79 return;
|
idamnjanovic@70
|
80 end
|
idamnjanovic@70
|
81
|
idamnjanovic@70
|
82 % update last display time
|
idamnjanovic@70
|
83 utiltbx_time_lastdisp(tid,:) = currtime;
|
idamnjanovic@70
|
84
|
idamnjanovic@70
|
85 % display timer
|
idamnjanovic@70
|
86 [hrs,mins,secs] = secs2hms(timeremain);
|
idamnjanovic@70
|
87 if (isempty(utiltbx_timer_name{tid}))
|
idamnjanovic@70
|
88 printf('Iteration %d / %d, estimated remaining time: %02d:%02d:%05.2f', iter, iternum, hrs, mins, secs);
|
idamnjanovic@70
|
89 else
|
idamnjanovic@70
|
90 timername = utiltbx_timer_name{tid};
|
idamnjanovic@70
|
91 printf('%s: iteration %d / %d, estimated remaining time: %02d:%02d:%05.2f', timername, iter, iternum, hrs, mins, secs);
|
idamnjanovic@70
|
92 end
|
idamnjanovic@70
|
93
|
idamnjanovic@70
|
94 % invalid number of outputs
|
idamnjanovic@70
|
95 else
|
idamnjanovic@70
|
96 error('Invalid number of output arguments');
|
idamnjanovic@70
|
97 end
|
idamnjanovic@70
|
98
|