function value = rsbrk(rs,part)
%RSBRK Part(s) of a rational spline in B-form
%
%   VALUE = RSBRK(RS,PART) returns the part specified by the string PART which 
%   may be (the beginning character(s) of) one of the following strings: 
%   'knots' or 't', 'coefs', 'number', 'order', 'dim'ension, 'interval'.
%
%   RSBRK(RS) returns nothing, but prints out all the parts.
%
%   See also RSMAK, RPBRK, PPBRK, SPBRK, FNBRK.

%   Carl de Boor 23may99
%   Copyright 1987-2000 by C. de Boor and The MathWorks, Inc.
%   $Revision: 1.3 $  $Date: 2000/04/25 14:14:04 $

if ~isstruct(rs)|~strcmp(rs.form([1 2]),'rB')
   error('The input does not seem to describe a function in rBform.')
end
if nargin>1
   if nargout>1, error('Too many output arguments for the given input.')
   else
      switch part(1)
      case 'd',       value = rs.dim;
      case 'n',       value = rs.number;
      case {'k','t'}, value = rs.knots;
      case 'o',       value = rs.order;
      case 'c',       value = rs.coefs;
      case 'i', % this must be treated differently in multivariate case
         if iscell(rs.knots)
            for i=length(rs.knots):-1:1  % loop backward to avoid redef.
               value{i} = rs.knots{i}([1 end]);
            end
         else
           value = rs.knots([1 end]);
         end
      otherwise
         error(['''',part,''' is not part of a rBform.'])
      end
      return
   end
else
   if nargout==0
      if iscell(rs.knots) % we have a multivariate spline and, at present,
                          % I can't think of anything clever to do; so...
        disp(rs)
      else
        disp('knots(1:n+k)'),disp(rs.knots),
        disp('coefficients(d+1,n)'),disp(rs.coefs),
        disp('number n of coefficients'),disp(rs.number),
        disp('order k'),disp(rs.order),
        disp('dimension d of target'),disp(rs.dim),
      end
   else
      error('More output arguments than expected.')
   end
end
