function MargRespObj = pvset(MargRespObj,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 and K. Gondoly
%   Revised: A. DiVergilio, 11-99
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.16 $ $Date: 2000/06/14 20:10:05 $

ni = nargin;
ContextMenu = get(MargRespObj.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 'MagnitudeUnits'
      if strncmpi(Value,'a',1)
         NewUnit = 'abs';
      elseif strncmpi(Value,'d',1)
         NewUnit = 'dB';
      else
         error(sprintf('Bad value for response property %s.',Property))
      end
      OldUnit = MargRespObj.MagnitudeUnits;
      MargRespObj.MagnitudeUnits = NewUnit;
      if ~strcmpi(OldUnit,NewUnit)
         MargRespObj = newunits(MargRespObj,'magnitude',OldUnit);
      end

   case 'PhaseUnits'
      if strncmpi(Value,'d',1)
         NewUnit = 'deg';
      elseif strncmpi(Value,'r',1)
         NewUnit = 'rad';
      else
         error(sprintf('Bad value for response property %s.',Property))
      end
      OldUnit = MargRespObj.PhaseUnits;
      MargRespObj.PhaseUnits = NewUnit;
      if ~strcmpi(OldUnit,NewUnit)
         MargRespObj = newunits(MargRespObj,'phase',OldUnit);
      end

   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 = MargRespObj.FrequencyUnits;
      MargRespObj.FrequencyUnits = NewUnit;
      if ~strcmpi(OldUnit,NewUnit)
         MargRespObj = newunits(MargRespObj,'frequency',OldUnit);
      end

   case  'StabilityMarginValue'
      error(sprintf('Attempt to modify read-only property %s',Property))

   otherwise
      % PROPERTY is a parent @response property.
      RespObjProp([i i+1]) = logical(1);
   end
end

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