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.

cgeevx.c 37 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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__1 = 1;
  381. static integer c__0 = 0;
  382. static integer c_n1 = -1;
  383. /* > \brief <b> CGEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE mat
  384. rices</b> */
  385. /* =========== DOCUMENTATION =========== */
  386. /* Online html documentation available at */
  387. /* http://www.netlib.org/lapack/explore-html/ */
  388. /* > \htmlonly */
  389. /* > Download CGEEVX + dependencies */
  390. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeevx.
  391. f"> */
  392. /* > [TGZ]</a> */
  393. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeevx.
  394. f"> */
  395. /* > [ZIP]</a> */
  396. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeevx.
  397. f"> */
  398. /* > [TXT]</a> */
  399. /* > \endhtmlonly */
  400. /* Definition: */
  401. /* =========== */
  402. /* SUBROUTINE CGEEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, W, VL, */
  403. /* LDVL, VR, LDVR, ILO, IHI, SCALE, ABNRM, RCONDE, */
  404. /* RCONDV, WORK, LWORK, RWORK, INFO ) */
  405. /* CHARACTER BALANC, JOBVL, JOBVR, SENSE */
  406. /* INTEGER IHI, ILO, INFO, LDA, LDVL, LDVR, LWORK, N */
  407. /* REAL ABNRM */
  408. /* REAL RCONDE( * ), RCONDV( * ), RWORK( * ), */
  409. /* $ SCALE( * ) */
  410. /* COMPLEX A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ), */
  411. /* $ W( * ), WORK( * ) */
  412. /* > \par Purpose: */
  413. /* ============= */
  414. /* > */
  415. /* > \verbatim */
  416. /* > */
  417. /* > CGEEVX computes for an N-by-N complex nonsymmetric matrix A, the */
  418. /* > eigenvalues and, optionally, the left and/or right eigenvectors. */
  419. /* > */
  420. /* > Optionally also, it computes a balancing transformation to improve */
  421. /* > the conditioning of the eigenvalues and eigenvectors (ILO, IHI, */
  422. /* > SCALE, and ABNRM), reciprocal condition numbers for the eigenvalues */
  423. /* > (RCONDE), and reciprocal condition numbers for the right */
  424. /* > eigenvectors (RCONDV). */
  425. /* > */
  426. /* > The right eigenvector v(j) of A satisfies */
  427. /* > A * v(j) = lambda(j) * v(j) */
  428. /* > where lambda(j) is its eigenvalue. */
  429. /* > The left eigenvector u(j) of A satisfies */
  430. /* > u(j)**H * A = lambda(j) * u(j)**H */
  431. /* > where u(j)**H denotes the conjugate transpose of u(j). */
  432. /* > */
  433. /* > The computed eigenvectors are normalized to have Euclidean norm */
  434. /* > equal to 1 and largest component real. */
  435. /* > */
  436. /* > Balancing a matrix means permuting the rows and columns to make it */
  437. /* > more nearly upper triangular, and applying a diagonal similarity */
  438. /* > transformation D * A * D**(-1), where D is a diagonal matrix, to */
  439. /* > make its rows and columns closer in norm and the condition numbers */
  440. /* > of its eigenvalues and eigenvectors smaller. The computed */
  441. /* > reciprocal condition numbers correspond to the balanced matrix. */
  442. /* > Permuting rows and columns will not change the condition numbers */
  443. /* > (in exact arithmetic) but diagonal scaling will. For further */
  444. /* > explanation of balancing, see section 4.10.2 of the LAPACK */
  445. /* > Users' Guide. */
  446. /* > \endverbatim */
  447. /* Arguments: */
  448. /* ========== */
  449. /* > \param[in] BALANC */
  450. /* > \verbatim */
  451. /* > BALANC is CHARACTER*1 */
  452. /* > Indicates how the input matrix should be diagonally scaled */
  453. /* > and/or permuted to improve the conditioning of its */
  454. /* > eigenvalues. */
  455. /* > = 'N': Do not diagonally scale or permute; */
  456. /* > = 'P': Perform permutations to make the matrix more nearly */
  457. /* > upper triangular. Do not diagonally scale; */
  458. /* > = 'S': Diagonally scale the matrix, ie. replace A by */
  459. /* > D*A*D**(-1), where D is a diagonal matrix chosen */
  460. /* > to make the rows and columns of A more equal in */
  461. /* > norm. Do not permute; */
  462. /* > = 'B': Both diagonally scale and permute A. */
  463. /* > */
  464. /* > Computed reciprocal condition numbers will be for the matrix */
  465. /* > after balancing and/or permuting. Permuting does not change */
  466. /* > condition numbers (in exact arithmetic), but balancing does. */
  467. /* > \endverbatim */
  468. /* > */
  469. /* > \param[in] JOBVL */
  470. /* > \verbatim */
  471. /* > JOBVL is CHARACTER*1 */
  472. /* > = 'N': left eigenvectors of A are not computed; */
  473. /* > = 'V': left eigenvectors of A are computed. */
  474. /* > If SENSE = 'E' or 'B', JOBVL must = 'V'. */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[in] JOBVR */
  478. /* > \verbatim */
  479. /* > JOBVR is CHARACTER*1 */
  480. /* > = 'N': right eigenvectors of A are not computed; */
  481. /* > = 'V': right eigenvectors of A are computed. */
  482. /* > If SENSE = 'E' or 'B', JOBVR must = 'V'. */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[in] SENSE */
  486. /* > \verbatim */
  487. /* > SENSE is CHARACTER*1 */
  488. /* > Determines which reciprocal condition numbers are computed. */
  489. /* > = 'N': None are computed; */
  490. /* > = 'E': Computed for eigenvalues only; */
  491. /* > = 'V': Computed for right eigenvectors only; */
  492. /* > = 'B': Computed for eigenvalues and right eigenvectors. */
  493. /* > */
  494. /* > If SENSE = 'E' or 'B', both left and right eigenvectors */
  495. /* > must also be computed (JOBVL = 'V' and JOBVR = 'V'). */
  496. /* > \endverbatim */
  497. /* > */
  498. /* > \param[in] N */
  499. /* > \verbatim */
  500. /* > N is INTEGER */
  501. /* > The order of the matrix A. N >= 0. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[in,out] A */
  505. /* > \verbatim */
  506. /* > A is COMPLEX array, dimension (LDA,N) */
  507. /* > On entry, the N-by-N matrix A. */
  508. /* > On exit, A has been overwritten. If JOBVL = 'V' or */
  509. /* > JOBVR = 'V', A contains the Schur form of the balanced */
  510. /* > version of the matrix A. */
  511. /* > \endverbatim */
  512. /* > */
  513. /* > \param[in] LDA */
  514. /* > \verbatim */
  515. /* > LDA is INTEGER */
  516. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  517. /* > \endverbatim */
  518. /* > */
  519. /* > \param[out] W */
  520. /* > \verbatim */
  521. /* > W is COMPLEX array, dimension (N) */
  522. /* > W contains the computed eigenvalues. */
  523. /* > \endverbatim */
  524. /* > */
  525. /* > \param[out] VL */
  526. /* > \verbatim */
  527. /* > VL is COMPLEX array, dimension (LDVL,N) */
  528. /* > If JOBVL = 'V', the left eigenvectors u(j) are stored one */
  529. /* > after another in the columns of VL, in the same order */
  530. /* > as their eigenvalues. */
  531. /* > If JOBVL = 'N', VL is not referenced. */
  532. /* > u(j) = VL(:,j), the j-th column of VL. */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[in] LDVL */
  536. /* > \verbatim */
  537. /* > LDVL is INTEGER */
  538. /* > The leading dimension of the array VL. LDVL >= 1; if */
  539. /* > JOBVL = 'V', LDVL >= N. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[out] VR */
  543. /* > \verbatim */
  544. /* > VR is COMPLEX array, dimension (LDVR,N) */
  545. /* > If JOBVR = 'V', the right eigenvectors v(j) are stored one */
  546. /* > after another in the columns of VR, in the same order */
  547. /* > as their eigenvalues. */
  548. /* > If JOBVR = 'N', VR is not referenced. */
  549. /* > v(j) = VR(:,j), the j-th column of VR. */
  550. /* > \endverbatim */
  551. /* > */
  552. /* > \param[in] LDVR */
  553. /* > \verbatim */
  554. /* > LDVR is INTEGER */
  555. /* > The leading dimension of the array VR. LDVR >= 1; if */
  556. /* > JOBVR = 'V', LDVR >= N. */
  557. /* > \endverbatim */
  558. /* > */
  559. /* > \param[out] ILO */
  560. /* > \verbatim */
  561. /* > ILO is INTEGER */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[out] IHI */
  565. /* > \verbatim */
  566. /* > IHI is INTEGER */
  567. /* > ILO and IHI are integer values determined when A was */
  568. /* > balanced. The balanced A(i,j) = 0 if I > J and */
  569. /* > J = 1,...,ILO-1 or I = IHI+1,...,N. */
  570. /* > \endverbatim */
  571. /* > */
  572. /* > \param[out] SCALE */
  573. /* > \verbatim */
  574. /* > SCALE is REAL array, dimension (N) */
  575. /* > Details of the permutations and scaling factors applied */
  576. /* > when balancing A. If P(j) is the index of the row and column */
  577. /* > interchanged with row and column j, and D(j) is the scaling */
  578. /* > factor applied to row and column j, then */
  579. /* > SCALE(J) = P(J), for J = 1,...,ILO-1 */
  580. /* > = D(J), for J = ILO,...,IHI */
  581. /* > = P(J) for J = IHI+1,...,N. */
  582. /* > The order in which the interchanges are made is N to IHI+1, */
  583. /* > then 1 to ILO-1. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[out] ABNRM */
  587. /* > \verbatim */
  588. /* > ABNRM is REAL */
  589. /* > The one-norm of the balanced matrix (the maximum */
  590. /* > of the sum of absolute values of elements of any column). */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[out] RCONDE */
  594. /* > \verbatim */
  595. /* > RCONDE is REAL array, dimension (N) */
  596. /* > RCONDE(j) is the reciprocal condition number of the j-th */
  597. /* > eigenvalue. */
  598. /* > \endverbatim */
  599. /* > */
  600. /* > \param[out] RCONDV */
  601. /* > \verbatim */
  602. /* > RCONDV is REAL array, dimension (N) */
  603. /* > RCONDV(j) is the reciprocal condition number of the j-th */
  604. /* > right eigenvector. */
  605. /* > \endverbatim */
  606. /* > */
  607. /* > \param[out] WORK */
  608. /* > \verbatim */
  609. /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
  610. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  611. /* > \endverbatim */
  612. /* > */
  613. /* > \param[in] LWORK */
  614. /* > \verbatim */
  615. /* > LWORK is INTEGER */
  616. /* > The dimension of the array WORK. If SENSE = 'N' or 'E', */
  617. /* > LWORK >= f2cmax(1,2*N), and if SENSE = 'V' or 'B', */
  618. /* > LWORK >= N*N+2*N. */
  619. /* > For good performance, LWORK must generally be larger. */
  620. /* > */
  621. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  622. /* > only calculates the optimal size of the WORK array, returns */
  623. /* > this value as the first entry of the WORK array, and no error */
  624. /* > message related to LWORK is issued by XERBLA. */
  625. /* > \endverbatim */
  626. /* > */
  627. /* > \param[out] RWORK */
  628. /* > \verbatim */
  629. /* > RWORK is REAL array, dimension (2*N) */
  630. /* > \endverbatim */
  631. /* > */
  632. /* > \param[out] INFO */
  633. /* > \verbatim */
  634. /* > INFO is INTEGER */
  635. /* > = 0: successful exit */
  636. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  637. /* > > 0: if INFO = i, the QR algorithm failed to compute all the */
  638. /* > eigenvalues, and no eigenvectors or condition numbers */
  639. /* > have been computed; elements 1:ILO-1 and i+1:N of W */
  640. /* > contain eigenvalues which have converged. */
  641. /* > \endverbatim */
  642. /* Authors: */
  643. /* ======== */
  644. /* > \author Univ. of Tennessee */
  645. /* > \author Univ. of California Berkeley */
  646. /* > \author Univ. of Colorado Denver */
  647. /* > \author NAG Ltd. */
  648. /* > \date June 2016 */
  649. /* @generated from zgeevx.f, fortran z -> c, Tue Apr 19 01:47:44 2016 */
  650. /* > \ingroup complexGEeigen */
  651. /* ===================================================================== */
  652. /* Subroutine */ int cgeevx_(char *balanc, char *jobvl, char *jobvr, char *
  653. sense, integer *n, complex *a, integer *lda, complex *w, complex *vl,
  654. integer *ldvl, complex *vr, integer *ldvr, integer *ilo, integer *ihi,
  655. real *scale, real *abnrm, real *rconde, real *rcondv, complex *work,
  656. integer *lwork, real *rwork, integer *info)
  657. {
  658. /* System generated locals */
  659. integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  660. i__2, i__3;
  661. real r__1, r__2;
  662. complex q__1, q__2;
  663. /* Local variables */
  664. char side[1];
  665. real anrm;
  666. integer ierr, itau, iwrk, nout, i__, k;
  667. extern /* Subroutine */ int cscal_(integer *, complex *, complex *,
  668. integer *);
  669. integer icond;
  670. extern logical lsame_(char *, char *);
  671. extern real scnrm2_(integer *, complex *, integer *);
  672. extern /* Subroutine */ int cgebak_(char *, char *, integer *, integer *,
  673. integer *, real *, integer *, complex *, integer *, integer *), cgebal_(char *, integer *, complex *, integer *,
  674. integer *, integer *, real *, integer *), slabad_(real *,
  675. real *);
  676. logical scalea;
  677. extern real clange_(char *, integer *, integer *, complex *, integer *,
  678. real *);
  679. real cscale;
  680. extern /* Subroutine */ int cgehrd_(integer *, integer *, integer *,
  681. complex *, integer *, complex *, complex *, integer *, integer *),
  682. clascl_(char *, integer *, integer *, real *, real *, integer *,
  683. integer *, complex *, integer *, integer *);
  684. extern real slamch_(char *);
  685. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  686. *), clacpy_(char *, integer *, integer *, complex *, integer *,
  687. complex *, integer *), xerbla_(char *, integer *, ftnlen);
  688. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  689. integer *, integer *, ftnlen, ftnlen);
  690. logical select[1];
  691. real bignum;
  692. extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
  693. real *, integer *, integer *, real *, integer *, integer *);
  694. extern integer isamax_(integer *, real *, integer *);
  695. extern /* Subroutine */ int chseqr_(char *, char *, integer *, integer *,
  696. integer *, complex *, integer *, complex *, complex *, integer *,
  697. complex *, integer *, integer *), cunghr_(integer
  698. *, integer *, integer *, complex *, integer *, complex *, complex
  699. *, integer *, integer *), ctrsna_(char *, char *, logical *,
  700. integer *, complex *, integer *, complex *, integer *, complex *,
  701. integer *, real *, real *, integer *, integer *, complex *,
  702. integer *, real *, integer *);
  703. integer minwrk, maxwrk;
  704. logical wantvl, wntsnb;
  705. integer hswork;
  706. logical wntsne;
  707. real smlnum;
  708. logical lquery, wantvr, wntsnn, wntsnv;
  709. extern /* Subroutine */ int ctrevc3_(char *, char *, logical *, integer *,
  710. complex *, integer *, complex *, integer *, complex *, integer *,
  711. integer *, integer *, complex *, integer *, real *, integer *,
  712. integer *);
  713. char job[1];
  714. real scl, dum[1], eps;
  715. complex tmp;
  716. integer lwork_trevc__;
  717. /* -- LAPACK driver routine (version 3.7.1) -- */
  718. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  719. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  720. /* June 2016 */
  721. /* ===================================================================== */
  722. /* Test the input arguments */
  723. /* Parameter adjustments */
  724. a_dim1 = *lda;
  725. a_offset = 1 + a_dim1 * 1;
  726. a -= a_offset;
  727. --w;
  728. vl_dim1 = *ldvl;
  729. vl_offset = 1 + vl_dim1 * 1;
  730. vl -= vl_offset;
  731. vr_dim1 = *ldvr;
  732. vr_offset = 1 + vr_dim1 * 1;
  733. vr -= vr_offset;
  734. --scale;
  735. --rconde;
  736. --rcondv;
  737. --work;
  738. --rwork;
  739. /* Function Body */
  740. *info = 0;
  741. lquery = *lwork == -1;
  742. wantvl = lsame_(jobvl, "V");
  743. wantvr = lsame_(jobvr, "V");
  744. wntsnn = lsame_(sense, "N");
  745. wntsne = lsame_(sense, "E");
  746. wntsnv = lsame_(sense, "V");
  747. wntsnb = lsame_(sense, "B");
  748. if (! (lsame_(balanc, "N") || lsame_(balanc, "S") || lsame_(balanc, "P")
  749. || lsame_(balanc, "B"))) {
  750. *info = -1;
  751. } else if (! wantvl && ! lsame_(jobvl, "N")) {
  752. *info = -2;
  753. } else if (! wantvr && ! lsame_(jobvr, "N")) {
  754. *info = -3;
  755. } else if (! (wntsnn || wntsne || wntsnb || wntsnv) || (wntsne || wntsnb)
  756. && ! (wantvl && wantvr)) {
  757. *info = -4;
  758. } else if (*n < 0) {
  759. *info = -5;
  760. } else if (*lda < f2cmax(1,*n)) {
  761. *info = -7;
  762. } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
  763. *info = -10;
  764. } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
  765. *info = -12;
  766. }
  767. /* Compute workspace */
  768. /* (Note: Comments in the code beginning "Workspace:" describe the */
  769. /* minimal amount of workspace needed at that point in the code, */
  770. /* as well as the preferred amount for good performance. */
  771. /* CWorkspace refers to complex workspace, and RWorkspace to real */
  772. /* workspace. NB refers to the optimal block size for the */
  773. /* immediately following subroutine, as returned by ILAENV. */
  774. /* HSWORK refers to the workspace preferred by CHSEQR, as */
  775. /* calculated below. HSWORK is computed assuming ILO=1 and IHI=N, */
  776. /* the worst case.) */
  777. if (*info == 0) {
  778. if (*n == 0) {
  779. minwrk = 1;
  780. maxwrk = 1;
  781. } else {
  782. maxwrk = *n + *n * ilaenv_(&c__1, "CGEHRD", " ", n, &c__1, n, &
  783. c__0, (ftnlen)6, (ftnlen)1);
  784. if (wantvl) {
  785. ctrevc3_("L", "B", select, n, &a[a_offset], lda, &vl[
  786. vl_offset], ldvl, &vr[vr_offset], ldvr, n, &nout, &
  787. work[1], &c_n1, &rwork[1], &c_n1, &ierr);
  788. lwork_trevc__ = (integer) work[1].r;
  789. maxwrk = f2cmax(maxwrk,lwork_trevc__);
  790. chseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &w[1], &vl[
  791. vl_offset], ldvl, &work[1], &c_n1, info);
  792. } else if (wantvr) {
  793. ctrevc3_("R", "B", select, n, &a[a_offset], lda, &vl[
  794. vl_offset], ldvl, &vr[vr_offset], ldvr, n, &nout, &
  795. work[1], &c_n1, &rwork[1], &c_n1, &ierr);
  796. lwork_trevc__ = (integer) work[1].r;
  797. maxwrk = f2cmax(maxwrk,lwork_trevc__);
  798. chseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &w[1], &vr[
  799. vr_offset], ldvr, &work[1], &c_n1, info);
  800. } else {
  801. if (wntsnn) {
  802. chseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &w[1], &
  803. vr[vr_offset], ldvr, &work[1], &c_n1, info);
  804. } else {
  805. chseqr_("S", "N", n, &c__1, n, &a[a_offset], lda, &w[1], &
  806. vr[vr_offset], ldvr, &work[1], &c_n1, info);
  807. }
  808. }
  809. hswork = (integer) work[1].r;
  810. if (! wantvl && ! wantvr) {
  811. minwrk = *n << 1;
  812. if (! (wntsnn || wntsne)) {
  813. /* Computing MAX */
  814. i__1 = minwrk, i__2 = *n * *n + (*n << 1);
  815. minwrk = f2cmax(i__1,i__2);
  816. }
  817. maxwrk = f2cmax(maxwrk,hswork);
  818. if (! (wntsnn || wntsne)) {
  819. /* Computing MAX */
  820. i__1 = maxwrk, i__2 = *n * *n + (*n << 1);
  821. maxwrk = f2cmax(i__1,i__2);
  822. }
  823. } else {
  824. minwrk = *n << 1;
  825. if (! (wntsnn || wntsne)) {
  826. /* Computing MAX */
  827. i__1 = minwrk, i__2 = *n * *n + (*n << 1);
  828. minwrk = f2cmax(i__1,i__2);
  829. }
  830. maxwrk = f2cmax(maxwrk,hswork);
  831. /* Computing MAX */
  832. i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "CUNGHR",
  833. " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
  834. maxwrk = f2cmax(i__1,i__2);
  835. if (! (wntsnn || wntsne)) {
  836. /* Computing MAX */
  837. i__1 = maxwrk, i__2 = *n * *n + (*n << 1);
  838. maxwrk = f2cmax(i__1,i__2);
  839. }
  840. /* Computing MAX */
  841. i__1 = maxwrk, i__2 = *n << 1;
  842. maxwrk = f2cmax(i__1,i__2);
  843. }
  844. maxwrk = f2cmax(maxwrk,minwrk);
  845. }
  846. work[1].r = (real) maxwrk, work[1].i = 0.f;
  847. if (*lwork < minwrk && ! lquery) {
  848. *info = -20;
  849. }
  850. }
  851. if (*info != 0) {
  852. i__1 = -(*info);
  853. xerbla_("CGEEVX", &i__1, (ftnlen)6);
  854. return 0;
  855. } else if (lquery) {
  856. return 0;
  857. }
  858. /* Quick return if possible */
  859. if (*n == 0) {
  860. return 0;
  861. }
  862. /* Get machine constants */
  863. eps = slamch_("P");
  864. smlnum = slamch_("S");
  865. bignum = 1.f / smlnum;
  866. slabad_(&smlnum, &bignum);
  867. smlnum = sqrt(smlnum) / eps;
  868. bignum = 1.f / smlnum;
  869. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  870. icond = 0;
  871. anrm = clange_("M", n, n, &a[a_offset], lda, dum);
  872. scalea = FALSE_;
  873. if (anrm > 0.f && anrm < smlnum) {
  874. scalea = TRUE_;
  875. cscale = smlnum;
  876. } else if (anrm > bignum) {
  877. scalea = TRUE_;
  878. cscale = bignum;
  879. }
  880. if (scalea) {
  881. clascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
  882. ierr);
  883. }
  884. /* Balance the matrix and compute ABNRM */
  885. cgebal_(balanc, n, &a[a_offset], lda, ilo, ihi, &scale[1], &ierr);
  886. *abnrm = clange_("1", n, n, &a[a_offset], lda, dum);
  887. if (scalea) {
  888. dum[0] = *abnrm;
  889. slascl_("G", &c__0, &c__0, &cscale, &anrm, &c__1, &c__1, dum, &c__1, &
  890. ierr);
  891. *abnrm = dum[0];
  892. }
  893. /* Reduce to upper Hessenberg form */
  894. /* (CWorkspace: need 2*N, prefer N+N*NB) */
  895. /* (RWorkspace: none) */
  896. itau = 1;
  897. iwrk = itau + *n;
  898. i__1 = *lwork - iwrk + 1;
  899. cgehrd_(n, ilo, ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1, &
  900. ierr);
  901. if (wantvl) {
  902. /* Want left eigenvectors */
  903. /* Copy Householder vectors to VL */
  904. *(unsigned char *)side = 'L';
  905. clacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
  906. ;
  907. /* Generate unitary matrix in VL */
  908. /* (CWorkspace: need 2*N-1, prefer N+(N-1)*NB) */
  909. /* (RWorkspace: none) */
  910. i__1 = *lwork - iwrk + 1;
  911. cunghr_(n, ilo, ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk], &
  912. i__1, &ierr);
  913. /* Perform QR iteration, accumulating Schur vectors in VL */
  914. /* (CWorkspace: need 1, prefer HSWORK (see comments) ) */
  915. /* (RWorkspace: none) */
  916. iwrk = itau;
  917. i__1 = *lwork - iwrk + 1;
  918. chseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &w[1], &vl[
  919. vl_offset], ldvl, &work[iwrk], &i__1, info);
  920. if (wantvr) {
  921. /* Want left and right eigenvectors */
  922. /* Copy Schur vectors to VR */
  923. *(unsigned char *)side = 'B';
  924. clacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
  925. }
  926. } else if (wantvr) {
  927. /* Want right eigenvectors */
  928. /* Copy Householder vectors to VR */
  929. *(unsigned char *)side = 'R';
  930. clacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
  931. ;
  932. /* Generate unitary matrix in VR */
  933. /* (CWorkspace: need 2*N-1, prefer N+(N-1)*NB) */
  934. /* (RWorkspace: none) */
  935. i__1 = *lwork - iwrk + 1;
  936. cunghr_(n, ilo, ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk], &
  937. i__1, &ierr);
  938. /* Perform QR iteration, accumulating Schur vectors in VR */
  939. /* (CWorkspace: need 1, prefer HSWORK (see comments) ) */
  940. /* (RWorkspace: none) */
  941. iwrk = itau;
  942. i__1 = *lwork - iwrk + 1;
  943. chseqr_("S", "V", n, ilo, ihi, &a[a_offset], lda, &w[1], &vr[
  944. vr_offset], ldvr, &work[iwrk], &i__1, info);
  945. } else {
  946. /* Compute eigenvalues only */
  947. /* If condition numbers desired, compute Schur form */
  948. if (wntsnn) {
  949. *(unsigned char *)job = 'E';
  950. } else {
  951. *(unsigned char *)job = 'S';
  952. }
  953. /* (CWorkspace: need 1, prefer HSWORK (see comments) ) */
  954. /* (RWorkspace: none) */
  955. iwrk = itau;
  956. i__1 = *lwork - iwrk + 1;
  957. chseqr_(job, "N", n, ilo, ihi, &a[a_offset], lda, &w[1], &vr[
  958. vr_offset], ldvr, &work[iwrk], &i__1, info);
  959. }
  960. /* If INFO .NE. 0 from CHSEQR, then quit */
  961. if (*info != 0) {
  962. goto L50;
  963. }
  964. if (wantvl || wantvr) {
  965. /* Compute left and/or right eigenvectors */
  966. /* (CWorkspace: need 2*N, prefer N + 2*N*NB) */
  967. /* (RWorkspace: need N) */
  968. i__1 = *lwork - iwrk + 1;
  969. ctrevc3_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset],
  970. ldvl, &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &i__1, &
  971. rwork[1], n, &ierr);
  972. }
  973. /* Compute condition numbers if desired */
  974. /* (CWorkspace: need N*N+2*N unless SENSE = 'E') */
  975. /* (RWorkspace: need 2*N unless SENSE = 'E') */
  976. if (! wntsnn) {
  977. ctrsna_(sense, "A", select, n, &a[a_offset], lda, &vl[vl_offset],
  978. ldvl, &vr[vr_offset], ldvr, &rconde[1], &rcondv[1], n, &nout,
  979. &work[iwrk], n, &rwork[1], &icond);
  980. }
  981. if (wantvl) {
  982. /* Undo balancing of left eigenvectors */
  983. cgebak_(balanc, "L", n, ilo, ihi, &scale[1], n, &vl[vl_offset], ldvl,
  984. &ierr);
  985. /* Normalize left eigenvectors and make largest component real */
  986. i__1 = *n;
  987. for (i__ = 1; i__ <= i__1; ++i__) {
  988. scl = 1.f / scnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
  989. csscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
  990. i__2 = *n;
  991. for (k = 1; k <= i__2; ++k) {
  992. i__3 = k + i__ * vl_dim1;
  993. /* Computing 2nd power */
  994. r__1 = vl[i__3].r;
  995. /* Computing 2nd power */
  996. r__2 = r_imag(&vl[k + i__ * vl_dim1]);
  997. rwork[k] = r__1 * r__1 + r__2 * r__2;
  998. /* L10: */
  999. }
  1000. k = isamax_(n, &rwork[1], &c__1);
  1001. r_cnjg(&q__2, &vl[k + i__ * vl_dim1]);
  1002. r__1 = sqrt(rwork[k]);
  1003. q__1.r = q__2.r / r__1, q__1.i = q__2.i / r__1;
  1004. tmp.r = q__1.r, tmp.i = q__1.i;
  1005. cscal_(n, &tmp, &vl[i__ * vl_dim1 + 1], &c__1);
  1006. i__2 = k + i__ * vl_dim1;
  1007. i__3 = k + i__ * vl_dim1;
  1008. r__1 = vl[i__3].r;
  1009. q__1.r = r__1, q__1.i = 0.f;
  1010. vl[i__2].r = q__1.r, vl[i__2].i = q__1.i;
  1011. /* L20: */
  1012. }
  1013. }
  1014. if (wantvr) {
  1015. /* Undo balancing of right eigenvectors */
  1016. cgebak_(balanc, "R", n, ilo, ihi, &scale[1], n, &vr[vr_offset], ldvr,
  1017. &ierr);
  1018. /* Normalize right eigenvectors and make largest component real */
  1019. i__1 = *n;
  1020. for (i__ = 1; i__ <= i__1; ++i__) {
  1021. scl = 1.f / scnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
  1022. csscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
  1023. i__2 = *n;
  1024. for (k = 1; k <= i__2; ++k) {
  1025. i__3 = k + i__ * vr_dim1;
  1026. /* Computing 2nd power */
  1027. r__1 = vr[i__3].r;
  1028. /* Computing 2nd power */
  1029. r__2 = r_imag(&vr[k + i__ * vr_dim1]);
  1030. rwork[k] = r__1 * r__1 + r__2 * r__2;
  1031. /* L30: */
  1032. }
  1033. k = isamax_(n, &rwork[1], &c__1);
  1034. r_cnjg(&q__2, &vr[k + i__ * vr_dim1]);
  1035. r__1 = sqrt(rwork[k]);
  1036. q__1.r = q__2.r / r__1, q__1.i = q__2.i / r__1;
  1037. tmp.r = q__1.r, tmp.i = q__1.i;
  1038. cscal_(n, &tmp, &vr[i__ * vr_dim1 + 1], &c__1);
  1039. i__2 = k + i__ * vr_dim1;
  1040. i__3 = k + i__ * vr_dim1;
  1041. r__1 = vr[i__3].r;
  1042. q__1.r = r__1, q__1.i = 0.f;
  1043. vr[i__2].r = q__1.r, vr[i__2].i = q__1.i;
  1044. /* L40: */
  1045. }
  1046. }
  1047. /* Undo scaling if necessary */
  1048. L50:
  1049. if (scalea) {
  1050. i__1 = *n - *info;
  1051. /* Computing MAX */
  1052. i__3 = *n - *info;
  1053. i__2 = f2cmax(i__3,1);
  1054. clascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &w[*info + 1]
  1055. , &i__2, &ierr);
  1056. if (*info == 0) {
  1057. if ((wntsnv || wntsnb) && icond == 0) {
  1058. slascl_("G", &c__0, &c__0, &cscale, &anrm, n, &c__1, &rcondv[
  1059. 1], n, &ierr);
  1060. }
  1061. } else {
  1062. i__1 = *ilo - 1;
  1063. clascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &w[1], n,
  1064. &ierr);
  1065. }
  1066. }
  1067. work[1].r = (real) maxwrk, work[1].i = 0.f;
  1068. return 0;
  1069. /* End of CGEEVX */
  1070. } /* cgeevx_ */