function y = PPeval(pp,x)
% usage: y = PPeval(pp,x)
% description:  given input pp a PP structure and x a vector of
% absicssas, this routine returns the vector of values of the PP
% structure pp at the coordinates of x.
 
% local variables: 
% j,k,m:  index variables
% n: size of node array
% klim: number of knots
% ord: order of pp
% xtmp: temporary variable

n = length(x);

y = zeros(size(x));
klim = pp.knum;
ord = pp.order;
for j = 1:n % loop over entries of x 
  xtmp = x(j); 
  % find index of interval containing entry with binary search
  low = 1;
  high = klim;
  while (low + 1 < high)
    mid = fix((low+high)/2);
    if (xtmp >= pp.knots(mid))
      low = mid;
    else
      high = mid;
    end;
  end;
  dx = xtmp - pp.knots(low);
  % use Horner's method to evaluate the polynomial
  y(j) = pp.coefs(low,1);
  for m = 2:ord
    y(j) = dx*y(j)+pp.coefs(low,m);
  end;
end;
