001:       SUBROUTINE ZLARZ( SIDE, M, N, L, V, INCV, TAU, C, LDC, WORK )
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:       CHARACTER          SIDE
010:       INTEGER            INCV, L, LDC, M, N
011:       COMPLEX*16         TAU
012: *     ..
013: *     .. Array Arguments ..
014:       COMPLEX*16         C( LDC, * ), V( * ), WORK( * )
015: *     ..
016: *
017: *  Purpose
018: *  =======
019: *
020: *  ZLARZ applies a complex elementary reflector H to a complex
021: *  M-by-N matrix C, from either the left or the right. H is represented
022: *  in the form
023: *
024: *        H = I - tau * v * v'
025: *
026: *  where tau is a complex scalar and v is a complex vector.
027: *
028: *  If tau = 0, then H is taken to be the unit matrix.
029: *
030: *  To apply H' (the conjugate transpose of H), supply conjg(tau) instead
031: *  tau.
032: *
033: *  H is a product of k elementary reflectors as returned by ZTZRZF.
034: *
035: *  Arguments
036: *  =========
037: *
038: *  SIDE    (input) CHARACTER*1
039: *          = 'L': form  H * C
040: *          = 'R': form  C * H
041: *
042: *  M       (input) INTEGER
043: *          The number of rows of the matrix C.
044: *
045: *  N       (input) INTEGER
046: *          The number of columns of the matrix C.
047: *
048: *  L       (input) INTEGER
049: *          The number of entries of the vector V containing
050: *          the meaningful part of the Householder vectors.
051: *          If SIDE = 'L', M >= L >= 0, if SIDE = 'R', N >= L >= 0.
052: *
053: *  V       (input) COMPLEX*16 array, dimension (1+(L-1)*abs(INCV))
054: *          The vector v in the representation of H as returned by
055: *          ZTZRZF. V is not used if TAU = 0.
056: *
057: *  INCV    (input) INTEGER
058: *          The increment between elements of v. INCV <> 0.
059: *
060: *  TAU     (input) COMPLEX*16
061: *          The value tau in the representation of H.
062: *
063: *  C       (input/output) COMPLEX*16 array, dimension (LDC,N)
064: *          On entry, the M-by-N matrix C.
065: *          On exit, C is overwritten by the matrix H * C if SIDE = 'L',
066: *          or C * H if SIDE = 'R'.
067: *
068: *  LDC     (input) INTEGER
069: *          The leading dimension of the array C. LDC >= max(1,M).
070: *
071: *  WORK    (workspace) COMPLEX*16 array, dimension
072: *                         (N) if SIDE = 'L'
073: *                      or (M) if SIDE = 'R'
074: *
075: *  Further Details
076: *  ===============
077: *
078: *  Based on contributions by
079: *    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
080: *
081: *  =====================================================================
082: *
083: *     .. Parameters ..
084:       COMPLEX*16         ONE, ZERO
085:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ),
086:      $                   ZERO = ( 0.0D+0, 0.0D+0 ) )
087: *     ..
088: *     .. External Subroutines ..
089:       EXTERNAL           ZAXPY, ZCOPY, ZGEMV, ZGERC, ZGERU, ZLACGV
090: *     ..
091: *     .. External Functions ..
092:       LOGICAL            LSAME
093:       EXTERNAL           LSAME
094: *     ..
095: *     .. Executable Statements ..
096: *
097:       IF( LSAME( SIDE, 'L' ) ) THEN
098: *
099: *        Form  H * C
100: *
101:          IF( TAU.NE.ZERO ) THEN
102: *
103: *           w( 1:n ) = conjg( C( 1, 1:n ) )
104: *
105:             CALL ZCOPY( N, C, LDC, WORK, 1 )
106:             CALL ZLACGV( N, WORK, 1 )
107: *
108: *           w( 1:n ) = conjg( w( 1:n ) + C( m-l+1:m, 1:n )' * v( 1:l ) )
109: *
110:             CALL ZGEMV( 'Conjugate transpose', L, N, ONE, C( M-L+1, 1 ),
111:      $                  LDC, V, INCV, ONE, WORK, 1 )
112:             CALL ZLACGV( N, WORK, 1 )
113: *
114: *           C( 1, 1:n ) = C( 1, 1:n ) - tau * w( 1:n )
115: *
116:             CALL ZAXPY( N, -TAU, WORK, 1, C, LDC )
117: *
118: *           C( m-l+1:m, 1:n ) = C( m-l+1:m, 1:n ) - ...
119: *                               tau * v( 1:l ) * conjg( w( 1:n )' )
120: *
121:             CALL ZGERU( L, N, -TAU, V, INCV, WORK, 1, C( M-L+1, 1 ),
122:      $                  LDC )
123:          END IF
124: *
125:       ELSE
126: *
127: *        Form  C * H
128: *
129:          IF( TAU.NE.ZERO ) THEN
130: *
131: *           w( 1:m ) = C( 1:m, 1 )
132: *
133:             CALL ZCOPY( M, C, 1, WORK, 1 )
134: *
135: *           w( 1:m ) = w( 1:m ) + C( 1:m, n-l+1:n, 1:n ) * v( 1:l )
136: *
137:             CALL ZGEMV( 'No transpose', M, L, ONE, C( 1, N-L+1 ), LDC,
138:      $                  V, INCV, ONE, WORK, 1 )
139: *
140: *           C( 1:m, 1 ) = C( 1:m, 1 ) - tau * w( 1:m )
141: *
142:             CALL ZAXPY( M, -TAU, WORK, 1, C, 1 )
143: *
144: *           C( 1:m, n-l+1:n ) = C( 1:m, n-l+1:n ) - ...
145: *                               tau * w( 1:m ) * v( 1:l )'
146: *
147:             CALL ZGERC( M, L, -TAU, WORK, 1, V, INCV, C( 1, N-L+1 ),
148:      $                  LDC )
149: *
150:          END IF
151: *
152:       END IF
153: *
154:       RETURN
155: *
156: *     End of ZLARZ
157: *
158:       END
159: