14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static integer c__4 = 4;
516 static doublereal c_b5 = 0.;
517 static integer c__1 = 1;
518 static integer c__2 = 2;
519 static doublereal c_b42 = 1.;
520 static doublereal c_b48 = -1.;
521 static integer c__0 = 0;
523 /* > \brief \b DTGEX2 swaps adjacent diagonal blocks in an upper (quasi) triangular matrix pair by an orthogon
524 al equivalence transformation. */
526 /* =========== DOCUMENTATION =========== */
528 /* Online html documentation available at */
529 /* http://www.netlib.org/lapack/explore-html/ */
532 /* > Download DTGEX2 + dependencies */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgex2.
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgex2.
539 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgex2.
547 /* SUBROUTINE DTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z, */
548 /* LDZ, J1, N1, N2, WORK, LWORK, INFO ) */
550 /* LOGICAL WANTQ, WANTZ */
551 /* INTEGER INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2 */
552 /* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
553 /* $ WORK( * ), Z( LDZ, * ) */
556 /* > \par Purpose: */
561 /* > DTGEX2 swaps adjacent diagonal blocks (A11, B11) and (A22, B22) */
562 /* > of size 1-by-1 or 2-by-2 in an upper (quasi) triangular matrix pair */
563 /* > (A, B) by an orthogonal equivalence transformation. */
565 /* > (A, B) must be in generalized real Schur canonical form (as returned */
566 /* > by DGGES), i.e. A is block upper triangular with 1-by-1 and 2-by-2 */
567 /* > diagonal blocks. B is upper triangular. */
569 /* > Optionally, the matrices Q and Z of generalized Schur vectors are */
572 /* > Q(in) * A(in) * Z(in)**T = Q(out) * A(out) * Z(out)**T */
573 /* > Q(in) * B(in) * Z(in)**T = Q(out) * B(out) * Z(out)**T */
580 /* > \param[in] WANTQ */
582 /* > WANTQ is LOGICAL */
583 /* > .TRUE. : update the left transformation matrix Q; */
584 /* > .FALSE.: do not update Q. */
587 /* > \param[in] WANTZ */
589 /* > WANTZ is LOGICAL */
590 /* > .TRUE. : update the right transformation matrix Z; */
591 /* > .FALSE.: do not update Z. */
597 /* > The order of the matrices A and B. N >= 0. */
600 /* > \param[in,out] A */
602 /* > A is DOUBLE PRECISION array, dimensions (LDA,N) */
603 /* > On entry, the matrix A in the pair (A, B). */
604 /* > On exit, the updated matrix A. */
607 /* > \param[in] LDA */
609 /* > LDA is INTEGER */
610 /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
613 /* > \param[in,out] B */
615 /* > B is DOUBLE PRECISION array, dimensions (LDB,N) */
616 /* > On entry, the matrix B in the pair (A, B). */
617 /* > On exit, the updated matrix B. */
620 /* > \param[in] LDB */
622 /* > LDB is INTEGER */
623 /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
626 /* > \param[in,out] Q */
628 /* > Q is DOUBLE PRECISION array, dimension (LDQ,N) */
629 /* > On entry, if WANTQ = .TRUE., the orthogonal matrix Q. */
630 /* > On exit, the updated matrix Q. */
631 /* > Not referenced if WANTQ = .FALSE.. */
634 /* > \param[in] LDQ */
636 /* > LDQ is INTEGER */
637 /* > The leading dimension of the array Q. LDQ >= 1. */
638 /* > If WANTQ = .TRUE., LDQ >= N. */
641 /* > \param[in,out] Z */
643 /* > Z is DOUBLE PRECISION array, dimension (LDZ,N) */
644 /* > On entry, if WANTZ =.TRUE., the orthogonal matrix Z. */
645 /* > On exit, the updated matrix Z. */
646 /* > Not referenced if WANTZ = .FALSE.. */
649 /* > \param[in] LDZ */
651 /* > LDZ is INTEGER */
652 /* > The leading dimension of the array Z. LDZ >= 1. */
653 /* > If WANTZ = .TRUE., LDZ >= N. */
656 /* > \param[in] J1 */
658 /* > J1 is INTEGER */
659 /* > The index to the first block (A11, B11). 1 <= J1 <= N. */
662 /* > \param[in] N1 */
664 /* > N1 is INTEGER */
665 /* > The order of the first block (A11, B11). N1 = 0, 1 or 2. */
668 /* > \param[in] N2 */
670 /* > N2 is INTEGER */
671 /* > The order of the second block (A22, B22). N2 = 0, 1 or 2. */
674 /* > \param[out] WORK */
676 /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)). */
679 /* > \param[in] LWORK */
681 /* > LWORK is INTEGER */
682 /* > The dimension of the array WORK. */
683 /* > LWORK >= MAX( 1, N*(N2+N1), (N2+N1)*(N2+N1)*2 ) */
686 /* > \param[out] INFO */
688 /* > INFO is INTEGER */
689 /* > =0: Successful exit */
690 /* > >0: If INFO = 1, the transformed matrix (A, B) would be */
691 /* > too far from generalized Schur form; the blocks are */
692 /* > not swapped and (A, B) and (Q, Z) are unchanged. */
693 /* > The problem of swapping is too ill-conditioned. */
694 /* > <0: If INFO = -16: LWORK is too small. Appropriate value */
695 /* > for LWORK is returned in WORK(1). */
701 /* > \author Univ. of Tennessee */
702 /* > \author Univ. of California Berkeley */
703 /* > \author Univ. of Colorado Denver */
704 /* > \author NAG Ltd. */
706 /* > \date December 2016 */
708 /* > \ingroup doubleGEauxiliary */
710 /* > \par Further Details: */
711 /* ===================== */
713 /* > In the current code both weak and strong stability tests are */
714 /* > performed. The user can omit the strong stability test by changing */
715 /* > the internal logical parameter WANDS to .FALSE.. See ref. [2] for */
718 /* > \par Contributors: */
719 /* ================== */
721 /* > Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
722 /* > Umea University, S-901 87 Umea, Sweden. */
724 /* > \par References: */
725 /* ================ */
729 /* > [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
730 /* > Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
731 /* > M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
732 /* > Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
734 /* > [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
735 /* > Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
736 /* > Estimation: Theory, Algorithms and Software, */
737 /* > Report UMINF - 94.04, Department of Computing Science, Umea */
738 /* > University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working */
739 /* > Note 87. To appear in Numerical Algorithms, 1996. */
742 /* ===================================================================== */
743 /* Subroutine */ int dtgex2_(logical *wantq, logical *wantz, integer *n,
744 doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *
745 q, integer *ldq, doublereal *z__, integer *ldz, integer *j1, integer *
746 n1, integer *n2, doublereal *work, integer *lwork, integer *info)
748 /* System generated locals */
749 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
750 z_offset, i__1, i__2;
753 /* Local variables */
757 doublereal taul[4], dsum;
758 extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
759 doublereal *, integer *, doublereal *, doublereal *);
760 doublereal taur[4], scpy[16] /* was [4][4] */, tcpy[16] /*
763 doublereal s[16] /* was [4][4] */, t[16] /* was [4][4] */;
764 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
766 doublereal scale, bqra21, brqa21;
767 extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
768 integer *, doublereal *, doublereal *, integer *, doublereal *,
769 integer *, doublereal *, doublereal *, integer *);
770 doublereal licop[16] /* was [4][4] */;
772 doublereal ircop[16] /* was [4][4] */, dnorm;
774 extern /* Subroutine */ int dlagv2_(doublereal *, integer *, doublereal *,
775 integer *, doublereal *, doublereal *, doublereal *, doublereal *
776 , doublereal *, doublereal *, doublereal *), dgeqr2_(integer *,
777 integer *, doublereal *, integer *, doublereal *, doublereal *,
778 integer *), dgerq2_(integer *, integer *, doublereal *, integer *,
779 doublereal *, doublereal *, integer *), dorg2r_(integer *,
780 integer *, integer *, doublereal *, integer *, doublereal *,
781 doublereal *, integer *), dorgr2_(integer *, integer *, integer *,
782 doublereal *, integer *, doublereal *, doublereal *, integer *),
783 dorm2r_(char *, char *, integer *, integer *, integer *,
784 doublereal *, integer *, doublereal *, doublereal *, integer *,
785 doublereal *, integer *), dormr2_(char *, char *,
786 integer *, integer *, integer *, doublereal *, integer *,
787 doublereal *, doublereal *, integer *, doublereal *, integer *);
788 doublereal be[2], ai[2];
789 extern /* Subroutine */ int dtgsy2_(char *, integer *, integer *, integer
790 *, doublereal *, integer *, doublereal *, integer *, doublereal *,
791 integer *, doublereal *, integer *, doublereal *, integer *,
792 doublereal *, integer *, doublereal *, doublereal *, doublereal *,
793 integer *, integer *, integer *);
794 doublereal ar[2], sa, sb, li[16] /* was [4][4] */;
795 extern doublereal dlamch_(char *);
796 doublereal dscale, ir[16] /* was [4][4] */, ss, ws;
797 extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
798 doublereal *, integer *, doublereal *, integer *),
799 dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
800 doublereal *), dlaset_(char *, integer *, integer *, doublereal *,
801 doublereal *, doublereal *, integer *), dlassq_(integer *
802 , doublereal *, integer *, doublereal *, doublereal *);
804 doublereal thresh, smlnum, eps;
807 /* -- LAPACK auxiliary routine (version 3.7.0) -- */
808 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
809 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
813 /* ===================================================================== */
814 /* Replaced various illegal calls to DCOPY by calls to DLASET, or by DO */
815 /* loops. Sven Hammarling, 1/5/02. */
818 /* Parameter adjustments */
820 a_offset = 1 + a_dim1 * 1;
823 b_offset = 1 + b_dim1 * 1;
826 q_offset = 1 + q_dim1 * 1;
829 z_offset = 1 + z_dim1 * 1;
836 /* Quick return if possible */
838 if (*n <= 1 || *n1 <= 0 || *n2 <= 0) {
841 if (*n1 > *n || *j1 + *n1 > *n) {
846 i__1 = 1, i__2 = *n * m, i__1 = f2cmax(i__1,i__2), i__2 = m * m << 1;
847 if (*lwork < f2cmax(i__1,i__2)) {
850 i__1 = 1, i__2 = *n * m, i__1 = f2cmax(i__1,i__2), i__2 = m * m << 1;
851 work[1] = (doublereal) f2cmax(i__1,i__2);
858 /* Make a local copy of selected block */
860 dlaset_("Full", &c__4, &c__4, &c_b5, &c_b5, li, &c__4);
861 dlaset_("Full", &c__4, &c__4, &c_b5, &c_b5, ir, &c__4);
862 dlacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, s, &c__4);
863 dlacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, t, &c__4);
865 /* Compute threshold for testing acceptance of swapping. */
868 smlnum = dlamch_("S") / eps;
871 dlacpy_("Full", &m, &m, s, &c__4, &work[1], &m);
873 dlassq_(&i__1, &work[1], &c__1, &dscale, &dsum);
874 dlacpy_("Full", &m, &m, t, &c__4, &work[1], &m);
876 dlassq_(&i__1, &work[1], &c__1, &dscale, &dsum);
877 dnorm = dscale * sqrt(dsum);
879 /* THRES has been changed from */
880 /* THRESH = MAX( TEN*EPS*SA, SMLNUM ) */
882 /* THRESH = MAX( TWENTY*EPS*SA, SMLNUM ) */
884 /* "Bug" reported by Ondra Kamenik, confirmed by Julie Langou, fixed by */
885 /* Jim Demmel and Guillaume Revy. See forum post 1783. */
888 d__1 = eps * 20. * dnorm;
889 thresh = f2cmax(d__1,smlnum);
893 /* CASE 1: Swap 1-by-1 and 1-by-1 blocks. */
895 /* Compute orthogonal QL and RQ that swap 1-by-1 and 1-by-1 blocks */
896 /* using Givens rotations and perform the swap tentatively. */
898 f = s[5] * t[0] - t[5] * s[0];
899 g = s[5] * t[4] - t[5] * s[4];
902 dlartg_(&f, &g, &ir[4], ir, &ddum);
905 drot_(&c__2, s, &c__1, &s[4], &c__1, ir, &ir[1]);
906 drot_(&c__2, t, &c__1, &t[4], &c__1, ir, &ir[1]);
908 dlartg_(s, &s[1], li, &li[1], &ddum);
910 dlartg_(t, &t[1], li, &li[1], &ddum);
912 drot_(&c__2, s, &c__4, &s[1], &c__4, li, &li[1]);
913 drot_(&c__2, t, &c__4, &t[1], &c__4, li, &li[1]);
917 /* Weak stability test: */
918 /* |S21| + |T21| <= O(EPS * F-norm((S, T))) */
920 ws = abs(s[1]) + abs(t[1]);
928 /* Strong stability test: */
929 /* F-norm((A-QL**T*S*QR, B-QL**T*T*QR)) <= O(EPS*F-norm((A,B))) */
931 dlacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, &work[m * m
933 dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, s, &c__4, &c_b5, &
935 dgemm_("N", "T", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
936 c_b42, &work[m * m + 1], &m);
940 dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
942 dlacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, &work[m * m
944 dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, t, &c__4, &c_b5, &
946 dgemm_("N", "T", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
947 c_b42, &work[m * m + 1], &m);
949 dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
950 ss = dscale * sqrt(dsum);
951 dtrong = ss <= thresh;
957 /* Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and */
958 /* (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)). */
961 drot_(&i__1, &a[*j1 * a_dim1 + 1], &c__1, &a[(*j1 + 1) * a_dim1 + 1],
964 drot_(&i__1, &b[*j1 * b_dim1 + 1], &c__1, &b[(*j1 + 1) * b_dim1 + 1],
967 drot_(&i__1, &a[*j1 + *j1 * a_dim1], lda, &a[*j1 + 1 + *j1 * a_dim1],
970 drot_(&i__1, &b[*j1 + *j1 * b_dim1], ldb, &b[*j1 + 1 + *j1 * b_dim1],
973 /* Set N1-by-N2 (2,1) - blocks to ZERO. */
975 a[*j1 + 1 + *j1 * a_dim1] = 0.;
976 b[*j1 + 1 + *j1 * b_dim1] = 0.;
978 /* Accumulate transformations into Q and Z if requested. */
981 drot_(n, &z__[*j1 * z_dim1 + 1], &c__1, &z__[(*j1 + 1) * z_dim1 +
982 1], &c__1, ir, &ir[1]);
985 drot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[(*j1 + 1) * q_dim1 + 1],
989 /* Exit with INFO = 0 if swap was successfully performed. */
995 /* CASE 2: Swap 1-by-1 and 2-by-2 blocks, or 2-by-2 */
996 /* and 2-by-2 blocks. */
998 /* Solve the generalized Sylvester equation */
999 /* S11 * R - L * S22 = SCALE * S12 */
1000 /* T11 * R - L * T22 = SCALE * T12 */
1001 /* for R and L. Solutions in LI and IR. */
1003 dlacpy_("Full", n1, n2, &t[(*n1 + 1 << 2) - 4], &c__4, li, &c__4);
1004 dlacpy_("Full", n1, n2, &s[(*n1 + 1 << 2) - 4], &c__4, &ir[*n2 + 1 + (
1005 *n1 + 1 << 2) - 5], &c__4);
1006 dtgsy2_("N", &c__0, n1, n2, s, &c__4, &s[*n1 + 1 + (*n1 + 1 << 2) - 5]
1007 , &c__4, &ir[*n2 + 1 + (*n1 + 1 << 2) - 5], &c__4, t, &c__4, &
1008 t[*n1 + 1 + (*n1 + 1 << 2) - 5], &c__4, li, &c__4, &scale, &
1009 dsum, &dscale, iwork, &idum, &linfo);
1011 /* Compute orthogonal matrix QL: */
1013 /* QL**T * LI = [ TL ] */
1017 /* [ SCALE * identity(N2) ] */
1020 for (i__ = 1; i__ <= i__1; ++i__) {
1021 dscal_(n1, &c_b48, &li[(i__ << 2) - 4], &c__1);
1022 li[*n1 + i__ + (i__ << 2) - 5] = scale;
1025 dgeqr2_(&m, n2, li, &c__4, taul, &work[1], &linfo);
1029 dorg2r_(&m, &m, n2, li, &c__4, taul, &work[1], &linfo);
1034 /* Compute orthogonal matrix RQ: */
1036 /* IR * RQ**T = [ 0 TR], */
1038 /* where IR = [ SCALE * identity(N1), R ] */
1041 for (i__ = 1; i__ <= i__1; ++i__) {
1042 ir[*n2 + i__ + (i__ << 2) - 5] = scale;
1045 dgerq2_(n1, &m, &ir[*n2], &c__4, taur, &work[1], &linfo);
1049 dorgr2_(&m, &m, n1, ir, &c__4, taur, &work[1], &linfo);
1054 /* Perform the swapping tentatively: */
1056 dgemm_("T", "N", &m, &m, &m, &c_b42, li, &c__4, s, &c__4, &c_b5, &
1058 dgemm_("N", "T", &m, &m, &m, &c_b42, &work[1], &m, ir, &c__4, &c_b5,
1060 dgemm_("T", "N", &m, &m, &m, &c_b42, li, &c__4, t, &c__4, &c_b5, &
1062 dgemm_("N", "T", &m, &m, &m, &c_b42, &work[1], &m, ir, &c__4, &c_b5,
1064 dlacpy_("F", &m, &m, s, &c__4, scpy, &c__4);
1065 dlacpy_("F", &m, &m, t, &c__4, tcpy, &c__4);
1066 dlacpy_("F", &m, &m, ir, &c__4, ircop, &c__4);
1067 dlacpy_("F", &m, &m, li, &c__4, licop, &c__4);
1069 /* Triangularize the B-part by an RQ factorization. */
1070 /* Apply transformation (from left) to A-part, giving S. */
1072 dgerq2_(&m, &m, t, &c__4, taur, &work[1], &linfo);
1076 dormr2_("R", "T", &m, &m, &m, t, &c__4, taur, s, &c__4, &work[1], &
1081 dormr2_("L", "N", &m, &m, &m, t, &c__4, taur, ir, &c__4, &work[1], &
1087 /* Compute F-norm(S21) in BRQA21. (T21 is 0.) */
1092 for (i__ = 1; i__ <= i__1; ++i__) {
1093 dlassq_(n1, &s[*n2 + 1 + (i__ << 2) - 5], &c__1, &dscale, &dsum);
1096 brqa21 = dscale * sqrt(dsum);
1098 /* Triangularize the B-part by a QR factorization. */
1099 /* Apply transformation (from right) to A-part, giving S. */
1101 dgeqr2_(&m, &m, tcpy, &c__4, taul, &work[1], &linfo);
1105 dorm2r_("L", "T", &m, &m, &m, tcpy, &c__4, taul, scpy, &c__4, &work[1]
1107 dorm2r_("R", "N", &m, &m, &m, tcpy, &c__4, taul, licop, &c__4, &work[
1113 /* Compute F-norm(S21) in BQRA21. (T21 is 0.) */
1118 for (i__ = 1; i__ <= i__1; ++i__) {
1119 dlassq_(n1, &scpy[*n2 + 1 + (i__ << 2) - 5], &c__1, &dscale, &
1123 bqra21 = dscale * sqrt(dsum);
1125 /* Decide which method to use. */
1126 /* Weak stability test: */
1127 /* F-norm(S21) <= O(EPS * F-norm((S, T))) */
1129 if (bqra21 <= brqa21 && bqra21 <= thresh) {
1130 dlacpy_("F", &m, &m, scpy, &c__4, s, &c__4);
1131 dlacpy_("F", &m, &m, tcpy, &c__4, t, &c__4);
1132 dlacpy_("F", &m, &m, ircop, &c__4, ir, &c__4);
1133 dlacpy_("F", &m, &m, licop, &c__4, li, &c__4);
1134 } else if (brqa21 >= thresh) {
1138 /* Set lower triangle of B-part to zero */
1142 dlaset_("Lower", &i__1, &i__2, &c_b5, &c_b5, &t[1], &c__4);
1146 /* Strong stability test: */
1147 /* F-norm((A-QL*S*QR**T, B-QL*T*QR**T)) <= O(EPS*F-norm((A,B))) */
1149 dlacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, &work[m * m
1151 dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, s, &c__4, &c_b5, &
1153 dgemm_("N", "N", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
1154 c_b42, &work[m * m + 1], &m);
1158 dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
1160 dlacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, &work[m * m
1162 dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, t, &c__4, &c_b5, &
1164 dgemm_("N", "N", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
1165 c_b42, &work[m * m + 1], &m);
1167 dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
1168 ss = dscale * sqrt(dsum);
1169 dtrong = ss <= thresh;
1176 /* If the swap is accepted ("weakly" and "strongly"), apply the */
1177 /* transformations and set N1-by-N2 (2,1)-block to zero. */
1179 dlaset_("Full", n1, n2, &c_b5, &c_b5, &s[*n2], &c__4);
1181 /* copy back M-by-M diagonal block starting at index J1 of (A, B) */
1183 dlacpy_("F", &m, &m, s, &c__4, &a[*j1 + *j1 * a_dim1], lda)
1185 dlacpy_("F", &m, &m, t, &c__4, &b[*j1 + *j1 * b_dim1], ldb)
1187 dlaset_("Full", &c__4, &c__4, &c_b5, &c_b5, t, &c__4);
1189 /* Standardize existing 2-by-2 blocks. */
1191 dlaset_("Full", &m, &m, &c_b5, &c_b5, &work[1], &m);
1194 idum = *lwork - m * m - 2;
1196 dlagv2_(&a[*j1 + *j1 * a_dim1], lda, &b[*j1 + *j1 * b_dim1], ldb,
1197 ar, ai, be, &work[1], &work[2], t, &t[1]);
1198 work[m + 1] = -work[2];
1199 work[m + 2] = work[1];
1200 t[*n2 + (*n2 << 2) - 5] = t[0];
1204 t[m + (m << 2) - 5] = 1.;
1207 dlagv2_(&a[*j1 + *n2 + (*j1 + *n2) * a_dim1], lda, &b[*j1 + *n2 +
1208 (*j1 + *n2) * b_dim1], ldb, taur, taul, &work[m * m + 1],
1209 &work[*n2 * m + *n2 + 1], &work[*n2 * m + *n2 + 2], &t[*
1210 n2 + 1 + (*n2 + 1 << 2) - 5], &t[m + (m - 1 << 2) - 5]);
1211 work[m * m] = work[*n2 * m + *n2 + 1];
1212 work[m * m - 1] = -work[*n2 * m + *n2 + 2];
1213 t[m + (m << 2) - 5] = t[*n2 + 1 + (*n2 + 1 << 2) - 5];
1214 t[m - 1 + (m << 2) - 5] = -t[m + (m - 1 << 2) - 5];
1216 dgemm_("T", "N", n2, n1, n2, &c_b42, &work[1], &m, &a[*j1 + (*j1 + *
1217 n2) * a_dim1], lda, &c_b5, &work[m * m + 1], n2);
1218 dlacpy_("Full", n2, n1, &work[m * m + 1], n2, &a[*j1 + (*j1 + *n2) *
1220 dgemm_("T", "N", n2, n1, n2, &c_b42, &work[1], &m, &b[*j1 + (*j1 + *
1221 n2) * b_dim1], ldb, &c_b5, &work[m * m + 1], n2);
1222 dlacpy_("Full", n2, n1, &work[m * m + 1], n2, &b[*j1 + (*j1 + *n2) *
1224 dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, &work[1], &m, &c_b5, &
1225 work[m * m + 1], &m);
1226 dlacpy_("Full", &m, &m, &work[m * m + 1], &m, li, &c__4);
1227 dgemm_("N", "N", n2, n1, n1, &c_b42, &a[*j1 + (*j1 + *n2) * a_dim1],
1228 lda, &t[*n2 + 1 + (*n2 + 1 << 2) - 5], &c__4, &c_b5, &work[1],
1230 dlacpy_("Full", n2, n1, &work[1], n2, &a[*j1 + (*j1 + *n2) * a_dim1],
1232 dgemm_("N", "N", n2, n1, n1, &c_b42, &b[*j1 + (*j1 + *n2) * b_dim1],
1233 ldb, &t[*n2 + 1 + (*n2 + 1 << 2) - 5], &c__4, &c_b5, &work[1],
1235 dlacpy_("Full", n2, n1, &work[1], n2, &b[*j1 + (*j1 + *n2) * b_dim1],
1237 dgemm_("T", "N", &m, &m, &m, &c_b42, ir, &c__4, t, &c__4, &c_b5, &
1239 dlacpy_("Full", &m, &m, &work[1], &m, ir, &c__4);
1241 /* Accumulate transformations into Q and Z if requested. */
1244 dgemm_("N", "N", n, &m, &m, &c_b42, &q[*j1 * q_dim1 + 1], ldq, li,
1245 &c__4, &c_b5, &work[1], n);
1246 dlacpy_("Full", n, &m, &work[1], n, &q[*j1 * q_dim1 + 1], ldq);
1251 dgemm_("N", "N", n, &m, &m, &c_b42, &z__[*j1 * z_dim1 + 1], ldz,
1252 ir, &c__4, &c_b5, &work[1], n);
1253 dlacpy_("Full", n, &m, &work[1], n, &z__[*j1 * z_dim1 + 1], ldz);
1257 /* Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and */
1258 /* (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)). */
1262 i__1 = *n - i__ + 1;
1263 dgemm_("T", "N", &m, &i__1, &m, &c_b42, li, &c__4, &a[*j1 + i__ *
1264 a_dim1], lda, &c_b5, &work[1], &m);
1265 i__1 = *n - i__ + 1;
1266 dlacpy_("Full", &m, &i__1, &work[1], &m, &a[*j1 + i__ * a_dim1],
1268 i__1 = *n - i__ + 1;
1269 dgemm_("T", "N", &m, &i__1, &m, &c_b42, li, &c__4, &b[*j1 + i__ *
1270 b_dim1], ldb, &c_b5, &work[1], &m);
1271 i__1 = *n - i__ + 1;
1272 dlacpy_("Full", &m, &i__1, &work[1], &m, &b[*j1 + i__ * b_dim1],
1277 dgemm_("N", "N", &i__, &m, &m, &c_b42, &a[*j1 * a_dim1 + 1], lda,
1278 ir, &c__4, &c_b5, &work[1], &i__);
1279 dlacpy_("Full", &i__, &m, &work[1], &i__, &a[*j1 * a_dim1 + 1],
1281 dgemm_("N", "N", &i__, &m, &m, &c_b42, &b[*j1 * b_dim1 + 1], ldb,
1282 ir, &c__4, &c_b5, &work[1], &i__);
1283 dlacpy_("Full", &i__, &m, &work[1], &i__, &b[*j1 * b_dim1 + 1],
1287 /* Exit with INFO = 0 if swap was successfully performed. */
1293 /* Exit with INFO = 1 if swap was rejected. */