function yy = splineeval(x, a, b, c, d, xx)
% Evaluate a piecewise cubic spline at the points xx.

n = length(x) - 1;
yy = zeros(size(xx));

for i = 1:n
    ix = xx >= x(i) & xx <= x(i + 1);
    yy(ix) = a(i) + ...
        b(i) * (xx(ix) - x(i)) + ...
        c(i) * (xx(ix) - x(i)).^2 + ...
        d(i) * (xx(ix) - x(i)).^3;
end
