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