function PZRespObj = pvset(PZRespObj,varargin)
%PVSET  Set properties of Response Objects.
%
%   RespObj = PVSET(RespObj,'Property1',Value1,'Property2',Value2,...)
%   sets the values of the properties with exact names 'Property1',
%   'Property2',...
%
%   See also SET.

%   Authors: P. Gahinet
%   Revised for Response Objects: K. Gondoly, 2-17-98
%   Revised: A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.18 $ $Date: 2000/06/14 20:08:43 $

ni = nargin;
ContextMenu = get(PZRespObj.response,'UicontextMenu');
RespObjProp = logical(zeros(ni-1,1));

for i=1:2:ni-1,
   % Set each Property Name/Value pair in turn. 
   Property = varargin{i};
   Value = varargin{i+1};
   if ischar(Value),
      Value = lower(Value);
   end
   
   switch Property
   case 'FrequencyUnits',
      if strncmpi(Value,'h',1)
         NewUnit = 'Hz';
      elseif strncmpi(Value,'r',1)
         NewUnit = 'rad/sec';
      else
         error(sprintf('Bad value for response property %s.',Property))
      end
      OldUnit = PZRespObj.FrequencyUnits;
      PZRespObj.FrequencyUnits = NewUnit;
      if ~strcmpi(OldUnit,NewUnit)
         PZRespObj = newunits(PZRespObj,'frequency',OldUnit);
      end

   case 'GridLabelType',
      if strncmpi(Value,'d',1)
         NewUnit = 'damping';
      elseif strncmpi(Value,'o',1)
         NewUnit = 'overshoot';
      else
         error(sprintf('Bad value for response property %s.',Property))
      end
      OldUnit = PZRespObj.GridLabelType;
      PZRespObj.GridLabelType = NewUnit;
      if ~strcmpi(OldUnit,NewUnit) & strcmp(get(PZRespObj,'Grid'),'on')
         PZRespObj = plotgrid(PZRespObj);
      end

   case 'GridLines',
      PZRespObj.GridLines = Value;
      
   case 'GridType',
      lVal = length(Value);
      ValidTypes = {'sgrid';'zgrid';'square'};
      CurrentType = find(strncmpi(Value,ValidTypes,lVal));
      if isempty(CurrentType) | length(CurrentType)>1,
         error(sprintf('Bad value for response property: %s.',Property))
      end
      
      if strcmpi(get(PZRespObj,'Grid'),'on'), 
         % Turn off old grid type
         PZRespObj = respfcn('setpzgrid',PZRespObj,'off');
         % Change type
         PZRespObj.GridType = ValidTypes{CurrentType};
         % Turn on new grid type         
         PZRespObj = respfcn('setpzgrid',PZRespObj,'on');
      else
         % Just change grid type 
         PZRespObj.GridType = ValidTypes{CurrentType};
      end
        
   case {'SampleTimes','Poles','Zeros'},
      error(sprintf('Attempt to modify read-only property %s',Property))
      
   case 'Grid'
      % Special grid for PZPLOT
      PZRespObj = respfcn('setpzgrid',PZRespObj,Value);
      
   otherwise
      % PROPERTY is a regular parent @response property. 
      RespObjProp([i i+1]) = logical(1);
      
   end
end % for i

% Set all @response properties
RespObjProp = find(RespObjProp);
if ~isempty(RespObjProp)
   PZRespObj.response = pvset(PZRespObj.response,varargin{RespObjProp});
end
