function cla(RespObj,IOflag,ASflag)
%CLA Clear current Response Object.
%   CLA(RespObj) clears the Response Object plot represented by RespObj,
%   where RespObj is any response object handle. 

%   CLA(RespObj,ChildFlag) indicates if the any lower level GUIs
%   should be closed when the response plot is cleared. By default, 
%   ChildFlag is 1 and the I/O Selector and Array Selector are closed. 
%   For the LTI Viewer, these windows are left open when toggling 
%   between response plot types.
%
%   CLA(RespObj,IOflag,ASflag) can be used to separate specify if
%   the I/O Selector and Array Selector should be closed.

%   Authors: Karen Gondoly, 1-27-98
%   Revised: Adam DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.12 $  $Date: 2000/06/14 20:07:28 $

% Overloaded CLA for Response Objects

ni=nargin;

if ni<3 | isempty(ASflag),
   ASflag=1;
end

if ni<2 | isempty(IOflag), 
   IOflag=1;
end

LTIdisplayAxes = RespObj.PlotAxes;
ResponseHandles = RespObj.ResponseHandles;

%---Close any I/O selector
SelectorHandle = get(RespObj.UIContextMenu.ChannelMenu,'UserData');
if ishandle(SelectorHandle) & IOflag,
   close(SelectorHandle)
end % if ishandle(SelectorHandle)

%---Close any array selector
ArrayHandle = get(RespObj.UIContextMenu.ArrayMenu,'UserData');
if ishandle(ArrayHandle) & ASflag,
   %---Must delete the Array Selector since its CloseRequestFcn was reset
   delete(ArrayHandle)
end % if ishandle(SelectorHandle)

%---Get all children of Display axes
Temp = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','on');
allkids = get(LTIdisplayAxes,{'Children'});
allkids = cat(1,allkids{:});
set(0,'ShowHiddenHandles',Temp);

%---Delete all graphical children of LTI display axes
gkids = [findobj(allkids,'flat','type','line') ;...
      findobj(allkids,'flat','type','patch') ;...
      findobj(allkids,'flat','type','text','tag','CSTgridLines')];
gkids = gkids(ishandle(gkids));
set(gkids,'DeleteFcn','')
delete(gkids)

%---Hide the LTIdisplayAxes and mark as free
set(LTIdisplayAxes,'XGrid','off','YGrid','off');
set(LTIdisplayAxes,'Tag','FreeDisplayAxes','Visible','off');

%---Erase the BackgroundAxes hidden line
L = findobj(RespObj.BackgroundAxes,'Tag','BackgroundResponseObjectLine');
set(L,'DeleteFcn','');
delete(L)

%---Delete Handles of listeners and labels
delete(RespObj.Handles.Listeners);
delete(RespObj.Handles.Title);
delete(RespObj.Handles.Xlabel);
delete(RespObj.Handles.Ylabel);
RespObj.Handles = [];

%---Delete the UIContextMenu
delete(RespObj.UIContextMenu.Main)

%---Turn BackgroundAxes visible and turn off any hold
set(RespObj.BackgroundAxes,'Nextplot','replace');
