function RLRespObj = pvset(RLRespObj,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, 5-99
%   Revised: A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.6 $ $Date: 2000/06/14 20:06:39 $

ni = nargin;
ContextMenu = get(RLRespObj.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 = RLRespObj.FrequencyUnits;
      RLRespObj.FrequencyUnits = NewUnit;
      if ~strcmpi(OldUnit,NewUnit)
         RLRespObj = newunits(RLRespObj,'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 = RLRespObj.GridLabelType;
      RLRespObj.GridLabelType = NewUnit;
      if ~strcmpi(OldUnit,NewUnit) & strcmp(get(RLRespObj,'Grid'),'on')
         RLRespObj = plotgrid(RLRespObj);
      end

   case 'GridLines',
      RLRespObj.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(RLRespObj,'Grid'),'on'), 
         % Turn off old grid type
         RLRespObj = respfcn('setpzgrid',RLRespObj,'off');
         % Change type
         RLRespObj.GridType = ValidTypes{CurrentType};
         % Turn on new grid type         
         RLRespObj = respfcn('setpzgrid',RLRespObj,'on');
      else
         % Just change grid type 
         RLRespObj.GridType = ValidTypes{CurrentType};
      end
      
   case 'Data'
      error(sprintf('Attempt to modify read-only property %s',Property))
      
   case 'Grid' 
      % Special grid for RLPLOT 
      RLRespObj = respfcn('setpzgrid',RLRespObj,Value); 
      
   otherwise
      % PROPERTY is a parent @response property. 
      RespObjProp([i i+1]) = logical(1);
      
   end % switch Property
end

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