FUNCTION SPLINEFIT,X,Y,W,XS,YS,SIGYS,DELY
;+
; NAME:
; SPLINEFIT
; PURPOSE:
; Non-linear least squares fit to a cubic spline function of an
; arbitrary number of nodes.
; CATEGORY:
; E2 - Curve and Surface Fitting
; CALLING SEQUENCE:
; YFIT = SPINEFIT(X,Y,W,XS,YS,SIGYS,DELY)
; INPUTS:
; X = Row vector of independent variables.
; Y = Row vector of dependent variable, same length as x.
; W = Row vector of weights, same length as x and y.
; For no weighting
; w(i) = 1., instrumental weighting w(i) =
; 1./y(i), etc.
; XS = Vector containing the x-positions of the spline nodes
; YS = Vector containing the intial y-position for the spline
; at each node (same length as XS)
; OPTIONAL INPUTS:
; DELY = distance to use in computing numerical derivatives
; with respect to YS values. The distance is DELY*YS(i)
; (Default= 0.001)
;
; OUTPUTS:
; YS = Vector of parameters containing fit.
; Function result = YFIT = Vector of calculated
; values. YFIT=CSPLINE(XS,YS,X)
; OPTIONAL OUTPUT PARAMETERS:
; Sigys = Vector of standard deviations for parameters
; ys.
;
; COMMON BLOCKS:
; NONE.
; RESTRICTIONS:
; NONE.
; PROCEDURE:
; Copied from "CURFIT", least squares fit to a non-linear
; function, pages 237-239, Bevington, Data Reduction and Error
; Analysis for the Physical Sciences.
;
; "This method is the Gradient-expansion algorithm which
; compines the best features of the gradient search with
; the method of linearizing the fitting function."
;
; Iterations are perform until the chi square changes by
; only 0.1% or until 20 iterations have been performed.
;
; The initial guess of the parameter values should be
; as close to the actual values as possible or the solution
; may not converge.
;
; MODIFICATION HISTORY:
; Modified (D. Lindler, Feb. 87) version of IDL routine CURVEFIT
; written by DMS, RSI, September, 1982.
;-
ON_ERROR,2 ;RETURN TO CALLER IF ERROR
YS = 1.*YS ;MAKE PARAMS FLOATING
NTERMS = N_ELEMENTS(YS) ;# OF PARAMS.
NFREE = (N_ELEMENTS(Y)