You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dtgex2.c 37 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #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++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #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]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static integer c__4 = 4;
  363. static doublereal c_b5 = 0.;
  364. static integer c__1 = 1;
  365. static integer c__2 = 2;
  366. static doublereal c_b42 = 1.;
  367. static doublereal c_b48 = -1.;
  368. static integer c__0 = 0;
  369. /* > \brief \b DTGEX2 swaps adjacent diagonal blocks in an upper (quasi) triangular matrix pair by an orthogon
  370. al equivalence transformation. */
  371. /* =========== DOCUMENTATION =========== */
  372. /* Online html documentation available at */
  373. /* http://www.netlib.org/lapack/explore-html/ */
  374. /* > \htmlonly */
  375. /* > Download DTGEX2 + dependencies */
  376. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtgex2.
  377. f"> */
  378. /* > [TGZ]</a> */
  379. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtgex2.
  380. f"> */
  381. /* > [ZIP]</a> */
  382. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtgex2.
  383. f"> */
  384. /* > [TXT]</a> */
  385. /* > \endhtmlonly */
  386. /* Definition: */
  387. /* =========== */
  388. /* SUBROUTINE DTGEX2( WANTQ, WANTZ, N, A, LDA, B, LDB, Q, LDQ, Z, */
  389. /* LDZ, J1, N1, N2, WORK, LWORK, INFO ) */
  390. /* LOGICAL WANTQ, WANTZ */
  391. /* INTEGER INFO, J1, LDA, LDB, LDQ, LDZ, LWORK, N, N1, N2 */
  392. /* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
  393. /* $ WORK( * ), Z( LDZ, * ) */
  394. /* > \par Purpose: */
  395. /* ============= */
  396. /* > */
  397. /* > \verbatim */
  398. /* > */
  399. /* > DTGEX2 swaps adjacent diagonal blocks (A11, B11) and (A22, B22) */
  400. /* > of size 1-by-1 or 2-by-2 in an upper (quasi) triangular matrix pair */
  401. /* > (A, B) by an orthogonal equivalence transformation. */
  402. /* > */
  403. /* > (A, B) must be in generalized real Schur canonical form (as returned */
  404. /* > by DGGES), i.e. A is block upper triangular with 1-by-1 and 2-by-2 */
  405. /* > diagonal blocks. B is upper triangular. */
  406. /* > */
  407. /* > Optionally, the matrices Q and Z of generalized Schur vectors are */
  408. /* > updated. */
  409. /* > */
  410. /* > Q(in) * A(in) * Z(in)**T = Q(out) * A(out) * Z(out)**T */
  411. /* > Q(in) * B(in) * Z(in)**T = Q(out) * B(out) * Z(out)**T */
  412. /* > */
  413. /* > \endverbatim */
  414. /* Arguments: */
  415. /* ========== */
  416. /* > \param[in] WANTQ */
  417. /* > \verbatim */
  418. /* > WANTQ is LOGICAL */
  419. /* > .TRUE. : update the left transformation matrix Q; */
  420. /* > .FALSE.: do not update Q. */
  421. /* > \endverbatim */
  422. /* > */
  423. /* > \param[in] WANTZ */
  424. /* > \verbatim */
  425. /* > WANTZ is LOGICAL */
  426. /* > .TRUE. : update the right transformation matrix Z; */
  427. /* > .FALSE.: do not update Z. */
  428. /* > \endverbatim */
  429. /* > */
  430. /* > \param[in] N */
  431. /* > \verbatim */
  432. /* > N is INTEGER */
  433. /* > The order of the matrices A and B. N >= 0. */
  434. /* > \endverbatim */
  435. /* > */
  436. /* > \param[in,out] A */
  437. /* > \verbatim */
  438. /* > A is DOUBLE PRECISION array, dimensions (LDA,N) */
  439. /* > On entry, the matrix A in the pair (A, B). */
  440. /* > On exit, the updated matrix A. */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[in] LDA */
  444. /* > \verbatim */
  445. /* > LDA is INTEGER */
  446. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  447. /* > \endverbatim */
  448. /* > */
  449. /* > \param[in,out] B */
  450. /* > \verbatim */
  451. /* > B is DOUBLE PRECISION array, dimensions (LDB,N) */
  452. /* > On entry, the matrix B in the pair (A, B). */
  453. /* > On exit, the updated matrix B. */
  454. /* > \endverbatim */
  455. /* > */
  456. /* > \param[in] LDB */
  457. /* > \verbatim */
  458. /* > LDB is INTEGER */
  459. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  460. /* > \endverbatim */
  461. /* > */
  462. /* > \param[in,out] Q */
  463. /* > \verbatim */
  464. /* > Q is DOUBLE PRECISION array, dimension (LDQ,N) */
  465. /* > On entry, if WANTQ = .TRUE., the orthogonal matrix Q. */
  466. /* > On exit, the updated matrix Q. */
  467. /* > Not referenced if WANTQ = .FALSE.. */
  468. /* > \endverbatim */
  469. /* > */
  470. /* > \param[in] LDQ */
  471. /* > \verbatim */
  472. /* > LDQ is INTEGER */
  473. /* > The leading dimension of the array Q. LDQ >= 1. */
  474. /* > If WANTQ = .TRUE., LDQ >= N. */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[in,out] Z */
  478. /* > \verbatim */
  479. /* > Z is DOUBLE PRECISION array, dimension (LDZ,N) */
  480. /* > On entry, if WANTZ =.TRUE., the orthogonal matrix Z. */
  481. /* > On exit, the updated matrix Z. */
  482. /* > Not referenced if WANTZ = .FALSE.. */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[in] LDZ */
  486. /* > \verbatim */
  487. /* > LDZ is INTEGER */
  488. /* > The leading dimension of the array Z. LDZ >= 1. */
  489. /* > If WANTZ = .TRUE., LDZ >= N. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[in] J1 */
  493. /* > \verbatim */
  494. /* > J1 is INTEGER */
  495. /* > The index to the first block (A11, B11). 1 <= J1 <= N. */
  496. /* > \endverbatim */
  497. /* > */
  498. /* > \param[in] N1 */
  499. /* > \verbatim */
  500. /* > N1 is INTEGER */
  501. /* > The order of the first block (A11, B11). N1 = 0, 1 or 2. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[in] N2 */
  505. /* > \verbatim */
  506. /* > N2 is INTEGER */
  507. /* > The order of the second block (A22, B22). N2 = 0, 1 or 2. */
  508. /* > \endverbatim */
  509. /* > */
  510. /* > \param[out] WORK */
  511. /* > \verbatim */
  512. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)). */
  513. /* > \endverbatim */
  514. /* > */
  515. /* > \param[in] LWORK */
  516. /* > \verbatim */
  517. /* > LWORK is INTEGER */
  518. /* > The dimension of the array WORK. */
  519. /* > LWORK >= MAX( 1, N*(N2+N1), (N2+N1)*(N2+N1)*2 ) */
  520. /* > \endverbatim */
  521. /* > */
  522. /* > \param[out] INFO */
  523. /* > \verbatim */
  524. /* > INFO is INTEGER */
  525. /* > =0: Successful exit */
  526. /* > >0: If INFO = 1, the transformed matrix (A, B) would be */
  527. /* > too far from generalized Schur form; the blocks are */
  528. /* > not swapped and (A, B) and (Q, Z) are unchanged. */
  529. /* > The problem of swapping is too ill-conditioned. */
  530. /* > <0: If INFO = -16: LWORK is too small. Appropriate value */
  531. /* > for LWORK is returned in WORK(1). */
  532. /* > \endverbatim */
  533. /* Authors: */
  534. /* ======== */
  535. /* > \author Univ. of Tennessee */
  536. /* > \author Univ. of California Berkeley */
  537. /* > \author Univ. of Colorado Denver */
  538. /* > \author NAG Ltd. */
  539. /* > \date December 2016 */
  540. /* > \ingroup doubleGEauxiliary */
  541. /* > \par Further Details: */
  542. /* ===================== */
  543. /* > */
  544. /* > In the current code both weak and strong stability tests are */
  545. /* > performed. The user can omit the strong stability test by changing */
  546. /* > the internal logical parameter WANDS to .FALSE.. See ref. [2] for */
  547. /* > details. */
  548. /* > \par Contributors: */
  549. /* ================== */
  550. /* > */
  551. /* > Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  552. /* > Umea University, S-901 87 Umea, Sweden. */
  553. /* > \par References: */
  554. /* ================ */
  555. /* > */
  556. /* > \verbatim */
  557. /* > */
  558. /* > [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
  559. /* > Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
  560. /* > M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
  561. /* > Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
  562. /* > */
  563. /* > [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
  564. /* > Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
  565. /* > Estimation: Theory, Algorithms and Software, */
  566. /* > Report UMINF - 94.04, Department of Computing Science, Umea */
  567. /* > University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working */
  568. /* > Note 87. To appear in Numerical Algorithms, 1996. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* ===================================================================== */
  572. /* Subroutine */ int dtgex2_(logical *wantq, logical *wantz, integer *n,
  573. doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *
  574. q, integer *ldq, doublereal *z__, integer *ldz, integer *j1, integer *
  575. n1, integer *n2, doublereal *work, integer *lwork, integer *info)
  576. {
  577. /* System generated locals */
  578. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  579. z_offset, i__1, i__2;
  580. doublereal d__1;
  581. /* Local variables */
  582. logical weak;
  583. doublereal ddum;
  584. integer idum;
  585. doublereal taul[4], dsum;
  586. extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
  587. doublereal *, integer *, doublereal *, doublereal *);
  588. doublereal taur[4], scpy[16] /* was [4][4] */, tcpy[16] /*
  589. was [4][4] */, f, g;
  590. integer i__, m;
  591. doublereal s[16] /* was [4][4] */, t[16] /* was [4][4] */;
  592. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  593. integer *);
  594. doublereal scale, bqra21, brqa21;
  595. extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
  596. integer *, doublereal *, doublereal *, integer *, doublereal *,
  597. integer *, doublereal *, doublereal *, integer *);
  598. doublereal licop[16] /* was [4][4] */;
  599. integer linfo;
  600. doublereal ircop[16] /* was [4][4] */, dnorm;
  601. integer iwork[4];
  602. extern /* Subroutine */ int dlagv2_(doublereal *, integer *, doublereal *,
  603. integer *, doublereal *, doublereal *, doublereal *, doublereal *
  604. , doublereal *, doublereal *, doublereal *), dgeqr2_(integer *,
  605. integer *, doublereal *, integer *, doublereal *, doublereal *,
  606. integer *), dgerq2_(integer *, integer *, doublereal *, integer *,
  607. doublereal *, doublereal *, integer *), dorg2r_(integer *,
  608. integer *, integer *, doublereal *, integer *, doublereal *,
  609. doublereal *, integer *), dorgr2_(integer *, integer *, integer *,
  610. doublereal *, integer *, doublereal *, doublereal *, integer *),
  611. dorm2r_(char *, char *, integer *, integer *, integer *,
  612. doublereal *, integer *, doublereal *, doublereal *, integer *,
  613. doublereal *, integer *), dormr2_(char *, char *,
  614. integer *, integer *, integer *, doublereal *, integer *,
  615. doublereal *, doublereal *, integer *, doublereal *, integer *);
  616. doublereal be[2], ai[2];
  617. extern /* Subroutine */ int dtgsy2_(char *, integer *, integer *, integer
  618. *, doublereal *, integer *, doublereal *, integer *, doublereal *,
  619. integer *, doublereal *, integer *, doublereal *, integer *,
  620. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  621. integer *, integer *, integer *);
  622. doublereal ar[2], sa, sb, li[16] /* was [4][4] */;
  623. extern doublereal dlamch_(char *);
  624. doublereal dscale, ir[16] /* was [4][4] */, ss, ws;
  625. extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
  626. doublereal *, integer *, doublereal *, integer *),
  627. dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  628. doublereal *), dlaset_(char *, integer *, integer *, doublereal *,
  629. doublereal *, doublereal *, integer *), dlassq_(integer *
  630. , doublereal *, integer *, doublereal *, doublereal *);
  631. logical dtrong;
  632. doublereal thresh, smlnum, eps;
  633. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  634. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  635. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  636. /* December 2016 */
  637. /* ===================================================================== */
  638. /* Replaced various illegal calls to DCOPY by calls to DLASET, or by DO */
  639. /* loops. Sven Hammarling, 1/5/02. */
  640. /* Parameter adjustments */
  641. a_dim1 = *lda;
  642. a_offset = 1 + a_dim1 * 1;
  643. a -= a_offset;
  644. b_dim1 = *ldb;
  645. b_offset = 1 + b_dim1 * 1;
  646. b -= b_offset;
  647. q_dim1 = *ldq;
  648. q_offset = 1 + q_dim1 * 1;
  649. q -= q_offset;
  650. z_dim1 = *ldz;
  651. z_offset = 1 + z_dim1 * 1;
  652. z__ -= z_offset;
  653. --work;
  654. /* Function Body */
  655. *info = 0;
  656. /* Quick return if possible */
  657. if (*n <= 1 || *n1 <= 0 || *n2 <= 0) {
  658. return 0;
  659. }
  660. if (*n1 > *n || *j1 + *n1 > *n) {
  661. return 0;
  662. }
  663. m = *n1 + *n2;
  664. /* Computing MAX */
  665. i__1 = 1, i__2 = *n * m, i__1 = f2cmax(i__1,i__2), i__2 = m * m << 1;
  666. if (*lwork < f2cmax(i__1,i__2)) {
  667. *info = -16;
  668. /* Computing MAX */
  669. i__1 = 1, i__2 = *n * m, i__1 = f2cmax(i__1,i__2), i__2 = m * m << 1;
  670. work[1] = (doublereal) f2cmax(i__1,i__2);
  671. return 0;
  672. }
  673. weak = FALSE_;
  674. dtrong = FALSE_;
  675. /* Make a local copy of selected block */
  676. dlaset_("Full", &c__4, &c__4, &c_b5, &c_b5, li, &c__4);
  677. dlaset_("Full", &c__4, &c__4, &c_b5, &c_b5, ir, &c__4);
  678. dlacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, s, &c__4);
  679. dlacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, t, &c__4);
  680. /* Compute threshold for testing acceptance of swapping. */
  681. eps = dlamch_("P");
  682. smlnum = dlamch_("S") / eps;
  683. dscale = 0.;
  684. dsum = 1.;
  685. dlacpy_("Full", &m, &m, s, &c__4, &work[1], &m);
  686. i__1 = m * m;
  687. dlassq_(&i__1, &work[1], &c__1, &dscale, &dsum);
  688. dlacpy_("Full", &m, &m, t, &c__4, &work[1], &m);
  689. i__1 = m * m;
  690. dlassq_(&i__1, &work[1], &c__1, &dscale, &dsum);
  691. dnorm = dscale * sqrt(dsum);
  692. /* THRES has been changed from */
  693. /* THRESH = MAX( TEN*EPS*SA, SMLNUM ) */
  694. /* to */
  695. /* THRESH = MAX( TWENTY*EPS*SA, SMLNUM ) */
  696. /* on 04/01/10. */
  697. /* "Bug" reported by Ondra Kamenik, confirmed by Julie Langou, fixed by */
  698. /* Jim Demmel and Guillaume Revy. See forum post 1783. */
  699. /* Computing MAX */
  700. d__1 = eps * 20. * dnorm;
  701. thresh = f2cmax(d__1,smlnum);
  702. if (m == 2) {
  703. /* CASE 1: Swap 1-by-1 and 1-by-1 blocks. */
  704. /* Compute orthogonal QL and RQ that swap 1-by-1 and 1-by-1 blocks */
  705. /* using Givens rotations and perform the swap tentatively. */
  706. f = s[5] * t[0] - t[5] * s[0];
  707. g = s[5] * t[4] - t[5] * s[4];
  708. sb = abs(t[5]);
  709. sa = abs(s[5]);
  710. dlartg_(&f, &g, &ir[4], ir, &ddum);
  711. ir[1] = -ir[4];
  712. ir[5] = ir[0];
  713. drot_(&c__2, s, &c__1, &s[4], &c__1, ir, &ir[1]);
  714. drot_(&c__2, t, &c__1, &t[4], &c__1, ir, &ir[1]);
  715. if (sa >= sb) {
  716. dlartg_(s, &s[1], li, &li[1], &ddum);
  717. } else {
  718. dlartg_(t, &t[1], li, &li[1], &ddum);
  719. }
  720. drot_(&c__2, s, &c__4, &s[1], &c__4, li, &li[1]);
  721. drot_(&c__2, t, &c__4, &t[1], &c__4, li, &li[1]);
  722. li[5] = li[0];
  723. li[4] = -li[1];
  724. /* Weak stability test: */
  725. /* |S21| + |T21| <= O(EPS * F-norm((S, T))) */
  726. ws = abs(s[1]) + abs(t[1]);
  727. weak = ws <= thresh;
  728. if (! weak) {
  729. goto L70;
  730. }
  731. if (TRUE_) {
  732. /* Strong stability test: */
  733. /* F-norm((A-QL**T*S*QR, B-QL**T*T*QR)) <= O(EPS*F-norm((A,B))) */
  734. dlacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, &work[m * m
  735. + 1], &m);
  736. dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, s, &c__4, &c_b5, &
  737. work[1], &m);
  738. dgemm_("N", "T", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
  739. c_b42, &work[m * m + 1], &m);
  740. dscale = 0.;
  741. dsum = 1.;
  742. i__1 = m * m;
  743. dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
  744. dlacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, &work[m * m
  745. + 1], &m);
  746. dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, t, &c__4, &c_b5, &
  747. work[1], &m);
  748. dgemm_("N", "T", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
  749. c_b42, &work[m * m + 1], &m);
  750. i__1 = m * m;
  751. dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
  752. ss = dscale * sqrt(dsum);
  753. dtrong = ss <= thresh;
  754. if (! dtrong) {
  755. goto L70;
  756. }
  757. }
  758. /* Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and */
  759. /* (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)). */
  760. i__1 = *j1 + 1;
  761. drot_(&i__1, &a[*j1 * a_dim1 + 1], &c__1, &a[(*j1 + 1) * a_dim1 + 1],
  762. &c__1, ir, &ir[1]);
  763. i__1 = *j1 + 1;
  764. drot_(&i__1, &b[*j1 * b_dim1 + 1], &c__1, &b[(*j1 + 1) * b_dim1 + 1],
  765. &c__1, ir, &ir[1]);
  766. i__1 = *n - *j1 + 1;
  767. drot_(&i__1, &a[*j1 + *j1 * a_dim1], lda, &a[*j1 + 1 + *j1 * a_dim1],
  768. lda, li, &li[1]);
  769. i__1 = *n - *j1 + 1;
  770. drot_(&i__1, &b[*j1 + *j1 * b_dim1], ldb, &b[*j1 + 1 + *j1 * b_dim1],
  771. ldb, li, &li[1]);
  772. /* Set N1-by-N2 (2,1) - blocks to ZERO. */
  773. a[*j1 + 1 + *j1 * a_dim1] = 0.;
  774. b[*j1 + 1 + *j1 * b_dim1] = 0.;
  775. /* Accumulate transformations into Q and Z if requested. */
  776. if (*wantz) {
  777. drot_(n, &z__[*j1 * z_dim1 + 1], &c__1, &z__[(*j1 + 1) * z_dim1 +
  778. 1], &c__1, ir, &ir[1]);
  779. }
  780. if (*wantq) {
  781. drot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[(*j1 + 1) * q_dim1 + 1],
  782. &c__1, li, &li[1]);
  783. }
  784. /* Exit with INFO = 0 if swap was successfully performed. */
  785. return 0;
  786. } else {
  787. /* CASE 2: Swap 1-by-1 and 2-by-2 blocks, or 2-by-2 */
  788. /* and 2-by-2 blocks. */
  789. /* Solve the generalized Sylvester equation */
  790. /* S11 * R - L * S22 = SCALE * S12 */
  791. /* T11 * R - L * T22 = SCALE * T12 */
  792. /* for R and L. Solutions in LI and IR. */
  793. dlacpy_("Full", n1, n2, &t[(*n1 + 1 << 2) - 4], &c__4, li, &c__4);
  794. dlacpy_("Full", n1, n2, &s[(*n1 + 1 << 2) - 4], &c__4, &ir[*n2 + 1 + (
  795. *n1 + 1 << 2) - 5], &c__4);
  796. dtgsy2_("N", &c__0, n1, n2, s, &c__4, &s[*n1 + 1 + (*n1 + 1 << 2) - 5]
  797. , &c__4, &ir[*n2 + 1 + (*n1 + 1 << 2) - 5], &c__4, t, &c__4, &
  798. t[*n1 + 1 + (*n1 + 1 << 2) - 5], &c__4, li, &c__4, &scale, &
  799. dsum, &dscale, iwork, &idum, &linfo);
  800. /* Compute orthogonal matrix QL: */
  801. /* QL**T * LI = [ TL ] */
  802. /* [ 0 ] */
  803. /* where */
  804. /* LI = [ -L ] */
  805. /* [ SCALE * identity(N2) ] */
  806. i__1 = *n2;
  807. for (i__ = 1; i__ <= i__1; ++i__) {
  808. dscal_(n1, &c_b48, &li[(i__ << 2) - 4], &c__1);
  809. li[*n1 + i__ + (i__ << 2) - 5] = scale;
  810. /* L10: */
  811. }
  812. dgeqr2_(&m, n2, li, &c__4, taul, &work[1], &linfo);
  813. if (linfo != 0) {
  814. goto L70;
  815. }
  816. dorg2r_(&m, &m, n2, li, &c__4, taul, &work[1], &linfo);
  817. if (linfo != 0) {
  818. goto L70;
  819. }
  820. /* Compute orthogonal matrix RQ: */
  821. /* IR * RQ**T = [ 0 TR], */
  822. /* where IR = [ SCALE * identity(N1), R ] */
  823. i__1 = *n1;
  824. for (i__ = 1; i__ <= i__1; ++i__) {
  825. ir[*n2 + i__ + (i__ << 2) - 5] = scale;
  826. /* L20: */
  827. }
  828. dgerq2_(n1, &m, &ir[*n2], &c__4, taur, &work[1], &linfo);
  829. if (linfo != 0) {
  830. goto L70;
  831. }
  832. dorgr2_(&m, &m, n1, ir, &c__4, taur, &work[1], &linfo);
  833. if (linfo != 0) {
  834. goto L70;
  835. }
  836. /* Perform the swapping tentatively: */
  837. dgemm_("T", "N", &m, &m, &m, &c_b42, li, &c__4, s, &c__4, &c_b5, &
  838. work[1], &m);
  839. dgemm_("N", "T", &m, &m, &m, &c_b42, &work[1], &m, ir, &c__4, &c_b5,
  840. s, &c__4);
  841. dgemm_("T", "N", &m, &m, &m, &c_b42, li, &c__4, t, &c__4, &c_b5, &
  842. work[1], &m);
  843. dgemm_("N", "T", &m, &m, &m, &c_b42, &work[1], &m, ir, &c__4, &c_b5,
  844. t, &c__4);
  845. dlacpy_("F", &m, &m, s, &c__4, scpy, &c__4);
  846. dlacpy_("F", &m, &m, t, &c__4, tcpy, &c__4);
  847. dlacpy_("F", &m, &m, ir, &c__4, ircop, &c__4);
  848. dlacpy_("F", &m, &m, li, &c__4, licop, &c__4);
  849. /* Triangularize the B-part by an RQ factorization. */
  850. /* Apply transformation (from left) to A-part, giving S. */
  851. dgerq2_(&m, &m, t, &c__4, taur, &work[1], &linfo);
  852. if (linfo != 0) {
  853. goto L70;
  854. }
  855. dormr2_("R", "T", &m, &m, &m, t, &c__4, taur, s, &c__4, &work[1], &
  856. linfo);
  857. if (linfo != 0) {
  858. goto L70;
  859. }
  860. dormr2_("L", "N", &m, &m, &m, t, &c__4, taur, ir, &c__4, &work[1], &
  861. linfo);
  862. if (linfo != 0) {
  863. goto L70;
  864. }
  865. /* Compute F-norm(S21) in BRQA21. (T21 is 0.) */
  866. dscale = 0.;
  867. dsum = 1.;
  868. i__1 = *n2;
  869. for (i__ = 1; i__ <= i__1; ++i__) {
  870. dlassq_(n1, &s[*n2 + 1 + (i__ << 2) - 5], &c__1, &dscale, &dsum);
  871. /* L30: */
  872. }
  873. brqa21 = dscale * sqrt(dsum);
  874. /* Triangularize the B-part by a QR factorization. */
  875. /* Apply transformation (from right) to A-part, giving S. */
  876. dgeqr2_(&m, &m, tcpy, &c__4, taul, &work[1], &linfo);
  877. if (linfo != 0) {
  878. goto L70;
  879. }
  880. dorm2r_("L", "T", &m, &m, &m, tcpy, &c__4, taul, scpy, &c__4, &work[1]
  881. , info);
  882. dorm2r_("R", "N", &m, &m, &m, tcpy, &c__4, taul, licop, &c__4, &work[
  883. 1], info);
  884. if (linfo != 0) {
  885. goto L70;
  886. }
  887. /* Compute F-norm(S21) in BQRA21. (T21 is 0.) */
  888. dscale = 0.;
  889. dsum = 1.;
  890. i__1 = *n2;
  891. for (i__ = 1; i__ <= i__1; ++i__) {
  892. dlassq_(n1, &scpy[*n2 + 1 + (i__ << 2) - 5], &c__1, &dscale, &
  893. dsum);
  894. /* L40: */
  895. }
  896. bqra21 = dscale * sqrt(dsum);
  897. /* Decide which method to use. */
  898. /* Weak stability test: */
  899. /* F-norm(S21) <= O(EPS * F-norm((S, T))) */
  900. if (bqra21 <= brqa21 && bqra21 <= thresh) {
  901. dlacpy_("F", &m, &m, scpy, &c__4, s, &c__4);
  902. dlacpy_("F", &m, &m, tcpy, &c__4, t, &c__4);
  903. dlacpy_("F", &m, &m, ircop, &c__4, ir, &c__4);
  904. dlacpy_("F", &m, &m, licop, &c__4, li, &c__4);
  905. } else if (brqa21 >= thresh) {
  906. goto L70;
  907. }
  908. /* Set lower triangle of B-part to zero */
  909. i__1 = m - 1;
  910. i__2 = m - 1;
  911. dlaset_("Lower", &i__1, &i__2, &c_b5, &c_b5, &t[1], &c__4);
  912. if (TRUE_) {
  913. /* Strong stability test: */
  914. /* F-norm((A-QL*S*QR**T, B-QL*T*QR**T)) <= O(EPS*F-norm((A,B))) */
  915. dlacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, &work[m * m
  916. + 1], &m);
  917. dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, s, &c__4, &c_b5, &
  918. work[1], &m);
  919. dgemm_("N", "N", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
  920. c_b42, &work[m * m + 1], &m);
  921. dscale = 0.;
  922. dsum = 1.;
  923. i__1 = m * m;
  924. dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
  925. dlacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, &work[m * m
  926. + 1], &m);
  927. dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, t, &c__4, &c_b5, &
  928. work[1], &m);
  929. dgemm_("N", "N", &m, &m, &m, &c_b48, &work[1], &m, ir, &c__4, &
  930. c_b42, &work[m * m + 1], &m);
  931. i__1 = m * m;
  932. dlassq_(&i__1, &work[m * m + 1], &c__1, &dscale, &dsum);
  933. ss = dscale * sqrt(dsum);
  934. dtrong = ss <= thresh;
  935. if (! dtrong) {
  936. goto L70;
  937. }
  938. }
  939. /* If the swap is accepted ("weakly" and "strongly"), apply the */
  940. /* transformations and set N1-by-N2 (2,1)-block to zero. */
  941. dlaset_("Full", n1, n2, &c_b5, &c_b5, &s[*n2], &c__4);
  942. /* copy back M-by-M diagonal block starting at index J1 of (A, B) */
  943. dlacpy_("F", &m, &m, s, &c__4, &a[*j1 + *j1 * a_dim1], lda)
  944. ;
  945. dlacpy_("F", &m, &m, t, &c__4, &b[*j1 + *j1 * b_dim1], ldb)
  946. ;
  947. dlaset_("Full", &c__4, &c__4, &c_b5, &c_b5, t, &c__4);
  948. /* Standardize existing 2-by-2 blocks. */
  949. dlaset_("Full", &m, &m, &c_b5, &c_b5, &work[1], &m);
  950. work[1] = 1.;
  951. t[0] = 1.;
  952. idum = *lwork - m * m - 2;
  953. if (*n2 > 1) {
  954. dlagv2_(&a[*j1 + *j1 * a_dim1], lda, &b[*j1 + *j1 * b_dim1], ldb,
  955. ar, ai, be, &work[1], &work[2], t, &t[1]);
  956. work[m + 1] = -work[2];
  957. work[m + 2] = work[1];
  958. t[*n2 + (*n2 << 2) - 5] = t[0];
  959. t[4] = -t[1];
  960. }
  961. work[m * m] = 1.;
  962. t[m + (m << 2) - 5] = 1.;
  963. if (*n1 > 1) {
  964. dlagv2_(&a[*j1 + *n2 + (*j1 + *n2) * a_dim1], lda, &b[*j1 + *n2 +
  965. (*j1 + *n2) * b_dim1], ldb, taur, taul, &work[m * m + 1],
  966. &work[*n2 * m + *n2 + 1], &work[*n2 * m + *n2 + 2], &t[*
  967. n2 + 1 + (*n2 + 1 << 2) - 5], &t[m + (m - 1 << 2) - 5]);
  968. work[m * m] = work[*n2 * m + *n2 + 1];
  969. work[m * m - 1] = -work[*n2 * m + *n2 + 2];
  970. t[m + (m << 2) - 5] = t[*n2 + 1 + (*n2 + 1 << 2) - 5];
  971. t[m - 1 + (m << 2) - 5] = -t[m + (m - 1 << 2) - 5];
  972. }
  973. dgemm_("T", "N", n2, n1, n2, &c_b42, &work[1], &m, &a[*j1 + (*j1 + *
  974. n2) * a_dim1], lda, &c_b5, &work[m * m + 1], n2);
  975. dlacpy_("Full", n2, n1, &work[m * m + 1], n2, &a[*j1 + (*j1 + *n2) *
  976. a_dim1], lda);
  977. dgemm_("T", "N", n2, n1, n2, &c_b42, &work[1], &m, &b[*j1 + (*j1 + *
  978. n2) * b_dim1], ldb, &c_b5, &work[m * m + 1], n2);
  979. dlacpy_("Full", n2, n1, &work[m * m + 1], n2, &b[*j1 + (*j1 + *n2) *
  980. b_dim1], ldb);
  981. dgemm_("N", "N", &m, &m, &m, &c_b42, li, &c__4, &work[1], &m, &c_b5, &
  982. work[m * m + 1], &m);
  983. dlacpy_("Full", &m, &m, &work[m * m + 1], &m, li, &c__4);
  984. dgemm_("N", "N", n2, n1, n1, &c_b42, &a[*j1 + (*j1 + *n2) * a_dim1],
  985. lda, &t[*n2 + 1 + (*n2 + 1 << 2) - 5], &c__4, &c_b5, &work[1],
  986. n2);
  987. dlacpy_("Full", n2, n1, &work[1], n2, &a[*j1 + (*j1 + *n2) * a_dim1],
  988. lda);
  989. dgemm_("N", "N", n2, n1, n1, &c_b42, &b[*j1 + (*j1 + *n2) * b_dim1],
  990. ldb, &t[*n2 + 1 + (*n2 + 1 << 2) - 5], &c__4, &c_b5, &work[1],
  991. n2);
  992. dlacpy_("Full", n2, n1, &work[1], n2, &b[*j1 + (*j1 + *n2) * b_dim1],
  993. ldb);
  994. dgemm_("T", "N", &m, &m, &m, &c_b42, ir, &c__4, t, &c__4, &c_b5, &
  995. work[1], &m);
  996. dlacpy_("Full", &m, &m, &work[1], &m, ir, &c__4);
  997. /* Accumulate transformations into Q and Z if requested. */
  998. if (*wantq) {
  999. dgemm_("N", "N", n, &m, &m, &c_b42, &q[*j1 * q_dim1 + 1], ldq, li,
  1000. &c__4, &c_b5, &work[1], n);
  1001. dlacpy_("Full", n, &m, &work[1], n, &q[*j1 * q_dim1 + 1], ldq);
  1002. }
  1003. if (*wantz) {
  1004. dgemm_("N", "N", n, &m, &m, &c_b42, &z__[*j1 * z_dim1 + 1], ldz,
  1005. ir, &c__4, &c_b5, &work[1], n);
  1006. dlacpy_("Full", n, &m, &work[1], n, &z__[*j1 * z_dim1 + 1], ldz);
  1007. }
  1008. /* Update (A(J1:J1+M-1, M+J1:N), B(J1:J1+M-1, M+J1:N)) and */
  1009. /* (A(1:J1-1, J1:J1+M), B(1:J1-1, J1:J1+M)). */
  1010. i__ = *j1 + m;
  1011. if (i__ <= *n) {
  1012. i__1 = *n - i__ + 1;
  1013. dgemm_("T", "N", &m, &i__1, &m, &c_b42, li, &c__4, &a[*j1 + i__ *
  1014. a_dim1], lda, &c_b5, &work[1], &m);
  1015. i__1 = *n - i__ + 1;
  1016. dlacpy_("Full", &m, &i__1, &work[1], &m, &a[*j1 + i__ * a_dim1],
  1017. lda);
  1018. i__1 = *n - i__ + 1;
  1019. dgemm_("T", "N", &m, &i__1, &m, &c_b42, li, &c__4, &b[*j1 + i__ *
  1020. b_dim1], ldb, &c_b5, &work[1], &m);
  1021. i__1 = *n - i__ + 1;
  1022. dlacpy_("Full", &m, &i__1, &work[1], &m, &b[*j1 + i__ * b_dim1],
  1023. ldb);
  1024. }
  1025. i__ = *j1 - 1;
  1026. if (i__ > 0) {
  1027. dgemm_("N", "N", &i__, &m, &m, &c_b42, &a[*j1 * a_dim1 + 1], lda,
  1028. ir, &c__4, &c_b5, &work[1], &i__);
  1029. dlacpy_("Full", &i__, &m, &work[1], &i__, &a[*j1 * a_dim1 + 1],
  1030. lda);
  1031. dgemm_("N", "N", &i__, &m, &m, &c_b42, &b[*j1 * b_dim1 + 1], ldb,
  1032. ir, &c__4, &c_b5, &work[1], &i__);
  1033. dlacpy_("Full", &i__, &m, &work[1], &i__, &b[*j1 * b_dim1 + 1],
  1034. ldb);
  1035. }
  1036. /* Exit with INFO = 0 if swap was successfully performed. */
  1037. return 0;
  1038. }
  1039. /* Exit with INFO = 1 if swap was rejected. */
  1040. L70:
  1041. *info = 1;
  1042. return 0;
  1043. /* End of DTGEX2 */
  1044. } /* dtgex2_ */