function rt=countdown(time)
% countdown Provides a visual countdown.
% Usage:: rt=countdown(time)
%
% Provides a visual countdown of duration time.

% revision history:
% 11/30/03 Mark D. Shattuck <mds>   countdown.m

ut=min(time,1);

st=clock;
rt=time;
fmt='[%02d:%05.2f]';
fprintf(1,fmt,fix(rt/60),mod(rt,60));
while(rt>=0)
  pause(ut);      
  pp=get(0,'PointerLocation');
  et=etime(clock,st);
  if (pp==[1 1])
    et=et*10;
  elseif (pp==[1600 1200])
    et=et*100;
  end
  rt=time-et;
  backspace(1,fmt,fix(rt/60),mod(rt,60));
  fprintf(1,fmt,fix(rt/60),mod(rt,60));
end
backspace(1,fmt,0,0);
fprintf(1,fmt,0,0);
fprintf(1,'\n');