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.

dgegv.c 36 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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 integer c__1 = 1;
  244. static integer c_n1 = -1;
  245. static doublereal c_b27 = 1.;
  246. static doublereal c_b38 = 0.;
  247. /* > \brief <b> DGEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE mat
  248. rices</b> */
  249. /* =========== DOCUMENTATION =========== */
  250. /* Online html documentation available at */
  251. /* http://www.netlib.org/lapack/explore-html/ */
  252. /* > \htmlonly */
  253. /* > Download DGEGV + dependencies */
  254. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgegv.f
  255. "> */
  256. /* > [TGZ]</a> */
  257. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgegv.f
  258. "> */
  259. /* > [ZIP]</a> */
  260. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgegv.f
  261. "> */
  262. /* > [TXT]</a> */
  263. /* > \endhtmlonly */
  264. /* Definition: */
  265. /* =========== */
  266. /* SUBROUTINE DGEGV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI, */
  267. /* BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO ) */
  268. /* CHARACTER JOBVL, JOBVR */
  269. /* INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N */
  270. /* DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  271. /* $ B( LDB, * ), BETA( * ), VL( LDVL, * ), */
  272. /* $ VR( LDVR, * ), WORK( * ) */
  273. /* > \par Purpose: */
  274. /* ============= */
  275. /* > */
  276. /* > \verbatim */
  277. /* > */
  278. /* > This routine is deprecated and has been replaced by routine DGGEV. */
  279. /* > */
  280. /* > DGEGV computes the eigenvalues and, optionally, the left and/or right */
  281. /* > eigenvectors of a real matrix pair (A,B). */
  282. /* > Given two square matrices A and B, */
  283. /* > the generalized nonsymmetric eigenvalue problem (GNEP) is to find the */
  284. /* > eigenvalues lambda and corresponding (non-zero) eigenvectors x such */
  285. /* > that */
  286. /* > */
  287. /* > A*x = lambda*B*x. */
  288. /* > */
  289. /* > An alternate form is to find the eigenvalues mu and corresponding */
  290. /* > eigenvectors y such that */
  291. /* > */
  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. /* > */
  303. /* > u**H*A = lambda*u**H*B or mu*v**H*A = v**H*B */
  304. /* > */
  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 DOUBLE PRECISION array, dimension (LDA, N) */
  336. /* > On entry, the matrix A. */
  337. /* > If JOBVL = 'V' or JOBVR = 'V', then on exit A */
  338. /* > contains the real Schur form of A from the generalized Schur */
  339. /* > factorization of the pair (A,B) after balancing. */
  340. /* > If no eigenvectors were computed, then only the diagonal */
  341. /* > blocks from the Schur form will be correct. See DGGHRD and */
  342. /* > DHGEQZ 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 DOUBLE PRECISION 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 those elements of */
  359. /* > B corresponding to the diagonal blocks from the Schur form of */
  360. /* > A will be correct. See DGGHRD and DHGEQZ for 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] ALPHAR */
  370. /* > \verbatim */
  371. /* > ALPHAR is DOUBLE PRECISION array, dimension (N) */
  372. /* > The real parts of each scalar alpha defining an eigenvalue of */
  373. /* > GNEP. */
  374. /* > \endverbatim */
  375. /* > */
  376. /* > \param[out] ALPHAI */
  377. /* > \verbatim */
  378. /* > ALPHAI is DOUBLE PRECISION array, dimension (N) */
  379. /* > The imaginary parts of each scalar alpha defining an */
  380. /* > eigenvalue of GNEP. If ALPHAI(j) is zero, then the j-th */
  381. /* > eigenvalue is real; if positive, then the j-th and */
  382. /* > (j+1)-st eigenvalues are a complex conjugate pair, with */
  383. /* > ALPHAI(j+1) = -ALPHAI(j). */
  384. /* > \endverbatim */
  385. /* > */
  386. /* > \param[out] BETA */
  387. /* > \verbatim */
  388. /* > BETA is DOUBLE PRECISION array, dimension (N) */
  389. /* > The scalars beta that define the eigenvalues of GNEP. */
  390. /* > */
  391. /* > Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
  392. /* > beta = BETA(j) represent the j-th eigenvalue of the matrix */
  393. /* > pair (A,B), in one of the forms lambda = alpha/beta or */
  394. /* > mu = beta/alpha. Since either lambda or mu may overflow, */
  395. /* > they should not, in general, be computed. */
  396. /* > \endverbatim */
  397. /* > */
  398. /* > \param[out] VL */
  399. /* > \verbatim */
  400. /* > VL is DOUBLE PRECISION array, dimension (LDVL,N) */
  401. /* > If JOBVL = 'V', the left eigenvectors u(j) are stored */
  402. /* > in the columns of VL, in the same order as their eigenvalues. */
  403. /* > If the j-th eigenvalue is real, then u(j) = VL(:,j). */
  404. /* > If the j-th and (j+1)-st eigenvalues form a complex conjugate */
  405. /* > pair, then */
  406. /* > u(j) = VL(:,j) + i*VL(:,j+1) */
  407. /* > and */
  408. /* > u(j+1) = VL(:,j) - i*VL(:,j+1). */
  409. /* > */
  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 JOBVL = 'N'. */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[in] LDVL */
  418. /* > \verbatim */
  419. /* > LDVL is INTEGER */
  420. /* > The leading dimension of the matrix VL. LDVL >= 1, and */
  421. /* > if JOBVL = 'V', LDVL >= N. */
  422. /* > \endverbatim */
  423. /* > */
  424. /* > \param[out] VR */
  425. /* > \verbatim */
  426. /* > VR is DOUBLE PRECISION array, dimension (LDVR,N) */
  427. /* > If JOBVR = 'V', the right eigenvectors x(j) are stored */
  428. /* > in the columns of VR, in the same order as their eigenvalues. */
  429. /* > If the j-th eigenvalue is real, then x(j) = VR(:,j). */
  430. /* > If the j-th and (j+1)-st eigenvalues form a complex conjugate */
  431. /* > pair, then */
  432. /* > x(j) = VR(:,j) + i*VR(:,j+1) */
  433. /* > and */
  434. /* > x(j+1) = VR(:,j) - i*VR(:,j+1). */
  435. /* > */
  436. /* > Each eigenvector is scaled so that its largest component has */
  437. /* > abs(real part) + abs(imag. part) = 1, except for eigenvalues */
  438. /* > corresponding to an eigenvalue with alpha = beta = 0, which */
  439. /* > are set to zero. */
  440. /* > Not referenced if JOBVR = 'N'. */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[in] LDVR */
  444. /* > \verbatim */
  445. /* > LDVR is INTEGER */
  446. /* > The leading dimension of the matrix VR. LDVR >= 1, and */
  447. /* > if JOBVR = 'V', LDVR >= N. */
  448. /* > \endverbatim */
  449. /* > */
  450. /* > \param[out] WORK */
  451. /* > \verbatim */
  452. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  453. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  454. /* > \endverbatim */
  455. /* > */
  456. /* > \param[in] LWORK */
  457. /* > \verbatim */
  458. /* > LWORK is INTEGER */
  459. /* > The dimension of the array WORK. LWORK >= f2cmax(1,8*N). */
  460. /* > For good performance, LWORK must generally be larger. */
  461. /* > To compute the optimal value of LWORK, call ILAENV to get */
  462. /* > blocksizes (for DGEQRF, DORMQR, and DORGQR.) Then compute: */
  463. /* > NB -- MAX of the blocksizes for DGEQRF, DORMQR, and DORGQR; */
  464. /* > The optimal LWORK is: */
  465. /* > 2*N + MAX( 6*N, N*(NB+1) ). */
  466. /* > */
  467. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  468. /* > only calculates the optimal size of the WORK array, returns */
  469. /* > this value as the first entry of the WORK array, and no error */
  470. /* > message related to LWORK is issued by XERBLA. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[out] INFO */
  474. /* > \verbatim */
  475. /* > INFO is INTEGER */
  476. /* > = 0: successful exit */
  477. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  478. /* > = 1,...,N: */
  479. /* > The QZ iteration failed. No eigenvectors have been */
  480. /* > calculated, but ALPHAR(j), ALPHAI(j), and BETA(j) */
  481. /* > should be correct for j=INFO+1,...,N. */
  482. /* > > N: errors that usually indicate LAPACK problems: */
  483. /* > =N+1: error return from DGGBAL */
  484. /* > =N+2: error return from DGEQRF */
  485. /* > =N+3: error return from DORMQR */
  486. /* > =N+4: error return from DORGQR */
  487. /* > =N+5: error return from DGGHRD */
  488. /* > =N+6: error return from DHGEQZ (other than failed */
  489. /* > iteration) */
  490. /* > =N+7: error return from DTGEVC */
  491. /* > =N+8: error return from DGGBAK (computing VL) */
  492. /* > =N+9: error return from DGGBAK (computing VR) */
  493. /* > =N+10: error return from DLASCL (various calls) */
  494. /* > \endverbatim */
  495. /* Authors: */
  496. /* ======== */
  497. /* > \author Univ. of Tennessee */
  498. /* > \author Univ. of California Berkeley */
  499. /* > \author Univ. of Colorado Denver */
  500. /* > \author NAG Ltd. */
  501. /* > \date December 2016 */
  502. /* > \ingroup doubleGEeigen */
  503. /* > \par Further Details: */
  504. /* ===================== */
  505. /* > */
  506. /* > \verbatim */
  507. /* > */
  508. /* > Balancing */
  509. /* > --------- */
  510. /* > */
  511. /* > This driver calls DGGBAL to both permute and scale rows and columns */
  512. /* > of A and B. The permutations PL and PR are chosen so that PL*A*PR */
  513. /* > and PL*B*R will be upper triangular except for the diagonal blocks */
  514. /* > A(i:j,i:j) and B(i:j,i:j), with i and j as close together as */
  515. /* > possible. The diagonal scaling matrices DL and DR are chosen so */
  516. /* > that the pair DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to */
  517. /* > one (except for the elements that start out zero.) */
  518. /* > */
  519. /* > After the eigenvalues and eigenvectors of the balanced matrices */
  520. /* > have been computed, DGGBAK transforms the eigenvectors back to what */
  521. /* > they would have been (in perfect arithmetic) if they had not been */
  522. /* > balanced. */
  523. /* > */
  524. /* > Contents of A and B on Exit */
  525. /* > -------- -- - --- - -- ---- */
  526. /* > */
  527. /* > If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or */
  528. /* > both), then on exit the arrays A and B will contain the real Schur */
  529. /* > form[*] of the "balanced" versions of A and B. If no eigenvectors */
  530. /* > are computed, then only the diagonal blocks will be correct. */
  531. /* > */
  532. /* > [*] See DHGEQZ, DGEGS, or read the book "Matrix Computations", */
  533. /* > by Golub & van Loan, pub. by Johns Hopkins U. Press. */
  534. /* > \endverbatim */
  535. /* > */
  536. /* ===================================================================== */
  537. /* Subroutine */ void dgegv_(char *jobvl, char *jobvr, integer *n, doublereal *
  538. a, integer *lda, doublereal *b, integer *ldb, doublereal *alphar,
  539. doublereal *alphai, doublereal *beta, doublereal *vl, integer *ldvl,
  540. doublereal *vr, integer *ldvr, doublereal *work, integer *lwork,
  541. integer *info)
  542. {
  543. /* System generated locals */
  544. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  545. vr_offset, i__1, i__2;
  546. doublereal d__1, d__2, d__3, d__4;
  547. /* Local variables */
  548. doublereal absb, anrm, bnrm;
  549. integer itau;
  550. doublereal temp;
  551. logical ilvl, ilvr;
  552. integer lopt;
  553. doublereal anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
  554. extern logical lsame_(char *, char *);
  555. integer ileft, iinfo, icols, iwork, irows, jc;
  556. extern /* Subroutine */ void dggbak_(char *, char *, integer *, integer *,
  557. integer *, doublereal *, doublereal *, integer *, doublereal *,
  558. integer *, integer *);
  559. integer nb;
  560. extern /* Subroutine */ void dggbal_(char *, integer *, doublereal *,
  561. integer *, doublereal *, integer *, integer *, integer *,
  562. doublereal *, doublereal *, doublereal *, integer *);
  563. integer in;
  564. extern doublereal dlamch_(char *), dlange_(char *, integer *,
  565. integer *, doublereal *, integer *, doublereal *);
  566. integer jr;
  567. doublereal salfai;
  568. extern /* Subroutine */ void dgghrd_(char *, char *, integer *, integer *,
  569. integer *, doublereal *, integer *, doublereal *, integer *,
  570. doublereal *, integer *, doublereal *, integer *, integer *), dlascl_(char *, integer *, integer *, doublereal
  571. *, doublereal *, integer *, integer *, doublereal *, integer *,
  572. integer *);
  573. doublereal salfar;
  574. extern /* Subroutine */ void dgeqrf_(integer *, integer *, doublereal *,
  575. integer *, doublereal *, doublereal *, integer *, integer *),
  576. dlacpy_(char *, integer *, integer *, doublereal *, integer *,
  577. doublereal *, integer *);
  578. doublereal safmin;
  579. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  580. doublereal *, doublereal *, doublereal *, integer *);
  581. doublereal safmax;
  582. char chtemp[1];
  583. logical ldumma[1];
  584. extern /* Subroutine */ void dhgeqz_(char *, char *, char *, integer *,
  585. integer *, integer *, doublereal *, integer *, doublereal *,
  586. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  587. integer *, doublereal *, integer *, doublereal *, integer *,
  588. integer *), dtgevc_(char *, char *,
  589. logical *, integer *, doublereal *, integer *, doublereal *,
  590. integer *, doublereal *, integer *, doublereal *, integer *,
  591. integer *, integer *, doublereal *, integer *);
  592. extern int xerbla_(char *, integer *, ftnlen);
  593. integer ijobvl, iright;
  594. logical ilimit;
  595. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  596. integer *, integer *, ftnlen, ftnlen);
  597. integer ijobvr;
  598. extern /* Subroutine */ void dorgqr_(integer *, integer *, integer *,
  599. doublereal *, integer *, doublereal *, doublereal *, integer *,
  600. integer *);
  601. doublereal onepls;
  602. integer lwkmin, nb1, nb2, nb3;
  603. extern /* Subroutine */ void dormqr_(char *, char *, integer *, integer *,
  604. integer *, doublereal *, integer *, doublereal *, doublereal *,
  605. integer *, doublereal *, integer *, integer *);
  606. integer lwkopt;
  607. logical lquery;
  608. integer ihi, ilo;
  609. doublereal eps;
  610. logical ilv;
  611. /* -- LAPACK driver routine (version 3.7.0) -- */
  612. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  613. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  614. /* December 2016 */
  615. /* ===================================================================== */
  616. /* Decode the input arguments */
  617. /* Parameter adjustments */
  618. a_dim1 = *lda;
  619. a_offset = 1 + a_dim1 * 1;
  620. a -= a_offset;
  621. b_dim1 = *ldb;
  622. b_offset = 1 + b_dim1 * 1;
  623. b -= b_offset;
  624. --alphar;
  625. --alphai;
  626. --beta;
  627. vl_dim1 = *ldvl;
  628. vl_offset = 1 + vl_dim1 * 1;
  629. vl -= vl_offset;
  630. vr_dim1 = *ldvr;
  631. vr_offset = 1 + vr_dim1 * 1;
  632. vr -= vr_offset;
  633. --work;
  634. /* Function Body */
  635. if (lsame_(jobvl, "N")) {
  636. ijobvl = 1;
  637. ilvl = FALSE_;
  638. } else if (lsame_(jobvl, "V")) {
  639. ijobvl = 2;
  640. ilvl = TRUE_;
  641. } else {
  642. ijobvl = -1;
  643. ilvl = FALSE_;
  644. }
  645. if (lsame_(jobvr, "N")) {
  646. ijobvr = 1;
  647. ilvr = FALSE_;
  648. } else if (lsame_(jobvr, "V")) {
  649. ijobvr = 2;
  650. ilvr = TRUE_;
  651. } else {
  652. ijobvr = -1;
  653. ilvr = FALSE_;
  654. }
  655. ilv = ilvl || ilvr;
  656. /* Test the input arguments */
  657. /* Computing MAX */
  658. i__1 = *n << 3;
  659. lwkmin = f2cmax(i__1,1);
  660. lwkopt = lwkmin;
  661. work[1] = (doublereal) lwkopt;
  662. lquery = *lwork == -1;
  663. *info = 0;
  664. if (ijobvl <= 0) {
  665. *info = -1;
  666. } else if (ijobvr <= 0) {
  667. *info = -2;
  668. } else if (*n < 0) {
  669. *info = -3;
  670. } else if (*lda < f2cmax(1,*n)) {
  671. *info = -5;
  672. } else if (*ldb < f2cmax(1,*n)) {
  673. *info = -7;
  674. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  675. *info = -12;
  676. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  677. *info = -14;
  678. } else if (*lwork < lwkmin && ! lquery) {
  679. *info = -16;
  680. }
  681. if (*info == 0) {
  682. nb1 = ilaenv_(&c__1, "DGEQRF", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
  683. ftnlen)1);
  684. nb2 = ilaenv_(&c__1, "DORMQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  685. ftnlen)1);
  686. nb3 = ilaenv_(&c__1, "DORGQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  687. ftnlen)1);
  688. /* Computing MAX */
  689. i__1 = f2cmax(nb1,nb2);
  690. nb = f2cmax(i__1,nb3);
  691. /* Computing MAX */
  692. i__1 = *n * 6, i__2 = *n * (nb + 1);
  693. lopt = (*n << 1) + f2cmax(i__1,i__2);
  694. work[1] = (doublereal) lopt;
  695. }
  696. if (*info != 0) {
  697. i__1 = -(*info);
  698. xerbla_("DGEGV ", &i__1, 6);
  699. return;
  700. } else if (lquery) {
  701. return;
  702. }
  703. /* Quick return if possible */
  704. if (*n == 0) {
  705. return;
  706. }
  707. /* Get machine constants */
  708. eps = dlamch_("E") * dlamch_("B");
  709. safmin = dlamch_("S");
  710. safmin += safmin;
  711. safmax = 1. / safmin;
  712. onepls = eps * 4 + 1.;
  713. /* Scale A */
  714. anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
  715. anrm1 = anrm;
  716. anrm2 = 1.;
  717. if (anrm < 1.) {
  718. if (safmax * anrm < 1.) {
  719. anrm1 = safmin;
  720. anrm2 = safmax * anrm;
  721. }
  722. }
  723. if (anrm > 0.) {
  724. dlascl_("G", &c_n1, &c_n1, &anrm, &c_b27, n, n, &a[a_offset], lda, &
  725. iinfo);
  726. if (iinfo != 0) {
  727. *info = *n + 10;
  728. return;
  729. }
  730. }
  731. /* Scale B */
  732. bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
  733. bnrm1 = bnrm;
  734. bnrm2 = 1.;
  735. if (bnrm < 1.) {
  736. if (safmax * bnrm < 1.) {
  737. bnrm1 = safmin;
  738. bnrm2 = safmax * bnrm;
  739. }
  740. }
  741. if (bnrm > 0.) {
  742. dlascl_("G", &c_n1, &c_n1, &bnrm, &c_b27, n, n, &b[b_offset], ldb, &
  743. iinfo);
  744. if (iinfo != 0) {
  745. *info = *n + 10;
  746. return;
  747. }
  748. }
  749. /* Permute the matrix to make it more nearly triangular */
  750. /* Workspace layout: (8*N words -- "work" requires 6*N words) */
  751. /* left_permutation, right_permutation, work... */
  752. ileft = 1;
  753. iright = *n + 1;
  754. iwork = iright + *n;
  755. dggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  756. ileft], &work[iright], &work[iwork], &iinfo);
  757. if (iinfo != 0) {
  758. *info = *n + 1;
  759. goto L120;
  760. }
  761. /* Reduce B to triangular form, and initialize VL and/or VR */
  762. /* Workspace layout: ("work..." must have at least N words) */
  763. /* left_permutation, right_permutation, tau, work... */
  764. irows = ihi + 1 - ilo;
  765. if (ilv) {
  766. icols = *n + 1 - ilo;
  767. } else {
  768. icols = irows;
  769. }
  770. itau = iwork;
  771. iwork = itau + irows;
  772. i__1 = *lwork + 1 - iwork;
  773. dgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  774. iwork], &i__1, &iinfo);
  775. if (iinfo >= 0) {
  776. /* Computing MAX */
  777. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  778. lwkopt = f2cmax(i__1,i__2);
  779. }
  780. if (iinfo != 0) {
  781. *info = *n + 2;
  782. goto L120;
  783. }
  784. i__1 = *lwork + 1 - iwork;
  785. dormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  786. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  787. iinfo);
  788. if (iinfo >= 0) {
  789. /* Computing MAX */
  790. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  791. lwkopt = f2cmax(i__1,i__2);
  792. }
  793. if (iinfo != 0) {
  794. *info = *n + 3;
  795. goto L120;
  796. }
  797. if (ilvl) {
  798. dlaset_("Full", n, n, &c_b38, &c_b27, &vl[vl_offset], ldvl)
  799. ;
  800. i__1 = irows - 1;
  801. i__2 = irows - 1;
  802. dlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo +
  803. 1 + ilo * vl_dim1], ldvl);
  804. i__1 = *lwork + 1 - iwork;
  805. dorgqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
  806. itau], &work[iwork], &i__1, &iinfo);
  807. if (iinfo >= 0) {
  808. /* Computing MAX */
  809. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  810. lwkopt = f2cmax(i__1,i__2);
  811. }
  812. if (iinfo != 0) {
  813. *info = *n + 4;
  814. goto L120;
  815. }
  816. }
  817. if (ilvr) {
  818. dlaset_("Full", n, n, &c_b38, &c_b27, &vr[vr_offset], ldvr)
  819. ;
  820. }
  821. /* Reduce to generalized Hessenberg form */
  822. if (ilv) {
  823. /* Eigenvectors requested -- work on whole matrix. */
  824. dgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  825. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo);
  826. } else {
  827. dgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
  828. &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  829. vr_offset], ldvr, &iinfo);
  830. }
  831. if (iinfo != 0) {
  832. *info = *n + 5;
  833. goto L120;
  834. }
  835. /* Perform QZ algorithm */
  836. /* Workspace layout: ("work..." must have at least 1 word) */
  837. /* left_permutation, right_permutation, work... */
  838. iwork = itau;
  839. if (ilv) {
  840. *(unsigned char *)chtemp = 'S';
  841. } else {
  842. *(unsigned char *)chtemp = 'E';
  843. }
  844. i__1 = *lwork + 1 - iwork;
  845. dhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  846. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset],
  847. ldvl, &vr[vr_offset], ldvr, &work[iwork], &i__1, &iinfo);
  848. if (iinfo >= 0) {
  849. /* Computing MAX */
  850. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  851. lwkopt = f2cmax(i__1,i__2);
  852. }
  853. if (iinfo != 0) {
  854. if (iinfo > 0 && iinfo <= *n) {
  855. *info = iinfo;
  856. } else if (iinfo > *n && iinfo <= *n << 1) {
  857. *info = iinfo - *n;
  858. } else {
  859. *info = *n + 6;
  860. }
  861. goto L120;
  862. }
  863. if (ilv) {
  864. /* Compute Eigenvectors (DTGEVC requires 6*N words of workspace) */
  865. if (ilvl) {
  866. if (ilvr) {
  867. *(unsigned char *)chtemp = 'B';
  868. } else {
  869. *(unsigned char *)chtemp = 'L';
  870. }
  871. } else {
  872. *(unsigned char *)chtemp = 'R';
  873. }
  874. dtgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
  875. &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
  876. iwork], &iinfo);
  877. if (iinfo != 0) {
  878. *info = *n + 7;
  879. goto L120;
  880. }
  881. /* Undo balancing on VL and VR, rescale */
  882. if (ilvl) {
  883. dggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  884. vl[vl_offset], ldvl, &iinfo);
  885. if (iinfo != 0) {
  886. *info = *n + 8;
  887. goto L120;
  888. }
  889. i__1 = *n;
  890. for (jc = 1; jc <= i__1; ++jc) {
  891. if (alphai[jc] < 0.) {
  892. goto L50;
  893. }
  894. temp = 0.;
  895. if (alphai[jc] == 0.) {
  896. i__2 = *n;
  897. for (jr = 1; jr <= i__2; ++jr) {
  898. /* Computing MAX */
  899. d__2 = temp, d__3 = (d__1 = vl[jr + jc * vl_dim1],
  900. abs(d__1));
  901. temp = f2cmax(d__2,d__3);
  902. /* L10: */
  903. }
  904. } else {
  905. i__2 = *n;
  906. for (jr = 1; jr <= i__2; ++jr) {
  907. /* Computing MAX */
  908. d__3 = temp, d__4 = (d__1 = vl[jr + jc * vl_dim1],
  909. abs(d__1)) + (d__2 = vl[jr + (jc + 1) *
  910. vl_dim1], abs(d__2));
  911. temp = f2cmax(d__3,d__4);
  912. /* L20: */
  913. }
  914. }
  915. if (temp < safmin) {
  916. goto L50;
  917. }
  918. temp = 1. / temp;
  919. if (alphai[jc] == 0.) {
  920. i__2 = *n;
  921. for (jr = 1; jr <= i__2; ++jr) {
  922. vl[jr + jc * vl_dim1] *= temp;
  923. /* L30: */
  924. }
  925. } else {
  926. i__2 = *n;
  927. for (jr = 1; jr <= i__2; ++jr) {
  928. vl[jr + jc * vl_dim1] *= temp;
  929. vl[jr + (jc + 1) * vl_dim1] *= temp;
  930. /* L40: */
  931. }
  932. }
  933. L50:
  934. ;
  935. }
  936. }
  937. if (ilvr) {
  938. dggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  939. vr[vr_offset], ldvr, &iinfo);
  940. if (iinfo != 0) {
  941. *info = *n + 9;
  942. goto L120;
  943. }
  944. i__1 = *n;
  945. for (jc = 1; jc <= i__1; ++jc) {
  946. if (alphai[jc] < 0.) {
  947. goto L100;
  948. }
  949. temp = 0.;
  950. if (alphai[jc] == 0.) {
  951. i__2 = *n;
  952. for (jr = 1; jr <= i__2; ++jr) {
  953. /* Computing MAX */
  954. d__2 = temp, d__3 = (d__1 = vr[jr + jc * vr_dim1],
  955. abs(d__1));
  956. temp = f2cmax(d__2,d__3);
  957. /* L60: */
  958. }
  959. } else {
  960. i__2 = *n;
  961. for (jr = 1; jr <= i__2; ++jr) {
  962. /* Computing MAX */
  963. d__3 = temp, d__4 = (d__1 = vr[jr + jc * vr_dim1],
  964. abs(d__1)) + (d__2 = vr[jr + (jc + 1) *
  965. vr_dim1], abs(d__2));
  966. temp = f2cmax(d__3,d__4);
  967. /* L70: */
  968. }
  969. }
  970. if (temp < safmin) {
  971. goto L100;
  972. }
  973. temp = 1. / temp;
  974. if (alphai[jc] == 0.) {
  975. i__2 = *n;
  976. for (jr = 1; jr <= i__2; ++jr) {
  977. vr[jr + jc * vr_dim1] *= temp;
  978. /* L80: */
  979. }
  980. } else {
  981. i__2 = *n;
  982. for (jr = 1; jr <= i__2; ++jr) {
  983. vr[jr + jc * vr_dim1] *= temp;
  984. vr[jr + (jc + 1) * vr_dim1] *= temp;
  985. /* L90: */
  986. }
  987. }
  988. L100:
  989. ;
  990. }
  991. }
  992. /* End of eigenvector calculation */
  993. }
  994. /* Undo scaling in alpha, beta */
  995. /* Note: this does not give the alpha and beta for the unscaled */
  996. /* problem. */
  997. /* Un-scaling is limited to avoid underflow in alpha and beta */
  998. /* if they are significant. */
  999. i__1 = *n;
  1000. for (jc = 1; jc <= i__1; ++jc) {
  1001. absar = (d__1 = alphar[jc], abs(d__1));
  1002. absai = (d__1 = alphai[jc], abs(d__1));
  1003. absb = (d__1 = beta[jc], abs(d__1));
  1004. salfar = anrm * alphar[jc];
  1005. salfai = anrm * alphai[jc];
  1006. sbeta = bnrm * beta[jc];
  1007. ilimit = FALSE_;
  1008. scale = 1.;
  1009. /* Check for significant underflow in ALPHAI */
  1010. /* Computing MAX */
  1011. d__1 = safmin, d__2 = eps * absar, d__1 = f2cmax(d__1,d__2), d__2 = eps *
  1012. absb;
  1013. if (abs(salfai) < safmin && absai >= f2cmax(d__1,d__2)) {
  1014. ilimit = TRUE_;
  1015. /* Computing MAX */
  1016. d__1 = onepls * safmin, d__2 = anrm2 * absai;
  1017. scale = onepls * safmin / anrm1 / f2cmax(d__1,d__2);
  1018. } else if (salfai == 0.) {
  1019. /* If insignificant underflow in ALPHAI, then make the */
  1020. /* conjugate eigenvalue real. */
  1021. if (alphai[jc] < 0. && jc > 1) {
  1022. alphai[jc - 1] = 0.;
  1023. } else if (alphai[jc] > 0. && jc < *n) {
  1024. alphai[jc + 1] = 0.;
  1025. }
  1026. }
  1027. /* Check for significant underflow in ALPHAR */
  1028. /* Computing MAX */
  1029. d__1 = safmin, d__2 = eps * absai, d__1 = f2cmax(d__1,d__2), d__2 = eps *
  1030. absb;
  1031. if (abs(salfar) < safmin && absar >= f2cmax(d__1,d__2)) {
  1032. ilimit = TRUE_;
  1033. /* Computing MAX */
  1034. /* Computing MAX */
  1035. d__3 = onepls * safmin, d__4 = anrm2 * absar;
  1036. d__1 = scale, d__2 = onepls * safmin / anrm1 / f2cmax(d__3,d__4);
  1037. scale = f2cmax(d__1,d__2);
  1038. }
  1039. /* Check for significant underflow in BETA */
  1040. /* Computing MAX */
  1041. d__1 = safmin, d__2 = eps * absar, d__1 = f2cmax(d__1,d__2), d__2 = eps *
  1042. absai;
  1043. if (abs(sbeta) < safmin && absb >= f2cmax(d__1,d__2)) {
  1044. ilimit = TRUE_;
  1045. /* Computing MAX */
  1046. /* Computing MAX */
  1047. d__3 = onepls * safmin, d__4 = bnrm2 * absb;
  1048. d__1 = scale, d__2 = onepls * safmin / bnrm1 / f2cmax(d__3,d__4);
  1049. scale = f2cmax(d__1,d__2);
  1050. }
  1051. /* Check for possible overflow when limiting scaling */
  1052. if (ilimit) {
  1053. /* Computing MAX */
  1054. d__1 = abs(salfar), d__2 = abs(salfai), d__1 = f2cmax(d__1,d__2),
  1055. d__2 = abs(sbeta);
  1056. temp = scale * safmin * f2cmax(d__1,d__2);
  1057. if (temp > 1.) {
  1058. scale /= temp;
  1059. }
  1060. if (scale < 1.) {
  1061. ilimit = FALSE_;
  1062. }
  1063. }
  1064. /* Recompute un-scaled ALPHAR, ALPHAI, BETA if necessary. */
  1065. if (ilimit) {
  1066. salfar = scale * alphar[jc] * anrm;
  1067. salfai = scale * alphai[jc] * anrm;
  1068. sbeta = scale * beta[jc] * bnrm;
  1069. }
  1070. alphar[jc] = salfar;
  1071. alphai[jc] = salfai;
  1072. beta[jc] = sbeta;
  1073. /* L110: */
  1074. }
  1075. L120:
  1076. work[1] = (doublereal) lwkopt;
  1077. return;
  1078. /* End of DGEGV */
  1079. } /* dgegv_ */