Debian Codegraph @

Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/double/dtgsen.f

raw
1 SUBROUTINE DTGSEN( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B, LDB,
2 $ ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, M, PL,
3 $ PR, DIF, WORK, LWORK, IWORK, LIWORK, INFO )
4 *
5 * -- LAPACK routine (version 3.0) --
6 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
7 * Courant Institute, Argonne National Lab, and Rice University
8 * June 30, 1999
9 *
10 * .. Scalar Arguments ..
11 LOGICAL WANTQ, WANTZ
12 INTEGER IJOB, INFO, LDA, LDB, LDQ, LDZ, LIWORK, LWORK,
13 $ M, N
14 DOUBLE PRECISION PL, PR
15 * ..
16 * .. Array Arguments ..
17 LOGICAL SELECT( * )
18 INTEGER IWORK( * )
19 DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
20 $ B( LDB, * ), BETA( * ), DIF( * ), Q( LDQ, * ),
21 $ WORK( * ), Z( LDZ, * )
22 * ..
23 *
24 * Purpose
25 * =======
26 *
27 * DTGSEN reorders the generalized real Schur decomposition of a real
28 * matrix pair (A, B) (in terms of an orthonormal equivalence trans-
29 * formation Q' * (A, B) * Z), so that a selected cluster of eigenvalues
30 * appears in the leading diagonal blocks of the upper quasi-triangular
31 * matrix A and the upper triangular B. The leading columns of Q and
32 * Z form orthonormal bases of the corresponding left and right eigen-
33 * spaces (deflating subspaces). (A, B) must be in generalized real
34 * Schur canonical form (as returned by DGGES), i.e. A is block upper
35 * triangular with 1-by-1 and 2-by-2 diagonal blocks. B is upper
36 * triangular.
37 *
38 * DTGSEN also computes the generalized eigenvalues
39 *
40 * w(j) = (ALPHAR(j) + i*ALPHAI(j))/BETA(j)
41 *
42 * of the reordered matrix pair (A, B).
43 *
44 * Optionally, DTGSEN computes the estimates of reciprocal condition
45 * numbers for eigenvalues and eigenspaces. These are Difu[(A11,B11),
46 * (A22,B22)] and Difl[(A11,B11), (A22,B22)], i.e. the separation(s)
47 * between the matrix pairs (A11, B11) and (A22,B22) that correspond to
48 * the selected cluster and the eigenvalues outside the cluster, resp.,
49 * and norms of "projections" onto left and right eigenspaces w.r.t.
50 * the selected cluster in the (1,1)-block.
51 *
52 * Arguments
53 * =========
54 *
55 * IJOB (input) INTEGER
56 * Specifies whether condition numbers are required for the
57 * cluster of eigenvalues (PL and PR) or the deflating subspaces
58 * (Difu and Difl):
59 * =0: Only reorder w.r.t. SELECT. No extras.
60 * =1: Reciprocal of norms of "projections" onto left and right
61 * eigenspaces w.r.t. the selected cluster (PL and PR).
62 * =2: Upper bounds on Difu and Difl. F-norm-based estimate
63 * (DIF(1:2)).
64 * =3: Estimate of Difu and Difl. 1-norm-based estimate
65 * (DIF(1:2)).
66 * About 5 times as expensive as IJOB = 2.
67 * =4: Compute PL, PR and DIF (i.e. 0, 1 and 2 above): Economic
68 * version to get it all.
69 * =5: Compute PL, PR and DIF (i.e. 0, 1 and 3 above)
70 *
71 * WANTQ (input) LOGICAL
72 * .TRUE. : update the left transformation matrix Q;
73 * .FALSE.: do not update Q.
74 *
75 * WANTZ (input) LOGICAL
76 * .TRUE. : update the right transformation matrix Z;
77 * .FALSE.: do not update Z.
78 *
79 * SELECT (input) LOGICAL array, dimension (N)
80 * SELECT specifies the eigenvalues in the selected cluster.
81 * To select a real eigenvalue w(j), SELECT(j) must be set to
82 * .TRUE.. To select a complex conjugate pair of eigenvalues
83 * w(j) and w(j+1), corresponding to a 2-by-2 diagonal block,
84 * either SELECT(j) or SELECT(j+1) or both must be set to
85 * .TRUE.; a complex conjugate pair of eigenvalues must be
86 * either both included in the cluster or both excluded.
87 *
88 * N (input) INTEGER
89 * The order of the matrices A and B. N >= 0.
90 *
91 * A (input/output) DOUBLE PRECISION array, dimension(LDA,N)
92 * On entry, the upper quasi-triangular matrix A, with (A, B) in
93 * generalized real Schur canonical form.
94 * On exit, A is overwritten by the reordered matrix A.
95 *
96 * LDA (input) INTEGER
97 * The leading dimension of the array A. LDA >= max(1,N).
98 *
99 * B (input/output) DOUBLE PRECISION array, dimension(LDB,N)
100 * On entry, the upper triangular matrix B, with (A, B) in
101 * generalized real Schur canonical form.
102 * On exit, B is overwritten by the reordered matrix B.
103 *
104 * LDB (input) INTEGER
105 * The leading dimension of the array B. LDB >= max(1,N).
106 *
107 * ALPHAR (output) DOUBLE PRECISION array, dimension (N)
108 * ALPHAI (output) DOUBLE PRECISION array, dimension (N)
109 * BETA (output) DOUBLE PRECISION array, dimension (N)
110 * On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
111 * be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i
112 * and BETA(j),j=1,...,N are the diagonals of the complex Schur
113 * form (S,T) that would result if the 2-by-2 diagonal blocks of
114 * the real generalized Schur form of (A,B) were further reduced
115 * to triangular form using complex unitary transformations.
116 * If ALPHAI(j) is zero, then the j-th eigenvalue is real; if
117 * positive, then the j-th and (j+1)-st eigenvalues are a
118 * complex conjugate pair, with ALPHAI(j+1) negative.
119 *
120 * Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N)
121 * On entry, if WANTQ = .TRUE., Q is an N-by-N matrix.
122 * On exit, Q has been postmultiplied by the left orthogonal
123 * transformation matrix which reorder (A, B); The leading M
124 * columns of Q form orthonormal bases for the specified pair of
125 * left eigenspaces (deflating subspaces).
126 * If WANTQ = .FALSE., Q is not referenced.
127 *
128 * LDQ (input) INTEGER
129 * The leading dimension of the array Q. LDQ >= 1;
130 * and if WANTQ = .TRUE., LDQ >= N.
131 *
132 * Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N)
133 * On entry, if WANTZ = .TRUE., Z is an N-by-N matrix.
134 * On exit, Z has been postmultiplied by the left orthogonal
135 * transformation matrix which reorder (A, B); The leading M
136 * columns of Z form orthonormal bases for the specified pair of
137 * left eigenspaces (deflating subspaces).
138 * If WANTZ = .FALSE., Z is not referenced.
139 *
140 * LDZ (input) INTEGER
141 * The leading dimension of the array Z. LDZ >= 1;
142 * If WANTZ = .TRUE., LDZ >= N.
143 *
144 * M (output) INTEGER
145 * The dimension of the specified pair of left and right eigen-
146 * spaces (deflating subspaces). 0 <= M <= N.
147 *
148 * PL, PR (output) DOUBLE PRECISION
149 * If IJOB = 1, 4 or 5, PL, PR are lower bounds on the
150 * reciprocal of the norm of "projections" onto left and right
151 * eigenspaces with respect to the selected cluster.
152 * 0 < PL, PR <= 1.
153 * If M = 0 or M = N, PL = PR = 1.
154 * If IJOB = 0, 2 or 3, PL and PR are not referenced.
155 *
156 * DIF (output) DOUBLE PRECISION array, dimension (2).
157 * If IJOB >= 2, DIF(1:2) store the estimates of Difu and Difl.
158 * If IJOB = 2 or 4, DIF(1:2) are F-norm-based upper bounds on
159 * Difu and Difl. If IJOB = 3 or 5, DIF(1:2) are 1-norm-based
160 * estimates of Difu and Difl.
161 * If M = 0 or N, DIF(1:2) = F-norm([A, B]).
162 * If IJOB = 0 or 1, DIF is not referenced.
163 *
164 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
165 * IF IJOB = 0, WORK is not referenced. Otherwise,
166 * on exit, if INFO = 0, WORK(1) returns the optimal LWORK.
167 *
168 * LWORK (input) INTEGER
169 * The dimension of the array WORK. LWORK >= 4*N+16.
170 * If IJOB = 1, 2 or 4, LWORK >= MAX(4*N+16, 2*M*(N-M)).
171 * If IJOB = 3 or 5, LWORK >= MAX(4*N+16, 4*M*(N-M)).
172 *
173 * If LWORK = -1, then a workspace query is assumed; the routine
174 * only calculates the optimal size of the WORK array, returns
175 * this value as the first entry of the WORK array, and no error
176 * message related to LWORK is issued by XERBLA.
177 *
178 * IWORK (workspace/output) INTEGER array, dimension (LIWORK)
179 * IF IJOB = 0, IWORK is not referenced. Otherwise,
180 * on exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
181 *
182 * LIWORK (input) INTEGER
183 * The dimension of the array IWORK. LIWORK >= 1.
184 * If IJOB = 1, 2 or 4, LIWORK >= N+6.
185 * If IJOB = 3 or 5, LIWORK >= MAX(2*M*(N-M), N+6).
186 *
187 * If LIWORK = -1, then a workspace query is assumed; the
188 * routine only calculates the optimal size of the IWORK array,
189 * returns this value as the first entry of the IWORK array, and
190 * no error message related to LIWORK is issued by XERBLA.
191 *
192 * INFO (output) INTEGER
193 * =0: Successful exit.
194 * <0: If INFO = -i, the i-th argument had an illegal value.
195 * =1: Reordering of (A, B) failed because the transformed
196 * matrix pair (A, B) would be too far from generalized
197 * Schur form; the problem is very ill-conditioned.
198 * (A, B) may have been partially reordered.
199 * If requested, 0 is returned in DIF(*), PL and PR.
200 *
201 * Further Details
202 * ===============
203 *
204 * DTGSEN first collects the selected eigenvalues by computing
205 * orthogonal U and W that move them to the top left corner of (A, B).
206 * In other words, the selected eigenvalues are the eigenvalues of
207 * (A11, B11) in:
208 *
209 * U'*(A, B)*W = (A11 A12) (B11 B12) n1
210 * ( 0 A22),( 0 B22) n2
211 * n1 n2 n1 n2
212 *
213 * where N = n1+n2 and U' means the transpose of U. The first n1 columns
214 * of U and W span the specified pair of left and right eigenspaces
215 * (deflating subspaces) of (A, B).
216 *
217 * If (A, B) has been obtained from the generalized real Schur
218 * decomposition of a matrix pair (C, D) = Q*(A, B)*Z', then the
219 * reordered generalized real Schur form of (C, D) is given by
220 *
221 * (C, D) = (Q*U)*(U'*(A, B)*W)*(Z*W)',
222 *
223 * and the first n1 columns of Q*U and Z*W span the corresponding
224 * deflating subspaces of (C, D) (Q and Z store Q*U and Z*W, resp.).
225 *
226 * Note that if the selected eigenvalue is sufficiently ill-conditioned,
227 * then its value may differ significantly from its value before
228 * reordering.
229 *
230 * The reciprocal condition numbers of the left and right eigenspaces
231 * spanned by the first n1 columns of U and W (or Q*U and Z*W) may
232 * be returned in DIF(1:2), corresponding to Difu and Difl, resp.
233 *
234 * The Difu and Difl are defined as:
235 *
236 * Difu[(A11, B11), (A22, B22)] = sigma-min( Zu )
237 * and
238 * Difl[(A11, B11), (A22, B22)] = Difu[(A22, B22), (A11, B11)],
239 *
240 * where sigma-min(Zu) is the smallest singular value of the
241 * (2*n1*n2)-by-(2*n1*n2) matrix
242 *
243 * Zu = [ kron(In2, A11) -kron(A22', In1) ]
244 * [ kron(In2, B11) -kron(B22', In1) ].
245 *
246 * Here, Inx is the identity matrix of size nx and A22' is the
247 * transpose of A22. kron(X, Y) is the Kronecker product between
248 * the matrices X and Y.
249 *
250 * When DIF(2) is small, small changes in (A, B) can cause large changes
251 * in the deflating subspace. An approximate (asymptotic) bound on the
252 * maximum angular error in the computed deflating subspaces is
253 *
254 * EPS * norm((A, B)) / DIF(2),
255 *
256 * where EPS is the machine precision.
257 *
258 * The reciprocal norm of the projectors on the left and right
259 * eigenspaces associated with (A11, B11) may be returned in PL and PR.
260 * They are computed as follows. First we compute L and R so that
261 * P*(A, B)*Q is block diagonal, where
262 *
263 * P = ( I -L ) n1 Q = ( I R ) n1
264 * ( 0 I ) n2 and ( 0 I ) n2
265 * n1 n2 n1 n2
266 *
267 * and (L, R) is the solution to the generalized Sylvester equation
268 *
269 * A11*R - L*A22 = -A12
270 * B11*R - L*B22 = -B12
271 *
272 * Then PL = (F-norm(L)**2+1)**(-1/2) and PR = (F-norm(R)**2+1)**(-1/2).
273 * An approximate (asymptotic) bound on the average absolute error of
274 * the selected eigenvalues is
275 *
276 * EPS * norm((A, B)) / PL.
277 *
278 * There are also global error bounds which valid for perturbations up
279 * to a certain restriction: A lower bound (x) on the smallest
280 * F-norm(E,F) for which an eigenvalue of (A11, B11) may move and
281 * coalesce with an eigenvalue of (A22, B22) under perturbation (E,F),
282 * (i.e. (A + E, B + F), is
283 *
284 * x = min(Difu,Difl)/((1/(PL*PL)+1/(PR*PR))**(1/2)+2*max(1/PL,1/PR)).
285 *
286 * An approximate bound on x can be computed from DIF(1:2), PL and PR.
287 *
288 * If y = ( F-norm(E,F) / x) <= 1, the angles between the perturbed
289 * (L', R') and unperturbed (L, R) left and right deflating subspaces
290 * associated with the selected cluster in the (1,1)-blocks can be
291 * bounded as
292 *
293 * max-angle(L, L') <= arctan( y * PL / (1 - y * (1 - PL * PL)**(1/2))
294 * max-angle(R, R') <= arctan( y * PR / (1 - y * (1 - PR * PR)**(1/2))
295 *
296 * See LAPACK User's Guide section 4.11 or the following references
297 * for more information.
298 *
299 * Note that if the default method for computing the Frobenius-norm-
300 * based estimate DIF is not wanted (see DLATDF), then the parameter
301 * IDIFJB (see below) should be changed from 3 to 4 (routine DLATDF
302 * (IJOB = 2 will be used)). See DTGSYL for more details.
303 *
304 * Based on contributions by
305 * Bo Kagstrom and Peter Poromaa, Department of Computing Science,
306 * Umea University, S-901 87 Umea, Sweden.
307 *
308 * References
309 * ==========
310 *
311 * [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the
312 * Generalized Real Schur Form of a Regular Matrix Pair (A, B), in
313 * M.S. Moonen et al (eds), Linear Algebra for Large Scale and
314 * Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218.
315 *
316 * [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified
317 * Eigenvalues of a Regular Matrix Pair (A, B) and Condition
318 * Estimation: Theory, Algorithms and Software,
319 * Report UMINF - 94.04, Department of Computing Science, Umea
320 * University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working
321 * Note 87. To appear in Numerical Algorithms, 1996.
322 *
323 * [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software
324 * for Solving the Generalized Sylvester Equation and Estimating the
325 * Separation between Regular Matrix Pairs, Report UMINF - 93.23,
326 * Department of Computing Science, Umea University, S-901 87 Umea,
327 * Sweden, December 1993, Revised April 1994, Also as LAPACK Working
328 * Note 75. To appear in ACM Trans. on Math. Software, Vol 22, No 1,
329 * 1996.
330 *
331 * =====================================================================
332 *
333 * .. Parameters ..
334 INTEGER IDIFJB
335 PARAMETER ( IDIFJB = 3 )
336 DOUBLE PRECISION ZERO, ONE
337 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
338 * ..
339 * .. Local Scalars ..
340 LOGICAL LQUERY, PAIR, SWAP, WANTD, WANTD1, WANTD2,
341 $ WANTP
342 INTEGER I, IERR, IJB, K, KASE, KK, KS, LIWMIN, LWMIN,
343 $ MN2, N1, N2
344 DOUBLE PRECISION DSCALE, DSUM, EPS, RDSCAL, SMLNUM
345 * ..
346 * .. External Subroutines ..
347 EXTERNAL DLACON, DLACPY, DLAG2, DLASSQ, DTGEXC, DTGSYL,
348 $ XERBLA
349 * ..
350 * .. External Functions ..
351 DOUBLE PRECISION DLAMCH
352 EXTERNAL DLAMCH
353 * ..
354 * .. Intrinsic Functions ..
355 INTRINSIC MAX, SIGN, SQRT
356 * ..
357 * .. Executable Statements ..
358 *
359 * Decode and test the input parameters
360 *
361 INFO = 0
362 LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
363 *
364 IF( IJOB.LT.0 .OR. IJOB.GT.5 ) THEN
365 INFO = -1
366 ELSE IF( N.LT.0 ) THEN
367 INFO = -5
368 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
369 INFO = -7
370 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
371 INFO = -9
372 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
373 INFO = -14
374 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
375 INFO = -16
376 END IF
377 *
378 IF( INFO.NE.0 ) THEN
379 CALL XERBLA( 'DTGSEN', -INFO )
380 RETURN
381 END IF
382 *
383 * Get machine constants
384 *
385 EPS = DLAMCH( 'P' )
386 SMLNUM = DLAMCH( 'S' ) / EPS
387 IERR = 0
388 *
389 WANTP = IJOB.EQ.1 .OR. IJOB.GE.4
390 WANTD1 = IJOB.EQ.2 .OR. IJOB.EQ.4
391 WANTD2 = IJOB.EQ.3 .OR. IJOB.EQ.5
392 WANTD = WANTD1 .OR. WANTD2
393 *
394 * Set M to the dimension of the specified pair of deflating
395 * subspaces.
396 *
397 M = 0
398 PAIR = .FALSE.
399 DO 10 K = 1, N
400 IF( PAIR ) THEN
401 PAIR = .FALSE.
402 ELSE
403 IF( K.LT.N ) THEN
404 IF( A( K+1, K ).EQ.ZERO ) THEN
405 IF( SELECT( K ) )
406 $ M = M + 1
407 ELSE
408 PAIR = .TRUE.
409 IF( SELECT( K ) .OR. SELECT( K+1 ) )
410 $ M = M + 2
411 END IF
412 ELSE
413 IF( SELECT( N ) )
414 $ M = M + 1
415 END IF
416 END IF
417 10 CONTINUE
418 *
419 IF( IJOB.EQ.1 .OR. IJOB.EQ.2 .OR. IJOB.EQ.4 ) THEN
420 LWMIN = MAX( 1, 4*N+16, 2*M*( N-M ) )
421 LIWMIN = MAX( 1, N+6 )
422 ELSE IF( IJOB.EQ.3 .OR. IJOB.EQ.5 ) THEN
423 LWMIN = MAX( 1, 4*N+16, 4*M*( N-M ) )
424 LIWMIN = MAX( 1, 2*M*( N-M ), N+6 )
425 ELSE
426 LWMIN = MAX( 1, 4*N+16 )
427 LIWMIN = 1
428 END IF
429 *
430 WORK( 1 ) = LWMIN
431 IWORK( 1 ) = LIWMIN
432 *
433 IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
434 INFO = -22
435 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
436 INFO = -24
437 END IF
438 *
439 IF( INFO.NE.0 ) THEN
440 CALL XERBLA( 'DTGSEN', -INFO )
441 RETURN
442 ELSE IF( LQUERY ) THEN
443 RETURN
444 END IF
445 *
446 * Quick return if possible.
447 *
448 IF( M.EQ.N .OR. M.EQ.0 ) THEN
449 IF( WANTP ) THEN
450 PL = ONE
451 PR = ONE
452 END IF
453 IF( WANTD ) THEN
454 DSCALE = ZERO
455 DSUM = ONE
456 DO 20 I = 1, N
457 CALL DLASSQ( N, A( 1, I ), 1, DSCALE, DSUM )
458 CALL DLASSQ( N, B( 1, I ), 1, DSCALE, DSUM )
459 20 CONTINUE
460 DIF( 1 ) = DSCALE*SQRT( DSUM )
461 DIF( 2 ) = DIF( 1 )
462 END IF
463 GO TO 60
464 END IF
465 *
466 * Collect the selected blocks at the top-left corner of (A, B).
467 *
468 KS = 0
469 PAIR = .FALSE.
470 DO 30 K = 1, N
471 IF( PAIR ) THEN
472 PAIR = .FALSE.
473 ELSE
474 *
475 SWAP = SELECT( K )
476 IF( K.LT.N ) THEN
477 IF( A( K+1, K ).NE.ZERO ) THEN
478 PAIR = .TRUE.
479 SWAP = SWAP .OR. SELECT( K+1 )
480 END IF
481 END IF
482 *
483 IF( SWAP ) THEN
484 KS = KS + 1
485 *
486 * Swap the K-th block to position KS.
487 * Perform the reordering of diagonal blocks in (A, B)
488 * by orthogonal transformation matrices and update
489 * Q and Z accordingly (if requested):
490 *
491 KK = K
492 IF( K.NE.KS )
493 $ CALL DTGEXC( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ,
494 $ Z, LDZ, KK, KS, WORK, LWORK, IERR )
495 *
496 IF( IERR.GT.0 ) THEN
497 *
498 * Swap is rejected: exit.
499 *
500 INFO = 1
501 IF( WANTP ) THEN
502 PL = ZERO
503 PR = ZERO
504 END IF
505 IF( WANTD ) THEN
506 DIF( 1 ) = ZERO
507 DIF( 2 ) = ZERO
508 END IF
509 GO TO 60
510 END IF
511 *
512 IF( PAIR )
513 $ KS = KS + 1
514 END IF
515 END IF
516 30 CONTINUE
517 IF( WANTP ) THEN
518 *
519 * Solve generalized Sylvester equation for R and L
520 * and compute PL and PR.
521 *
522 N1 = M
523 N2 = N - M
524 I = N1 + 1
525 IJB = 0
526 CALL DLACPY( 'Full', N1, N2, A( 1, I ), LDA, WORK, N1 )
527 CALL DLACPY( 'Full', N1, N2, B( 1, I ), LDB, WORK( N1*N2+1 ),
528 $ N1 )
529 CALL DTGSYL( 'N', IJB, N1, N2, A, LDA, A( I, I ), LDA, WORK,
530 $ N1, B, LDB, B( I, I ), LDB, WORK( N1*N2+1 ), N1,
531 $ DSCALE, DIF( 1 ), WORK( N1*N2*2+1 ),
532 $ LWORK-2*N1*N2, IWORK, IERR )
533 *
534 * Estimate the reciprocal of norms of "projections" onto left
535 * and right eigenspaces.
536 *
537 RDSCAL = ZERO
538 DSUM = ONE
539 CALL DLASSQ( N1*N2, WORK, 1, RDSCAL, DSUM )
540 PL = RDSCAL*SQRT( DSUM )
541 IF( PL.EQ.ZERO ) THEN
542 PL = ONE
543 ELSE
544 PL = DSCALE / ( SQRT( DSCALE*DSCALE / PL+PL )*SQRT( PL ) )
545 END IF
546 RDSCAL = ZERO
547 DSUM = ONE
548 CALL DLASSQ( N1*N2, WORK( N1*N2+1 ), 1, RDSCAL, DSUM )
549 PR = RDSCAL*SQRT( DSUM )
550 IF( PR.EQ.ZERO ) THEN
551 PR = ONE
552 ELSE
553 PR = DSCALE / ( SQRT( DSCALE*DSCALE / PR+PR )*SQRT( PR ) )
554 END IF
555 END IF
556 *
557 IF( WANTD ) THEN
558 *
559 * Compute estimates of Difu and Difl.
560 *
561 IF( WANTD1 ) THEN
562 N1 = M
563 N2 = N - M
564 I = N1 + 1
565 IJB = IDIFJB
566 *
567 * Frobenius norm-based Difu-estimate.
568 *
569 CALL DTGSYL( 'N', IJB, N1, N2, A, LDA, A( I, I ), LDA, WORK,
570 $ N1, B, LDB, B( I, I ), LDB, WORK( N1*N2+1 ),
571 $ N1, DSCALE, DIF( 1 ), WORK( 2*N1*N2+1 ),
572 $ LWORK-2*N1*N2, IWORK, IERR )
573 *
574 * Frobenius norm-based Difl-estimate.
575 *
576 CALL DTGSYL( 'N', IJB, N2, N1, A( I, I ), LDA, A, LDA, WORK,
577 $ N2, B( I, I ), LDB, B, LDB, WORK( N1*N2+1 ),
578 $ N2, DSCALE, DIF( 2 ), WORK( 2*N1*N2+1 ),
579 $ LWORK-2*N1*N2, IWORK, IERR )
580 ELSE
581 *
582 *
583 * Compute 1-norm-based estimates of Difu and Difl using
584 * reversed communication with DLACON. In each step a
585 * generalized Sylvester equation or a transposed variant
586 * is solved.
587 *
588 KASE = 0
589 N1 = M
590 N2 = N - M
591 I = N1 + 1
592 IJB = 0
593 MN2 = 2*N1*N2
594 *
595 * 1-norm-based estimate of Difu.
596 *
597 40 CONTINUE
598 CALL DLACON( MN2, WORK( MN2+1 ), WORK, IWORK, DIF( 1 ),
599 $ KASE )
600 IF( KASE.NE.0 ) THEN
601 IF( KASE.EQ.1 ) THEN
602 *
603 * Solve generalized Sylvester equation.
604 *
605 CALL DTGSYL( 'N', IJB, N1, N2, A, LDA, A( I, I ), LDA,
606 $ WORK, N1, B, LDB, B( I, I ), LDB,
607 $ WORK( N1*N2+1 ), N1, DSCALE, DIF( 1 ),
608 $ WORK( 2*N1*N2+1 ), LWORK-2*N1*N2, IWORK,
609 $ IERR )
610 ELSE
611 *
612 * Solve the transposed variant.
613 *
614 CALL DTGSYL( 'T', IJB, N1, N2, A, LDA, A( I, I ), LDA,
615 $ WORK, N1, B, LDB, B( I, I ), LDB,
616 $ WORK( N1*N2+1 ), N1, DSCALE, DIF( 1 ),
617 $ WORK( 2*N1*N2+1 ), LWORK-2*N1*N2, IWORK,
618 $ IERR )
619 END IF
620 GO TO 40
621 END IF
622 DIF( 1 ) = DSCALE / DIF( 1 )
623 *
624 * 1-norm-based estimate of Difl.
625 *
626 50 CONTINUE
627 CALL DLACON( MN2, WORK( MN2+1 ), WORK, IWORK, DIF( 2 ),
628 $ KASE )
629 IF( KASE.NE.0 ) THEN
630 IF( KASE.EQ.1 ) THEN
631 *
632 * Solve generalized Sylvester equation.
633 *
634 CALL DTGSYL( 'N', IJB, N2, N1, A( I, I ), LDA, A, LDA,
635 $ WORK, N2, B( I, I ), LDB, B, LDB,
636 $ WORK( N1*N2+1 ), N2, DSCALE, DIF( 2 ),
637 $ WORK( 2*N1*N2+1 ), LWORK-2*N1*N2, IWORK,
638 $ IERR )
639 ELSE
640 *
641 * Solve the transposed variant.
642 *
643 CALL DTGSYL( 'T', IJB, N2, N1, A( I, I ), LDA, A, LDA,
644 $ WORK, N2, B( I, I ), LDB, B, LDB,
645 $ WORK( N1*N2+1 ), N2, DSCALE, DIF( 2 ),
646 $ WORK( 2*N1*N2+1 ), LWORK-2*N1*N2, IWORK,
647 $ IERR )
648 END IF
649 GO TO 50
650 END IF
651 DIF( 2 ) = DSCALE / DIF( 2 )
652 *
653 END IF
654 END IF
655 *
656 60 CONTINUE
657 *
658 * Compute generalized eigenvalues of reordered pair (A, B) and
659 * normalize the generalized Schur form.
660 *
661 PAIR = .FALSE.
662 DO 80 K = 1, N
663 IF( PAIR ) THEN
664 PAIR = .FALSE.
665 ELSE
666 *
667 IF( K.LT.N ) THEN
668 IF( A( K+1, K ).NE.ZERO ) THEN
669 PAIR = .TRUE.
670 END IF
671 END IF
672 *
673 IF( PAIR ) THEN
674 *
675 * Compute the eigenvalue(s) at position K.
676 *
677 WORK( 1 ) = A( K, K )
678 WORK( 2 ) = A( K+1, K )
679 WORK( 3 ) = A( K, K+1 )
680 WORK( 4 ) = A( K+1, K+1 )
681 WORK( 5 ) = B( K, K )
682 WORK( 6 ) = B( K+1, K )
683 WORK( 7 ) = B( K, K+1 )
684 WORK( 8 ) = B( K+1, K+1 )
685 CALL DLAG2( WORK, 2, WORK( 5 ), 2, SMLNUM*EPS, BETA( K ),
686 $ BETA( K+1 ), ALPHAR( K ), ALPHAR( K+1 ),
687 $ ALPHAI( K ) )
688 ALPHAI( K+1 ) = -ALPHAI( K )
689 *
690 ELSE
691 *
692 IF( SIGN( ONE, B( K, K ) ).LT.ZERO ) THEN
693 *
694 * If B(K,K) is negative, make it positive
695 *
696 DO 70 I = 1, N
697 A( K, I ) = -A( K, I )
698 B( K, I ) = -B( K, I )
699 Q( I, K ) = -Q( I, K )
700 70 CONTINUE
701 END IF
702 *
703 ALPHAR( K ) = A( K, K )
704 ALPHAI( K ) = ZERO
705 BETA( K ) = B( K, K )
706 *
707 END IF
708 END IF
709 80 CONTINUE
710 *
711 WORK( 1 ) = LWMIN
712 IWORK( 1 ) = LIWMIN
713 *
714 RETURN
715 *
716 * End of DTGSEN
717 *
718 END