annotate Problems/private/timereta.m @ 39:8f734534839a

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