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.

cgegv.c 34 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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 complex c_b1 = {0.f,0.f};
  244. static complex c_b2 = {1.f,0.f};
  245. static integer c__1 = 1;
  246. static integer c_n1 = -1;
  247. static real c_b29 = 1.f;
  248. /* > \brief <b> CGEEVX 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 CGEGV + dependencies */
  255. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgegv.f
  256. "> */
  257. /* > [TGZ]</a> */
  258. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgegv.f
  259. "> */
  260. /* > [ZIP]</a> */
  261. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgegv.f
  262. "> */
  263. /* > [TXT]</a> */
  264. /* > \endhtmlonly */
  265. /* Definition: */
  266. /* =========== */
  267. /* SUBROUTINE CGEGV( 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. /* REAL RWORK( * ) */
  272. /* COMPLEX 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 CGGEV. */
  281. /* > */
  282. /* > CGEGV 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 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 CGGHRD and CHGEQZ */
  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 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 CGGHRD and CHGEQZ 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 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 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 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 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 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 CGEQRF, CUNMQR, and CUNGQR.) Then compute: */
  437. /* > NB -- MAX of the blocksizes for CGEQRF, CUNMQR, and CUNGQR; */
  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 REAL 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 CGGBAL */
  462. /* > =N+2: error return from CGEQRF */
  463. /* > =N+3: error return from CUNMQR */
  464. /* > =N+4: error return from CUNGQR */
  465. /* > =N+5: error return from CGGHRD */
  466. /* > =N+6: error return from CHGEQZ (other than failed */
  467. /* > iteration) */
  468. /* > =N+7: error return from CTGEVC */
  469. /* > =N+8: error return from CGGBAK (computing VL) */
  470. /* > =N+9: error return from CGGBAK (computing VR) */
  471. /* > =N+10: error return from CLASCL (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 complexGEeigen */
  481. /* > \par Further Details: */
  482. /* ===================== */
  483. /* > */
  484. /* > \verbatim */
  485. /* > */
  486. /* > Balancing */
  487. /* > --------- */
  488. /* > */
  489. /* > This driver calls CGGBAL 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, CGGBAK 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 cgegv_(char *jobvl, char *jobvr, integer *n, complex *a,
  515. integer *lda, complex *b, integer *ldb, complex *alpha, complex *beta,
  516. complex *vl, integer *ldvl, complex *vr, integer *ldvr, complex *
  517. work, integer *lwork, real *rwork, integer *info)
  518. {
  519. /* System generated locals */
  520. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  521. vr_offset, i__1, i__2, i__3, i__4;
  522. real r__1, r__2, r__3, r__4;
  523. complex q__1, q__2;
  524. /* Local variables */
  525. real absb, anrm, bnrm;
  526. integer itau;
  527. real temp;
  528. logical ilvl, ilvr;
  529. integer lopt;
  530. real anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
  531. extern logical lsame_(char *, char *);
  532. integer ileft, iinfo, icols, iwork, irows, jc;
  533. extern /* Subroutine */ void cggbak_(char *, char *, integer *, integer *,
  534. integer *, real *, real *, integer *, complex *, integer *,
  535. integer *), cggbal_(char *, integer *, complex *,
  536. integer *, complex *, integer *, integer *, integer *, real *,
  537. real *, real *, integer *);
  538. integer nb, in;
  539. extern real clange_(char *, integer *, integer *, complex *, integer *,
  540. real *);
  541. integer jr;
  542. extern /* Subroutine */ void cgghrd_(char *, char *, integer *, integer *,
  543. integer *, complex *, integer *, complex *, integer *, complex *,
  544. integer *, complex *, integer *, integer *);
  545. real salfai;
  546. extern /* Subroutine */ void clascl_(char *, integer *, integer *, real *,
  547. real *, integer *, integer *, complex *, integer *, integer *), cgeqrf_(integer *, integer *, complex *, integer *,
  548. complex *, complex *, integer *, integer *);
  549. real salfar;
  550. extern real slamch_(char *);
  551. extern /* Subroutine */ void clacpy_(char *, integer *, integer *, complex
  552. *, integer *, complex *, integer *), claset_(char *,
  553. integer *, integer *, complex *, complex *, complex *, integer *);
  554. real safmin;
  555. extern /* Subroutine */ void ctgevc_(char *, char *, logical *, integer *,
  556. complex *, integer *, complex *, integer *, complex *, integer *,
  557. complex *, integer *, integer *, integer *, complex *, real *,
  558. integer *);
  559. real safmax;
  560. char chtemp[1];
  561. logical ldumma[1];
  562. extern /* Subroutine */ void chgeqz_(char *, char *, char *, integer *,
  563. integer *, integer *, complex *, integer *, complex *, integer *,
  564. complex *, complex *, complex *, integer *, complex *, integer *,
  565. complex *, integer *, real *, integer *);
  566. extern int xerbla_(char *, integer *, ftnlen);
  567. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  568. integer *, integer *, ftnlen, ftnlen);
  569. integer ijobvl, iright;
  570. logical ilimit;
  571. integer ijobvr;
  572. extern /* Subroutine */ void cungqr_(integer *, integer *, integer *,
  573. complex *, integer *, complex *, complex *, integer *, integer *);
  574. integer lwkmin, nb1, nb2, nb3;
  575. extern /* Subroutine */ void cunmqr_(char *, char *, integer *, integer *,
  576. integer *, complex *, integer *, complex *, complex *, integer *,
  577. complex *, integer *, integer *);
  578. integer irwork, lwkopt;
  579. logical lquery;
  580. integer ihi, ilo;
  581. real eps;
  582. logical ilv;
  583. /* -- LAPACK driver routine (version 3.7.0) -- */
  584. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  585. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  586. /* December 2016 */
  587. /* ===================================================================== */
  588. /* Decode the input arguments */
  589. /* Parameter adjustments */
  590. a_dim1 = *lda;
  591. a_offset = 1 + a_dim1 * 1;
  592. a -= a_offset;
  593. b_dim1 = *ldb;
  594. b_offset = 1 + b_dim1 * 1;
  595. b -= b_offset;
  596. --alpha;
  597. --beta;
  598. vl_dim1 = *ldvl;
  599. vl_offset = 1 + vl_dim1 * 1;
  600. vl -= vl_offset;
  601. vr_dim1 = *ldvr;
  602. vr_offset = 1 + vr_dim1 * 1;
  603. vr -= vr_offset;
  604. --work;
  605. --rwork;
  606. /* Function Body */
  607. if (lsame_(jobvl, "N")) {
  608. ijobvl = 1;
  609. ilvl = FALSE_;
  610. } else if (lsame_(jobvl, "V")) {
  611. ijobvl = 2;
  612. ilvl = TRUE_;
  613. } else {
  614. ijobvl = -1;
  615. ilvl = FALSE_;
  616. }
  617. if (lsame_(jobvr, "N")) {
  618. ijobvr = 1;
  619. ilvr = FALSE_;
  620. } else if (lsame_(jobvr, "V")) {
  621. ijobvr = 2;
  622. ilvr = TRUE_;
  623. } else {
  624. ijobvr = -1;
  625. ilvr = FALSE_;
  626. }
  627. ilv = ilvl || ilvr;
  628. /* Test the input arguments */
  629. /* Computing MAX */
  630. i__1 = *n << 1;
  631. lwkmin = f2cmax(i__1,1);
  632. lwkopt = lwkmin;
  633. work[1].r = (real) lwkopt, work[1].i = 0.f;
  634. lquery = *lwork == -1;
  635. *info = 0;
  636. if (ijobvl <= 0) {
  637. *info = -1;
  638. } else if (ijobvr <= 0) {
  639. *info = -2;
  640. } else if (*n < 0) {
  641. *info = -3;
  642. } else if (*lda < f2cmax(1,*n)) {
  643. *info = -5;
  644. } else if (*ldb < f2cmax(1,*n)) {
  645. *info = -7;
  646. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  647. *info = -11;
  648. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  649. *info = -13;
  650. } else if (*lwork < lwkmin && ! lquery) {
  651. *info = -15;
  652. }
  653. if (*info == 0) {
  654. nb1 = ilaenv_(&c__1, "CGEQRF", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
  655. ftnlen)1);
  656. nb2 = ilaenv_(&c__1, "CUNMQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  657. ftnlen)1);
  658. nb3 = ilaenv_(&c__1, "CUNGQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  659. ftnlen)1);
  660. /* Computing MAX */
  661. i__1 = f2cmax(nb1,nb2);
  662. nb = f2cmax(i__1,nb3);
  663. /* Computing MAX */
  664. i__1 = *n << 1, i__2 = *n * (nb + 1);
  665. lopt = f2cmax(i__1,i__2);
  666. work[1].r = (real) lopt, work[1].i = 0.f;
  667. }
  668. if (*info != 0) {
  669. i__1 = -(*info);
  670. xerbla_("CGEGV ", &i__1, 6);
  671. return;
  672. } else if (lquery) {
  673. return;
  674. }
  675. /* Quick return if possible */
  676. if (*n == 0) {
  677. return;
  678. }
  679. /* Get machine constants */
  680. eps = slamch_("E") * slamch_("B");
  681. safmin = slamch_("S");
  682. safmin += safmin;
  683. safmax = 1.f / safmin;
  684. /* Scale A */
  685. anrm = clange_("M", n, n, &a[a_offset], lda, &rwork[1]);
  686. anrm1 = anrm;
  687. anrm2 = 1.f;
  688. if (anrm < 1.f) {
  689. if (safmax * anrm < 1.f) {
  690. anrm1 = safmin;
  691. anrm2 = safmax * anrm;
  692. }
  693. }
  694. if (anrm > 0.f) {
  695. clascl_("G", &c_n1, &c_n1, &anrm, &c_b29, n, n, &a[a_offset], lda, &
  696. iinfo);
  697. if (iinfo != 0) {
  698. *info = *n + 10;
  699. return;
  700. }
  701. }
  702. /* Scale B */
  703. bnrm = clange_("M", n, n, &b[b_offset], ldb, &rwork[1]);
  704. bnrm1 = bnrm;
  705. bnrm2 = 1.f;
  706. if (bnrm < 1.f) {
  707. if (safmax * bnrm < 1.f) {
  708. bnrm1 = safmin;
  709. bnrm2 = safmax * bnrm;
  710. }
  711. }
  712. if (bnrm > 0.f) {
  713. clascl_("G", &c_n1, &c_n1, &bnrm, &c_b29, n, n, &b[b_offset], ldb, &
  714. iinfo);
  715. if (iinfo != 0) {
  716. *info = *n + 10;
  717. return;
  718. }
  719. }
  720. /* Permute the matrix to make it more nearly triangular */
  721. /* Also "balance" the matrix. */
  722. ileft = 1;
  723. iright = *n + 1;
  724. irwork = iright + *n;
  725. cggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[
  726. ileft], &rwork[iright], &rwork[irwork], &iinfo);
  727. if (iinfo != 0) {
  728. *info = *n + 1;
  729. goto L80;
  730. }
  731. /* Reduce B to triangular form, and initialize VL and/or VR */
  732. irows = ihi + 1 - ilo;
  733. if (ilv) {
  734. icols = *n + 1 - ilo;
  735. } else {
  736. icols = irows;
  737. }
  738. itau = 1;
  739. iwork = itau + irows;
  740. i__1 = *lwork + 1 - iwork;
  741. cgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  742. iwork], &i__1, &iinfo);
  743. if (iinfo >= 0) {
  744. /* Computing MAX */
  745. i__3 = iwork;
  746. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  747. lwkopt = f2cmax(i__1,i__2);
  748. }
  749. if (iinfo != 0) {
  750. *info = *n + 2;
  751. goto L80;
  752. }
  753. i__1 = *lwork + 1 - iwork;
  754. cunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  755. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  756. iinfo);
  757. if (iinfo >= 0) {
  758. /* Computing MAX */
  759. i__3 = iwork;
  760. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  761. lwkopt = f2cmax(i__1,i__2);
  762. }
  763. if (iinfo != 0) {
  764. *info = *n + 3;
  765. goto L80;
  766. }
  767. if (ilvl) {
  768. claset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl);
  769. i__1 = irows - 1;
  770. i__2 = irows - 1;
  771. clacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo +
  772. 1 + ilo * vl_dim1], ldvl);
  773. i__1 = *lwork + 1 - iwork;
  774. cungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
  775. itau], &work[iwork], &i__1, &iinfo);
  776. if (iinfo >= 0) {
  777. /* Computing MAX */
  778. i__3 = iwork;
  779. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  780. lwkopt = f2cmax(i__1,i__2);
  781. }
  782. if (iinfo != 0) {
  783. *info = *n + 4;
  784. goto L80;
  785. }
  786. }
  787. if (ilvr) {
  788. claset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr);
  789. }
  790. /* Reduce to generalized Hessenberg form */
  791. if (ilv) {
  792. /* Eigenvectors requested -- work on whole matrix. */
  793. cgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  794. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo);
  795. } else {
  796. cgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
  797. &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  798. vr_offset], ldvr, &iinfo);
  799. }
  800. if (iinfo != 0) {
  801. *info = *n + 5;
  802. goto L80;
  803. }
  804. /* Perform QZ algorithm */
  805. iwork = itau;
  806. if (ilv) {
  807. *(unsigned char *)chtemp = 'S';
  808. } else {
  809. *(unsigned char *)chtemp = 'E';
  810. }
  811. i__1 = *lwork + 1 - iwork;
  812. chgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  813. b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[
  814. vr_offset], ldvr, &work[iwork], &i__1, &rwork[irwork], &iinfo);
  815. if (iinfo >= 0) {
  816. /* Computing MAX */
  817. i__3 = iwork;
  818. i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1;
  819. lwkopt = f2cmax(i__1,i__2);
  820. }
  821. if (iinfo != 0) {
  822. if (iinfo > 0 && iinfo <= *n) {
  823. *info = iinfo;
  824. } else if (iinfo > *n && iinfo <= *n << 1) {
  825. *info = iinfo - *n;
  826. } else {
  827. *info = *n + 6;
  828. }
  829. goto L80;
  830. }
  831. if (ilv) {
  832. /* Compute Eigenvectors */
  833. if (ilvl) {
  834. if (ilvr) {
  835. *(unsigned char *)chtemp = 'B';
  836. } else {
  837. *(unsigned char *)chtemp = 'L';
  838. }
  839. } else {
  840. *(unsigned char *)chtemp = 'R';
  841. }
  842. ctgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
  843. &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
  844. iwork], &rwork[irwork], &iinfo);
  845. if (iinfo != 0) {
  846. *info = *n + 7;
  847. goto L80;
  848. }
  849. /* Undo balancing on VL and VR, rescale */
  850. if (ilvl) {
  851. cggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
  852. &vl[vl_offset], ldvl, &iinfo);
  853. if (iinfo != 0) {
  854. *info = *n + 8;
  855. goto L80;
  856. }
  857. i__1 = *n;
  858. for (jc = 1; jc <= i__1; ++jc) {
  859. temp = 0.f;
  860. i__2 = *n;
  861. for (jr = 1; jr <= i__2; ++jr) {
  862. /* Computing MAX */
  863. i__3 = jr + jc * vl_dim1;
  864. r__3 = temp, r__4 = (r__1 = vl[i__3].r, abs(r__1)) + (
  865. r__2 = r_imag(&vl[jr + jc * vl_dim1]), abs(r__2));
  866. temp = f2cmax(r__3,r__4);
  867. /* L10: */
  868. }
  869. if (temp < safmin) {
  870. goto L30;
  871. }
  872. temp = 1.f / temp;
  873. i__2 = *n;
  874. for (jr = 1; jr <= i__2; ++jr) {
  875. i__3 = jr + jc * vl_dim1;
  876. i__4 = jr + jc * vl_dim1;
  877. q__1.r = temp * vl[i__4].r, q__1.i = temp * vl[i__4].i;
  878. vl[i__3].r = q__1.r, vl[i__3].i = q__1.i;
  879. /* L20: */
  880. }
  881. L30:
  882. ;
  883. }
  884. }
  885. if (ilvr) {
  886. cggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n,
  887. &vr[vr_offset], ldvr, &iinfo);
  888. if (iinfo != 0) {
  889. *info = *n + 9;
  890. goto L80;
  891. }
  892. i__1 = *n;
  893. for (jc = 1; jc <= i__1; ++jc) {
  894. temp = 0.f;
  895. i__2 = *n;
  896. for (jr = 1; jr <= i__2; ++jr) {
  897. /* Computing MAX */
  898. i__3 = jr + jc * vr_dim1;
  899. r__3 = temp, r__4 = (r__1 = vr[i__3].r, abs(r__1)) + (
  900. r__2 = r_imag(&vr[jr + jc * vr_dim1]), abs(r__2));
  901. temp = f2cmax(r__3,r__4);
  902. /* L40: */
  903. }
  904. if (temp < safmin) {
  905. goto L60;
  906. }
  907. temp = 1.f / temp;
  908. i__2 = *n;
  909. for (jr = 1; jr <= i__2; ++jr) {
  910. i__3 = jr + jc * vr_dim1;
  911. i__4 = jr + jc * vr_dim1;
  912. q__1.r = temp * vr[i__4].r, q__1.i = temp * vr[i__4].i;
  913. vr[i__3].r = q__1.r, vr[i__3].i = q__1.i;
  914. /* L50: */
  915. }
  916. L60:
  917. ;
  918. }
  919. }
  920. /* End of eigenvector calculation */
  921. }
  922. /* Undo scaling in alpha, beta */
  923. /* Note: this does not give the alpha and beta for the unscaled */
  924. /* problem. */
  925. /* Un-scaling is limited to avoid underflow in alpha and beta */
  926. /* if they are significant. */
  927. i__1 = *n;
  928. for (jc = 1; jc <= i__1; ++jc) {
  929. i__2 = jc;
  930. absar = (r__1 = alpha[i__2].r, abs(r__1));
  931. absai = (r__1 = r_imag(&alpha[jc]), abs(r__1));
  932. i__2 = jc;
  933. absb = (r__1 = beta[i__2].r, abs(r__1));
  934. i__2 = jc;
  935. salfar = anrm * alpha[i__2].r;
  936. salfai = anrm * r_imag(&alpha[jc]);
  937. i__2 = jc;
  938. sbeta = bnrm * beta[i__2].r;
  939. ilimit = FALSE_;
  940. scale = 1.f;
  941. /* Check for significant underflow in imaginary part of ALPHA */
  942. /* Computing MAX */
  943. r__1 = safmin, r__2 = eps * absar, r__1 = f2cmax(r__1,r__2), r__2 = eps *
  944. absb;
  945. if (abs(salfai) < safmin && absai >= f2cmax(r__1,r__2)) {
  946. ilimit = TRUE_;
  947. /* Computing MAX */
  948. r__1 = safmin, r__2 = anrm2 * absai;
  949. scale = safmin / anrm1 / f2cmax(r__1,r__2);
  950. }
  951. /* Check for significant underflow in real part of ALPHA */
  952. /* Computing MAX */
  953. r__1 = safmin, r__2 = eps * absai, r__1 = f2cmax(r__1,r__2), r__2 = eps *
  954. absb;
  955. if (abs(salfar) < safmin && absar >= f2cmax(r__1,r__2)) {
  956. ilimit = TRUE_;
  957. /* Computing MAX */
  958. /* Computing MAX */
  959. r__3 = safmin, r__4 = anrm2 * absar;
  960. r__1 = scale, r__2 = safmin / anrm1 / f2cmax(r__3,r__4);
  961. scale = f2cmax(r__1,r__2);
  962. }
  963. /* Check for significant underflow in BETA */
  964. /* Computing MAX */
  965. r__1 = safmin, r__2 = eps * absar, r__1 = f2cmax(r__1,r__2), r__2 = eps *
  966. absai;
  967. if (abs(sbeta) < safmin && absb >= f2cmax(r__1,r__2)) {
  968. ilimit = TRUE_;
  969. /* Computing MAX */
  970. /* Computing MAX */
  971. r__3 = safmin, r__4 = bnrm2 * absb;
  972. r__1 = scale, r__2 = safmin / bnrm1 / f2cmax(r__3,r__4);
  973. scale = f2cmax(r__1,r__2);
  974. }
  975. /* Check for possible overflow when limiting scaling */
  976. if (ilimit) {
  977. /* Computing MAX */
  978. r__1 = abs(salfar), r__2 = abs(salfai), r__1 = f2cmax(r__1,r__2),
  979. r__2 = abs(sbeta);
  980. temp = scale * safmin * f2cmax(r__1,r__2);
  981. if (temp > 1.f) {
  982. scale /= temp;
  983. }
  984. if (scale < 1.f) {
  985. ilimit = FALSE_;
  986. }
  987. }
  988. /* Recompute un-scaled ALPHA, BETA if necessary. */
  989. if (ilimit) {
  990. i__2 = jc;
  991. salfar = scale * alpha[i__2].r * anrm;
  992. salfai = scale * r_imag(&alpha[jc]) * anrm;
  993. i__2 = jc;
  994. q__2.r = scale * beta[i__2].r, q__2.i = scale * beta[i__2].i;
  995. q__1.r = bnrm * q__2.r, q__1.i = bnrm * q__2.i;
  996. sbeta = q__1.r;
  997. }
  998. i__2 = jc;
  999. q__1.r = salfar, q__1.i = salfai;
  1000. alpha[i__2].r = q__1.r, alpha[i__2].i = q__1.i;
  1001. i__2 = jc;
  1002. beta[i__2].r = sbeta, beta[i__2].i = 0.f;
  1003. /* L70: */
  1004. }
  1005. L80:
  1006. work[1].r = (real) lwkopt, work[1].i = 0.f;
  1007. return;
  1008. /* End of CGEGV */
  1009. } /* cgegv_ */