annotate DL/RLS-DLA/private/timereta.m @ 65:55faa9b5d1ac

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