Debian Codegraph @

Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/complex16/ztrevc.f

raw
1 SUBROUTINE ZTREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR,
2 $ LDVR, MM, M, WORK, RWORK, INFO )
3 *
4 * -- LAPACK routine (version 3.0) --
5 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
6 * Courant Institute, Argonne National Lab, and Rice University
7 * June 30, 1999
8 *
9 * .. Scalar Arguments ..
10 CHARACTER HOWMNY, SIDE
11 INTEGER INFO, LDT, LDVL, LDVR, M, MM, N
12 * ..
13 * .. Array Arguments ..
14 LOGICAL SELECT( * )
15 DOUBLE PRECISION RWORK( * )
16 COMPLEX*16 T( LDT, * ), VL( LDVL, * ), VR( LDVR, * ),
17 $ WORK( * )
18 * ..
19 *
20 * Purpose
21 * =======
22 *
23 * ZTREVC computes some or all of the right and/or left eigenvectors of
24 * a complex upper triangular matrix T.
25 *
26 * The right eigenvector x and the left eigenvector y of T corresponding
27 * to an eigenvalue w are defined by:
28 *
29 * T*x = w*x, y'*T = w*y'
30 *
31 * where y' denotes the conjugate transpose of the vector y.
32 *
33 * If all eigenvectors are requested, the routine may either return the
34 * matrices X and/or Y of right or left eigenvectors of T, or the
35 * products Q*X and/or Q*Y, where Q is an input unitary
36 * matrix. If T was obtained from the Schur factorization of an
37 * original matrix A = Q*T*Q', then Q*X and Q*Y are the matrices of
38 * right or left eigenvectors of A.
39 *
40 * Arguments
41 * =========
42 *
43 * SIDE (input) CHARACTER*1
44 * = 'R': compute right eigenvectors only;
45 * = 'L': compute left eigenvectors only;
46 * = 'B': compute both right and left eigenvectors.
47 *
48 * HOWMNY (input) CHARACTER*1
49 * = 'A': compute all right and/or left eigenvectors;
50 * = 'B': compute all right and/or left eigenvectors,
51 * and backtransform them using the input matrices
52 * supplied in VR and/or VL;
53 * = 'S': compute selected right and/or left eigenvectors,
54 * specified by the logical array SELECT.
55 *
56 * SELECT (input) LOGICAL array, dimension (N)
57 * If HOWMNY = 'S', SELECT specifies the eigenvectors to be
58 * computed.
59 * If HOWMNY = 'A' or 'B', SELECT is not referenced.
60 * To select the eigenvector corresponding to the j-th
61 * eigenvalue, SELECT(j) must be set to .TRUE..
62 *
63 * N (input) INTEGER
64 * The order of the matrix T. N >= 0.
65 *
66 * T (input/output) COMPLEX*16 array, dimension (LDT,N)
67 * The upper triangular matrix T. T is modified, but restored
68 * on exit.
69 *
70 * LDT (input) INTEGER
71 * The leading dimension of the array T. LDT >= max(1,N).
72 *
73 * VL (input/output) COMPLEX*16 array, dimension (LDVL,MM)
74 * On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
75 * contain an N-by-N matrix Q (usually the unitary matrix Q of
76 * Schur vectors returned by ZHSEQR).
77 * On exit, if SIDE = 'L' or 'B', VL contains:
78 * if HOWMNY = 'A', the matrix Y of left eigenvectors of T;
79 * VL is lower triangular. The i-th column
80 * VL(i) of VL is the eigenvector corresponding
81 * to T(i,i).
82 * if HOWMNY = 'B', the matrix Q*Y;
83 * if HOWMNY = 'S', the left eigenvectors of T specified by
84 * SELECT, stored consecutively in the columns
85 * of VL, in the same order as their
86 * eigenvalues.
87 * If SIDE = 'R', VL is not referenced.
88 *
89 * LDVL (input) INTEGER
90 * The leading dimension of the array VL. LDVL >= max(1,N) if
91 * SIDE = 'L' or 'B'; LDVL >= 1 otherwise.
92 *
93 * VR (input/output) COMPLEX*16 array, dimension (LDVR,MM)
94 * On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
95 * contain an N-by-N matrix Q (usually the unitary matrix Q of
96 * Schur vectors returned by ZHSEQR).
97 * On exit, if SIDE = 'R' or 'B', VR contains:
98 * if HOWMNY = 'A', the matrix X of right eigenvectors of T;
99 * VR is upper triangular. The i-th column
100 * VR(i) of VR is the eigenvector corresponding
101 * to T(i,i).
102 * if HOWMNY = 'B', the matrix Q*X;
103 * if HOWMNY = 'S', the right eigenvectors of T specified by
104 * SELECT, stored consecutively in the columns
105 * of VR, in the same order as their
106 * eigenvalues.
107 * If SIDE = 'L', VR is not referenced.
108 *
109 * LDVR (input) INTEGER
110 * The leading dimension of the array VR. LDVR >= max(1,N) if
111 * SIDE = 'R' or 'B'; LDVR >= 1 otherwise.
112 *
113 * MM (input) INTEGER
114 * The number of columns in the arrays VL and/or VR. MM >= M.
115 *
116 * M (output) INTEGER
117 * The number of columns in the arrays VL and/or VR actually
118 * used to store the eigenvectors. If HOWMNY = 'A' or 'B', M
119 * is set to N. Each selected eigenvector occupies one
120 * column.
121 *
122 * WORK (workspace) COMPLEX*16 array, dimension (2*N)
123 *
124 * RWORK (workspace) DOUBLE PRECISION array, dimension (N)
125 *
126 * INFO (output) INTEGER
127 * = 0: successful exit
128 * < 0: if INFO = -i, the i-th argument had an illegal value
129 *
130 * Further Details
131 * ===============
132 *
133 * The algorithm used in this program is basically backward (forward)
134 * substitution, with scaling to make the the code robust against
135 * possible overflow.
136 *
137 * Each eigenvector is normalized so that the element of largest
138 * magnitude has magnitude 1; here the magnitude of a complex number
139 * (x,y) is taken to be |x| + |y|.
140 *
141 * =====================================================================
142 *
143 * .. Parameters ..
144 DOUBLE PRECISION ZERO, ONE
145 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
146 COMPLEX*16 CMZERO, CMONE
147 PARAMETER ( CMZERO = ( 0.0D+0, 0.0D+0 ),
148 $ CMONE = ( 1.0D+0, 0.0D+0 ) )
149 * ..
150 * .. Local Scalars ..
151 LOGICAL ALLV, BOTHV, LEFTV, OVER, RIGHTV, SOMEV
152 INTEGER I, II, IS, J, K, KI
153 DOUBLE PRECISION OVFL, REMAX, SCALE, SMIN, SMLNUM, ULP, UNFL
154 COMPLEX*16 CDUM
155 * ..
156 * .. External Functions ..
157 LOGICAL LSAME
158 INTEGER IZAMAX
159 DOUBLE PRECISION DLAMCH, DZASUM
160 EXTERNAL LSAME, IZAMAX, DLAMCH, DZASUM
161 * ..
162 * .. External Subroutines ..
163 EXTERNAL XERBLA, ZCOPY, ZDSCAL, ZGEMV, ZLATRS
164 * ..
165 * .. Intrinsic Functions ..
166 INTRINSIC ABS, DBLE, DCMPLX, DCONJG, DIMAG, MAX
167 * ..
168 * .. Statement Functions ..
169 DOUBLE PRECISION CABS1
170 * ..
171 * .. Statement Function definitions ..
172 CABS1( CDUM ) = ABS( DBLE( CDUM ) ) + ABS( DIMAG( CDUM ) )
173 * ..
174 * .. Executable Statements ..
175 *
176 * Decode and test the input parameters
177 *
178 BOTHV = LSAME( SIDE, 'B' )
179 RIGHTV = LSAME( SIDE, 'R' ) .OR. BOTHV
180 LEFTV = LSAME( SIDE, 'L' ) .OR. BOTHV
181 *
182 ALLV = LSAME( HOWMNY, 'A' )
183 OVER = LSAME( HOWMNY, 'B' )
184 SOMEV = LSAME( HOWMNY, 'S' )
185 *
186 * Set M to the number of columns required to store the selected
187 * eigenvectors.
188 *
189 IF( SOMEV ) THEN
190 M = 0
191 DO 10 J = 1, N
192 IF( SELECT( J ) )
193 $ M = M + 1
194 10 CONTINUE
195 ELSE
196 M = N
197 END IF
198 *
199 INFO = 0
200 IF( .NOT.RIGHTV .AND. .NOT.LEFTV ) THEN
201 INFO = -1
202 ELSE IF( .NOT.ALLV .AND. .NOT.OVER .AND. .NOT.SOMEV ) THEN
203 INFO = -2
204 ELSE IF( N.LT.0 ) THEN
205 INFO = -4
206 ELSE IF( LDT.LT.MAX( 1, N ) ) THEN
207 INFO = -6
208 ELSE IF( LDVL.LT.1 .OR. ( LEFTV .AND. LDVL.LT.N ) ) THEN
209 INFO = -8
210 ELSE IF( LDVR.LT.1 .OR. ( RIGHTV .AND. LDVR.LT.N ) ) THEN
211 INFO = -10
212 ELSE IF( MM.LT.M ) THEN
213 INFO = -11
214 END IF
215 IF( INFO.NE.0 ) THEN
216 CALL XERBLA( 'ZTREVC', -INFO )
217 RETURN
218 END IF
219 *
220 * Quick return if possible.
221 *
222 IF( N.EQ.0 )
223 $ RETURN
224 *
225 * Set the constants to control overflow.
226 *
227 UNFL = DLAMCH( 'Safe minimum' )
228 OVFL = ONE / UNFL
229 CALL DLABAD( UNFL, OVFL )
230 ULP = DLAMCH( 'Precision' )
231 SMLNUM = UNFL*( N / ULP )
232 *
233 * Store the diagonal elements of T in working array WORK.
234 *
235 DO 20 I = 1, N
236 WORK( I+N ) = T( I, I )
237 20 CONTINUE
238 *
239 * Compute 1-norm of each column of strictly upper triangular
240 * part of T to control overflow in triangular solver.
241 *
242 RWORK( 1 ) = ZERO
243 DO 30 J = 2, N
244 RWORK( J ) = DZASUM( J-1, T( 1, J ), 1 )
245 30 CONTINUE
246 *
247 IF( RIGHTV ) THEN
248 *
249 * Compute right eigenvectors.
250 *
251 IS = M
252 DO 80 KI = N, 1, -1
253 *
254 IF( SOMEV ) THEN
255 IF( .NOT.SELECT( KI ) )
256 $ GO TO 80
257 END IF
258 SMIN = MAX( ULP*( CABS1( T( KI, KI ) ) ), SMLNUM )
259 *
260 WORK( 1 ) = CMONE
261 *
262 * Form right-hand side.
263 *
264 DO 40 K = 1, KI - 1
265 WORK( K ) = -T( K, KI )
266 40 CONTINUE
267 *
268 * Solve the triangular system:
269 * (T(1:KI-1,1:KI-1) - T(KI,KI))*X = SCALE*WORK.
270 *
271 DO 50 K = 1, KI - 1
272 T( K, K ) = T( K, K ) - T( KI, KI )
273 IF( CABS1( T( K, K ) ).LT.SMIN )
274 $ T( K, K ) = SMIN
275 50 CONTINUE
276 *
277 IF( KI.GT.1 ) THEN
278 CALL ZLATRS( 'Upper', 'No transpose', 'Non-unit', 'Y',
279 $ KI-1, T, LDT, WORK( 1 ), SCALE, RWORK,
280 $ INFO )
281 WORK( KI ) = SCALE
282 END IF
283 *
284 * Copy the vector x or Q*x to VR and normalize.
285 *
286 IF( .NOT.OVER ) THEN
287 CALL ZCOPY( KI, WORK( 1 ), 1, VR( 1, IS ), 1 )
288 *
289 II = IZAMAX( KI, VR( 1, IS ), 1 )
290 REMAX = ONE / CABS1( VR( II, IS ) )
291 CALL ZDSCAL( KI, REMAX, VR( 1, IS ), 1 )
292 *
293 DO 60 K = KI + 1, N
294 VR( K, IS ) = CMZERO
295 60 CONTINUE
296 ELSE
297 IF( KI.GT.1 )
298 $ CALL ZGEMV( 'N', N, KI-1, CMONE, VR, LDVR, WORK( 1 ),
299 $ 1, DCMPLX( SCALE ), VR( 1, KI ), 1 )
300 *
301 II = IZAMAX( N, VR( 1, KI ), 1 )
302 REMAX = ONE / CABS1( VR( II, KI ) )
303 CALL ZDSCAL( N, REMAX, VR( 1, KI ), 1 )
304 END IF
305 *
306 * Set back the original diagonal elements of T.
307 *
308 DO 70 K = 1, KI - 1
309 T( K, K ) = WORK( K+N )
310 70 CONTINUE
311 *
312 IS = IS - 1
313 80 CONTINUE
314 END IF
315 *
316 IF( LEFTV ) THEN
317 *
318 * Compute left eigenvectors.
319 *
320 IS = 1
321 DO 130 KI = 1, N
322 *
323 IF( SOMEV ) THEN
324 IF( .NOT.SELECT( KI ) )
325 $ GO TO 130
326 END IF
327 SMIN = MAX( ULP*( CABS1( T( KI, KI ) ) ), SMLNUM )
328 *
329 WORK( N ) = CMONE
330 *
331 * Form right-hand side.
332 *
333 DO 90 K = KI + 1, N
334 WORK( K ) = -DCONJG( T( KI, K ) )
335 90 CONTINUE
336 *
337 * Solve the triangular system:
338 * (T(KI+1:N,KI+1:N) - T(KI,KI))'*X = SCALE*WORK.
339 *
340 DO 100 K = KI + 1, N
341 T( K, K ) = T( K, K ) - T( KI, KI )
342 IF( CABS1( T( K, K ) ).LT.SMIN )
343 $ T( K, K ) = SMIN
344 100 CONTINUE
345 *
346 IF( KI.LT.N ) THEN
347 CALL ZLATRS( 'Upper', 'Conjugate transpose', 'Non-unit',
348 $ 'Y', N-KI, T( KI+1, KI+1 ), LDT,
349 $ WORK( KI+1 ), SCALE, RWORK, INFO )
350 WORK( KI ) = SCALE
351 END IF
352 *
353 * Copy the vector x or Q*x to VL and normalize.
354 *
355 IF( .NOT.OVER ) THEN
356 CALL ZCOPY( N-KI+1, WORK( KI ), 1, VL( KI, IS ), 1 )
357 *
358 II = IZAMAX( N-KI+1, VL( KI, IS ), 1 ) + KI - 1
359 REMAX = ONE / CABS1( VL( II, IS ) )
360 CALL ZDSCAL( N-KI+1, REMAX, VL( KI, IS ), 1 )
361 *
362 DO 110 K = 1, KI - 1
363 VL( K, IS ) = CMZERO
364 110 CONTINUE
365 ELSE
366 IF( KI.LT.N )
367 $ CALL ZGEMV( 'N', N, N-KI, CMONE, VL( 1, KI+1 ), LDVL,
368 $ WORK( KI+1 ), 1, DCMPLX( SCALE ),
369 $ VL( 1, KI ), 1 )
370 *
371 II = IZAMAX( N, VL( 1, KI ), 1 )
372 REMAX = ONE / CABS1( VL( II, KI ) )
373 CALL ZDSCAL( N, REMAX, VL( 1, KI ), 1 )
374 END IF
375 *
376 * Set back the original diagonal elements of T.
377 *
378 DO 120 K = KI + 1, N
379 T( K, K ) = WORK( K+N )
380 120 CONTINUE
381 *
382 IS = IS + 1
383 130 CONTINUE
384 END IF
385 *
386 RETURN
387 *
388 * End of ZTREVC
389 *
390 END