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