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