function [out1,d,k,center,dimpjd,mm] = mpbrk(mp,part) 
%MPBRK parts of a multivariate polynomial in (shifted normalized) power form 
%
%        [COEFS,D,K,CENTER,DIMPJD,M] = MPBRK(MP)
%
% breaks the mp-form in MP into its parts and returns as many of them as
% are specified by the output arguments.
%
%        OUT1 = MPBRK(MP, PART)
%
% returns the part, specified by PART, of the multivariate polynomial in 
% (shifted normalized) power form described in MP. 
%
% The string PART may be (the beginning character(s) of) one of the following 
% strings: 'coefs', 'dimension', 'k' or 'degree', 'center', 'poldims', 'mm'.
%
% If no output it specified, prints all the details instead.
%
%   See also: MPMAK

% cb: 26jul97, 10aug97; reverted to v4 7sep97
%   Copyright (c) 1997 by C. de Boor

%v5 % good only for v5
%v5if iscell(mp)        % mp = {94, center, coefs, dimpjd, mm};
%v5   if mp{1}~=94
%v5      error(['The input cell array does not seem to describe', ...
%v5             ' a multivariate polynomial in shifted power form.'])
%v5   end
%v5   centeri = mp{2}; coefsi = mp{3}; dimpjdi = mp{4}; mmi = mp{5};
%v5   di = length(centeri); [dfi,nci] = size(coefsi); ki = length(dimpjdi)-2;
%v5else                 % dealing with pre-v5 MATLAB
   if mp(1)~=94
      error(['The input array does not seem to describe', ...
             ' a multivariate polynomial in shifted power form.'])
   end
   
   dfi = mp(2); di = mp(3); centeri = mp(3+[1:di]).'; ki = mp(4+di);
   sofar = 4+di;
   dimpjdi = mp(sofar+[1:ki+2]); sofar = sofar +ki+2; nci = dimpjdi(ki+2);
   coefsi = reshape(mp(sofar+[1:(dfi*nci)]),dfi,nci); sofar = sofar + dfi*nci;
   mmi = reshape(mp(sofar+[1:di*nci]),di,nci);
%v5end

if nargin>1 % a specific part is called for
   if nargout>1, error('Too many output arguments for the given input.')
%v5   else
%v5      switch part(1)
%v5      case 'c'
%v5         if length(part)<2, error('Second argument is ambiguous'), end
%v5         switch part(2)
%v5         case 'o'
%v5            out1 = coefsi; return
%v5         case 'e' 
%v5            out1 = centeri; return
%v5         otherwise
%v5            error(sprintf('''%s'' is not part of a mp-form.',part))
%v5         end
%v5      case 'd'
%v5         if length(part)<2, error('Second argument is ambiguous'), end
%v5         switch part(2)
%v5         case 'i', out1 = di; return
%v5         case 'e', out1 = ki; return
%v5         otherwise
%v5            error(sprintf('''%s'' is not part of a mp-form.',part))
%v5         end
%v5      case 'k', out1 = ki; return
%v5      case 'p', out1 = dimpjdi; return
%v5      case 'm', out1 = mmi; return
%v5      otherwise
%v5         error(sprintf('''%s'' is not part of a mp-form.',part))
%v5      end
%v5   end
   else
      if part(1)=='c'
         if length(part)<2, error('Second argument is ambiguous')
         elseif part(2)=='o'
            out1 = coefsi; return
         elseif part(2)=='e' 
            out1 = centeri; return
         else
            error(sprintf('''%s'' is not part of a mp-form.',part))
         end
      elseif part(1)=='d'
         if length(part)<2, error('Second argument is ambiguous')
         elseif part(2)=='i', out1 = di; return
         elseif part(2)=='e', out1 = ki; return
         else
            error(sprintf('''%s'' is not part of a mp-form.',part))
         end
      elseif part(1)=='k', out1 = ki; return
      elseif part(1)=='p', out1 = dimpjdi; return
      elseif part(1)=='m', out1 = mmi; return
      else
         error(sprintf('''%s'' is not part of a mp-form.',part))
      end
   end
else
   if nargout==0 % print out all the parts
      fprintf(['The input is a ',num2str(di),'-variate'])
      if dfi>1 fprintf([' R^',num2str(dfi),'-valued']), end
      fprintf([' polynomial of degree ',num2str(ki), ...
               ',\n centered at the point\n'])
      disp(centeri)
      % coefsi = [coefsi;mmi];
      fprintf('with coefficients of degree 0 :\n')
      disp(coefsi(:,1))
      for j=1:ki
         fprintf(['and coefficients of degree ',num2str(j),' :\n'])
         disp(coefsi(:,dimpjdi(j+1)+1:dimpjdi(j+2)))
      end
   else
      out1=coefsi; d=di; k=ki; center=centeri; dimpjd=dimpjdi; mm=mmi;
   end
end
