idamnjanovic@60: function varargout = timereta(tid,iter,delay) idamnjanovic@60: %TIMERETA Estimated remaining time. idamnjanovic@60: % S = TIMERETA(TID,ITER) returns the estimated remaining time (in idamnjanovic@60: % seconds) for the process associated with timer TID, assuming the idamnjanovic@60: % process has completed ITER iterations. Note: the function will exit idamnjanovic@60: % with an error if the timer TID does not have an associated number of idamnjanovic@60: % iterations (see function TIMERINIT). idamnjanovic@60: % idamnjanovic@60: % [H,M,S] = TIMERETA(TID,ITER) returns the estimated remaining time in idamnjanovic@60: % hours, minutes and seconds. idamnjanovic@60: % idamnjanovic@60: % TIMERETA(TID,ITER), with no output arguments, prints the estimated idamnjanovic@60: % remaining time to the screen. The time is displayed in the format idamnjanovic@60: % idamnjanovic@60: % TIMERNAME: iteration ITER / ITERNUM, estimated remaining time: HH:MM:SS.SS idamnjanovic@60: % idamnjanovic@60: % If the timer has no assigned name, the display format changes to idamnjanovic@60: % idamnjanovic@60: % Iteration ITER / ITERNUM, estimated remaining time: HH:MM:SS.SS idamnjanovic@60: % idamnjanovic@60: % TIMERETA(TID,ITER,DELAY) only displays the remaining time if the idamnjanovic@60: % time elapsed since the previous printout is at least DELAY seconds. idamnjanovic@60: % idamnjanovic@60: % See also TIMERINIT, TIMERCLEAR. idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: % Ron Rubinstein idamnjanovic@60: % Computer Science Department idamnjanovic@60: % Technion, Haifa 32000 Israel idamnjanovic@60: % ronrubin@cs idamnjanovic@60: % idamnjanovic@60: % June 2008 idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: global utiltbx_timer_start_times idamnjanovic@60: global utiltbx_timer_iternums idamnjanovic@60: global utiltbx_timer_lastiter idamnjanovic@60: global utiltbx_time_lastdisp idamnjanovic@60: global utiltbx_timer_name idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: if (tid<1 || tid>length(utiltbx_timer_iternums)) idamnjanovic@60: error('Unknown timer id'); idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: if (utiltbx_timer_iternums(tid) < 0) idamnjanovic@60: error('Specified timer does not have an associated number of iterations'); idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: % update last reported iteration number idamnjanovic@60: utiltbx_timer_lastiter(tid) = iter; idamnjanovic@60: idamnjanovic@60: % compute elapsed time idamnjanovic@60: starttime = utiltbx_timer_start_times(tid,:); idamnjanovic@60: currtime = clock; idamnjanovic@60: timediff = etime(currtime, starttime); idamnjanovic@60: idamnjanovic@60: % total iteration number idamnjanovic@60: iternum = utiltbx_timer_iternums(tid); idamnjanovic@60: idamnjanovic@60: % compute eta idamnjanovic@60: timeremain = (iternum-iter)*timediff/iter; idamnjanovic@60: idamnjanovic@60: % return eta in seconds idamnjanovic@60: if (nargout==1) idamnjanovic@60: varargout{1} = timeremain; idamnjanovic@60: idamnjanovic@60: % return eta in hms idamnjanovic@60: elseif (nargout==3) idamnjanovic@60: [varargout{1}, varargout{2}, varargout{3}] = secs2hms(timeremain); idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: % print eta idamnjanovic@60: elseif (nargout==0) idamnjanovic@60: idamnjanovic@60: % check last display time idamnjanovic@60: lastdisptime = utiltbx_time_lastdisp(tid,:); idamnjanovic@60: if (nargin>2 && etime(currtime,lastdisptime) < delay) idamnjanovic@60: return; idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: % update last display time idamnjanovic@60: utiltbx_time_lastdisp(tid,:) = currtime; idamnjanovic@60: idamnjanovic@60: % display timer idamnjanovic@60: [hrs,mins,secs] = secs2hms(timeremain); idamnjanovic@60: if (isempty(utiltbx_timer_name{tid})) idamnjanovic@60: printf('Iteration %d / %d, estimated remaining time: %02d:%02d:%05.2f', iter, iternum, hrs, mins, secs); idamnjanovic@60: else idamnjanovic@60: timername = utiltbx_timer_name{tid}; idamnjanovic@60: printf('%s: iteration %d / %d, estimated remaining time: %02d:%02d:%05.2f', timername, iter, iternum, hrs, mins, secs); idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: % invalid number of outputs idamnjanovic@60: else idamnjanovic@60: error('Invalid number of output arguments'); idamnjanovic@60: end idamnjanovic@60: