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