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