function SD = sp_deriv(S,ord)
%
% SD = dspline(S,ord)
%
% Function to compute the spline structure for the
% first or second derivative of a cubic spline structure.
%
% 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 inacurate
%
% Outupts:
% SD = spline structure for derivative
D = diag(3:-1:1,1);
SD = S;
for i = 1:ord
SD.coefs = SD.coefs*D;
end