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.

zgegv.c 34 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #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++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #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]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. #define z_abs(z) (cabs(Cd(z)))
  229. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  230. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  231. #define myexit_() break;
  232. #define mycycle() continue;
  233. #define myceiling(w) {ceil(w)}
  234. #define myhuge(w) {HUGE_VAL}
  235. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  236. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  237. /* procedure parameter types for -A and -C++ */
  238. /* -- translated by f2c (version 20000121).
  239. You must link the resulting object file with the libraries:
  240. -lf2c -lm (in that order)
  241. */
  242. /* Table of constant values */
  243. static doublecomplex c_b1 = {0.,0.};
  244. static doublecomplex c_b2 = {1.,0.};
  245. static integer c__1 = 1;
  246. static integer c_n1 = -1;
  247. static doublereal c_b29 = 1.;
  248. /* > \brief <b> ZGEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE mat
  249. rices</b> */
  250. /* =========== DOCUMENTATION =========== */
  251. /* Online html documentation available at */
  252. /* http://www.netlib.org/lapack/explore-html/ */
  253. /* > \htmlonly */
  254. /* > Download ZGEGV + dependencies */
  255. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgegv.f
  256. "> */
  257. /* > [TGZ]</a> */
  258. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgegv.f
  259. "> */
  260. /* > [ZIP]</a> */
  261. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgegv.f
  262. "> */
  263. /* > [TXT]</a> */
  264. /* > \endhtmlonly */
  265. /* Definition: */
  266. /* =========== */
  267. /* SUBROUTINE ZGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA, BETA, */
  268. /* VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO ) */
  269. /* CHARACTER JOBVL, JOBVR */
  270. /* INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N */
  271. /* DOUBLE PRECISION RWORK( * ) */
  272. /* COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ), */
  273. /* $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ), */
  274. /* $ WORK( * ) */
  275. /* > \par Purpose: */
  276. /* ============= */
  277. /* > */
  278. /* > \verbatim */
  279. /* > */
  280. /* > This routine is deprecated and has been replaced by routine ZGGEV. */
  281. /* > */
  282. /* > ZGEGV computes the eigenvalues and, optionally, the left and/or right */
  283. /* > eigenvectors of a complex matrix pair (A,B). */
  284. /* > Given two square matrices A and B, */
  285. /* > the generalized nonsymmetric eigenvalue problem (GNEP) is to find the */
  286. /* > eigenvalues lambda and corresponding (non-zero) eigenvectors x such */
  287. /* > that */
  288. /* > A*x = lambda*B*x. */
  289. /* > */
  290. /* > An alternate form is to find the eigenvalues mu and corresponding */
  291. /* > eigenvectors y such that */
  292. /* > mu*A*y = B*y. */
  293. /* > */
  294. /* > These two forms are equivalent with mu = 1/lambda and x = y if */
  295. /* > neither lambda nor mu is zero. In order to deal with the case that */
  296. /* > lambda or mu is zero or small, two values alpha and beta are returned */
  297. /* > for each eigenvalue, such that lambda = alpha/beta and */
  298. /* > mu = beta/alpha. */
  299. /* > */
  300. /* > The vectors x and y in the above equations are right eigenvectors of */
  301. /* > the matrix pair (A,B). Vectors u and v satisfying */
  302. /* > u**H*A = lambda*u**H*B or mu*v**H*A = v**H*B */
  303. /* > are left eigenvectors of (A,B). */
  304. /* > */
  305. /* > Note: this routine performs "full balancing" on A and B */
  306. /* > \endverbatim */
  307. /* Arguments: */
  308. /* ========== */
  309. /* > \param[in] JOBVL */
  310. /* > \verbatim */
  311. /* > JOBVL is CHARACTER*1 */
  312. /* > = 'N': do not compute the left generalized eigenvectors; */
  313. /* > = 'V': compute the left generalized eigenvectors (returned */
  314. /* > in VL). */
  315. /* > \endverbatim */
  316. /* > */
  317. /* > \param[in] JOBVR */
  318. /* > \verbatim */
  319. /* > JOBVR is CHARACTER*1 */
  320. /* > = 'N': do not compute the right generalized eigenvectors; */
  321. /* > = 'V': compute the right generalized eigenvectors (returned */
  322. /* > in VR). */
  323. /* > \endverbatim */
  324. /* > */
  325. /* > \param[in] N */
  326. /* > \verbatim */
  327. /* > N is INTEGER */
  328. /* > The order of the matrices A, B, VL, and VR. N >= 0. */
  329. /* > \endverbatim */
  330. /* > */
  331. /* > \param[in,out] A */
  332. /* > \verbatim */
  333. /* > A is COMPLEX*16 array, dimension (LDA, N) */
  334. /* > On entry, the matrix A. */
  335. /* > If JOBVL = 'V' or JOBVR = 'V', then on exit A */
  336. /* > contains the Schur form of A from the generalized Schur */
  337. /* > factorization of the pair (A,B) after balancing. If no */
  338. /* > eigenvectors were computed, then only the diagonal elements */
  339. /* > of the Schur form will be correct. See ZGGHRD and ZHGEQZ */
  340. /* > for details. */
  341. /* > \endverbatim */
  342. /* > */
  343. /* > \param[in] LDA */
  344. /* > \verbatim */
  345. /* > LDA is INTEGER */
  346. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  347. /* > \endverbatim */
  348. /* > */
  349. /* > \param[in,out] B */
  350. /* > \verbatim */
  351. /* > B is COMPLEX*16 array, dimension (LDB, N) */
  352. /* > On entry, the matrix B. */
  353. /* > If JOBVL = 'V' or JOBVR = 'V', then on exit B contains the */
  354. /* > upper triangular matrix obtained from B in the generalized */
  355. /* > Schur factorization of the pair (A,B) after balancing. */
  356. /* > If no eigenvectors were computed, then only the diagonal */
  357. /* > elements of B will be correct. See ZGGHRD and ZHGEQZ for */
  358. /* > details. */
  359. /* > \endverbatim */
  360. /* > */
  361. /* > \param[in] LDB */
  362. /* > \verbatim */
  363. /* > LDB is INTEGER */
  364. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  365. /* > \endverbatim */
  366. /* > */
  367. /* > \param[out] ALPHA */
  368. /* > \verbatim */
  369. /* > ALPHA is COMPLEX*16 array, dimension (N) */
  370. /* > The complex scalars alpha that define the eigenvalues of */
  371. /* > GNEP. */
  372. /* > \endverbatim */
  373. /* > */
  374. /* > \param[out] BETA */
  375. /* > \verbatim */
  376. /* > BETA is COMPLEX*16 array, dimension (N) */
  377. /* > The complex scalars beta that define the eigenvalues of GNEP. */
  378. /* > */
  379. /* > Together, the quantities alpha = ALPHA(j) and beta = BETA(j) */
  380. /* > represent the j-th eigenvalue of the matrix pair (A,B), in */
  381. /* > one of the forms lambda = alpha/beta or mu = beta/alpha. */
  382. /* > Since either lambda or mu may overflow, they should not, */
  383. /* > in general, be computed. */
  384. /* > \endverbatim */
  385. /* > */
  386. /* > \param[out] VL */
  387. /* > \verbatim */
  388. /* > VL is COMPLEX*16 array, dimension (LDVL,N) */
  389. /* > If JOBVL = 'V', the left eigenvectors u(j) are stored */
  390. /* > in the columns of VL, in the same order as their eigenvalues. */
  391. /* > Each eigenvector is scaled so that its largest component has */
  392. /* > abs(real part) + abs(imag. part) = 1, except for eigenvectors */
  393. /* > corresponding to an eigenvalue with alpha = beta = 0, which */
  394. /* > are set to zero. */
  395. /* > Not referenced if JOBVL = 'N'. */
  396. /* > \endverbatim */
  397. /* > */
  398. /* > \param[in] LDVL */
  399. /* > \verbatim */
  400. /* > LDVL is INTEGER */
  401. /* > The leading dimension of the matrix VL. LDVL >= 1, and */
  402. /* > if JOBVL = 'V', LDVL >= N. */
  403. /* > \endverbatim */
  404. /* > */
  405. /* > \param[out] VR */
  406. /* > \verbatim */
  407. /* > VR is COMPLEX*16 array, dimension (LDVR,N) */
  408. /* > If JOBVR = 'V', the right eigenvectors x(j) are stored */
  409. /* > in the columns of VR, in the same order as their eigenvalues. */
  410. /* > Each eigenvector is scaled so that its largest component has */
  411. /* > abs(real part) + abs(imag. part) = 1, except for eigenvectors */
  412. /* > corresponding to an eigenvalue with alpha = beta = 0, which */
  413. /* > are set to zero. */
  414. /* > Not referenced if JOBVR = 'N'. */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[in] LDVR */
  418. /* > \verbatim */
  419. /* > LDVR is INTEGER */
  420. /* > The leading dimension of the matrix VR. LDVR >= 1, and */
  421. /* > if JOBVR = 'V', LDVR >= N. */
  422. /* > \endverbatim */
  423. /* > */
  424. /* > \param[out] WORK */
  425. /* > \verbatim */
  426. /* > WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) */
  427. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  428. /* > \endverbatim */
  429. /* > */
  430. /* > \param[in] LWORK */
  431. /* > \verbatim */
  432. /* > LWORK is INTEGER */
  433. /* > The dimension of the array WORK. LWORK >= f2cmax(1,2*N). */
  434. /* > For good performance, LWORK must generally be larger. */
  435. /* > To compute the optimal value of LWORK, call ILAENV to get */
  436. /* > blocksizes (for ZGEQRF, ZUNMQR, and ZUNGQR.) Then compute: */
  437. /* > NB -- MAX of the blocksizes for ZGEQRF, ZUNMQR, and ZUNGQR; */
  438. /* > The optimal LWORK is MAX( 2*N, N*(NB+1) ). */
  439. /* > */
  440. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  441. /* > only calculates the optimal size of the WORK array, returns */
  442. /* > this value as the first entry of the WORK array, and no error */
  443. /* > message related to LWORK is issued by XERBLA. */
  444. /* > \endverbatim */
  445. /* > */
  446. /* > \param[out] RWORK */
  447. /* > \verbatim */
  448. /* > RWORK is DOUBLE PRECISION array, dimension (8*N) */
  449. /* > \endverbatim */
  450. /* > */
  451. /* > \param[out] INFO */
  452. /* > \verbatim */
  453. /* > INFO is INTEGER */
  454. /* > = 0: successful exit */
  455. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  456. /* > =1,...,N: */
  457. /* > The QZ iteration failed. No eigenvectors have been */
  458. /* > calculated, but ALPHA(j) and BETA(j) should be */
  459. /* > correct for j=INFO+1,...,N. */
  460. /* > > N: errors that usually indicate LAPACK problems: */
  461. /* > =N+1: error return from ZGGBAL */
  462. /* > =N+2: error return from ZGEQRF */
  463. /* > =N+3: error return from ZUNMQR */
  464. /* > =N+4: error return from ZUNGQR */
  465. /* > =N+5: error return from ZGGHRD */
  466. /* > =N+6: error return from ZHGEQZ (other than failed */
  467. /* > iteration) */
  468. /* > =N+7: error return from ZTGEVC */
  469. /* > =N+8: error return from ZGGBAK (computing VL) */
  470. /* > =N+9: error return from ZGGBAK (computing VR) */
  471. /* > =N+10: error return from ZLASCL (various calls) */
  472. /* > \endverbatim */
  473. /* Authors: */
  474. /* ======== */
  475. /* > \author Univ. of Tennessee */
  476. /* > \author Univ. of California Berkeley */
  477. /* > \author Univ. of Colorado Denver */
  478. /* > \author NAG Ltd. */
  479. /* > \date December 2016 */
  480. /* > \ingroup complex16GEeigen */
  481. /* > \par Further Details: */
  482. /* ===================== */
  483. /* > */
  484. /* > \verbatim */
  485. /* > */
  486. /* > Balancing */
  487. /* > --------- */
  488. /* > */
  489. /* > This driver calls ZGGBAL to both permute and scale rows and columns */
  490. /* > of A and B. The permutations PL and PR are chosen so that PL*A*PR */
  491. /* > and PL*B*R will be upper triangular except for the diagonal blocks */
  492. /* > A(i:j,i:j) and B(i:j,i:j), with i and j as close together as */
  493. /* > possible. The diagonal scaling matrices DL and DR are chosen so */
  494. /* > that the pair DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to */
  495. /* > one (except for the elements that start out zero.) */
  496. /* > */
  497. /* > After the eigenvalues and eigenvectors of the balanced matrices */
  498. /* > have been computed, ZGGBAK transforms the eigenvectors back to what */
  499. /* > they would have been (in perfect arithmetic) if they had not been */
  500. /* > balanced. */
  501. /* > */
  502. /* > Contents of A and B on Exit */
  503. /* > -------- -- - --- - -- ---- */
  504. /* > */
  505. /* > If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or */
  506. /* > both), then on exit the arrays A and B will contain the complex Schur */
  507. /* > form[*] of the "balanced" versions of A and B. If no eigenvectors */
  508. /* > are computed, then only the diagonal blocks will be correct. */
  509. /* > */
  510. /* > [*] In other words, upper triangular form. */
  511. /* > \endverbatim */
  512. /* > */
  513. /* ===================================================================== */
  514. /* Subroutine */ void zgegv_(char *jobvl, char *jobvr, integer *n,
  515. doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
  516. doublecomplex *alpha, doublecomplex *beta, doublecomplex *vl, integer
  517. *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work, integer
  518. *lwork, doublereal *rwork, integer *info)
  519. {
  520. /* System generated locals */
  521. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  522. vr_offset, i__1, i__2, i__3, i__4;
  523. doublereal d__1, d__2, d__3, d__4;
  524. doublecomplex z__1, z__2;
  525. /* Local variables */
  526. doublereal absb, anrm, bnrm;
  527. integer itau;
  528. doublereal temp;
  529. logical ilvl, ilvr;
  530. integer lopt;
  531. doublereal anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
  532. extern logical lsame_(char *, char *);
  533. integer ileft, iinfo, icols, iwork, irows, jc, nb, in;
  534. extern doublereal dlamch_(char *);
  535. integer jr;
  536. doublereal salfai;
  537. extern /* Subroutine */ void zggbak_(char *, char *, integer *, integer *,
  538. integer *, doublereal *, doublereal *, integer *, doublecomplex *,
  539. integer *, integer *), zggbal_(char *, integer *,
  540. doublecomplex *, integer *, doublecomplex *, integer *, integer *
  541. , integer *, doublereal *, doublereal *, doublereal *, integer *);
  542. doublereal salfar, safmin;
  543. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  544. doublereal safmax;
  545. char chtemp[1];
  546. logical ldumma[1];
  547. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  548. integer *, integer *, ftnlen, ftnlen);
  549. extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
  550. integer *, doublereal *);
  551. integer ijobvl, iright;
  552. logical ilimit;
  553. extern /* Subroutine */ void zgghrd_(char *, char *, integer *, integer *,
  554. integer *, doublecomplex *, integer *, doublecomplex *, integer *,
  555. doublecomplex *, integer *, doublecomplex *, integer *, integer *
  556. ), zlascl_(char *, integer *, integer *,
  557. doublereal *, doublereal *, integer *, integer *, doublecomplex *,
  558. integer *, integer *);
  559. integer ijobvr;
  560. extern /* Subroutine */ void zgeqrf_(integer *, integer *, doublecomplex *,
  561. integer *, doublecomplex *, doublecomplex *, integer *, integer *
  562. );
  563. integer lwkmin, nb1, nb2, nb3;
  564. extern /* Subroutine */ void zlacpy_(char *, integer *, integer *,
  565. doublecomplex *, integer *, doublecomplex *, integer *),
  566. zlaset_(char *, integer *, integer *, doublecomplex *,
  567. doublecomplex *, doublecomplex *, integer *), ztgevc_(
  568. char *, char *, logical *, integer *, doublecomplex *, integer *,
  569. doublecomplex *, integer *, doublecomplex *, integer *,
  570. doublecomplex *, integer *, integer *, integer *, doublecomplex *,
  571. doublereal *, integer *), zhgeqz_(char *, char *,
  572. char *, integer *, integer *, integer *, doublecomplex *,
  573. integer *, doublecomplex *, integer *, doublecomplex *,
  574. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  575. integer *, doublecomplex *, integer *, doublereal *, integer *);
  576. integer irwork, lwkopt;
  577. logical lquery;
  578. extern /* Subroutine */ void zungqr_(integer *, integer *, integer *,
  579. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  580. integer *, integer *), zunmqr_(char *, char *, integer *, integer
  581. *, integer *, doublecomplex *, integer *, doublecomplex *,
  582. doublecomplex *, integer *, doublecomplex *, integer *, integer *);
  583. integer ihi, ilo;
  584. doublereal eps;
  585. logical ilv;
  586. /* -- LAPACK driver routine (version 3.7.0) -- */
  587. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  588. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  589. /* December 2016 */
  590. /* ===================================================================== */
  591. /* Decode the input arguments */
  592. /* Parameter adjustments */
  593. a_dim1 = *lda;
  594. a_offset = 1 + a_dim1 * 1;
  595. a -= a_offset;
  596. b_dim1 = *ldb;
  597. b_offset = 1 + b_dim1 * 1;
  598. b -= b_offset;
  599. --alpha;
  600. --beta;
  601. vl_dim1 = *ldvl;
  602. vl_offset = 1 + vl_dim1 * 1;
  603. vl -= vl_offset;
  604. vr_dim1 = *ldvr;
  605. vr_offset = 1 + vr_dim1 * 1;
  606. vr -= vr_offset;
  607. --work;
  608. --rwork;
  609. /* Function Body */
  610. if (lsame_(jobvl, "N")) {
  611. ijobvl = 1;
  612. ilvl = FALSE_;
  613. } else if (lsame_(jobvl, "V")) {
  614. ijobvl = 2;
  615. ilvl = TRUE_;
  616. } else {
  617. ijobvl = -1;
  618. ilvl = FALSE_;
  619. }
  620. if (lsame_(jobvr, "N")) {
  621. ijobvr = 1;
  622. ilvr = FALSE_;
  623. } else if (lsame_(jobvr, "V")) {
  624. ijobvr = 2;
  625. ilvr = TRUE_;
  626. } else {
  627. ijobvr = -1;
  628. ilvr = FALSE_;
  629. }
  630. ilv = ilvl || ilvr;
  631. /* Test the input arguments */
  632. /* Computing MAX */
  633. i__1 = *n << 1;
  634. lwkmin = f2cmax(i__1,1);
  635. lwkopt = lwkmin;
  636. work[1].r = (doublereal) lwkopt, work[1].i = 0.;
  637. lquery = *lwork == -1;
  638. *info = 0;
  639. if (ijobvl <= 0) {
  640. *info = -1;
  641. } else if (ijobvr <= 0) {
  642. *info = -2;
  643. } else if (*n < 0) {
  644. *info = -3;
  645. } else if (*lda < f2cmax(1,*n)) {
  646. *info = -5;
  647. } else if (*ldb < f2cmax(1,*n)) {
  648. *info = -7;
  649. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  650. *info = -11;
  651. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  652. *info = -13;
  653. } else if (*lwork < lwkmin && ! lquery) {
  654. *info = -15;
  655. }
  656. if (*info == 0) {
  657. nb1 = ilaenv_(&c__1, "ZGEQRF", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
  658. ftnlen)1);
  659. nb2 = ilaenv_(&c__1, "ZUNMQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  660. ftnlen)1);
  661. nb3 = ilaenv_(&c__1, "ZUNGQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  662. ftnlen)1);
  663. /* Computing MAX */
  664. i__1 = f2cmax(nb1,nb2);
  665. nb = f2cmax(i__1,nb3);
  666. /* Computing MAX */
  667. i__1 = *n << 1, i__2 = *n * (nb + 1);
  668. lopt = f2cmax(i__1,i__2);
  669. work[1].r = (doublereal) lopt, work[1].i = 0.;
  670. }
  671. if (*info != 0) {
  672. i__1 = -(*info);
  673. xerbla_("ZGEGV ", &i__1, 6);
  674. return;
  675. } else if (lquery) {
  676. return;
  677. }
  678. /* Quick return if possible */
  679. if (*n == 0) {
  680. return;
  681. }
  682. /* Get machine constants */
  683. eps = dlamch_("E") * dlamch_("B");
  684. safmin = dlamch_("S");
  685. safmin += safmin;
  686. safmax = 1. / safmin;
  687. /* Scale A */
  688. anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]);
  689. anrm1 = anrm;
  690. anrm2 = 1.;
  691. if (anrm < 1.) {
  692. if (safmax * anrm < 1.) {
  693. anrm1 = safmin;
  694. anrm2 = safmax * anrm;
  695. }
  696. }
  697. if (anrm > 0.) {
  698. zlascl_("G", &c_n1, &c_n1, &anrm, &c_b29, n, n, &a[a_offset], lda, &
  699. iinfo);
  700. if (iinfo != 0) {
  701. *info = *n + 10;
  702. return;
  703. }
  704. }
  705. /* Scale B */
  706. bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
  707. bnrm1 = bnrm;
  708. bnrm2 = 1.;
  709. if (bnrm < 1.) {
  710. if (safmax * bnrm < 1.) {
  711. bnrm1 = safmin;
  712. bnrm2 = safmax * bnrm;
  713. }
  714. }
  715. if (bnrm > 0.) {
  716. zlascl_("G", &c_n1, &c_n1, &bnrm, &c_b29, n, n, &b[b_offset], ldb, &
  717. iinfo);
  718. if (iinfo != 0) {
  719. *info = *n + 10;
  720. return;
  721. }
  722. }
  723. /* Permute the matrix to make it more nearly triangular */
  724. /* Also "balance" the matrix. */
  725. ileft = 1;
  726. iright = *n + 1;
  727. irwork = iright + *n;
  728. zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
  729. ileft], &rwork[iright], &rwork[irwork], &iinfo);
  730. if (iinfo != 0) {
  731. *info = *n + 1;
  732. goto L80;
  733. }
  734. /* Reduce B to triangular form, and initialize VL and/or VR */
  735. irows = ihi + 1 - ilo;
  736. if (ilv) {
  737. icols = *n + 1 - ilo;
  738. } else {
  739. icols = irows;
  740. }
  741. itau = 1;
  742. iwork = itau + irows;
  743. i__1 = *lwork + 1 - iwork;
  744. zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  745. iwork], &i__1, &iinfo);
  746. if (iinfo >= 0) {
  747. /* Computing MAX */
  748. i__3 = iwork;
  749. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  750. lwkopt = f2cmax(i__1,i__2);
  751. }
  752. if (iinfo != 0) {
  753. *info = *n + 2;
  754. goto L80;
  755. }
  756. i__1 = *lwork + 1 - iwork;
  757. zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  758. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  759. iinfo);
  760. if (iinfo >= 0) {
  761. /* Computing MAX */
  762. i__3 = iwork;
  763. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  764. lwkopt = f2cmax(i__1,i__2);
  765. }
  766. if (iinfo != 0) {
  767. *info = *n + 3;
  768. goto L80;
  769. }
  770. if (ilvl) {
  771. zlaset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl);
  772. i__1 = irows - 1;
  773. i__2 = irows - 1;
  774. zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo +
  775. 1 + ilo * vl_dim1], ldvl);
  776. i__1 = *lwork + 1 - iwork;
  777. zungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
  778. itau], &work[iwork], &i__1, &iinfo);
  779. if (iinfo >= 0) {
  780. /* Computing MAX */
  781. i__3 = iwork;
  782. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  783. lwkopt = f2cmax(i__1,i__2);
  784. }
  785. if (iinfo != 0) {
  786. *info = *n + 4;
  787. goto L80;
  788. }
  789. }
  790. if (ilvr) {
  791. zlaset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr);
  792. }
  793. /* Reduce to generalized Hessenberg form */
  794. if (ilv) {
  795. /* Eigenvectors requested -- work on whole matrix. */
  796. zgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  797. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo);
  798. } else {
  799. zgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
  800. &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  801. vr_offset], ldvr, &iinfo);
  802. }
  803. if (iinfo != 0) {
  804. *info = *n + 5;
  805. goto L80;
  806. }
  807. /* Perform QZ algorithm */
  808. iwork = itau;
  809. if (ilv) {
  810. *(unsigned char *)chtemp = 'S';
  811. } else {
  812. *(unsigned char *)chtemp = 'E';
  813. }
  814. i__1 = *lwork + 1 - iwork;
  815. zhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  816. b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[
  817. vr_offset], ldvr, &work[iwork], &i__1, &rwork[irwork], &iinfo);
  818. if (iinfo >= 0) {
  819. /* Computing MAX */
  820. i__3 = iwork;
  821. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  822. lwkopt = f2cmax(i__1,i__2);
  823. }
  824. if (iinfo != 0) {
  825. if (iinfo > 0 && iinfo <= *n) {
  826. *info = iinfo;
  827. } else if (iinfo > *n && iinfo <= *n << 1) {
  828. *info = iinfo - *n;
  829. } else {
  830. *info = *n + 6;
  831. }
  832. goto L80;
  833. }
  834. if (ilv) {
  835. /* Compute Eigenvectors */
  836. if (ilvl) {
  837. if (ilvr) {
  838. *(unsigned char *)chtemp = 'B';
  839. } else {
  840. *(unsigned char *)chtemp = 'L';
  841. }
  842. } else {
  843. *(unsigned char *)chtemp = 'R';
  844. }
  845. ztgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
  846. &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
  847. iwork], &rwork[irwork], &iinfo);
  848. if (iinfo != 0) {
  849. *info = *n + 7;
  850. goto L80;
  851. }
  852. /* Undo balancing on VL and VR, rescale */
  853. if (ilvl) {
  854. zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
  855. &vl[vl_offset], ldvl, &iinfo);
  856. if (iinfo != 0) {
  857. *info = *n + 8;
  858. goto L80;
  859. }
  860. i__1 = *n;
  861. for (jc = 1; jc <= i__1; ++jc) {
  862. temp = 0.;
  863. i__2 = *n;
  864. for (jr = 1; jr <= i__2; ++jr) {
  865. /* Computing MAX */
  866. i__3 = jr + jc * vl_dim1;
  867. d__3 = temp, d__4 = (d__1 = vl[i__3].r, abs(d__1)) + (
  868. d__2 = d_imag(&vl[jr + jc * vl_dim1]), abs(d__2));
  869. temp = f2cmax(d__3,d__4);
  870. /* L10: */
  871. }
  872. if (temp < safmin) {
  873. goto L30;
  874. }
  875. temp = 1. / temp;
  876. i__2 = *n;
  877. for (jr = 1; jr <= i__2; ++jr) {
  878. i__3 = jr + jc * vl_dim1;
  879. i__4 = jr + jc * vl_dim1;
  880. z__1.r = temp * vl[i__4].r, z__1.i = temp * vl[i__4].i;
  881. vl[i__3].r = z__1.r, vl[i__3].i = z__1.i;
  882. /* L20: */
  883. }
  884. L30:
  885. ;
  886. }
  887. }
  888. if (ilvr) {
  889. zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
  890. &vr[vr_offset], ldvr, &iinfo);
  891. if (iinfo != 0) {
  892. *info = *n + 9;
  893. goto L80;
  894. }
  895. i__1 = *n;
  896. for (jc = 1; jc <= i__1; ++jc) {
  897. temp = 0.;
  898. i__2 = *n;
  899. for (jr = 1; jr <= i__2; ++jr) {
  900. /* Computing MAX */
  901. i__3 = jr + jc * vr_dim1;
  902. d__3 = temp, d__4 = (d__1 = vr[i__3].r, abs(d__1)) + (
  903. d__2 = d_imag(&vr[jr + jc * vr_dim1]), abs(d__2));
  904. temp = f2cmax(d__3,d__4);
  905. /* L40: */
  906. }
  907. if (temp < safmin) {
  908. goto L60;
  909. }
  910. temp = 1. / temp;
  911. i__2 = *n;
  912. for (jr = 1; jr <= i__2; ++jr) {
  913. i__3 = jr + jc * vr_dim1;
  914. i__4 = jr + jc * vr_dim1;
  915. z__1.r = temp * vr[i__4].r, z__1.i = temp * vr[i__4].i;
  916. vr[i__3].r = z__1.r, vr[i__3].i = z__1.i;
  917. /* L50: */
  918. }
  919. L60:
  920. ;
  921. }
  922. }
  923. /* End of eigenvector calculation */
  924. }
  925. /* Undo scaling in alpha, beta */
  926. /* Note: this does not give the alpha and beta for the unscaled */
  927. /* problem. */
  928. /* Un-scaling is limited to avoid underflow in alpha and beta */
  929. /* if they are significant. */
  930. i__1 = *n;
  931. for (jc = 1; jc <= i__1; ++jc) {
  932. i__2 = jc;
  933. absar = (d__1 = alpha[i__2].r, abs(d__1));
  934. absai = (d__1 = d_imag(&alpha[jc]), abs(d__1));
  935. i__2 = jc;
  936. absb = (d__1 = beta[i__2].r, abs(d__1));
  937. i__2 = jc;
  938. salfar = anrm * alpha[i__2].r;
  939. salfai = anrm * d_imag(&alpha[jc]);
  940. i__2 = jc;
  941. sbeta = bnrm * beta[i__2].r;
  942. ilimit = FALSE_;
  943. scale = 1.;
  944. /* Check for significant underflow in imaginary part of ALPHA */
  945. /* Computing MAX */
  946. d__1 = safmin, d__2 = eps * absar, d__1 = f2cmax(d__1,d__2), d__2 = eps *
  947. absb;
  948. if (abs(salfai) < safmin && absai >= f2cmax(d__1,d__2)) {
  949. ilimit = TRUE_;
  950. /* Computing MAX */
  951. d__1 = safmin, d__2 = anrm2 * absai;
  952. scale = safmin / anrm1 / f2cmax(d__1,d__2);
  953. }
  954. /* Check for significant underflow in real part of ALPHA */
  955. /* Computing MAX */
  956. d__1 = safmin, d__2 = eps * absai, d__1 = f2cmax(d__1,d__2), d__2 = eps *
  957. absb;
  958. if (abs(salfar) < safmin && absar >= f2cmax(d__1,d__2)) {
  959. ilimit = TRUE_;
  960. /* Computing MAX */
  961. /* Computing MAX */
  962. d__3 = safmin, d__4 = anrm2 * absar;
  963. d__1 = scale, d__2 = safmin / anrm1 / f2cmax(d__3,d__4);
  964. scale = f2cmax(d__1,d__2);
  965. }
  966. /* Check for significant underflow in BETA */
  967. /* Computing MAX */
  968. d__1 = safmin, d__2 = eps * absar, d__1 = f2cmax(d__1,d__2), d__2 = eps *
  969. absai;
  970. if (abs(sbeta) < safmin && absb >= f2cmax(d__1,d__2)) {
  971. ilimit = TRUE_;
  972. /* Computing MAX */
  973. /* Computing MAX */
  974. d__3 = safmin, d__4 = bnrm2 * absb;
  975. d__1 = scale, d__2 = safmin / bnrm1 / f2cmax(d__3,d__4);
  976. scale = f2cmax(d__1,d__2);
  977. }
  978. /* Check for possible overflow when limiting scaling */
  979. if (ilimit) {
  980. /* Computing MAX */
  981. d__1 = abs(salfar), d__2 = abs(salfai), d__1 = f2cmax(d__1,d__2),
  982. d__2 = abs(sbeta);
  983. temp = scale * safmin * f2cmax(d__1,d__2);
  984. if (temp > 1.) {
  985. scale /= temp;
  986. }
  987. if (scale < 1.) {
  988. ilimit = FALSE_;
  989. }
  990. }
  991. /* Recompute un-scaled ALPHA, BETA if necessary. */
  992. if (ilimit) {
  993. i__2 = jc;
  994. salfar = scale * alpha[i__2].r * anrm;
  995. salfai = scale * d_imag(&alpha[jc]) * anrm;
  996. i__2 = jc;
  997. z__2.r = scale * beta[i__2].r, z__2.i = scale * beta[i__2].i;
  998. z__1.r = bnrm * z__2.r, z__1.i = bnrm * z__2.i;
  999. sbeta = z__1.r;
  1000. }
  1001. i__2 = jc;
  1002. z__1.r = salfar, z__1.i = salfai;
  1003. alpha[i__2].r = z__1.r, alpha[i__2].i = z__1.i;
  1004. i__2 = jc;
  1005. beta[i__2].r = sbeta, beta[i__2].i = 0.;
  1006. /* L70: */
  1007. }
  1008. L80:
  1009. work[1].r = (doublereal) lwkopt, work[1].i = 0.;
  1010. return;
  1011. /* End of ZGEGV */
  1012. } /* zgegv_ */