function uiwait(hFigDlg)
%UIWAIT Block execution and wait for resume.
%   UIWAIT(FIG) blocks execution until either UIRESUME is called or the
%   figure FIG is destroyed (closed).  UIWAIT with no input arguments is
%   the same as UIWAIT(GCF).
%
%   When the dialog or figure is created, it should have a 
%   uicontrol that either:
%       has a callback that calls UIRESUME, or
%       has a callback that destroys the dialog box
%   since these are the only methods that can resume program execution
%   after it has been suspended by the waitfor command.
%
%   UIWAIT is a convenient way to use the waitfor command and is used in
%   conjunction with a dialog box or figure.  When used with a modal
%   dialog (which captures all keyboard and mouse events), it provides a
%   way to suspend an m-file and prevent the user from accessing any
%   MATLAB window until they respond to the dialog box.
%
%   See also UIRESUME, WAITFOR.

%   Copyright 1984-2000 The Mathworks, Inc. 
%   $Revision: 1.9 $  $Date: 2000/06/02 04:41:55 $

% -------- Validate argument
if nargin < 1,
    hFigDlg = gcf;
end
if ~strcmp (get(hFigDlg, 'Type'), 'figure')
    error ('Input argument must be of type Figure')
end

% --------  Set the dialog's waitstatus property, and call waitfor
set (hFigDlg, 'vis', 'on', 'waitstatus', 'waiting');
waitfor (hFigDlg, 'waitstatus', 'inactive');
