function RespObj = plotgrid(RespObj)
%PLOTGRID  Plots or adjusts grid for pzmap response plots.
%
%    RESPOBJ = PLOTGRID(RESPOBJ) plots a new grid on the axis 
%    associated with the SISO response object RESPOBJ. 
%
%    See also RESPFCN.

%   Authors: P. Gahinet and K. Gondoly
%   Revised: A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.5 $  $Date: 2000/06/14 20:06:39 $

% Get plot axis and current axis limits
ax = get(RespObj.response,'PlotAxes');

% First destroy existing grid
delete(RespObj.GridLines(ishandle(RespObj.GridLines)))

% Grid Options
s.FrequencyUnits = RespObj.FrequencyUnits;
s.GridLabelType  = RespObj.GridLabelType;
Data = RespObj.Data;
if ~isempty(Data) & all(Data(1).Ts==[Data.Ts]) & Data(1).Ts>0
   s.SampleTime  = Data(1).Ts;  % all systems have same sample time, so use it
else
   s.SampleTime  = -1;  % undefined
end

% Generate and plot new grid 
switch RespObj.GridType
case 'sgrid'
   [GridHandles,TextHandles] = spchart(ax,s);
   RespObj.GridLines = [GridHandles; TextHandles];
case 'zgrid'
   [GridHandles,TextHandles] = zpchart(ax,s);
   RespObj.GridLines = [GridHandles; TextHandles];
case 'square'
   set(ax(:),'Xgrid','on','Ygrid','on')
   RespObj.GridLines = [];
end
