function[ ] = jcgrid(zeta,sigma)

% JCGRID  Generate s-plane grid lines for a root locus or pole-zero map.
%
%       JCGRID(zeta,sigma) generates a grid of constant damping ratio (zeta)
%	and constant sigma over an existing continuous s-plane root locus or 
%       pole-zero map. 
%
% INPUTS        zeta, sigma are vectors with desired grid values
% OUTPUTS	none
% SIDEEFFECTS   A zeta-sigma grid over the current figure.
%
% SYNTAX   JCGRID(zeta,sigma)	% plots sigma-zeta grid
%          JCGRID([],sigma)	% plots only sigma grid
%          JCGRID(zeta,[]) or
%          JCGRID(zeta)		% plots only zeta  grid
%
%       See also: RLOCUS, ZGRID, SGRID, and PZMAP.

% Modified by Juan C. Cockburn from JGRID.M
% Revised: JCCK 3-9-97

if (nargin<1) | (nargin>2), 
   error('Type help jgrid for ussage'),
elseif nargin==1,	% only zeta grid
   sigma=0;
else 			% take care of empty arguments
  if isempty(zeta),  zeta=1;  end
  if isempty(sigma), sigma=0; end
end

status = ishold;

hold on

% Plot sigma lines
    limits = axis;
    for i = 1:30*max(limits(:)),
        sl(i) = 1;
    end
    [w,z] = meshgrid(sigma,sl);
    re = -w.*z;
    [mcols, nrows] = size(z);
    im = 0.1:0.1:3*max(limits(:));
    plot(re,im,'w:',re,-im,'w:');
    hold on

% Plot damping ratio lines
    [w,z] = meshgrid([0;sigma(:);2*max(limits(:))]',zeta);
    re =  -w.*z;
	[mcols, nrows] = size(z);
    im = w.*sqrt( ones(mcols,nrows) -z.*z);
	plot(re',im','w:',re',-im','w:');

if (~status), hold off, end
