```001:       SUBROUTINE DLAHRD( 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:       DOUBLE PRECISION   A( LDA, * ), T( LDT, NB ), TAU( NB ),
012:      \$                   Y( LDY, NB )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  DLAHRD reduces the first NB columns of a real 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 an orthogonal 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.
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) DOUBLE PRECISION 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) DOUBLE PRECISION array, dimension (NB)
054: *          The scalar factors of the elementary reflectors. See Further
055: *          Details.
056: *
057: *  T       (output) DOUBLE PRECISION 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) DOUBLE PRECISION 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 >= 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 real scalar, and v is a real 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:       DOUBLE PRECISION   ZERO, ONE
108:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
109: *     ..
110: *     .. Local Scalars ..
111:       INTEGER            I
112:       DOUBLE PRECISION   EI
113: *     ..
114: *     .. External Subroutines ..
115:       EXTERNAL           DAXPY, DCOPY, DGEMV, DLARFG, DSCAL, DTRMV
116: *     ..
117: *     .. Intrinsic Functions ..
118:       INTRINSIC          MIN
119: *     ..
120: *     .. Executable Statements ..
121: *
122: *     Quick return if possible
123: *
124:       IF( N.LE.1 )
125:      \$   RETURN
126: *
127:       DO 10 I = 1, NB
128:          IF( I.GT.1 ) THEN
129: *
130: *           Update A(1:n,i)
131: *
132: *           Compute i-th column of A - Y * V'
133: *
134:             CALL DGEMV( 'No transpose', N, I-1, -ONE, Y, LDY,
135:      \$                  A( K+I-1, 1 ), LDA, ONE, A( 1, I ), 1 )
136: *
137: *           Apply I - V * T' * V' to this column (call it b) from the
138: *           left, using the last column of T as workspace
139: *
140: *           Let  V = ( V1 )   and   b = ( b1 )   (first I-1 rows)
141: *                    ( V2 )             ( b2 )
142: *
143: *           where V1 is unit lower triangular
144: *
145: *           w := V1' * b1
146: *
147:             CALL DCOPY( I-1, A( K+1, I ), 1, T( 1, NB ), 1 )
148:             CALL DTRMV( 'Lower', 'Transpose', 'Unit', I-1, A( K+1, 1 ),
149:      \$                  LDA, T( 1, NB ), 1 )
150: *
151: *           w := w + V2'*b2
152: *
153:             CALL DGEMV( 'Transpose', N-K-I+1, I-1, ONE, A( K+I, 1 ),
154:      \$                  LDA, A( K+I, I ), 1, ONE, T( 1, NB ), 1 )
155: *
156: *           w := T'*w
157: *
158:             CALL DTRMV( 'Upper', 'Transpose', 'Non-unit', I-1, T, LDT,
159:      \$                  T( 1, NB ), 1 )
160: *
161: *           b2 := b2 - V2*w
162: *
163:             CALL DGEMV( 'No transpose', N-K-I+1, I-1, -ONE, A( K+I, 1 ),
164:      \$                  LDA, T( 1, NB ), 1, ONE, A( K+I, I ), 1 )
165: *
166: *           b1 := b1 - V1*w
167: *
168:             CALL DTRMV( 'Lower', 'No transpose', 'Unit', I-1,
169:      \$                  A( K+1, 1 ), LDA, T( 1, NB ), 1 )
170:             CALL DAXPY( I-1, -ONE, T( 1, NB ), 1, A( K+1, I ), 1 )
171: *
172:             A( K+I-1, I-1 ) = EI
173:          END IF
174: *
175: *        Generate the elementary reflector H(i) to annihilate
176: *        A(k+i+1:n,i)
177: *
178:          CALL DLARFG( N-K-I+1, A( K+I, I ), A( MIN( K+I+1, N ), I ), 1,
179:      \$                TAU( I ) )
180:          EI = A( K+I, I )
181:          A( K+I, I ) = ONE
182: *
183: *        Compute  Y(1:n,i)
184: *
185:          CALL DGEMV( 'No transpose', N, N-K-I+1, ONE, A( 1, I+1 ), LDA,
186:      \$               A( K+I, I ), 1, ZERO, Y( 1, I ), 1 )
187:          CALL DGEMV( 'Transpose', N-K-I+1, I-1, ONE, A( K+I, 1 ), LDA,
188:      \$               A( K+I, I ), 1, ZERO, T( 1, I ), 1 )
189:          CALL DGEMV( 'No transpose', N, I-1, -ONE, Y, LDY, T( 1, I ), 1,
190:      \$               ONE, Y( 1, I ), 1 )
191:          CALL DSCAL( N, TAU( I ), Y( 1, I ), 1 )
192: *
193: *        Compute T(1:i,i)
194: *
195:          CALL DSCAL( I-1, -TAU( I ), T( 1, I ), 1 )
196:          CALL DTRMV( 'Upper', 'No transpose', 'Non-unit', I-1, T, LDT,
197:      \$               T( 1, I ), 1 )
198:          T( I, I ) = TAU( I )
199: *
200:    10 CONTINUE
201:       A( K+NB, NB ) = EI
202: *
203:       RETURN
204: *
205: *     End of DLAHRD
206: *
207:       END
208: ```