001:       SUBROUTINE CLAHRD( N, K, NB, A, LDA, TAU, T, LDT, Y, LDY )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            K, LDA, LDT, LDY, N, NB
009: *     ..
010: *     .. Array Arguments ..
011:       COMPLEX            A( LDA, * ), T( LDT, NB ), TAU( NB ),
012:      $                   Y( LDY, NB )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  CLAHRD reduces the first NB columns of a complex general n-by-(n-k+1)
019: *  matrix A so that elements below the k-th subdiagonal are zero. The
020: *  reduction is performed by a unitary similarity transformation
021: *  Q' * A * Q. The routine returns the matrices V and T which determine
022: *  Q as a block reflector I - V*T*V', and also the matrix Y = A * V * T.
023: *
024: *  This is an OBSOLETE auxiliary routine. 
025: *  This routine will be 'deprecated' in a  future release.
026: *  Please use the new routine CLAHR2 instead.
027: *
028: *  Arguments
029: *  =========
030: *
031: *  N       (input) INTEGER
032: *          The order of the matrix A.
033: *
034: *  K       (input) INTEGER
035: *          The offset for the reduction. Elements below the k-th
036: *          subdiagonal in the first NB columns are reduced to zero.
037: *
038: *  NB      (input) INTEGER
039: *          The number of columns to be reduced.
040: *
041: *  A       (input/output) COMPLEX array, dimension (LDA,N-K+1)
042: *          On entry, the n-by-(n-k+1) general matrix A.
043: *          On exit, the elements on and above the k-th subdiagonal in
044: *          the first NB columns are overwritten with the corresponding
045: *          elements of the reduced matrix; the elements below the k-th
046: *          subdiagonal, with the array TAU, represent the matrix Q as a
047: *          product of elementary reflectors. The other columns of A are
048: *          unchanged. See Further Details.
049: *
050: *  LDA     (input) INTEGER
051: *          The leading dimension of the array A.  LDA >= max(1,N).
052: *
053: *  TAU     (output) COMPLEX array, dimension (NB)
054: *          The scalar factors of the elementary reflectors. See Further
055: *          Details.
056: *
057: *  T       (output) COMPLEX array, dimension (LDT,NB)
058: *          The upper triangular matrix T.
059: *
060: *  LDT     (input) INTEGER
061: *          The leading dimension of the array T.  LDT >= NB.
062: *
063: *  Y       (output) COMPLEX array, dimension (LDY,NB)
064: *          The n-by-nb matrix Y.
065: *
066: *  LDY     (input) INTEGER
067: *          The leading dimension of the array Y. LDY >= max(1,N).
068: *
069: *  Further Details
070: *  ===============
071: *
072: *  The matrix Q is represented as a product of nb elementary reflectors
073: *
074: *     Q = H(1) H(2) . . . H(nb).
075: *
076: *  Each H(i) has the form
077: *
078: *     H(i) = I - tau * v * v'
079: *
080: *  where tau is a complex scalar, and v is a complex vector with
081: *  v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in
082: *  A(i+k+1:n,i), and tau in TAU(i).
083: *
084: *  The elements of the vectors v together form the (n-k+1)-by-nb matrix
085: *  V which is needed, with T and Y, to apply the transformation to the
086: *  unreduced part of the matrix, using an update of the form:
087: *  A := (I - V*T*V') * (A - Y*V').
088: *
089: *  The contents of A on exit are illustrated by the following example
090: *  with n = 7, k = 3 and nb = 2:
091: *
092: *     ( a   h   a   a   a )
093: *     ( a   h   a   a   a )
094: *     ( a   h   a   a   a )
095: *     ( h   h   a   a   a )
096: *     ( v1  h   a   a   a )
097: *     ( v1  v2  a   a   a )
098: *     ( v1  v2  a   a   a )
099: *
100: *  where a denotes an element of the original matrix A, h denotes a
101: *  modified element of the upper Hessenberg matrix H, and vi denotes an
102: *  element of the vector defining H(i).
103: *
104: *  =====================================================================
105: *
106: *     .. Parameters ..
107:       COMPLEX            ZERO, ONE
108:       PARAMETER          ( ZERO = ( 0.0E+0, 0.0E+0 ),
109:      $                   ONE = ( 1.0E+0, 0.0E+0 ) )
110: *     ..
111: *     .. Local Scalars ..
112:       INTEGER            I
113:       COMPLEX            EI
114: *     ..
115: *     .. External Subroutines ..
116:       EXTERNAL           CAXPY, CCOPY, CGEMV, CLACGV, CLARFG, CSCAL,
117:      $                   CTRMV
118: *     ..
119: *     .. Intrinsic Functions ..
120:       INTRINSIC          MIN
121: *     ..
122: *     .. Executable Statements ..
123: *
124: *     Quick return if possible
125: *
126:       IF( N.LE.1 )
127:      $   RETURN
128: *
129:       DO 10 I = 1, NB
130:          IF( I.GT.1 ) THEN
131: *
132: *           Update A(1:n,i)
133: *
134: *           Compute i-th column of A - Y * V'
135: *
136:             CALL CLACGV( I-1, A( K+I-1, 1 ), LDA )
137:             CALL CGEMV( 'No transpose', N, I-1, -ONE, Y, LDY,
138:      $                  A( K+I-1, 1 ), LDA, ONE, A( 1, I ), 1 )
139:             CALL CLACGV( I-1, A( K+I-1, 1 ), LDA )
140: *
141: *           Apply I - V * T' * V' to this column (call it b) from the
142: *           left, using the last column of T as workspace
143: *
144: *           Let  V = ( V1 )   and   b = ( b1 )   (first I-1 rows)
145: *                    ( V2 )             ( b2 )
146: *
147: *           where V1 is unit lower triangular
148: *
149: *           w := V1' * b1
150: *
151:             CALL CCOPY( I-1, A( K+1, I ), 1, T( 1, NB ), 1 )
152:             CALL CTRMV( 'Lower', 'Conjugate transpose', 'Unit', I-1,
153:      $                  A( K+1, 1 ), LDA, T( 1, NB ), 1 )
154: *
155: *           w := w + V2'*b2
156: *
157:             CALL CGEMV( 'Conjugate transpose', N-K-I+1, I-1, ONE,
158:      $                  A( K+I, 1 ), LDA, A( K+I, I ), 1, ONE,
159:      $                  T( 1, NB ), 1 )
160: *
161: *           w := T'*w
162: *
163:             CALL CTRMV( 'Upper', 'Conjugate transpose', 'Non-unit', I-1,
164:      $                  T, LDT, T( 1, NB ), 1 )
165: *
166: *           b2 := b2 - V2*w
167: *
168:             CALL CGEMV( 'No transpose', N-K-I+1, I-1, -ONE, A( K+I, 1 ),
169:      $                  LDA, T( 1, NB ), 1, ONE, A( K+I, I ), 1 )
170: *
171: *           b1 := b1 - V1*w
172: *
173:             CALL CTRMV( 'Lower', 'No transpose', 'Unit', I-1,
174:      $                  A( K+1, 1 ), LDA, T( 1, NB ), 1 )
175:             CALL CAXPY( I-1, -ONE, T( 1, NB ), 1, A( K+1, I ), 1 )
176: *
177:             A( K+I-1, I-1 ) = EI
178:          END IF
179: *
180: *        Generate the elementary reflector H(i) to annihilate
181: *        A(k+i+1:n,i)
182: *
183:          EI = A( K+I, I )
184:          CALL CLARFG( N-K-I+1, EI, A( MIN( K+I+1, N ), I ), 1,
185:      $                TAU( I ) )
186:          A( K+I, I ) = ONE
187: *
188: *        Compute  Y(1:n,i)
189: *
190:          CALL CGEMV( 'No transpose', N, N-K-I+1, ONE, A( 1, I+1 ), LDA,
191:      $               A( K+I, I ), 1, ZERO, Y( 1, I ), 1 )
192:          CALL CGEMV( 'Conjugate transpose', N-K-I+1, I-1, ONE,
193:      $               A( K+I, 1 ), LDA, A( K+I, I ), 1, ZERO, T( 1, I ),
194:      $               1 )
195:          CALL CGEMV( 'No transpose', N, I-1, -ONE, Y, LDY, T( 1, I ), 1,
196:      $               ONE, Y( 1, I ), 1 )
197:          CALL CSCAL( N, TAU( I ), Y( 1, I ), 1 )
198: *
199: *        Compute T(1:i,i)
200: *
201:          CALL CSCAL( I-1, -TAU( I ), T( 1, I ), 1 )
202:          CALL CTRMV( 'Upper', 'No transpose', 'Non-unit', I-1, T, LDT,
203:      $               T( 1, I ), 1 )
204:          T( I, I ) = TAU( I )
205: *
206:    10 CONTINUE
207:       A( K+NB, NB ) = EI
208: *
209:       RETURN
210: *
211: *     End of CLAHRD
212: *
213:       END
214: