--- 
:name: sgels
:md5sum: 994913d24d2a9adf9a93e5dbac66f485
:category: :subroutine
:arguments: 
- trans: 
    :type: char
    :intent: input
- m: 
    :type: integer
    :intent: input
- n: 
    :type: integer
    :intent: input
- nrhs: 
    :type: integer
    :intent: input
- a: 
    :type: real
    :intent: input/output
    :dims: 
    - lda
    - n
- lda: 
    :type: integer
    :intent: input
- b: 
    :type: real
    :intent: input/output
    :dims: 
    - m
    - nrhs
    :outdims:
    - n
    - nrhs
- ldb: 
    :type: integer
    :intent: input
- work: 
    :type: real
    :intent: output
    :dims: 
    - MAX(1,lwork)
- lwork: 
    :type: integer
    :intent: input
    :option: true
    :default: MIN(m,n) + MAX(MIN(m,n),nrhs)
- info: 
    :type: integer
    :intent: output
:substitutions: 
  m: lda
  ldb: MAX(m,n)
:fortran_help: "      SUBROUTINE SGELS( TRANS, M, N, NRHS, A, LDA, B, LDB, WORK, LWORK, INFO )\n\n\
  *  Purpose\n\
  *  =======\n\
  *\n\
  *  SGELS solves overdetermined or underdetermined real linear systems\n\
  *  involving an M-by-N matrix A, or its transpose, using a QR or LQ\n\
  *  factorization of A.  It is assumed that A has full rank.\n\
  *\n\
  *  The following options are provided: \n\
  *\n\
  *  1. If TRANS = 'N' and m >= n:  find the least squares solution of\n\
  *     an overdetermined system, i.e., solve the least squares problem\n\
  *                  minimize || B - A*X ||.\n\
  *\n\
  *  2. If TRANS = 'N' and m < n:  find the minimum norm solution of\n\
  *     an underdetermined system A * X = B.\n\
  *\n\
  *  3. If TRANS = 'T' and m >= n:  find the minimum norm solution of\n\
  *     an undetermined system A**T * X = B.\n\
  *\n\
  *  4. If TRANS = 'T' and m < n:  find the least squares solution of\n\
  *     an overdetermined system, i.e., solve the least squares problem\n\
  *                  minimize || B - A**T * X ||.\n\
  *\n\
  *  Several right hand side vectors b and solution vectors x can be \n\
  *  handled in a single call; they are stored as the columns of the\n\
  *  M-by-NRHS right hand side matrix B and the N-by-NRHS solution \n\
  *  matrix X.\n\
  *\n\n\
  *  Arguments\n\
  *  =========\n\
  *\n\
  *  TRANS   (input) CHARACTER*1\n\
  *          = 'N': the linear system involves A;\n\
  *          = 'T': the linear system involves A**T. \n\
  *\n\
  *  M       (input) INTEGER\n\
  *          The number of rows of the matrix A.  M >= 0.\n\
  *\n\
  *  N       (input) INTEGER\n\
  *          The number of columns of the matrix A.  N >= 0.\n\
  *\n\
  *  NRHS    (input) INTEGER\n\
  *          The number of right hand sides, i.e., the number of\n\
  *          columns of the matrices B and X. NRHS >=0.\n\
  *\n\
  *  A       (input/output) REAL array, dimension (LDA,N)\n\
  *          On entry, the M-by-N matrix A.\n\
  *          On exit,\n\
  *            if M >= N, A is overwritten by details of its QR\n\
  *                       factorization as returned by SGEQRF;\n\
  *            if M <  N, A is overwritten by details of its LQ\n\
  *                       factorization as returned by SGELQF.\n\
  *\n\
  *  LDA     (input) INTEGER\n\
  *          The leading dimension of the array A.  LDA >= max(1,M).\n\
  *\n\
  *  B       (input/output) REAL array, dimension (LDB,NRHS)\n\
  *          On entry, the matrix B of right hand side vectors, stored\n\
  *          columnwise; B is M-by-NRHS if TRANS = 'N', or N-by-NRHS\n\
  *          if TRANS = 'T'.  \n\
  *          On exit, if INFO = 0, B is overwritten by the solution\n\
  *          vectors, stored columnwise:\n\
  *          if TRANS = 'N' and m >= n, rows 1 to n of B contain the least\n\
  *          squares solution vectors; the residual sum of squares for the\n\
  *          solution in each column is given by the sum of squares of\n\
  *          elements N+1 to M in that column;\n\
  *          if TRANS = 'N' and m < n, rows 1 to N of B contain the\n\
  *          minimum norm solution vectors;\n\
  *          if TRANS = 'T' and m >= n, rows 1 to M of B contain the\n\
  *          minimum norm solution vectors;\n\
  *          if TRANS = 'T' and m < n, rows 1 to M of B contain the\n\
  *          least squares solution vectors; the residual sum of squares\n\
  *          for the solution in each column is given by the sum of\n\
  *          squares of elements M+1 to N in that column.\n\
  *\n\
  *  LDB     (input) INTEGER\n\
  *          The leading dimension of the array B. LDB >= MAX(1,M,N).\n\
  *\n\
  *  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK))\n\
  *          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.\n\
  *\n\
  *  LWORK   (input) INTEGER\n\
  *          The dimension of the array WORK.\n\
  *          LWORK >= max( 1, MN + max( MN, NRHS ) ).\n\
  *          For optimal performance,\n\
  *          LWORK >= max( 1, MN + max( MN, NRHS )*NB ).\n\
  *          where MN = min(M,N) and NB is the optimum block size.\n\
  *\n\
  *          If LWORK = -1, then a workspace query is assumed; the routine\n\
  *          only calculates the optimal size of the WORK array, returns\n\
  *          this value as the first entry of the WORK array, and no error\n\
  *          message related to LWORK is issued by XERBLA.\n\
  *\n\
  *  INFO    (output) INTEGER\n\
  *          = 0:  successful exit\n\
  *          < 0:  if INFO = -i, the i-th argument had an illegal value\n\
  *          > 0:  if INFO =  i, the i-th diagonal element of the\n\
  *                triangular factor of A is zero, so that A does not have\n\
  *                full rank; the least squares solution could not be\n\
  *                computed.\n\
  *\n\n\
  *  =====================================================================\n\
  *\n"
