--- 
:name: dggglm
:md5sum: b132b24d18eb3c974ddf79f3c310f812
:category: :subroutine
:arguments: 
- n: 
    :type: integer
    :intent: input
- m: 
    :type: integer
    :intent: input
- p: 
    :type: integer
    :intent: input
- a: 
    :type: doublereal
    :intent: input/output
    :dims: 
    - lda
    - m
- lda: 
    :type: integer
    :intent: input
- b: 
    :type: doublereal
    :intent: input/output
    :dims: 
    - ldb
    - p
- ldb: 
    :type: integer
    :intent: input
- d: 
    :type: doublereal
    :intent: input/output
    :dims: 
    - n
- x: 
    :type: doublereal
    :intent: output
    :dims: 
    - m
- y: 
    :type: doublereal
    :intent: output
    :dims: 
    - p
- work: 
    :type: doublereal
    :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 DGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK, INFO )\n\n\
  *  Purpose\n\
  *  =======\n\
  *\n\
  *  DGGGLM solves a general Gauss-Markov linear model (GLM) problem:\n\
  *\n\
  *          minimize || y ||_2   subject to   d = A*x + B*y\n\
  *              x\n\
  *\n\
  *  where A is an N-by-M matrix, B is an N-by-P matrix, and d is a\n\
  *  given N-vector. It is assumed that M <= N <= M+P, and\n\
  *\n\
  *             rank(A) = M    and    rank( A B ) = N.\n\
  *\n\
  *  Under these assumptions, the constrained equation is always\n\
  *  consistent, and there is a unique solution x and a minimal 2-norm\n\
  *  solution y, which is obtained using a generalized QR factorization\n\
  *  of the matrices (A, B) given by\n\
  *\n\
  *     A = Q*(R),   B = Q*T*Z.\n\
  *           (0)\n\
  *\n\
  *  In particular, if matrix B is square nonsingular, then the problem\n\
  *  GLM is equivalent to the following weighted linear least squares\n\
  *  problem\n\
  *\n\
  *               minimize || inv(B)*(d-A*x) ||_2\n\
  *                   x\n\
  *\n\
  *  where inv(B) denotes the inverse of B.\n\
  *\n\n\
  *  Arguments\n\
  *  =========\n\
  *\n\
  *  N       (input) INTEGER\n\
  *          The number of rows of the matrices A and B.  N >= 0.\n\
  *\n\
  *  M       (input) INTEGER\n\
  *          The number of columns of the matrix A.  0 <= M <= N.\n\
  *\n\
  *  P       (input) INTEGER\n\
  *          The number of columns of the matrix B.  P >= N-M.\n\
  *\n\
  *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,M)\n\
  *          On entry, the N-by-M matrix A.\n\
  *          On exit, the upper triangular part of the array A contains\n\
  *          the M-by-M upper triangular matrix R.\n\
  *\n\
  *  LDA     (input) INTEGER\n\
  *          The leading dimension of the array A. LDA >= max(1,N).\n\
  *\n\
  *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,P)\n\
  *          On entry, the N-by-P matrix B.\n\
  *          On exit, if N <= P, the upper triangle of the subarray\n\
  *          B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T;\n\
  *          if N > P, the elements on and above the (N-P)th subdiagonal\n\
  *          contain the N-by-P upper trapezoidal matrix T.\n\
  *\n\
  *  LDB     (input) INTEGER\n\
  *          The leading dimension of the array B. LDB >= max(1,N).\n\
  *\n\
  *  D       (input/output) DOUBLE PRECISION array, dimension (N)\n\
  *          On entry, D is the left hand side of the GLM equation.\n\
  *          On exit, D is destroyed.\n\
  *\n\
  *  X       (output) DOUBLE PRECISION array, dimension (M)\n\
  *  Y       (output) DOUBLE PRECISION array, dimension (P)\n\
  *          On exit, X and Y are the solutions of the GLM problem.\n\
  *\n\
  *  WORK    (workspace/output) DOUBLE PRECISION 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,N+M+P).\n\
  *          For optimum performance, LWORK >= M+min(N,P)+max(N,P)*NB,\n\
  *          where NB is an upper bound for the optimal blocksizes for\n\
  *          DGEQRF, SGERQF, DORMQR 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 A in the\n\
  *                generalized QR factorization of the pair (A, B) is\n\
  *                singular, so that rank(A) < M; the least squares\n\
  *                solution could not be computed.\n\
  *          = 2:  the bottom (N-M) by (N-M) part of the upper trapezoidal\n\
  *                factor T associated with B in the generalized QR\n\
  *                factorization of the pair (A, B) is singular, so that\n\
  *                rank( A B ) < N; the least squares solution could not\n\
  *                be computed.\n\
  *\n\n\
  *  ===================================================================\n\
  *\n"
