function a = set(a,varargin)
% SET Set Body properties and return the updated object
propertyArgIn = varargin;
while length(propertyArgIn) >= 2,
   prop = propertyArgIn{1};
   val = propertyArgIn{2};
   propertyArgIn = propertyArgIn(3:end);
   switch prop
   case 'name'
      a.name = val;
   case 'dof'
      a.dof = val;
   case 'I'
      a.I = val;
   case 'mass'
      a.mass = val;
   case 'disp'
      a.disp = val;
   case 'xG'
      a.xG = val;
   case 'xB'
      a.xB = val;
   case 'S'
      a.S = val;
   case 'S11'
      a.S11 = val;
   case 'S22'
      a.S22 = val;
      
   case 'mu_inf'
      a.mu_inf = val;
      
   case 'dt'
      a.dt = val;
      a.t = a.dt*(0:a.N-1);
      
   case 'N'
      old_N = a.N;
      old_x = a.x;
      old_xdot = a.xdot;
      old_xddot = a.xddot;

      a.N = val;
           
      a.t = a.dt*(0:a.N-1);
      a.x = zeros(a.N,a.dof);  %Relative to body in equilibrium position.
      a.xdot = zeros(a.N,a.dof);  
      a.xddot = zeros(a.N,a.dof); 
      a.x(1:min(a.N,old_N),:) = old_x(1:min(a.N,old_N),:);
      a.xdot(1:min(a.N,old_N),:) = old_xdot(1:min(a.N,old_N),:);
      a.xddot(1:min(a.N,old_N),:) = old_xddot(1:min(a.N,old_N),:);   
      
      for n = 1:a.n_Forces
         old_F = a.Forces{n};
         a.Forces{n} = zeros(a.N,a.dof);
         a.Forces{n} = old_F(1:min(a.N,old_N),:);
      end
      
      
   case 'sv'
      a.sv = val;    
      
   case 'x0'
      a.x0 = val; 
      
   case 'Fixed'  %(0 = Free to move)   (1 = Fixed in space)   (2 = Prescribed motion)
      a.Fixed = val;
      
   case 'g'
      a.g = val;
   case 'rho'
      a.rho = val;      
      
%   case 'n_Forces'  %This should never be set explicity, add_force_fcn
%   will increment
%      a.n_Forces = val;
%      a.Forces = cell(val,1);
        
   case 'Area'   
      a.Area=val;
   case 'Cd'
      a.Cd=val;
   case 'AreaW'
      a.AreaW=val;  
   case 'CdW'
      a.CdW=val;    
      
   otherwise
      error('Invalid Body property');
   end
end