--- 
:name: sgglse
:md5sum: f499922c0d1a1977b7b6beb425364495
:category: :subroutine
:arguments: 
- m: 
    :type: integer
    :intent: input
- n: 
    :type: integer
    :intent: input
- p: 
    :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: 
    - ldb
    - n
- ldb: 
    :type: integer
    :intent: input
- c: 
    :type: real
    :intent: input/output
    :dims: 
    - m
- d: 
    :type: real
    :intent: input/output
    :dims: 
    - p
- x: 
    :type: real
    :intent: output
    :dims: 
    - n
- work: 
    :type: real
    :intent: output
    :dims: 
    - MAX(1,lwork)
- lwork: 
    :type: integer
    :intent: input
    :option: true
    :default: m+n+p
- info: 
    :type: integer
    :intent: output
:substitutions: {}

:fortran_help: "      SUBROUTINE SGGLSE( M, N, P, A, LDA, B, LDB, C, D, X, WORK, LWORK, INFO )\n\n\
  *  Purpose\n\
  *  =======\n\
  *\n\
  *  SGGLSE solves the linear equality-constrained least squares (LSE)\n\
  *  problem:\n\
  *\n\
  *          minimize || c - A*x ||_2   subject to   B*x = d\n\
  *\n\
  *  where A is an M-by-N matrix, B is a P-by-N matrix, c is a given\n\
  *  M-vector, and d is a given P-vector. It is assumed that\n\
  *  P <= N <= M+P, and\n\
  *\n\
  *           rank(B) = P and  rank( (A) ) = N.\n\
  *                                ( (B) )\n\
  *\n\
  *  These conditions ensure that the LSE problem has a unique solution,\n\
  *  which is obtained using a generalized RQ factorization of the\n\
  *  matrices (B, A) given by\n\
  *\n\
  *     B = (0 R)*Q,   A = Z*T*Q.\n\
  *\n\n\
  *  Arguments\n\
  *  =========\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 matrices A and B. N >= 0.\n\
  *\n\
  *  P       (input) INTEGER\n\
  *          The number of rows of the matrix B. 0 <= P <= N <= M+P.\n\
  *\n\
  *  A       (input/output) REAL array, dimension (LDA,N)\n\
  *          On entry, the M-by-N matrix A.\n\
  *          On exit, the elements on and above the diagonal of the array\n\
  *          contain the min(M,N)-by-N upper trapezoidal matrix T.\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,N)\n\
  *          On entry, the P-by-N matrix B.\n\
  *          On exit, the upper triangle of the subarray B(1:P,N-P+1:N)\n\
  *          contains the P-by-P upper triangular matrix R.\n\
  *\n\
  *  LDB     (input) INTEGER\n\
  *          The leading dimension of the array B. LDB >= max(1,P).\n\
  *\n\
  *  C       (input/output) REAL array, dimension (M)\n\
  *          On entry, C contains the right hand side vector for the\n\
  *          least squares part of the LSE problem.\n\
  *          On exit, the residual sum of squares for the solution\n\
  *          is given by the sum of squares of elements N-P+1 to M of\n\
  *          vector C.\n\
  *\n\
  *  D       (input/output) REAL array, dimension (P)\n\
  *          On entry, D contains the right hand side vector for the\n\
  *          constrained equation.\n\
  *          On exit, D is destroyed.\n\
  *\n\
  *  X       (output) REAL array, dimension (N)\n\
  *          On exit, X is the solution of the LSE problem.\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. LWORK >= max(1,M+N+P).\n\
  *          For optimum performance LWORK >= P+min(M,N)+max(M,N)*NB,\n\
  *          where NB is an upper bound for the optimal blocksizes for\n\
  *          SGEQRF, SGERQF, SORMQR and SORMRQ.\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\
  *          = 1:  the upper triangular factor R associated with B in the\n\
  *                generalized RQ factorization of the pair (B, A) is\n\
  *                singular, so that rank(B) < P; the least squares\n\
  *                solution could not be computed.\n\
  *          = 2:  the (N-P) by (N-P) part of the upper trapezoidal factor\n\
  *                T associated with A in the generalized RQ factorization\n\
  *                of the pair (B, A) is singular, so that\n\
  *                rank( (A) ) < N; the least squares solution could not\n\
  *                    ( (B) )\n\
  *                be computed.\n\
  *\n\n\
  *  =====================================================================\n\
  *\n"
