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