001:       SUBROUTINE ZLARZT( DIRECT, STOREV, N, K, V, LDV, TAU, T, LDT )
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          DIRECT, STOREV
009:       INTEGER            K, LDT, LDV, N
010: *     ..
011: *     .. Array Arguments ..
012:       COMPLEX*16         T( LDT, * ), TAU( * ), V( LDV, * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  ZLARZT forms the triangular factor T of a complex block reflector
019: *  H of order > n, which is defined as a product of k elementary
020: *  reflectors.
021: *
022: *  If DIRECT = 'F', H = H(1) H(2) . . . H(k) and T is upper triangular;
023: *
024: *  If DIRECT = 'B', H = H(k) . . . H(2) H(1) and T is lower triangular.
025: *
026: *  If STOREV = 'C', the vector which defines the elementary reflector
027: *  H(i) is stored in the i-th column of the array V, and
028: *
029: *     H  =  I - V * T * V'
030: *
031: *  If STOREV = 'R', the vector which defines the elementary reflector
032: *  H(i) is stored in the i-th row of the array V, and
033: *
034: *     H  =  I - V' * T * V
035: *
036: *  Currently, only STOREV = 'R' and DIRECT = 'B' are supported.
037: *
038: *  Arguments
039: *  =========
040: *
041: *  DIRECT  (input) CHARACTER*1
042: *          Specifies the order in which the elementary reflectors are
043: *          multiplied to form the block reflector:
044: *          = 'F': H = H(1) H(2) . . . H(k) (Forward, not supported yet)
045: *          = 'B': H = H(k) . . . H(2) H(1) (Backward)
046: *
047: *  STOREV  (input) CHARACTER*1
048: *          Specifies how the vectors which define the elementary
049: *          reflectors are stored (see also Further Details):
050: *          = 'C': columnwise                        (not supported yet)
051: *          = 'R': rowwise
052: *
053: *  N       (input) INTEGER
054: *          The order of the block reflector H. N >= 0.
055: *
056: *  K       (input) INTEGER
057: *          The order of the triangular factor T (= the number of
058: *          elementary reflectors). K >= 1.
059: *
060: *  V       (input/output) COMPLEX*16 array, dimension
061: *                               (LDV,K) if STOREV = 'C'
062: *                               (LDV,N) if STOREV = 'R'
063: *          The matrix V. See further details.
064: *
065: *  LDV     (input) INTEGER
066: *          The leading dimension of the array V.
067: *          If STOREV = 'C', LDV >= max(1,N); if STOREV = 'R', LDV >= K.
068: *
069: *  TAU     (input) COMPLEX*16 array, dimension (K)
070: *          TAU(i) must contain the scalar factor of the elementary
071: *          reflector H(i).
072: *
073: *  T       (output) COMPLEX*16 array, dimension (LDT,K)
074: *          The k by k triangular factor T of the block reflector.
075: *          If DIRECT = 'F', T is upper triangular; if DIRECT = 'B', T is
076: *          lower triangular. The rest of the array is not used.
077: *
078: *  LDT     (input) INTEGER
079: *          The leading dimension of the array T. LDT >= K.
080: *
081: *  Further Details
082: *  ===============
083: *
084: *  Based on contributions by
085: *    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
086: *
087: *  The shape of the matrix V and the storage of the vectors which define
088: *  the H(i) is best illustrated by the following example with n = 5 and
089: *  k = 3. The elements equal to 1 are not stored; the corresponding
090: *  array elements are modified but restored on exit. The rest of the
091: *  array is not used.
092: *
093: *  DIRECT = 'F' and STOREV = 'C':         DIRECT = 'F' and STOREV = 'R':
094: *
095: *                                              ______V_____
096: *         ( v1 v2 v3 )                        /            \
097: *         ( v1 v2 v3 )                      ( v1 v1 v1 v1 v1 . . . . 1 )
098: *     V = ( v1 v2 v3 )                      ( v2 v2 v2 v2 v2 . . . 1   )
099: *         ( v1 v2 v3 )                      ( v3 v3 v3 v3 v3 . . 1     )
100: *         ( v1 v2 v3 )
101: *            .  .  .
102: *            .  .  .
103: *            1  .  .
104: *               1  .
105: *                  1
106: *
107: *  DIRECT = 'B' and STOREV = 'C':         DIRECT = 'B' and STOREV = 'R':
108: *
109: *                                                        ______V_____
110: *            1                                          /            \
111: *            .  1                           ( 1 . . . . v1 v1 v1 v1 v1 )
112: *            .  .  1                        ( . 1 . . . v2 v2 v2 v2 v2 )
113: *            .  .  .                        ( . . 1 . . v3 v3 v3 v3 v3 )
114: *            .  .  .
115: *         ( v1 v2 v3 )
116: *         ( v1 v2 v3 )
117: *     V = ( v1 v2 v3 )
118: *         ( v1 v2 v3 )
119: *         ( v1 v2 v3 )
120: *
121: *  =====================================================================
122: *
123: *     .. Parameters ..
124:       COMPLEX*16         ZERO
125:       PARAMETER          ( ZERO = ( 0.0D+0, 0.0D+0 ) )
126: *     ..
127: *     .. Local Scalars ..
128:       INTEGER            I, INFO, J
129: *     ..
130: *     .. External Subroutines ..
131:       EXTERNAL           XERBLA, ZGEMV, ZLACGV, ZTRMV
132: *     ..
133: *     .. External Functions ..
134:       LOGICAL            LSAME
135:       EXTERNAL           LSAME
136: *     ..
137: *     .. Executable Statements ..
138: *
139: *     Check for currently supported options
140: *
141:       INFO = 0
142:       IF( .NOT.LSAME( DIRECT, 'B' ) ) THEN
143:          INFO = -1
144:       ELSE IF( .NOT.LSAME( STOREV, 'R' ) ) THEN
145:          INFO = -2
146:       END IF
147:       IF( INFO.NE.0 ) THEN
148:          CALL XERBLA( 'ZLARZT', -INFO )
149:          RETURN
150:       END IF
151: *
152:       DO 20 I = K, 1, -1
153:          IF( TAU( I ).EQ.ZERO ) THEN
154: *
155: *           H(i)  =  I
156: *
157:             DO 10 J = I, K
158:                T( J, I ) = ZERO
159:    10       CONTINUE
160:          ELSE
161: *
162: *           general case
163: *
164:             IF( I.LT.K ) THEN
165: *
166: *              T(i+1:k,i) = - tau(i) * V(i+1:k,1:n) * V(i,1:n)'
167: *
168:                CALL ZLACGV( N, V( I, 1 ), LDV )
169:                CALL ZGEMV( 'No transpose', K-I, N, -TAU( I ),
170:      $                     V( I+1, 1 ), LDV, V( I, 1 ), LDV, ZERO,
171:      $                     T( I+1, I ), 1 )
172:                CALL ZLACGV( N, V( I, 1 ), LDV )
173: *
174: *              T(i+1:k,i) = T(i+1:k,i+1:k) * T(i+1:k,i)
175: *
176:                CALL ZTRMV( 'Lower', 'No transpose', 'Non-unit', K-I,
177:      $                     T( I+1, I+1 ), LDT, T( I+1, I ), 1 )
178:             END IF
179:             T( I, I ) = TAU( I )
180:          END IF
181:    20 CONTINUE
182:       RETURN
183: *
184: *     End of ZLARZT
185: *
186:       END
187: