function SD = dspline(S,ord)
%
% SD = dspline(S,ord)
%
% Function to compute the first or second derivative
% of a cubic spline.
%
% Inputs:
% S = spline structure
% ord = order of derivative (1 or 2)
% In theory you can take a 3rd derivative,
% but the spline would be a series of
% constant functions and highly innacurate
%
% Outupts:
% SD = spline structure for derivative
D = diag(3:-1:1,1);
SD = S;
for i = 1:ord
SD.coefs = SD.coefs*D;
end