function h= waitwaitbar(name, delay, varargin)
% Usage: handle= waitwaitbar('title', delay, )
%
% DEPRECATED: Check out 'waitbar alternative' instead:
% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11398
%
% Creates a waitbar that only shows after a delay -- or never if the waitbar
% is closed before the delay is up.
%
% If you find any errors, please let me know! (peder at axensten dot se)
%
% title: (default: '') The string in the waitbar.
%
% delay: (default: 5) Delay in seconds (0 <= delay <= 60) before waitbar is shown.
%
% EXAMPLE: h= waitwaitbar('Please wait...');
% for i= 1:50
% waitbar(i/50);
% pause(0.2);
% end
% close(h);
%
% NOTE: waitwaitbar('My title', 0, ...) is the same as waitbar(0, 'My title', ...).
%
% HISTORY: Version 1.0, 2006-04-19.
% Version 1.1, 2006-06-06:
% - Now works on Matlab 6.5.1 (R13SP1), probably on older versions too.
%
% Copyright (C) Peder Axensten (peder at axensten dot se), 2006.
% KEYWORDS: waitbar, gui, delay
%
% INSPIRATION:
%
% REQUIREMENTS:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Defaults.
closestr= 'Close the darn thing down! 935672129'; % Kind'a unique string...
if(nargin < 1), name= ''; end
if(nargin < 2), delay= 5.0; end
% Do the stuff
if(ischar(name) && strcmp(name, closestr))
% We are making the waitbar visible (called only by timer, never by user).
try % Ignore errors (it might already be closed).
set(delay, 'Visible', 'on');
catch % Not necessary, but mlint complains if there is no catch.
end
elseif(~ischar(name) || ~isnumeric(delay) || (delay < 0) || (delay > 60))
% Report argument error.
error('See ''help waitwaitbar'' for correct arguments.');
else
% Create the waitbar.
h= waitbar(0.0, name, 'Visible', 'off');
% Matlab 6.5.1 (R13SP1) doesn't seem to read the properties tucked on
% to the end of the arguments. So they must be repeated.
set(h, 'Visible', 'off', varargin{:});
% Define the timer action (call this function with a unique string).
action= sprintf('waitwaitbar(''%s'', %20.16f)', closestr, h);
% Create and start the timer.
start(timer('TimerFcn', action, 'StartDelay', delay));
end
end