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.

dtrsen.c 30 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #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++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #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]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c_n1 = -1;
  381. /* > \brief \b DTRSEN */
  382. /* =========== DOCUMENTATION =========== */
  383. /* Online html documentation available at */
  384. /* http://www.netlib.org/lapack/explore-html/ */
  385. /* > \htmlonly */
  386. /* > Download DTRSEN + dependencies */
  387. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dtrsen.
  388. f"> */
  389. /* > [TGZ]</a> */
  390. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dtrsen.
  391. f"> */
  392. /* > [ZIP]</a> */
  393. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dtrsen.
  394. f"> */
  395. /* > [TXT]</a> */
  396. /* > \endhtmlonly */
  397. /* Definition: */
  398. /* =========== */
  399. /* SUBROUTINE DTRSEN( JOB, COMPQ, SELECT, N, T, LDT, Q, LDQ, WR, WI, */
  400. /* M, S, SEP, WORK, LWORK, IWORK, LIWORK, INFO ) */
  401. /* CHARACTER COMPQ, JOB */
  402. /* INTEGER INFO, LDQ, LDT, LIWORK, LWORK, M, N */
  403. /* DOUBLE PRECISION S, SEP */
  404. /* LOGICAL SELECT( * ) */
  405. /* INTEGER IWORK( * ) */
  406. /* DOUBLE PRECISION Q( LDQ, * ), T( LDT, * ), WI( * ), WORK( * ), */
  407. /* $ WR( * ) */
  408. /* > \par Purpose: */
  409. /* ============= */
  410. /* > */
  411. /* > \verbatim */
  412. /* > */
  413. /* > DTRSEN reorders the real Schur factorization of a real matrix */
  414. /* > A = Q*T*Q**T, so that a selected cluster of eigenvalues appears in */
  415. /* > the leading diagonal blocks of the upper quasi-triangular matrix T, */
  416. /* > and the leading columns of Q form an orthonormal basis of the */
  417. /* > corresponding right invariant subspace. */
  418. /* > */
  419. /* > Optionally the routine computes the reciprocal condition numbers of */
  420. /* > the cluster of eigenvalues and/or the invariant subspace. */
  421. /* > */
  422. /* > T must be in Schur canonical form (as returned by DHSEQR), that is, */
  423. /* > block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; each */
  424. /* > 2-by-2 diagonal block has its diagonal elements equal and its */
  425. /* > off-diagonal elements of opposite sign. */
  426. /* > \endverbatim */
  427. /* Arguments: */
  428. /* ========== */
  429. /* > \param[in] JOB */
  430. /* > \verbatim */
  431. /* > JOB is CHARACTER*1 */
  432. /* > Specifies whether condition numbers are required for the */
  433. /* > cluster of eigenvalues (S) or the invariant subspace (SEP): */
  434. /* > = 'N': none; */
  435. /* > = 'E': for eigenvalues only (S); */
  436. /* > = 'V': for invariant subspace only (SEP); */
  437. /* > = 'B': for both eigenvalues and invariant subspace (S and */
  438. /* > SEP). */
  439. /* > \endverbatim */
  440. /* > */
  441. /* > \param[in] COMPQ */
  442. /* > \verbatim */
  443. /* > COMPQ is CHARACTER*1 */
  444. /* > = 'V': update the matrix Q of Schur vectors; */
  445. /* > = 'N': do not update Q. */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[in] SELECT */
  449. /* > \verbatim */
  450. /* > SELECT is LOGICAL array, dimension (N) */
  451. /* > SELECT specifies the eigenvalues in the selected cluster. To */
  452. /* > select a real eigenvalue w(j), SELECT(j) must be set to */
  453. /* > .TRUE.. To select a complex conjugate pair of eigenvalues */
  454. /* > w(j) and w(j+1), corresponding to a 2-by-2 diagonal block, */
  455. /* > either SELECT(j) or SELECT(j+1) or both must be set to */
  456. /* > .TRUE.; a complex conjugate pair of eigenvalues must be */
  457. /* > either both included in the cluster or both excluded. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in] N */
  461. /* > \verbatim */
  462. /* > N is INTEGER */
  463. /* > The order of the matrix T. N >= 0. */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[in,out] T */
  467. /* > \verbatim */
  468. /* > T is DOUBLE PRECISION array, dimension (LDT,N) */
  469. /* > On entry, the upper quasi-triangular matrix T, in Schur */
  470. /* > canonical form. */
  471. /* > On exit, T is overwritten by the reordered matrix T, again in */
  472. /* > Schur canonical form, with the selected eigenvalues in the */
  473. /* > leading diagonal blocks. */
  474. /* > \endverbatim */
  475. /* > */
  476. /* > \param[in] LDT */
  477. /* > \verbatim */
  478. /* > LDT is INTEGER */
  479. /* > The leading dimension of the array T. LDT >= f2cmax(1,N). */
  480. /* > \endverbatim */
  481. /* > */
  482. /* > \param[in,out] Q */
  483. /* > \verbatim */
  484. /* > Q is DOUBLE PRECISION array, dimension (LDQ,N) */
  485. /* > On entry, if COMPQ = 'V', the matrix Q of Schur vectors. */
  486. /* > On exit, if COMPQ = 'V', Q has been postmultiplied by the */
  487. /* > orthogonal transformation matrix which reorders T; the */
  488. /* > leading M columns of Q form an orthonormal basis for the */
  489. /* > specified invariant subspace. */
  490. /* > If COMPQ = 'N', Q is not referenced. */
  491. /* > \endverbatim */
  492. /* > */
  493. /* > \param[in] LDQ */
  494. /* > \verbatim */
  495. /* > LDQ is INTEGER */
  496. /* > The leading dimension of the array Q. */
  497. /* > LDQ >= 1; and if COMPQ = 'V', LDQ >= N. */
  498. /* > \endverbatim */
  499. /* > */
  500. /* > \param[out] WR */
  501. /* > \verbatim */
  502. /* > WR is DOUBLE PRECISION array, dimension (N) */
  503. /* > \endverbatim */
  504. /* > \param[out] WI */
  505. /* > \verbatim */
  506. /* > WI is DOUBLE PRECISION array, dimension (N) */
  507. /* > */
  508. /* > The real and imaginary parts, respectively, of the reordered */
  509. /* > eigenvalues of T. The eigenvalues are stored in the same */
  510. /* > order as on the diagonal of T, with WR(i) = T(i,i) and, if */
  511. /* > T(i:i+1,i:i+1) is a 2-by-2 diagonal block, WI(i) > 0 and */
  512. /* > WI(i+1) = -WI(i). Note that if a complex eigenvalue is */
  513. /* > sufficiently ill-conditioned, then its value may differ */
  514. /* > significantly from its value before reordering. */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[out] M */
  518. /* > \verbatim */
  519. /* > M is INTEGER */
  520. /* > The dimension of the specified invariant subspace. */
  521. /* > 0 < = M <= N. */
  522. /* > \endverbatim */
  523. /* > */
  524. /* > \param[out] S */
  525. /* > \verbatim */
  526. /* > S is DOUBLE PRECISION */
  527. /* > If JOB = 'E' or 'B', S is a lower bound on the reciprocal */
  528. /* > condition number for the selected cluster of eigenvalues. */
  529. /* > S cannot underestimate the true reciprocal condition number */
  530. /* > by more than a factor of sqrt(N). If M = 0 or N, S = 1. */
  531. /* > If JOB = 'N' or 'V', S is not referenced. */
  532. /* > \endverbatim */
  533. /* > */
  534. /* > \param[out] SEP */
  535. /* > \verbatim */
  536. /* > SEP is DOUBLE PRECISION */
  537. /* > If JOB = 'V' or 'B', SEP is the estimated reciprocal */
  538. /* > condition number of the specified invariant subspace. If */
  539. /* > M = 0 or N, SEP = norm(T). */
  540. /* > If JOB = 'N' or 'E', SEP is not referenced. */
  541. /* > \endverbatim */
  542. /* > */
  543. /* > \param[out] WORK */
  544. /* > \verbatim */
  545. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  546. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  547. /* > \endverbatim */
  548. /* > */
  549. /* > \param[in] LWORK */
  550. /* > \verbatim */
  551. /* > LWORK is INTEGER */
  552. /* > The dimension of the array WORK. */
  553. /* > If JOB = 'N', LWORK >= f2cmax(1,N); */
  554. /* > if JOB = 'E', LWORK >= f2cmax(1,M*(N-M)); */
  555. /* > if JOB = 'V' or 'B', LWORK >= f2cmax(1,2*M*(N-M)). */
  556. /* > */
  557. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  558. /* > only calculates the optimal size of the WORK array, returns */
  559. /* > this value as the first entry of the WORK array, and no error */
  560. /* > message related to LWORK is issued by XERBLA. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[out] IWORK */
  564. /* > \verbatim */
  565. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  566. /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  567. /* > \endverbatim */
  568. /* > */
  569. /* > \param[in] LIWORK */
  570. /* > \verbatim */
  571. /* > LIWORK is INTEGER */
  572. /* > The dimension of the array IWORK. */
  573. /* > If JOB = 'N' or 'E', LIWORK >= 1; */
  574. /* > if JOB = 'V' or 'B', LIWORK >= f2cmax(1,M*(N-M)). */
  575. /* > */
  576. /* > If LIWORK = -1, then a workspace query is assumed; the */
  577. /* > routine only calculates the optimal size of the IWORK array, */
  578. /* > returns this value as the first entry of the IWORK array, and */
  579. /* > no error message related to LIWORK is issued by XERBLA. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[out] INFO */
  583. /* > \verbatim */
  584. /* > INFO is INTEGER */
  585. /* > = 0: successful exit */
  586. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  587. /* > = 1: reordering of T failed because some eigenvalues are too */
  588. /* > close to separate (the problem is very ill-conditioned); */
  589. /* > T may have been partially reordered, and WR and WI */
  590. /* > contain the eigenvalues in the same order as in T; S and */
  591. /* > SEP (if requested) are set to zero. */
  592. /* > \endverbatim */
  593. /* Authors: */
  594. /* ======== */
  595. /* > \author Univ. of Tennessee */
  596. /* > \author Univ. of California Berkeley */
  597. /* > \author Univ. of Colorado Denver */
  598. /* > \author NAG Ltd. */
  599. /* > \date April 2012 */
  600. /* > \ingroup doubleOTHERcomputational */
  601. /* > \par Further Details: */
  602. /* ===================== */
  603. /* > */
  604. /* > \verbatim */
  605. /* > */
  606. /* > DTRSEN first collects the selected eigenvalues by computing an */
  607. /* > orthogonal transformation Z to move them to the top left corner of T. */
  608. /* > In other words, the selected eigenvalues are the eigenvalues of T11 */
  609. /* > in: */
  610. /* > */
  611. /* > Z**T * T * Z = ( T11 T12 ) n1 */
  612. /* > ( 0 T22 ) n2 */
  613. /* > n1 n2 */
  614. /* > */
  615. /* > where N = n1+n2 and Z**T means the transpose of Z. The first n1 columns */
  616. /* > of Z span the specified invariant subspace of T. */
  617. /* > */
  618. /* > If T has been obtained from the real Schur factorization of a matrix */
  619. /* > A = Q*T*Q**T, then the reordered real Schur factorization of A is given */
  620. /* > by A = (Q*Z)*(Z**T*T*Z)*(Q*Z)**T, and the first n1 columns of Q*Z span */
  621. /* > the corresponding invariant subspace of A. */
  622. /* > */
  623. /* > The reciprocal condition number of the average of the eigenvalues of */
  624. /* > T11 may be returned in S. S lies between 0 (very badly conditioned) */
  625. /* > and 1 (very well conditioned). It is computed as follows. First we */
  626. /* > compute R so that */
  627. /* > */
  628. /* > P = ( I R ) n1 */
  629. /* > ( 0 0 ) n2 */
  630. /* > n1 n2 */
  631. /* > */
  632. /* > is the projector on the invariant subspace associated with T11. */
  633. /* > R is the solution of the Sylvester equation: */
  634. /* > */
  635. /* > T11*R - R*T22 = T12. */
  636. /* > */
  637. /* > Let F-norm(M) denote the Frobenius-norm of M and 2-norm(M) denote */
  638. /* > the two-norm of M. Then S is computed as the lower bound */
  639. /* > */
  640. /* > (1 + F-norm(R)**2)**(-1/2) */
  641. /* > */
  642. /* > on the reciprocal of 2-norm(P), the true reciprocal condition number. */
  643. /* > S cannot underestimate 1 / 2-norm(P) by more than a factor of */
  644. /* > sqrt(N). */
  645. /* > */
  646. /* > An approximate error bound for the computed average of the */
  647. /* > eigenvalues of T11 is */
  648. /* > */
  649. /* > EPS * norm(T) / S */
  650. /* > */
  651. /* > where EPS is the machine precision. */
  652. /* > */
  653. /* > The reciprocal condition number of the right invariant subspace */
  654. /* > spanned by the first n1 columns of Z (or of Q*Z) is returned in SEP. */
  655. /* > SEP is defined as the separation of T11 and T22: */
  656. /* > */
  657. /* > sep( T11, T22 ) = sigma-f2cmin( C ) */
  658. /* > */
  659. /* > where sigma-f2cmin(C) is the smallest singular value of the */
  660. /* > n1*n2-by-n1*n2 matrix */
  661. /* > */
  662. /* > C = kprod( I(n2), T11 ) - kprod( transpose(T22), I(n1) ) */
  663. /* > */
  664. /* > I(m) is an m by m identity matrix, and kprod denotes the Kronecker */
  665. /* > product. We estimate sigma-f2cmin(C) by the reciprocal of an estimate of */
  666. /* > the 1-norm of inverse(C). The true reciprocal 1-norm of inverse(C) */
  667. /* > cannot differ from sigma-f2cmin(C) by more than a factor of sqrt(n1*n2). */
  668. /* > */
  669. /* > When SEP is small, small changes in T can cause large changes in */
  670. /* > the invariant subspace. An approximate bound on the maximum angular */
  671. /* > error in the computed right invariant subspace is */
  672. /* > */
  673. /* > EPS * norm(T) / SEP */
  674. /* > \endverbatim */
  675. /* > */
  676. /* ===================================================================== */
  677. /* Subroutine */ int dtrsen_(char *job, char *compq, logical *select, integer
  678. *n, doublereal *t, integer *ldt, doublereal *q, integer *ldq,
  679. doublereal *wr, doublereal *wi, integer *m, doublereal *s, doublereal
  680. *sep, doublereal *work, integer *lwork, integer *iwork, integer *
  681. liwork, integer *info)
  682. {
  683. /* System generated locals */
  684. integer q_dim1, q_offset, t_dim1, t_offset, i__1, i__2;
  685. doublereal d__1, d__2;
  686. /* Local variables */
  687. integer kase;
  688. logical pair;
  689. integer ierr;
  690. logical swap;
  691. integer k;
  692. doublereal scale;
  693. extern logical lsame_(char *, char *);
  694. integer isave[3], lwmin;
  695. logical wantq, wants;
  696. doublereal rnorm;
  697. integer n1, n2;
  698. extern /* Subroutine */ int dlacn2_(integer *, doublereal *, doublereal *,
  699. integer *, doublereal *, integer *, integer *);
  700. integer kk;
  701. extern doublereal dlange_(char *, integer *, integer *, doublereal *,
  702. integer *, doublereal *);
  703. integer nn, ks;
  704. extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
  705. doublereal *, integer *, doublereal *, integer *),
  706. xerbla_(char *, integer *, ftnlen);
  707. logical wantbh;
  708. extern /* Subroutine */ int dtrexc_(char *, integer *, doublereal *,
  709. integer *, doublereal *, integer *, integer *, integer *,
  710. doublereal *, integer *);
  711. integer liwmin;
  712. logical wantsp, lquery;
  713. extern /* Subroutine */ int dtrsyl_(char *, char *, integer *, integer *,
  714. integer *, doublereal *, integer *, doublereal *, integer *,
  715. doublereal *, integer *, doublereal *, integer *);
  716. doublereal est;
  717. /* -- LAPACK computational routine (version 3.7.0) -- */
  718. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  719. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  720. /* April 2012 */
  721. /* ===================================================================== */
  722. /* Decode and test the input parameters */
  723. /* Parameter adjustments */
  724. --select;
  725. t_dim1 = *ldt;
  726. t_offset = 1 + t_dim1 * 1;
  727. t -= t_offset;
  728. q_dim1 = *ldq;
  729. q_offset = 1 + q_dim1 * 1;
  730. q -= q_offset;
  731. --wr;
  732. --wi;
  733. --work;
  734. --iwork;
  735. /* Function Body */
  736. wantbh = lsame_(job, "B");
  737. wants = lsame_(job, "E") || wantbh;
  738. wantsp = lsame_(job, "V") || wantbh;
  739. wantq = lsame_(compq, "V");
  740. *info = 0;
  741. lquery = *lwork == -1;
  742. if (! lsame_(job, "N") && ! wants && ! wantsp) {
  743. *info = -1;
  744. } else if (! lsame_(compq, "N") && ! wantq) {
  745. *info = -2;
  746. } else if (*n < 0) {
  747. *info = -4;
  748. } else if (*ldt < f2cmax(1,*n)) {
  749. *info = -6;
  750. } else if (*ldq < 1 || wantq && *ldq < *n) {
  751. *info = -8;
  752. } else {
  753. /* Set M to the dimension of the specified invariant subspace, */
  754. /* and test LWORK and LIWORK. */
  755. *m = 0;
  756. pair = FALSE_;
  757. i__1 = *n;
  758. for (k = 1; k <= i__1; ++k) {
  759. if (pair) {
  760. pair = FALSE_;
  761. } else {
  762. if (k < *n) {
  763. if (t[k + 1 + k * t_dim1] == 0.) {
  764. if (select[k]) {
  765. ++(*m);
  766. }
  767. } else {
  768. pair = TRUE_;
  769. if (select[k] || select[k + 1]) {
  770. *m += 2;
  771. }
  772. }
  773. } else {
  774. if (select[*n]) {
  775. ++(*m);
  776. }
  777. }
  778. }
  779. /* L10: */
  780. }
  781. n1 = *m;
  782. n2 = *n - *m;
  783. nn = n1 * n2;
  784. if (wantsp) {
  785. /* Computing MAX */
  786. i__1 = 1, i__2 = nn << 1;
  787. lwmin = f2cmax(i__1,i__2);
  788. liwmin = f2cmax(1,nn);
  789. } else if (lsame_(job, "N")) {
  790. lwmin = f2cmax(1,*n);
  791. liwmin = 1;
  792. } else if (lsame_(job, "E")) {
  793. lwmin = f2cmax(1,nn);
  794. liwmin = 1;
  795. }
  796. if (*lwork < lwmin && ! lquery) {
  797. *info = -15;
  798. } else if (*liwork < liwmin && ! lquery) {
  799. *info = -17;
  800. }
  801. }
  802. if (*info == 0) {
  803. work[1] = (doublereal) lwmin;
  804. iwork[1] = liwmin;
  805. }
  806. if (*info != 0) {
  807. i__1 = -(*info);
  808. xerbla_("DTRSEN", &i__1, (ftnlen)6);
  809. return 0;
  810. } else if (lquery) {
  811. return 0;
  812. }
  813. /* Quick return if possible. */
  814. if (*m == *n || *m == 0) {
  815. if (wants) {
  816. *s = 1.;
  817. }
  818. if (wantsp) {
  819. *sep = dlange_("1", n, n, &t[t_offset], ldt, &work[1]);
  820. }
  821. goto L40;
  822. }
  823. /* Collect the selected blocks at the top-left corner of T. */
  824. ks = 0;
  825. pair = FALSE_;
  826. i__1 = *n;
  827. for (k = 1; k <= i__1; ++k) {
  828. if (pair) {
  829. pair = FALSE_;
  830. } else {
  831. swap = select[k];
  832. if (k < *n) {
  833. if (t[k + 1 + k * t_dim1] != 0.) {
  834. pair = TRUE_;
  835. swap = swap || select[k + 1];
  836. }
  837. }
  838. if (swap) {
  839. ++ks;
  840. /* Swap the K-th block to position KS. */
  841. ierr = 0;
  842. kk = k;
  843. if (k != ks) {
  844. dtrexc_(compq, n, &t[t_offset], ldt, &q[q_offset], ldq, &
  845. kk, &ks, &work[1], &ierr);
  846. }
  847. if (ierr == 1 || ierr == 2) {
  848. /* Blocks too close to swap: exit. */
  849. *info = 1;
  850. if (wants) {
  851. *s = 0.;
  852. }
  853. if (wantsp) {
  854. *sep = 0.;
  855. }
  856. goto L40;
  857. }
  858. if (pair) {
  859. ++ks;
  860. }
  861. }
  862. }
  863. /* L20: */
  864. }
  865. if (wants) {
  866. /* Solve Sylvester equation for R: */
  867. /* T11*R - R*T22 = scale*T12 */
  868. dlacpy_("F", &n1, &n2, &t[(n1 + 1) * t_dim1 + 1], ldt, &work[1], &n1);
  869. dtrsyl_("N", "N", &c_n1, &n1, &n2, &t[t_offset], ldt, &t[n1 + 1 + (n1
  870. + 1) * t_dim1], ldt, &work[1], &n1, &scale, &ierr);
  871. /* Estimate the reciprocal of the condition number of the cluster */
  872. /* of eigenvalues. */
  873. rnorm = dlange_("F", &n1, &n2, &work[1], &n1, &work[1]);
  874. if (rnorm == 0.) {
  875. *s = 1.;
  876. } else {
  877. *s = scale / (sqrt(scale * scale / rnorm + rnorm) * sqrt(rnorm));
  878. }
  879. }
  880. if (wantsp) {
  881. /* Estimate sep(T11,T22). */
  882. est = 0.;
  883. kase = 0;
  884. L30:
  885. dlacn2_(&nn, &work[nn + 1], &work[1], &iwork[1], &est, &kase, isave);
  886. if (kase != 0) {
  887. if (kase == 1) {
  888. /* Solve T11*R - R*T22 = scale*X. */
  889. dtrsyl_("N", "N", &c_n1, &n1, &n2, &t[t_offset], ldt, &t[n1 +
  890. 1 + (n1 + 1) * t_dim1], ldt, &work[1], &n1, &scale, &
  891. ierr);
  892. } else {
  893. /* Solve T11**T*R - R*T22**T = scale*X. */
  894. dtrsyl_("T", "T", &c_n1, &n1, &n2, &t[t_offset], ldt, &t[n1 +
  895. 1 + (n1 + 1) * t_dim1], ldt, &work[1], &n1, &scale, &
  896. ierr);
  897. }
  898. goto L30;
  899. }
  900. *sep = scale / est;
  901. }
  902. L40:
  903. /* Store the output eigenvalues in WR and WI. */
  904. i__1 = *n;
  905. for (k = 1; k <= i__1; ++k) {
  906. wr[k] = t[k + k * t_dim1];
  907. wi[k] = 0.;
  908. /* L50: */
  909. }
  910. i__1 = *n - 1;
  911. for (k = 1; k <= i__1; ++k) {
  912. if (t[k + 1 + k * t_dim1] != 0.) {
  913. wi[k] = sqrt((d__1 = t[k + (k + 1) * t_dim1], abs(d__1))) * sqrt((
  914. d__2 = t[k + 1 + k * t_dim1], abs(d__2)));
  915. wi[k + 1] = -wi[k];
  916. }
  917. /* L60: */
  918. }
  919. work[1] = (doublereal) lwmin;
  920. iwork[1] = liwmin;
  921. return 0;
  922. /* End of DTRSEN */
  923. } /* dtrsen_ */