function [augknot,addl]=augknt(knots,k,mults)
% AUGKNT	Augment a knot sequence.
%
%        [augknot,addl]=augknt(knots,k[,mults])
%
% returns an augmented knot sequence which has the first and last knot with
% exact multiplicity  k . (This may actually shorten the knot sequence.)
% Also returns the number of knots added on the left. (This may be negative.)
%
%   If the third argument is present, the augmented knot sequence will, in 
% addition, contain each interior knot  mults  times. If  knots  is strictly
% increasing, this insures that the splines of order  k  with knotsequence
%  augknot  satisfy  k-mults  smoothness conditions across each interior knot.

% C. de Boor / latest change: Feb.25, 1989
% Copyright (c) 1990-92 by Carl de Boor and The MathWorks, Inc.

if (nargin==3),ones(mults,1)*knots(:)';knots=ans(:)';end
   
km1=k-1;
augknot=[knots(1)*ones(1,km1) knots(:)' knots(length(knots))*ones(1,km1)];

index=find(diff(augknot)>0);
augknot=augknot(index(1)-km1:index(length(index))+k);

find(diff(knots)>0);addl=k-ans(1);
