%N llsqu %F $MIR/src/subs/lsqu.for
%D Linear least squares fitting
%P bpw
%: least-squares, fitting
%B
        subroutine llsqu(f,A,n,m,c,ifail,B,pivot)

        implicit none
        integer m,n,ifail,pivot(n)
        real f(m),A(n,m),c(n),B(n,n)

  Solve a linear least squares problem in "n" unknowns, and "m" equations.
  As usual, m must be greater or equal to n.

  The problem is solved by finding:
                                       t
                                 y' = A y

  and                                  t
                                 B  = A A

  then solving this system of linear equations.

  The LINPACK routines SGEFA and SGESL are called to solve a system of
  linear equations.

  Inputs:
    n          Number of unknowns.
    m          Number of equations.
    f          Function values for the m equations.
    A          The matrix giving the weights for each equation.

  Scratch:
    B
    pivot

  Output:
    c          The solution coefficients.
    ifail      Success status:
                 0     Finished OK.
                 1     Singular matrix encountered.
