001:       SUBROUTINE CLATRZ( M, N, L, A, LDA, TAU, WORK )
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            L, LDA, M, N
009: *     ..
010: *     .. Array Arguments ..
011:       COMPLEX            A( LDA, * ), TAU( * ), WORK( * )
012: *     ..
013: *
014: *  Purpose
015: *  =======
016: *
017: *  CLATRZ factors the M-by-(M+L) complex upper trapezoidal matrix
018: *  [ A1 A2 ] = [ A(1:M,1:M) A(1:M,N-L+1:N) ] as ( R  0 ) * Z by means
019: *  of unitary transformations, where  Z is an (M+L)-by-(M+L) unitary
020: *  matrix and, R and A1 are M-by-M upper triangular matrices.
021: *
022: *  Arguments
023: *  =========
024: *
025: *  M       (input) INTEGER
026: *          The number of rows of the matrix A.  M >= 0.
027: *
028: *  N       (input) INTEGER
029: *          The number of columns of the matrix A.  N >= 0.
030: *
031: *  L       (input) INTEGER
032: *          The number of columns of the matrix A containing the
033: *          meaningful part of the Householder vectors. N-M >= L >= 0.
034: *
035: *  A       (input/output) COMPLEX array, dimension (LDA,N)
036: *          On entry, the leading M-by-N upper trapezoidal part of the
037: *          array A must contain the matrix to be factorized.
038: *          On exit, the leading M-by-M upper triangular part of A
039: *          contains the upper triangular matrix R, and elements N-L+1 to
040: *          N of the first M rows of A, with the array TAU, represent the
041: *          unitary matrix Z as a product of M elementary reflectors.
042: *
043: *  LDA     (input) INTEGER
044: *          The leading dimension of the array A.  LDA >= max(1,M).
045: *
046: *  TAU     (output) COMPLEX array, dimension (M)
047: *          The scalar factors of the elementary reflectors.
048: *
049: *  WORK    (workspace) COMPLEX array, dimension (M)
050: *
051: *  Further Details
052: *  ===============
053: *
054: *  Based on contributions by
055: *    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
056: *
057: *  The factorization is obtained by Householder's method.  The kth
058: *  transformation matrix, Z( k ), which is used to introduce zeros into
059: *  the ( m - k + 1 )th row of A, is given in the form
060: *
061: *     Z( k ) = ( I     0   ),
062: *              ( 0  T( k ) )
063: *
064: *  where
065: *
066: *     T( k ) = I - tau*u( k )*u( k )',   u( k ) = (   1    ),
067: *                                                 (   0    )
068: *                                                 ( z( k ) )
069: *
070: *  tau is a scalar and z( k ) is an l element vector. tau and z( k )
071: *  are chosen to annihilate the elements of the kth row of A2.
072: *
073: *  The scalar tau is returned in the kth element of TAU and the vector
074: *  u( k ) in the kth row of A2, such that the elements of z( k ) are
075: *  in  a( k, l + 1 ), ..., a( k, n ). The elements of R are returned in
076: *  the upper triangular part of A1.
077: *
078: *  Z is given by
079: *
080: *     Z =  Z( 1 ) * Z( 2 ) * ... * Z( m ).
081: *
082: *  =====================================================================
083: *
084: *     .. Parameters ..
085:       COMPLEX            ZERO
086:       PARAMETER          ( ZERO = ( 0.0E+0, 0.0E+0 ) )
087: *     ..
088: *     .. Local Scalars ..
089:       INTEGER            I
090:       COMPLEX            ALPHA
091: *     ..
092: *     .. External Subroutines ..
093:       EXTERNAL           CLACGV, CLARFG, CLARZ
094: *     ..
095: *     .. Intrinsic Functions ..
096:       INTRINSIC          CONJG
097: *     ..
098: *     .. Executable Statements ..
099: *
100: *     Quick return if possible
101: *
102:       IF( M.EQ.0 ) THEN
103:          RETURN
104:       ELSE IF( M.EQ.N ) THEN
105:          DO 10 I = 1, N
106:             TAU( I ) = ZERO
107:    10    CONTINUE
108:          RETURN
109:       END IF
110: *
111:       DO 20 I = M, 1, -1
112: *
113: *        Generate elementary reflector H(i) to annihilate
114: *        [ A(i,i) A(i,n-l+1:n) ]
115: *
116:          CALL CLACGV( L, A( I, N-L+1 ), LDA )
117:          ALPHA = CONJG( A( I, I ) )
118:          CALL CLARFG( L+1, ALPHA, A( I, N-L+1 ), LDA, TAU( I ) )
119:          TAU( I ) = CONJG( TAU( I ) )
120: *
121: *        Apply H(i) to A(1:i-1,i:n) from the right
122: *
123:          CALL CLARZ( 'Right', I-1, N-I+1, L, A( I, N-L+1 ), LDA,
124:      $               CONJG( TAU( I ) ), A( 1, I ), LDA, WORK )
125:          A( I, I ) = CONJG( ALPHA )
126: *
127:    20 CONTINUE
128: *
129:       RETURN
130: *
131: *     End of CLATRZ
132: *
133:       END
134: