001:       SUBROUTINE DGELQ2( M, N, A, LDA, TAU, WORK, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            INFO, LDA, M, N
009: *     ..
010: *     .. Array Arguments ..
011:       DOUBLE PRECISION   A( LDA, * ), TAU( * ), WORK( * )
012: *     ..
013: *
014: *  Purpose
015: *  =======
016: *
017: *  DGELQ2 computes an LQ factorization of a real m by n matrix A:
018: *  A = L * Q.
019: *
020: *  Arguments
021: *  =========
022: *
023: *  M       (input) INTEGER
024: *          The number of rows of the matrix A.  M >= 0.
025: *
026: *  N       (input) INTEGER
027: *          The number of columns of the matrix A.  N >= 0.
028: *
029: *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
030: *          On entry, the m by n matrix A.
031: *          On exit, the elements on and below the diagonal of the array
032: *          contain the m by min(m,n) lower trapezoidal matrix L (L is
033: *          lower triangular if m <= n); the elements above the diagonal,
034: *          with the array TAU, represent the orthogonal matrix Q as a
035: *          product of elementary reflectors (see Further Details).
036: *
037: *  LDA     (input) INTEGER
038: *          The leading dimension of the array A.  LDA >= max(1,M).
039: *
040: *  TAU     (output) DOUBLE PRECISION array, dimension (min(M,N))
041: *          The scalar factors of the elementary reflectors (see Further
042: *          Details).
043: *
044: *  WORK    (workspace) DOUBLE PRECISION array, dimension (M)
045: *
046: *  INFO    (output) INTEGER
047: *          = 0: successful exit
048: *          < 0: if INFO = -i, the i-th argument had an illegal value
049: *
050: *  Further Details
051: *  ===============
052: *
053: *  The matrix Q is represented as a product of elementary reflectors
054: *
055: *     Q = H(k) . . . H(2) H(1), where k = min(m,n).
056: *
057: *  Each H(i) has the form
058: *
059: *     H(i) = I - tau * v * v'
060: *
061: *  where tau is a real scalar, and v is a real vector with
062: *  v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n),
063: *  and tau in TAU(i).
064: *
065: *  =====================================================================
066: *
067: *     .. Parameters ..
068:       DOUBLE PRECISION   ONE
069:       PARAMETER          ( ONE = 1.0D+0 )
070: *     ..
071: *     .. Local Scalars ..
072:       INTEGER            I, K
073:       DOUBLE PRECISION   AII
074: *     ..
075: *     .. External Subroutines ..
076:       EXTERNAL           DLARF, DLARFP, XERBLA
077: *     ..
078: *     .. Intrinsic Functions ..
079:       INTRINSIC          MAX, MIN
080: *     ..
081: *     .. Executable Statements ..
082: *
083: *     Test the input arguments
084: *
085:       INFO = 0
086:       IF( M.LT.0 ) THEN
087:          INFO = -1
088:       ELSE IF( N.LT.0 ) THEN
089:          INFO = -2
090:       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
091:          INFO = -4
092:       END IF
093:       IF( INFO.NE.0 ) THEN
094:          CALL XERBLA( 'DGELQ2', -INFO )
095:          RETURN
096:       END IF
097: *
098:       K = MIN( M, N )
099: *
100:       DO 10 I = 1, K
101: *
102: *        Generate elementary reflector H(i) to annihilate A(i,i+1:n)
103: *
104:          CALL DLARFP( N-I+1, A( I, I ), A( I, MIN( I+1, N ) ), LDA,
105:      $                TAU( I ) )
106:          IF( I.LT.M ) THEN
107: *
108: *           Apply H(i) to A(i+1:m,i:n) from the right
109: *
110:             AII = A( I, I )
111:             A( I, I ) = ONE
112:             CALL DLARF( 'Right', M-I, N-I+1, A( I, I ), LDA, TAU( I ),
113:      $                  A( I+1, I ), LDA, WORK )
114:             A( I, I ) = AII
115:          END IF
116:    10 CONTINUE
117:       RETURN
118: *
119: *     End of DGELQ2
120: *
121:       END
122: