function pc = calccf ( XI, C )

%*****************************************************************************80
%
%MATLAB version of SUBROUTINE CALCCF on page 287 of conte/deboor
% returns in the structure  pc  the breaks  XI and coefficients  c
% of 
%  f(x) = c(1,i) + (x-XI(i))*(c(2,i)+(x-XI(i))*(c(3,i)+(x-XI(i))*c(4,i))),
% for
%                x < XI(2),   i=1,
%       XI(i) <= x < XI(i+1), i=2:N-1,   with  N := length(XI)-1
%       XI(i) <= x ,          i= N
% that satisfies the interpolation conditions
%     f(XI(j)) = C(1,j),  f'(XI(j)) = C(2,j), j=1:length(XI)
% for the given  2-by-(N+1) array  C .
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
  N = length(XI)-1; 
  DX = diff(XI);
  DIVDF1 = diff(C(1,:))./DX; 
  DIVDF3 = C(2,1:N) - 2*DIVDF1 + C(2,2:N+1);
  c = [C([1 2],1:N); zeros(2,N)];
  c(3,:) = (DIVDF1 - c(2,:) - DIVDF3)./DX;
  c(4,:) = DIVDF3./(DX.*DX);

  pc = struct('breaks',XI,'coefs',c);

  return
end

