function pp=mkpp(breaks,coefs,d)
%MKPP Make piece-wise polynomial.  
%   PP = MKPP(BREAKS,COEFS) puts together a pp function from the
%   breaks and coefficients input, with COEFS(i,:) the K coefficients,
%   from highest to lowest, of the i-th polynomial piece. The number L of
%   polynomial pieces is determined as
%        L = LENGTH(BREAKS)-1 .
%   The  order  K  of the pp function is obtained as
%        K = LENGTH(COEFS(:))/L ,
%   and this ratio had better be an integer. 
%
%   If the optional third argument is a positive integer, the pp function
%   is taken to be d-vector valued. This means that COEFS is interpreted
%   to contain, in COEFS(r,i,:), the K coefficients of the i-th polynomial
%   piece of the r-th component of the pp function. In particular, K is
%   obtained as  K = LENGTH(COEFS(:))/(D*L) .
%
%   See also UNMKPP, PPVAL, SPLINE.

%   Carl de Boor 7-2-86
%   Revised 9-30-88 LS
%   Revised 11-18-93 CB to use spline toolbox format
%   Revised 10-14-97 CB to handle vector-valued functions
%   Copyright (c) 1984-1998 by The MathWorks, Inc.
%   $Revision: 1.2 $  $Date: 1998/08/12 14:07:23 $

if nargin==2, d = 1; end
coefs=coefs(:).';dlk=length(coefs);l=length(breaks)-1;k=fix(dlk/(d*l)+100*eps);
if (k<=0)|(d*l*k~=dlk)
   error(['Number of polynomial pieces, ' int2str(l) ', is incompatible with number of coefficients, ' int2str(dlk) '.'])
else
   pp=[10 d l breaks(:).' k coefs];
end
