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.

zggevx.c 42 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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 doublecomplex c_b1 = {0.,0.};
  381. static doublecomplex c_b2 = {1.,0.};
  382. static integer c__1 = 1;
  383. static integer c__0 = 0;
  384. /* > \brief <b> ZGGEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE mat
  385. rices</b> */
  386. /* =========== DOCUMENTATION =========== */
  387. /* Online html documentation available at */
  388. /* http://www.netlib.org/lapack/explore-html/ */
  389. /* > \htmlonly */
  390. /* > Download ZGGEVX + dependencies */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zggevx.
  392. f"> */
  393. /* > [TGZ]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zggevx.
  395. f"> */
  396. /* > [ZIP]</a> */
  397. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zggevx.
  398. f"> */
  399. /* > [TXT]</a> */
  400. /* > \endhtmlonly */
  401. /* Definition: */
  402. /* =========== */
  403. /* SUBROUTINE ZGGEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, B, LDB, */
  404. /* ALPHA, BETA, VL, LDVL, VR, LDVR, ILO, IHI, */
  405. /* LSCALE, RSCALE, ABNRM, BBNRM, RCONDE, RCONDV, */
  406. /* WORK, LWORK, RWORK, IWORK, BWORK, INFO ) */
  407. /* CHARACTER BALANC, JOBVL, JOBVR, SENSE */
  408. /* INTEGER IHI, ILO, INFO, LDA, LDB, LDVL, LDVR, LWORK, N */
  409. /* DOUBLE PRECISION ABNRM, BBNRM */
  410. /* LOGICAL BWORK( * ) */
  411. /* INTEGER IWORK( * ) */
  412. /* DOUBLE PRECISION LSCALE( * ), RCONDE( * ), RCONDV( * ), */
  413. /* $ RSCALE( * ), RWORK( * ) */
  414. /* COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ), */
  415. /* $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ), */
  416. /* $ WORK( * ) */
  417. /* > \par Purpose: */
  418. /* ============= */
  419. /* > */
  420. /* > \verbatim */
  421. /* > */
  422. /* > ZGGEVX computes for a pair of N-by-N complex nonsymmetric matrices */
  423. /* > (A,B) the generalized eigenvalues, and optionally, the left and/or */
  424. /* > right generalized eigenvectors. */
  425. /* > */
  426. /* > Optionally, it also computes a balancing transformation to improve */
  427. /* > the conditioning of the eigenvalues and eigenvectors (ILO, IHI, */
  428. /* > LSCALE, RSCALE, ABNRM, and BBNRM), reciprocal condition numbers for */
  429. /* > the eigenvalues (RCONDE), and reciprocal condition numbers for the */
  430. /* > right eigenvectors (RCONDV). */
  431. /* > */
  432. /* > A generalized eigenvalue for a pair of matrices (A,B) is a scalar */
  433. /* > lambda or a ratio alpha/beta = lambda, such that A - lambda*B is */
  434. /* > singular. It is usually represented as the pair (alpha,beta), as */
  435. /* > there is a reasonable interpretation for beta=0, and even for both */
  436. /* > being zero. */
  437. /* > */
  438. /* > The right eigenvector v(j) corresponding to the eigenvalue lambda(j) */
  439. /* > of (A,B) satisfies */
  440. /* > A * v(j) = lambda(j) * B * v(j) . */
  441. /* > The left eigenvector u(j) corresponding to the eigenvalue lambda(j) */
  442. /* > of (A,B) satisfies */
  443. /* > u(j)**H * A = lambda(j) * u(j)**H * B. */
  444. /* > where u(j)**H is the conjugate-transpose of u(j). */
  445. /* > */
  446. /* > \endverbatim */
  447. /* Arguments: */
  448. /* ========== */
  449. /* > \param[in] BALANC */
  450. /* > \verbatim */
  451. /* > BALANC is CHARACTER*1 */
  452. /* > Specifies the balance option to be performed: */
  453. /* > = 'N': do not diagonally scale or permute; */
  454. /* > = 'P': permute only; */
  455. /* > = 'S': scale only; */
  456. /* > = 'B': both permute and scale. */
  457. /* > Computed reciprocal condition numbers will be for the */
  458. /* > matrices after permuting and/or balancing. Permuting does */
  459. /* > not change condition numbers (in exact arithmetic), but */
  460. /* > balancing does. */
  461. /* > \endverbatim */
  462. /* > */
  463. /* > \param[in] JOBVL */
  464. /* > \verbatim */
  465. /* > JOBVL is CHARACTER*1 */
  466. /* > = 'N': do not compute the left generalized eigenvectors; */
  467. /* > = 'V': compute the left generalized eigenvectors. */
  468. /* > \endverbatim */
  469. /* > */
  470. /* > \param[in] JOBVR */
  471. /* > \verbatim */
  472. /* > JOBVR is CHARACTER*1 */
  473. /* > = 'N': do not compute the right generalized eigenvectors; */
  474. /* > = 'V': compute the right generalized eigenvectors. */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[in] SENSE */
  478. /* > \verbatim */
  479. /* > SENSE is CHARACTER*1 */
  480. /* > Determines which reciprocal condition numbers are computed. */
  481. /* > = 'N': none are computed; */
  482. /* > = 'E': computed for eigenvalues only; */
  483. /* > = 'V': computed for eigenvectors only; */
  484. /* > = 'B': computed for eigenvalues and eigenvectors. */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[in] N */
  488. /* > \verbatim */
  489. /* > N is INTEGER */
  490. /* > The order of the matrices A, B, VL, and VR. N >= 0. */
  491. /* > \endverbatim */
  492. /* > */
  493. /* > \param[in,out] A */
  494. /* > \verbatim */
  495. /* > A is COMPLEX*16 array, dimension (LDA, N) */
  496. /* > On entry, the matrix A in the pair (A,B). */
  497. /* > On exit, A has been overwritten. If JOBVL='V' or JOBVR='V' */
  498. /* > or both, then A contains the first part of the complex Schur */
  499. /* > form of the "balanced" versions of the input A and B. */
  500. /* > \endverbatim */
  501. /* > */
  502. /* > \param[in] LDA */
  503. /* > \verbatim */
  504. /* > LDA is INTEGER */
  505. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  506. /* > \endverbatim */
  507. /* > */
  508. /* > \param[in,out] B */
  509. /* > \verbatim */
  510. /* > B is COMPLEX*16 array, dimension (LDB, N) */
  511. /* > On entry, the matrix B in the pair (A,B). */
  512. /* > On exit, B has been overwritten. If JOBVL='V' or JOBVR='V' */
  513. /* > or both, then B contains the second part of the complex */
  514. /* > Schur form of the "balanced" versions of the input A and B. */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[in] LDB */
  518. /* > \verbatim */
  519. /* > LDB is INTEGER */
  520. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  521. /* > \endverbatim */
  522. /* > */
  523. /* > \param[out] ALPHA */
  524. /* > \verbatim */
  525. /* > ALPHA is COMPLEX*16 array, dimension (N) */
  526. /* > \endverbatim */
  527. /* > */
  528. /* > \param[out] BETA */
  529. /* > \verbatim */
  530. /* > BETA is COMPLEX*16 array, dimension (N) */
  531. /* > On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the generalized */
  532. /* > eigenvalues. */
  533. /* > */
  534. /* > Note: the quotient ALPHA(j)/BETA(j) ) may easily over- or */
  535. /* > underflow, and BETA(j) may even be zero. Thus, the user */
  536. /* > should avoid naively computing the ratio ALPHA/BETA. */
  537. /* > However, ALPHA will be always less than and usually */
  538. /* > comparable with norm(A) in magnitude, and BETA always less */
  539. /* > than and usually comparable with norm(B). */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[out] VL */
  543. /* > \verbatim */
  544. /* > VL is COMPLEX*16 array, dimension (LDVL,N) */
  545. /* > If JOBVL = 'V', the left generalized eigenvectors u(j) are */
  546. /* > stored one after another in the columns of VL, in the same */
  547. /* > order as their eigenvalues. */
  548. /* > Each eigenvector will be scaled so the largest component */
  549. /* > will have abs(real part) + abs(imag. part) = 1. */
  550. /* > Not referenced if JOBVL = 'N'. */
  551. /* > \endverbatim */
  552. /* > */
  553. /* > \param[in] LDVL */
  554. /* > \verbatim */
  555. /* > LDVL is INTEGER */
  556. /* > The leading dimension of the matrix VL. LDVL >= 1, and */
  557. /* > if JOBVL = 'V', LDVL >= N. */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[out] VR */
  561. /* > \verbatim */
  562. /* > VR is COMPLEX*16 array, dimension (LDVR,N) */
  563. /* > If JOBVR = 'V', the right generalized eigenvectors v(j) are */
  564. /* > stored one after another in the columns of VR, in the same */
  565. /* > order as their eigenvalues. */
  566. /* > Each eigenvector will be scaled so the largest component */
  567. /* > will have abs(real part) + abs(imag. part) = 1. */
  568. /* > Not referenced if JOBVR = 'N'. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] LDVR */
  572. /* > \verbatim */
  573. /* > LDVR is INTEGER */
  574. /* > The leading dimension of the matrix VR. LDVR >= 1, and */
  575. /* > if JOBVR = 'V', LDVR >= N. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[out] ILO */
  579. /* > \verbatim */
  580. /* > ILO is INTEGER */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[out] IHI */
  584. /* > \verbatim */
  585. /* > IHI is INTEGER */
  586. /* > ILO and IHI are integer values such that on exit */
  587. /* > A(i,j) = 0 and B(i,j) = 0 if i > j and */
  588. /* > j = 1,...,ILO-1 or i = IHI+1,...,N. */
  589. /* > If BALANC = 'N' or 'S', ILO = 1 and IHI = N. */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[out] LSCALE */
  593. /* > \verbatim */
  594. /* > LSCALE is DOUBLE PRECISION array, dimension (N) */
  595. /* > Details of the permutations and scaling factors applied */
  596. /* > to the left side of A and B. If PL(j) is the index of the */
  597. /* > row interchanged with row j, and DL(j) is the scaling */
  598. /* > factor applied to row j, then */
  599. /* > LSCALE(j) = PL(j) for j = 1,...,ILO-1 */
  600. /* > = DL(j) for j = ILO,...,IHI */
  601. /* > = PL(j) for j = IHI+1,...,N. */
  602. /* > The order in which the interchanges are made is N to IHI+1, */
  603. /* > then 1 to ILO-1. */
  604. /* > \endverbatim */
  605. /* > */
  606. /* > \param[out] RSCALE */
  607. /* > \verbatim */
  608. /* > RSCALE is DOUBLE PRECISION array, dimension (N) */
  609. /* > Details of the permutations and scaling factors applied */
  610. /* > to the right side of A and B. If PR(j) is the index of the */
  611. /* > column interchanged with column j, and DR(j) is the scaling */
  612. /* > factor applied to column j, then */
  613. /* > RSCALE(j) = PR(j) for j = 1,...,ILO-1 */
  614. /* > = DR(j) for j = ILO,...,IHI */
  615. /* > = PR(j) for j = IHI+1,...,N */
  616. /* > The order in which the interchanges are made is N to IHI+1, */
  617. /* > then 1 to ILO-1. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[out] ABNRM */
  621. /* > \verbatim */
  622. /* > ABNRM is DOUBLE PRECISION */
  623. /* > The one-norm of the balanced matrix A. */
  624. /* > \endverbatim */
  625. /* > */
  626. /* > \param[out] BBNRM */
  627. /* > \verbatim */
  628. /* > BBNRM is DOUBLE PRECISION */
  629. /* > The one-norm of the balanced matrix B. */
  630. /* > \endverbatim */
  631. /* > */
  632. /* > \param[out] RCONDE */
  633. /* > \verbatim */
  634. /* > RCONDE is DOUBLE PRECISION array, dimension (N) */
  635. /* > If SENSE = 'E' or 'B', the reciprocal condition numbers of */
  636. /* > the eigenvalues, stored in consecutive elements of the array. */
  637. /* > If SENSE = 'N' or 'V', RCONDE is not referenced. */
  638. /* > \endverbatim */
  639. /* > */
  640. /* > \param[out] RCONDV */
  641. /* > \verbatim */
  642. /* > RCONDV is DOUBLE PRECISION array, dimension (N) */
  643. /* > If JOB = 'V' or 'B', the estimated reciprocal condition */
  644. /* > numbers of the eigenvectors, stored in consecutive elements */
  645. /* > of the array. If the eigenvalues cannot be reordered to */
  646. /* > compute RCONDV(j), RCONDV(j) is set to 0; this can only occur */
  647. /* > when the true value would be very small anyway. */
  648. /* > If SENSE = 'N' or 'E', RCONDV is not referenced. */
  649. /* > \endverbatim */
  650. /* > */
  651. /* > \param[out] WORK */
  652. /* > \verbatim */
  653. /* > WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) */
  654. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  655. /* > \endverbatim */
  656. /* > */
  657. /* > \param[in] LWORK */
  658. /* > \verbatim */
  659. /* > LWORK is INTEGER */
  660. /* > The dimension of the array WORK. LWORK >= f2cmax(1,2*N). */
  661. /* > If SENSE = 'E', LWORK >= f2cmax(1,4*N). */
  662. /* > If SENSE = 'V' or 'B', LWORK >= f2cmax(1,2*N*N+2*N). */
  663. /* > */
  664. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  665. /* > only calculates the optimal size of the WORK array, returns */
  666. /* > this value as the first entry of the WORK array, and no error */
  667. /* > message related to LWORK is issued by XERBLA. */
  668. /* > \endverbatim */
  669. /* > */
  670. /* > \param[out] RWORK */
  671. /* > \verbatim */
  672. /* > RWORK is DOUBLE PRECISION array, dimension (lrwork) */
  673. /* > lrwork must be at least f2cmax(1,6*N) if BALANC = 'S' or 'B', */
  674. /* > and at least f2cmax(1,2*N) otherwise. */
  675. /* > Real workspace. */
  676. /* > \endverbatim */
  677. /* > */
  678. /* > \param[out] IWORK */
  679. /* > \verbatim */
  680. /* > IWORK is INTEGER array, dimension (N+2) */
  681. /* > If SENSE = 'E', IWORK is not referenced. */
  682. /* > \endverbatim */
  683. /* > */
  684. /* > \param[out] BWORK */
  685. /* > \verbatim */
  686. /* > BWORK is LOGICAL array, dimension (N) */
  687. /* > If SENSE = 'N', BWORK is not referenced. */
  688. /* > \endverbatim */
  689. /* > */
  690. /* > \param[out] INFO */
  691. /* > \verbatim */
  692. /* > INFO is INTEGER */
  693. /* > = 0: successful exit */
  694. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  695. /* > = 1,...,N: */
  696. /* > The QZ iteration failed. No eigenvectors have been */
  697. /* > calculated, but ALPHA(j) and BETA(j) should be correct */
  698. /* > for j=INFO+1,...,N. */
  699. /* > > N: =N+1: other than QZ iteration failed in ZHGEQZ. */
  700. /* > =N+2: error return from ZTGEVC. */
  701. /* > \endverbatim */
  702. /* Authors: */
  703. /* ======== */
  704. /* > \author Univ. of Tennessee */
  705. /* > \author Univ. of California Berkeley */
  706. /* > \author Univ. of Colorado Denver */
  707. /* > \author NAG Ltd. */
  708. /* > \date April 2012 */
  709. /* > \ingroup complex16GEeigen */
  710. /* > \par Further Details: */
  711. /* ===================== */
  712. /* > */
  713. /* > \verbatim */
  714. /* > */
  715. /* > Balancing a matrix pair (A,B) includes, first, permuting rows and */
  716. /* > columns to isolate eigenvalues, second, applying diagonal similarity */
  717. /* > transformation to the rows and columns to make the rows and columns */
  718. /* > as close in norm as possible. The computed reciprocal condition */
  719. /* > numbers correspond to the balanced matrix. Permuting rows and columns */
  720. /* > will not change the condition numbers (in exact arithmetic) but */
  721. /* > diagonal scaling will. For further explanation of balancing, see */
  722. /* > section 4.11.1.2 of LAPACK Users' Guide. */
  723. /* > */
  724. /* > An approximate error bound on the chordal distance between the i-th */
  725. /* > computed generalized eigenvalue w and the corresponding exact */
  726. /* > eigenvalue lambda is */
  727. /* > */
  728. /* > chord(w, lambda) <= EPS * norm(ABNRM, BBNRM) / RCONDE(I) */
  729. /* > */
  730. /* > An approximate error bound for the angle between the i-th computed */
  731. /* > eigenvector VL(i) or VR(i) is given by */
  732. /* > */
  733. /* > EPS * norm(ABNRM, BBNRM) / DIF(i). */
  734. /* > */
  735. /* > For further explanation of the reciprocal condition numbers RCONDE */
  736. /* > and RCONDV, see section 4.11 of LAPACK User's Guide. */
  737. /* > \endverbatim */
  738. /* > */
  739. /* ===================================================================== */
  740. /* Subroutine */ int zggevx_(char *balanc, char *jobvl, char *jobvr, char *
  741. sense, integer *n, doublecomplex *a, integer *lda, doublecomplex *b,
  742. integer *ldb, doublecomplex *alpha, doublecomplex *beta,
  743. doublecomplex *vl, integer *ldvl, doublecomplex *vr, integer *ldvr,
  744. integer *ilo, integer *ihi, doublereal *lscale, doublereal *rscale,
  745. doublereal *abnrm, doublereal *bbnrm, doublereal *rconde, doublereal *
  746. rcondv, doublecomplex *work, integer *lwork, doublereal *rwork,
  747. integer *iwork, logical *bwork, integer *info)
  748. {
  749. /* System generated locals */
  750. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  751. vr_offset, i__1, i__2, i__3, i__4;
  752. doublereal d__1, d__2, d__3, d__4;
  753. doublecomplex z__1;
  754. /* Local variables */
  755. doublereal anrm, bnrm;
  756. integer ierr, itau;
  757. doublereal temp;
  758. logical ilvl, ilvr;
  759. integer iwrk, iwrk1, i__, j, m;
  760. extern logical lsame_(char *, char *);
  761. integer icols;
  762. logical noscl;
  763. integer irows;
  764. extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
  765. integer jc, in;
  766. extern doublereal dlamch_(char *);
  767. integer jr;
  768. extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
  769. doublereal *, doublereal *, integer *, integer *, doublereal *,
  770. integer *, integer *), zggbak_(char *, char *, integer *,
  771. integer *, integer *, doublereal *, doublereal *, integer *,
  772. doublecomplex *, integer *, integer *), zggbal_(
  773. char *, integer *, doublecomplex *, integer *, doublecomplex *,
  774. integer *, integer *, integer *, doublereal *, doublereal *,
  775. doublereal *, integer *);
  776. logical ilascl, ilbscl;
  777. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  778. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  779. integer *, integer *, ftnlen, ftnlen);
  780. logical ldumma[1];
  781. char chtemp[1];
  782. doublereal bignum;
  783. extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
  784. integer *, doublereal *);
  785. integer ijobvl;
  786. extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *,
  787. integer *, doublecomplex *, integer *, doublecomplex *, integer *,
  788. doublecomplex *, integer *, doublecomplex *, integer *, integer *
  789. ), zlascl_(char *, integer *, integer *,
  790. doublereal *, doublereal *, integer *, integer *, doublecomplex *,
  791. integer *, integer *);
  792. integer ijobvr;
  793. logical wantsb;
  794. extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *,
  795. integer *, doublecomplex *, doublecomplex *, integer *, integer *
  796. );
  797. doublereal anrmto;
  798. logical wantse;
  799. doublereal bnrmto;
  800. extern /* Subroutine */ int zlacpy_(char *, integer *, integer *,
  801. doublecomplex *, integer *, doublecomplex *, integer *),
  802. zlaset_(char *, integer *, integer *, doublecomplex *,
  803. doublecomplex *, doublecomplex *, integer *), ztgevc_(
  804. char *, char *, logical *, integer *, doublecomplex *, integer *,
  805. doublecomplex *, integer *, doublecomplex *, integer *,
  806. doublecomplex *, integer *, integer *, integer *, doublecomplex *,
  807. doublereal *, integer *), ztgsna_(char *, char *,
  808. logical *, integer *, doublecomplex *, integer *, doublecomplex *
  809. , integer *, doublecomplex *, integer *, doublecomplex *, integer
  810. *, doublereal *, doublereal *, integer *, integer *,
  811. doublecomplex *, integer *, integer *, integer *);
  812. integer minwrk;
  813. extern /* Subroutine */ int zhgeqz_(char *, char *, char *, integer *,
  814. integer *, integer *, doublecomplex *, integer *, doublecomplex *,
  815. integer *, doublecomplex *, doublecomplex *, doublecomplex *,
  816. integer *, doublecomplex *, integer *, doublecomplex *, integer *,
  817. doublereal *, integer *);
  818. integer maxwrk;
  819. logical wantsn;
  820. doublereal smlnum;
  821. logical lquery, wantsv;
  822. extern /* Subroutine */ int zungqr_(integer *, integer *, integer *,
  823. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  824. integer *, integer *), zunmqr_(char *, char *, integer *, integer
  825. *, integer *, doublecomplex *, integer *, doublecomplex *,
  826. doublecomplex *, integer *, doublecomplex *, integer *, integer *);
  827. doublereal eps;
  828. logical ilv;
  829. /* -- LAPACK driver routine (version 3.7.0) -- */
  830. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  831. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  832. /* April 2012 */
  833. /* ===================================================================== */
  834. /* Decode the input arguments */
  835. /* Parameter adjustments */
  836. a_dim1 = *lda;
  837. a_offset = 1 + a_dim1 * 1;
  838. a -= a_offset;
  839. b_dim1 = *ldb;
  840. b_offset = 1 + b_dim1 * 1;
  841. b -= b_offset;
  842. --alpha;
  843. --beta;
  844. vl_dim1 = *ldvl;
  845. vl_offset = 1 + vl_dim1 * 1;
  846. vl -= vl_offset;
  847. vr_dim1 = *ldvr;
  848. vr_offset = 1 + vr_dim1 * 1;
  849. vr -= vr_offset;
  850. --lscale;
  851. --rscale;
  852. --rconde;
  853. --rcondv;
  854. --work;
  855. --rwork;
  856. --iwork;
  857. --bwork;
  858. /* Function Body */
  859. if (lsame_(jobvl, "N")) {
  860. ijobvl = 1;
  861. ilvl = FALSE_;
  862. } else if (lsame_(jobvl, "V")) {
  863. ijobvl = 2;
  864. ilvl = TRUE_;
  865. } else {
  866. ijobvl = -1;
  867. ilvl = FALSE_;
  868. }
  869. if (lsame_(jobvr, "N")) {
  870. ijobvr = 1;
  871. ilvr = FALSE_;
  872. } else if (lsame_(jobvr, "V")) {
  873. ijobvr = 2;
  874. ilvr = TRUE_;
  875. } else {
  876. ijobvr = -1;
  877. ilvr = FALSE_;
  878. }
  879. ilv = ilvl || ilvr;
  880. noscl = lsame_(balanc, "N") || lsame_(balanc, "P");
  881. wantsn = lsame_(sense, "N");
  882. wantse = lsame_(sense, "E");
  883. wantsv = lsame_(sense, "V");
  884. wantsb = lsame_(sense, "B");
  885. /* Test the input arguments */
  886. *info = 0;
  887. lquery = *lwork == -1;
  888. if (! (noscl || lsame_(balanc, "S") || lsame_(
  889. balanc, "B"))) {
  890. *info = -1;
  891. } else if (ijobvl <= 0) {
  892. *info = -2;
  893. } else if (ijobvr <= 0) {
  894. *info = -3;
  895. } else if (! (wantsn || wantse || wantsb || wantsv)) {
  896. *info = -4;
  897. } else if (*n < 0) {
  898. *info = -5;
  899. } else if (*lda < f2cmax(1,*n)) {
  900. *info = -7;
  901. } else if (*ldb < f2cmax(1,*n)) {
  902. *info = -9;
  903. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  904. *info = -13;
  905. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  906. *info = -15;
  907. }
  908. /* Compute workspace */
  909. /* (Note: Comments in the code beginning "Workspace:" describe the */
  910. /* minimal amount of workspace needed at that point in the code, */
  911. /* as well as the preferred amount for good performance. */
  912. /* NB refers to the optimal block size for the immediately */
  913. /* following subroutine, as returned by ILAENV. The workspace is */
  914. /* computed assuming ILO = 1 and IHI = N, the worst case.) */
  915. if (*info == 0) {
  916. if (*n == 0) {
  917. minwrk = 1;
  918. maxwrk = 1;
  919. } else {
  920. minwrk = *n << 1;
  921. if (wantse) {
  922. minwrk = *n << 2;
  923. } else if (wantsv || wantsb) {
  924. minwrk = (*n << 1) * (*n + 1);
  925. }
  926. maxwrk = minwrk;
  927. /* Computing MAX */
  928. i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &
  929. c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  930. maxwrk = f2cmax(i__1,i__2);
  931. /* Computing MAX */
  932. i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "ZUNMQR", " ", n, &
  933. c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  934. maxwrk = f2cmax(i__1,i__2);
  935. if (ilvl) {
  936. /* Computing MAX */
  937. i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR",
  938. " ", n, &c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  939. maxwrk = f2cmax(i__1,i__2);
  940. }
  941. }
  942. work[1].r = (doublereal) maxwrk, work[1].i = 0.;
  943. if (*lwork < minwrk && ! lquery) {
  944. *info = -25;
  945. }
  946. }
  947. if (*info != 0) {
  948. i__1 = -(*info);
  949. xerbla_("ZGGEVX", &i__1, (ftnlen)6);
  950. return 0;
  951. } else if (lquery) {
  952. return 0;
  953. }
  954. /* Quick return if possible */
  955. if (*n == 0) {
  956. return 0;
  957. }
  958. /* Get machine constants */
  959. eps = dlamch_("P");
  960. smlnum = dlamch_("S");
  961. bignum = 1. / smlnum;
  962. dlabad_(&smlnum, &bignum);
  963. smlnum = sqrt(smlnum) / eps;
  964. bignum = 1. / smlnum;
  965. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  966. anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]);
  967. ilascl = FALSE_;
  968. if (anrm > 0. && anrm < smlnum) {
  969. anrmto = smlnum;
  970. ilascl = TRUE_;
  971. } else if (anrm > bignum) {
  972. anrmto = bignum;
  973. ilascl = TRUE_;
  974. }
  975. if (ilascl) {
  976. zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  977. ierr);
  978. }
  979. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  980. bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
  981. ilbscl = FALSE_;
  982. if (bnrm > 0. && bnrm < smlnum) {
  983. bnrmto = smlnum;
  984. ilbscl = TRUE_;
  985. } else if (bnrm > bignum) {
  986. bnrmto = bignum;
  987. ilbscl = TRUE_;
  988. }
  989. if (ilbscl) {
  990. zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  991. ierr);
  992. }
  993. /* Permute and/or balance the matrix pair (A,B) */
  994. /* (Real Workspace: need 6*N if BALANC = 'S' or 'B', 1 otherwise) */
  995. zggbal_(balanc, n, &a[a_offset], lda, &b[b_offset], ldb, ilo, ihi, &
  996. lscale[1], &rscale[1], &rwork[1], &ierr);
  997. /* Compute ABNRM and BBNRM */
  998. *abnrm = zlange_("1", n, n, &a[a_offset], lda, &rwork[1]);
  999. if (ilascl) {
  1000. rwork[1] = *abnrm;
  1001. dlascl_("G", &c__0, &c__0, &anrmto, &anrm, &c__1, &c__1, &rwork[1], &
  1002. c__1, &ierr);
  1003. *abnrm = rwork[1];
  1004. }
  1005. *bbnrm = zlange_("1", n, n, &b[b_offset], ldb, &rwork[1]);
  1006. if (ilbscl) {
  1007. rwork[1] = *bbnrm;
  1008. dlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, &c__1, &c__1, &rwork[1], &
  1009. c__1, &ierr);
  1010. *bbnrm = rwork[1];
  1011. }
  1012. /* Reduce B to triangular form (QR decomposition of B) */
  1013. /* (Complex Workspace: need N, prefer N*NB ) */
  1014. irows = *ihi + 1 - *ilo;
  1015. if (ilv || ! wantsn) {
  1016. icols = *n + 1 - *ilo;
  1017. } else {
  1018. icols = irows;
  1019. }
  1020. itau = 1;
  1021. iwrk = itau + irows;
  1022. i__1 = *lwork + 1 - iwrk;
  1023. zgeqrf_(&irows, &icols, &b[*ilo + *ilo * b_dim1], ldb, &work[itau], &work[
  1024. iwrk], &i__1, &ierr);
  1025. /* Apply the unitary transformation to A */
  1026. /* (Complex Workspace: need N, prefer N*NB) */
  1027. i__1 = *lwork + 1 - iwrk;
  1028. zunmqr_("L", "C", &irows, &icols, &irows, &b[*ilo + *ilo * b_dim1], ldb, &
  1029. work[itau], &a[*ilo + *ilo * a_dim1], lda, &work[iwrk], &i__1, &
  1030. ierr);
  1031. /* Initialize VL and/or VR */
  1032. /* (Workspace: need N, prefer N*NB) */
  1033. if (ilvl) {
  1034. zlaset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl);
  1035. if (irows > 1) {
  1036. i__1 = irows - 1;
  1037. i__2 = irows - 1;
  1038. zlacpy_("L", &i__1, &i__2, &b[*ilo + 1 + *ilo * b_dim1], ldb, &vl[
  1039. *ilo + 1 + *ilo * vl_dim1], ldvl);
  1040. }
  1041. i__1 = *lwork + 1 - iwrk;
  1042. zungqr_(&irows, &irows, &irows, &vl[*ilo + *ilo * vl_dim1], ldvl, &
  1043. work[itau], &work[iwrk], &i__1, &ierr);
  1044. }
  1045. if (ilvr) {
  1046. zlaset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr);
  1047. }
  1048. /* Reduce to generalized Hessenberg form */
  1049. /* (Workspace: none needed) */
  1050. if (ilv || ! wantsn) {
  1051. /* Eigenvectors requested -- work on whole matrix. */
  1052. zgghrd_(jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset],
  1053. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
  1054. } else {
  1055. zgghrd_("N", "N", &irows, &c__1, &irows, &a[*ilo + *ilo * a_dim1],
  1056. lda, &b[*ilo + *ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  1057. vr_offset], ldvr, &ierr);
  1058. }
  1059. /* Perform QZ algorithm (Compute eigenvalues, and optionally, the */
  1060. /* Schur forms and Schur vectors) */
  1061. /* (Complex Workspace: need N) */
  1062. /* (Real Workspace: need N) */
  1063. iwrk = itau;
  1064. if (ilv || ! wantsn) {
  1065. *(unsigned char *)chtemp = 'S';
  1066. } else {
  1067. *(unsigned char *)chtemp = 'E';
  1068. }
  1069. i__1 = *lwork + 1 - iwrk;
  1070. zhgeqz_(chtemp, jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset]
  1071. , ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[vr_offset],
  1072. ldvr, &work[iwrk], &i__1, &rwork[1], &ierr);
  1073. if (ierr != 0) {
  1074. if (ierr > 0 && ierr <= *n) {
  1075. *info = ierr;
  1076. } else if (ierr > *n && ierr <= *n << 1) {
  1077. *info = ierr - *n;
  1078. } else {
  1079. *info = *n + 1;
  1080. }
  1081. goto L90;
  1082. }
  1083. /* Compute Eigenvectors and estimate condition numbers if desired */
  1084. /* ZTGEVC: (Complex Workspace: need 2*N ) */
  1085. /* (Real Workspace: need 2*N ) */
  1086. /* ZTGSNA: (Complex Workspace: need 2*N*N if SENSE='V' or 'B') */
  1087. /* (Integer Workspace: need N+2 ) */
  1088. if (ilv || ! wantsn) {
  1089. if (ilv) {
  1090. if (ilvl) {
  1091. if (ilvr) {
  1092. *(unsigned char *)chtemp = 'B';
  1093. } else {
  1094. *(unsigned char *)chtemp = 'L';
  1095. }
  1096. } else {
  1097. *(unsigned char *)chtemp = 'R';
  1098. }
  1099. ztgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset],
  1100. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &
  1101. work[iwrk], &rwork[1], &ierr);
  1102. if (ierr != 0) {
  1103. *info = *n + 2;
  1104. goto L90;
  1105. }
  1106. }
  1107. if (! wantsn) {
  1108. /* compute eigenvectors (DTGEVC) and estimate condition */
  1109. /* numbers (DTGSNA). Note that the definition of the condition */
  1110. /* number is not invariant under transformation (u,v) to */
  1111. /* (Q*u, Z*v), where (u,v) are eigenvectors of the generalized */
  1112. /* Schur form (S,T), Q and Z are orthogonal matrices. In order */
  1113. /* to avoid using extra 2*N*N workspace, we have to */
  1114. /* re-calculate eigenvectors and estimate the condition numbers */
  1115. /* one at a time. */
  1116. i__1 = *n;
  1117. for (i__ = 1; i__ <= i__1; ++i__) {
  1118. i__2 = *n;
  1119. for (j = 1; j <= i__2; ++j) {
  1120. bwork[j] = FALSE_;
  1121. /* L10: */
  1122. }
  1123. bwork[i__] = TRUE_;
  1124. iwrk = *n + 1;
  1125. iwrk1 = iwrk + *n;
  1126. if (wantse || wantsb) {
  1127. ztgevc_("B", "S", &bwork[1], n, &a[a_offset], lda, &b[
  1128. b_offset], ldb, &work[1], n, &work[iwrk], n, &
  1129. c__1, &m, &work[iwrk1], &rwork[1], &ierr);
  1130. if (ierr != 0) {
  1131. *info = *n + 2;
  1132. goto L90;
  1133. }
  1134. }
  1135. i__2 = *lwork - iwrk1 + 1;
  1136. ztgsna_(sense, "S", &bwork[1], n, &a[a_offset], lda, &b[
  1137. b_offset], ldb, &work[1], n, &work[iwrk], n, &rconde[
  1138. i__], &rcondv[i__], &c__1, &m, &work[iwrk1], &i__2, &
  1139. iwork[1], &ierr);
  1140. /* L20: */
  1141. }
  1142. }
  1143. }
  1144. /* Undo balancing on VL and VR and normalization */
  1145. /* (Workspace: none needed) */
  1146. if (ilvl) {
  1147. zggbak_(balanc, "L", n, ilo, ihi, &lscale[1], &rscale[1], n, &vl[
  1148. vl_offset], ldvl, &ierr);
  1149. i__1 = *n;
  1150. for (jc = 1; jc <= i__1; ++jc) {
  1151. temp = 0.;
  1152. i__2 = *n;
  1153. for (jr = 1; jr <= i__2; ++jr) {
  1154. /* Computing MAX */
  1155. i__3 = jr + jc * vl_dim1;
  1156. d__3 = temp, d__4 = (d__1 = vl[i__3].r, abs(d__1)) + (d__2 =
  1157. d_imag(&vl[jr + jc * vl_dim1]), abs(d__2));
  1158. temp = f2cmax(d__3,d__4);
  1159. /* L30: */
  1160. }
  1161. if (temp < smlnum) {
  1162. goto L50;
  1163. }
  1164. temp = 1. / temp;
  1165. i__2 = *n;
  1166. for (jr = 1; jr <= i__2; ++jr) {
  1167. i__3 = jr + jc * vl_dim1;
  1168. i__4 = jr + jc * vl_dim1;
  1169. z__1.r = temp * vl[i__4].r, z__1.i = temp * vl[i__4].i;
  1170. vl[i__3].r = z__1.r, vl[i__3].i = z__1.i;
  1171. /* L40: */
  1172. }
  1173. L50:
  1174. ;
  1175. }
  1176. }
  1177. if (ilvr) {
  1178. zggbak_(balanc, "R", n, ilo, ihi, &lscale[1], &rscale[1], n, &vr[
  1179. vr_offset], ldvr, &ierr);
  1180. i__1 = *n;
  1181. for (jc = 1; jc <= i__1; ++jc) {
  1182. temp = 0.;
  1183. i__2 = *n;
  1184. for (jr = 1; jr <= i__2; ++jr) {
  1185. /* Computing MAX */
  1186. i__3 = jr + jc * vr_dim1;
  1187. d__3 = temp, d__4 = (d__1 = vr[i__3].r, abs(d__1)) + (d__2 =
  1188. d_imag(&vr[jr + jc * vr_dim1]), abs(d__2));
  1189. temp = f2cmax(d__3,d__4);
  1190. /* L60: */
  1191. }
  1192. if (temp < smlnum) {
  1193. goto L80;
  1194. }
  1195. temp = 1. / temp;
  1196. i__2 = *n;
  1197. for (jr = 1; jr <= i__2; ++jr) {
  1198. i__3 = jr + jc * vr_dim1;
  1199. i__4 = jr + jc * vr_dim1;
  1200. z__1.r = temp * vr[i__4].r, z__1.i = temp * vr[i__4].i;
  1201. vr[i__3].r = z__1.r, vr[i__3].i = z__1.i;
  1202. /* L70: */
  1203. }
  1204. L80:
  1205. ;
  1206. }
  1207. }
  1208. /* Undo scaling if necessary */
  1209. L90:
  1210. if (ilascl) {
  1211. zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &
  1212. ierr);
  1213. }
  1214. if (ilbscl) {
  1215. zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  1216. ierr);
  1217. }
  1218. work[1].r = (doublereal) maxwrk, work[1].i = 0.;
  1219. return 0;
  1220. /* End of ZGGEVX */
  1221. } /* zggevx_ */