! -*- f90 -*-
!
! Contains wrappers for the following LAPACK routines:
!
!  Simple Driver Routines for Standard and Generalized Linear Least Squares Problems:
!   gels (using QR or LQ factorization, assume full rank) - Not Implemented
!   gglse (solve LSE problem using GRQ) - Not Implemented
!   ggglm (solve GLM problem using GQR) - Not Implemented
!
!  Divide and Conquer and Expert Driver Routines for Linear Least Squares Problems:
!   gelss (using SVD, allow rank-deficiency)
!   gelsy (using complete orthogonal factor) - Not Implemented
!   gelsd (using D&C SVD, allow rank-deficiency) - Not Implemented
!


   subroutine <prefix>gelss(m,n,minmn,maxmn,nrhs,a,b,s,cond,r,work,lwork,<,,rwork\,,rwork\,>info)

   ! v,x,s,rank,info = gelss(a,b,cond=-1.0,overwrite_a=0,overwrite_b=0)
   ! Solve Minimize 2-norm(A * X - B).

     callstatement (*f2py_func)(&m,&n,&nrhs,a,&m,b,&maxmn,s,&cond,&r,work,&lwork,<,,rwork\,,rwork\,>&info)
     callprotoargument int*,int*,int*,<ctype>*,int*,<ctype>*,int*,<ctypereal>*,<ctypereal>*,int*,<ctype>*,int*,<,,float*\,,double*\,>int*

     integer intent(hide),depend(a):: m = shape(a,0)
     integer intent(hide),depend(a):: n = shape(a,1)
     integer intent(hide),depend(m,n):: minmn = MIN(m,n)
     integer intent(hide),depend(m,n):: maxmn = MAX(m,n)
     <ftype> dimension(m,n),intent(in,out,copy,out=v) :: a

     integer depend(b),intent(hide):: nrhs = shape(b,1)
     <ftype> dimension(maxmn,nrhs),check(maxmn==shape(b,0)),depend(maxmn) :: b
     intent(in,out,copy,out=x) b

     integer intent(out)::info
     ! <_lwork=3*minmn+MAX(2*minmn\,MAX(maxmn\,nrhs)),\0,2*minmn+MAX(maxmn\,nrhs),\2>
     integer optional,intent(in),depend(nrhs,minmn,maxmn), &
          check(lwork>=1) &
          :: lwork=<_lwork>
          !check(lwork>=<_lwork>)
     <ftype> dimension(lwork),intent(hide),depend(lwork) :: work
     <ftypereal> dimension(5*minmn-1),intent(hide),depend(lwork) :: rwork
     <ftypereal> intent(in),optional :: cond = -1.0
     integer intent(out,out=rank) :: r
     <ftypereal> intent(out),dimension(minmn),depend(minmn) :: s

   end subroutine <prefix>gelss

