%N lspoly %F $MIR/src/subs/lspoly.for
%D Least squares polynomial fit
%P mchw
%: polynomials
%B
      subroutine lspoly(nn,l,x,y,w,z,coeff)

      implicit none
      integer nn,l
      real x(l),y(l),z(l),w(l),coeff(9)

       Least-squares polynomial fit of degree NN, up to 8, for L data
       points [X,Y] w. weights W.

       Fit is with Legendre polynomials of argument XL=C*(X-XM),
       where XM is midpoint of extreme range of X, and C is a
       factor that converts ends of range to +1 and -1.
       Coefficients returned are those of power series, however.
       COEFF(J) is coefficient of (X-x(1))**(J-1). 
       Also returned are Z(I), values of the polynomial at X(I).
       Calling routine must dimension COEFF at least NN+1.

       To evaluate polynomials, see also VALPOL.
