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.

sgegv.c 35 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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 real c_b27 = 1.f;
  246. static real c_b38 = 0.f;
  247. /* > \brief <b> SGEEVX 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 SGEGV + dependencies */
  254. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgegv.f
  255. "> */
  256. /* > [TGZ]</a> */
  257. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgegv.f
  258. "> */
  259. /* > [ZIP]</a> */
  260. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgegv.f
  261. "> */
  262. /* > [TXT]</a> */
  263. /* > \endhtmlonly */
  264. /* Definition: */
  265. /* =========== */
  266. /* SUBROUTINE SGEGV( 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. /* REAL 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 SGGEV. */
  279. /* > */
  280. /* > SGEGV 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 REAL 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 SGGHRD and */
  342. /* > SHGEQZ 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 REAL 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 SGGHRD and SHGEQZ 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL 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 SGEQRF, SORMQR, and SORGQR.) Then compute: */
  463. /* > NB -- MAX of the blocksizes for SGEQRF, SORMQR, and SORGQR; */
  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 SGGBAL */
  484. /* > =N+2: error return from SGEQRF */
  485. /* > =N+3: error return from SORMQR */
  486. /* > =N+4: error return from SORGQR */
  487. /* > =N+5: error return from SGGHRD */
  488. /* > =N+6: error return from SHGEQZ (other than failed */
  489. /* > iteration) */
  490. /* > =N+7: error return from STGEVC */
  491. /* > =N+8: error return from SGGBAK (computing VL) */
  492. /* > =N+9: error return from SGGBAK (computing VR) */
  493. /* > =N+10: error return from SLASCL (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 realGEeigen */
  503. /* > \par Further Details: */
  504. /* ===================== */
  505. /* > */
  506. /* > \verbatim */
  507. /* > */
  508. /* > Balancing */
  509. /* > --------- */
  510. /* > */
  511. /* > This driver calls SGGBAL 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, SGGBAK 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 SHGEQZ, SGEGS, or read the book "Matrix Computations", */
  533. /* > by Golub & van Loan, pub. by Johns Hopkins U. Press. */
  534. /* > \endverbatim */
  535. /* > */
  536. /* ===================================================================== */
  537. /* Subroutine */ void sgegv_(char *jobvl, char *jobvr, integer *n, real *a,
  538. integer *lda, real *b, integer *ldb, real *alphar, real *alphai, real
  539. *beta, real *vl, integer *ldvl, real *vr, integer *ldvr, real *work,
  540. integer *lwork, integer *info)
  541. {
  542. /* System generated locals */
  543. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  544. vr_offset, i__1, i__2;
  545. real r__1, r__2, r__3, r__4;
  546. /* Local variables */
  547. real absb, anrm, bnrm;
  548. integer itau;
  549. real temp;
  550. logical ilvl, ilvr;
  551. integer lopt;
  552. real anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta;
  553. extern logical lsame_(char *, char *);
  554. integer ileft, iinfo, icols, iwork, irows, jc, nb, in, jr;
  555. real salfai;
  556. extern /* Subroutine */ void sggbak_(char *, char *, integer *, integer *,
  557. integer *, real *, real *, integer *, real *, integer *, integer *
  558. ), sggbal_(char *, integer *, real *, integer *,
  559. real *, integer *, integer *, integer *, real *, real *, real *,
  560. integer *);
  561. real salfar;
  562. extern real slamch_(char *), slange_(char *, integer *, integer *,
  563. real *, integer *, real *);
  564. real safmin;
  565. extern /* Subroutine */ void sgghrd_(char *, char *, integer *, integer *,
  566. integer *, real *, integer *, real *, integer *, real *, integer *
  567. , real *, integer *, integer *);
  568. real safmax;
  569. char chtemp[1];
  570. logical ldumma[1];
  571. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  572. real *, integer *, integer *, real *, integer *, integer *);
  573. extern int xerbla_(char *, integer *, ftnlen);
  574. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  575. integer *, integer *, ftnlen, ftnlen);
  576. integer ijobvl, iright;
  577. logical ilimit;
  578. extern /* Subroutine */ void sgeqrf_(integer *, integer *, real *, integer
  579. *, real *, real *, integer *, integer *);
  580. integer ijobvr;
  581. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  582. integer *, real *, integer *), slaset_(char *, integer *,
  583. integer *, real *, real *, real *, integer *), stgevc_(
  584. char *, char *, logical *, integer *, real *, integer *, real *,
  585. integer *, real *, integer *, real *, integer *, integer *,
  586. integer *, real *, integer *);
  587. real onepls;
  588. integer lwkmin, nb1, nb2, nb3;
  589. extern /* Subroutine */ void shgeqz_(char *, char *, char *, integer *,
  590. integer *, integer *, real *, integer *, real *, integer *, real *
  591. , real *, real *, real *, integer *, real *, integer *, real *,
  592. integer *, integer *), sorgqr_(integer *,
  593. integer *, integer *, real *, integer *, real *, real *, integer *
  594. , integer *);
  595. integer lwkopt;
  596. logical lquery;
  597. extern /* Subroutine */ void sormqr_(char *, char *, integer *, integer *,
  598. integer *, real *, integer *, real *, real *, integer *, real *,
  599. integer *, integer *);
  600. integer ihi, ilo;
  601. real eps;
  602. logical ilv;
  603. /* -- LAPACK driver routine (version 3.7.0) -- */
  604. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  605. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  606. /* December 2016 */
  607. /* ===================================================================== */
  608. /* Decode the input arguments */
  609. /* Parameter adjustments */
  610. a_dim1 = *lda;
  611. a_offset = 1 + a_dim1 * 1;
  612. a -= a_offset;
  613. b_dim1 = *ldb;
  614. b_offset = 1 + b_dim1 * 1;
  615. b -= b_offset;
  616. --alphar;
  617. --alphai;
  618. --beta;
  619. vl_dim1 = *ldvl;
  620. vl_offset = 1 + vl_dim1 * 1;
  621. vl -= vl_offset;
  622. vr_dim1 = *ldvr;
  623. vr_offset = 1 + vr_dim1 * 1;
  624. vr -= vr_offset;
  625. --work;
  626. /* Function Body */
  627. if (lsame_(jobvl, "N")) {
  628. ijobvl = 1;
  629. ilvl = FALSE_;
  630. } else if (lsame_(jobvl, "V")) {
  631. ijobvl = 2;
  632. ilvl = TRUE_;
  633. } else {
  634. ijobvl = -1;
  635. ilvl = FALSE_;
  636. }
  637. if (lsame_(jobvr, "N")) {
  638. ijobvr = 1;
  639. ilvr = FALSE_;
  640. } else if (lsame_(jobvr, "V")) {
  641. ijobvr = 2;
  642. ilvr = TRUE_;
  643. } else {
  644. ijobvr = -1;
  645. ilvr = FALSE_;
  646. }
  647. ilv = ilvl || ilvr;
  648. /* Test the input arguments */
  649. /* Computing MAX */
  650. i__1 = *n << 3;
  651. lwkmin = f2cmax(i__1,1);
  652. lwkopt = lwkmin;
  653. work[1] = (real) lwkopt;
  654. lquery = *lwork == -1;
  655. *info = 0;
  656. if (ijobvl <= 0) {
  657. *info = -1;
  658. } else if (ijobvr <= 0) {
  659. *info = -2;
  660. } else if (*n < 0) {
  661. *info = -3;
  662. } else if (*lda < f2cmax(1,*n)) {
  663. *info = -5;
  664. } else if (*ldb < f2cmax(1,*n)) {
  665. *info = -7;
  666. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  667. *info = -12;
  668. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  669. *info = -14;
  670. } else if (*lwork < lwkmin && ! lquery) {
  671. *info = -16;
  672. }
  673. if (*info == 0) {
  674. nb1 = ilaenv_(&c__1, "SGEQRF", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
  675. ftnlen)1);
  676. nb2 = ilaenv_(&c__1, "SORMQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  677. ftnlen)1);
  678. nb3 = ilaenv_(&c__1, "SORGQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  679. ftnlen)1);
  680. /* Computing MAX */
  681. i__1 = f2cmax(nb1,nb2);
  682. nb = f2cmax(i__1,nb3);
  683. /* Computing MAX */
  684. i__1 = *n * 6, i__2 = *n * (nb + 1);
  685. lopt = (*n << 1) + f2cmax(i__1,i__2);
  686. work[1] = (real) lopt;
  687. }
  688. if (*info != 0) {
  689. i__1 = -(*info);
  690. xerbla_("SGEGV ", &i__1, 6);
  691. return;
  692. } else if (lquery) {
  693. return;
  694. }
  695. /* Quick return if possible */
  696. if (*n == 0) {
  697. return;
  698. }
  699. /* Get machine constants */
  700. eps = slamch_("E") * slamch_("B");
  701. safmin = slamch_("S");
  702. safmin += safmin;
  703. safmax = 1.f / safmin;
  704. onepls = eps * 4 + 1.f;
  705. /* Scale A */
  706. anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
  707. anrm1 = anrm;
  708. anrm2 = 1.f;
  709. if (anrm < 1.f) {
  710. if (safmax * anrm < 1.f) {
  711. anrm1 = safmin;
  712. anrm2 = safmax * anrm;
  713. }
  714. }
  715. if (anrm > 0.f) {
  716. slascl_("G", &c_n1, &c_n1, &anrm, &c_b27, n, n, &a[a_offset], lda, &
  717. iinfo);
  718. if (iinfo != 0) {
  719. *info = *n + 10;
  720. return;
  721. }
  722. }
  723. /* Scale B */
  724. bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
  725. bnrm1 = bnrm;
  726. bnrm2 = 1.f;
  727. if (bnrm < 1.f) {
  728. if (safmax * bnrm < 1.f) {
  729. bnrm1 = safmin;
  730. bnrm2 = safmax * bnrm;
  731. }
  732. }
  733. if (bnrm > 0.f) {
  734. slascl_("G", &c_n1, &c_n1, &bnrm, &c_b27, n, n, &b[b_offset], ldb, &
  735. iinfo);
  736. if (iinfo != 0) {
  737. *info = *n + 10;
  738. return;
  739. }
  740. }
  741. /* Permute the matrix to make it more nearly triangular */
  742. /* Workspace layout: (8*N words -- "work" requires 6*N words) */
  743. /* left_permutation, right_permutation, work... */
  744. ileft = 1;
  745. iright = *n + 1;
  746. iwork = iright + *n;
  747. sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  748. ileft], &work[iright], &work[iwork], &iinfo);
  749. if (iinfo != 0) {
  750. *info = *n + 1;
  751. goto L120;
  752. }
  753. /* Reduce B to triangular form, and initialize VL and/or VR */
  754. /* Workspace layout: ("work..." must have at least N words) */
  755. /* left_permutation, right_permutation, tau, work... */
  756. irows = ihi + 1 - ilo;
  757. if (ilv) {
  758. icols = *n + 1 - ilo;
  759. } else {
  760. icols = irows;
  761. }
  762. itau = iwork;
  763. iwork = itau + irows;
  764. i__1 = *lwork + 1 - iwork;
  765. sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  766. iwork], &i__1, &iinfo);
  767. if (iinfo >= 0) {
  768. /* Computing MAX */
  769. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  770. lwkopt = f2cmax(i__1,i__2);
  771. }
  772. if (iinfo != 0) {
  773. *info = *n + 2;
  774. goto L120;
  775. }
  776. i__1 = *lwork + 1 - iwork;
  777. sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  778. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  779. iinfo);
  780. if (iinfo >= 0) {
  781. /* Computing MAX */
  782. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  783. lwkopt = f2cmax(i__1,i__2);
  784. }
  785. if (iinfo != 0) {
  786. *info = *n + 3;
  787. goto L120;
  788. }
  789. if (ilvl) {
  790. slaset_("Full", n, n, &c_b38, &c_b27, &vl[vl_offset], ldvl)
  791. ;
  792. i__1 = irows - 1;
  793. i__2 = irows - 1;
  794. slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo +
  795. 1 + ilo * vl_dim1], ldvl);
  796. i__1 = *lwork + 1 - iwork;
  797. sorgqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
  798. itau], &work[iwork], &i__1, &iinfo);
  799. if (iinfo >= 0) {
  800. /* Computing MAX */
  801. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  802. lwkopt = f2cmax(i__1,i__2);
  803. }
  804. if (iinfo != 0) {
  805. *info = *n + 4;
  806. goto L120;
  807. }
  808. }
  809. if (ilvr) {
  810. slaset_("Full", n, n, &c_b38, &c_b27, &vr[vr_offset], ldvr)
  811. ;
  812. }
  813. /* Reduce to generalized Hessenberg form */
  814. if (ilv) {
  815. /* Eigenvectors requested -- work on whole matrix. */
  816. sgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  817. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo);
  818. } else {
  819. sgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
  820. &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  821. vr_offset], ldvr, &iinfo);
  822. }
  823. if (iinfo != 0) {
  824. *info = *n + 5;
  825. goto L120;
  826. }
  827. /* Perform QZ algorithm */
  828. /* Workspace layout: ("work..." must have at least 1 word) */
  829. /* left_permutation, right_permutation, work... */
  830. iwork = itau;
  831. if (ilv) {
  832. *(unsigned char *)chtemp = 'S';
  833. } else {
  834. *(unsigned char *)chtemp = 'E';
  835. }
  836. i__1 = *lwork + 1 - iwork;
  837. shgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  838. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset],
  839. ldvl, &vr[vr_offset], ldvr, &work[iwork], &i__1, &iinfo);
  840. if (iinfo >= 0) {
  841. /* Computing MAX */
  842. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  843. lwkopt = f2cmax(i__1,i__2);
  844. }
  845. if (iinfo != 0) {
  846. if (iinfo > 0 && iinfo <= *n) {
  847. *info = iinfo;
  848. } else if (iinfo > *n && iinfo <= *n << 1) {
  849. *info = iinfo - *n;
  850. } else {
  851. *info = *n + 6;
  852. }
  853. goto L120;
  854. }
  855. if (ilv) {
  856. /* Compute Eigenvectors (STGEVC requires 6*N words of workspace) */
  857. if (ilvl) {
  858. if (ilvr) {
  859. *(unsigned char *)chtemp = 'B';
  860. } else {
  861. *(unsigned char *)chtemp = 'L';
  862. }
  863. } else {
  864. *(unsigned char *)chtemp = 'R';
  865. }
  866. stgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
  867. &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
  868. iwork], &iinfo);
  869. if (iinfo != 0) {
  870. *info = *n + 7;
  871. goto L120;
  872. }
  873. /* Undo balancing on VL and VR, rescale */
  874. if (ilvl) {
  875. sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  876. vl[vl_offset], ldvl, &iinfo);
  877. if (iinfo != 0) {
  878. *info = *n + 8;
  879. goto L120;
  880. }
  881. i__1 = *n;
  882. for (jc = 1; jc <= i__1; ++jc) {
  883. if (alphai[jc] < 0.f) {
  884. goto L50;
  885. }
  886. temp = 0.f;
  887. if (alphai[jc] == 0.f) {
  888. i__2 = *n;
  889. for (jr = 1; jr <= i__2; ++jr) {
  890. /* Computing MAX */
  891. r__2 = temp, r__3 = (r__1 = vl[jr + jc * vl_dim1],
  892. abs(r__1));
  893. temp = f2cmax(r__2,r__3);
  894. /* L10: */
  895. }
  896. } else {
  897. i__2 = *n;
  898. for (jr = 1; jr <= i__2; ++jr) {
  899. /* Computing MAX */
  900. r__3 = temp, r__4 = (r__1 = vl[jr + jc * vl_dim1],
  901. abs(r__1)) + (r__2 = vl[jr + (jc + 1) *
  902. vl_dim1], abs(r__2));
  903. temp = f2cmax(r__3,r__4);
  904. /* L20: */
  905. }
  906. }
  907. if (temp < safmin) {
  908. goto L50;
  909. }
  910. temp = 1.f / temp;
  911. if (alphai[jc] == 0.f) {
  912. i__2 = *n;
  913. for (jr = 1; jr <= i__2; ++jr) {
  914. vl[jr + jc * vl_dim1] *= temp;
  915. /* L30: */
  916. }
  917. } else {
  918. i__2 = *n;
  919. for (jr = 1; jr <= i__2; ++jr) {
  920. vl[jr + jc * vl_dim1] *= temp;
  921. vl[jr + (jc + 1) * vl_dim1] *= temp;
  922. /* L40: */
  923. }
  924. }
  925. L50:
  926. ;
  927. }
  928. }
  929. if (ilvr) {
  930. sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  931. vr[vr_offset], ldvr, &iinfo);
  932. if (iinfo != 0) {
  933. *info = *n + 9;
  934. goto L120;
  935. }
  936. i__1 = *n;
  937. for (jc = 1; jc <= i__1; ++jc) {
  938. if (alphai[jc] < 0.f) {
  939. goto L100;
  940. }
  941. temp = 0.f;
  942. if (alphai[jc] == 0.f) {
  943. i__2 = *n;
  944. for (jr = 1; jr <= i__2; ++jr) {
  945. /* Computing MAX */
  946. r__2 = temp, r__3 = (r__1 = vr[jr + jc * vr_dim1],
  947. abs(r__1));
  948. temp = f2cmax(r__2,r__3);
  949. /* L60: */
  950. }
  951. } else {
  952. i__2 = *n;
  953. for (jr = 1; jr <= i__2; ++jr) {
  954. /* Computing MAX */
  955. r__3 = temp, r__4 = (r__1 = vr[jr + jc * vr_dim1],
  956. abs(r__1)) + (r__2 = vr[jr + (jc + 1) *
  957. vr_dim1], abs(r__2));
  958. temp = f2cmax(r__3,r__4);
  959. /* L70: */
  960. }
  961. }
  962. if (temp < safmin) {
  963. goto L100;
  964. }
  965. temp = 1.f / temp;
  966. if (alphai[jc] == 0.f) {
  967. i__2 = *n;
  968. for (jr = 1; jr <= i__2; ++jr) {
  969. vr[jr + jc * vr_dim1] *= temp;
  970. /* L80: */
  971. }
  972. } else {
  973. i__2 = *n;
  974. for (jr = 1; jr <= i__2; ++jr) {
  975. vr[jr + jc * vr_dim1] *= temp;
  976. vr[jr + (jc + 1) * vr_dim1] *= temp;
  977. /* L90: */
  978. }
  979. }
  980. L100:
  981. ;
  982. }
  983. }
  984. /* End of eigenvector calculation */
  985. }
  986. /* Undo scaling in alpha, beta */
  987. /* Note: this does not give the alpha and beta for the unscaled */
  988. /* problem. */
  989. /* Un-scaling is limited to avoid underflow in alpha and beta */
  990. /* if they are significant. */
  991. i__1 = *n;
  992. for (jc = 1; jc <= i__1; ++jc) {
  993. absar = (r__1 = alphar[jc], abs(r__1));
  994. absai = (r__1 = alphai[jc], abs(r__1));
  995. absb = (r__1 = beta[jc], abs(r__1));
  996. salfar = anrm * alphar[jc];
  997. salfai = anrm * alphai[jc];
  998. sbeta = bnrm * beta[jc];
  999. ilimit = FALSE_;
  1000. scale = 1.f;
  1001. /* Check for significant underflow in ALPHAI */
  1002. /* Computing MAX */
  1003. r__1 = safmin, r__2 = eps * absar, r__1 = f2cmax(r__1,r__2), r__2 = eps *
  1004. absb;
  1005. if (abs(salfai) < safmin && absai >= f2cmax(r__1,r__2)) {
  1006. ilimit = TRUE_;
  1007. /* Computing MAX */
  1008. r__1 = onepls * safmin, r__2 = anrm2 * absai;
  1009. scale = onepls * safmin / anrm1 / f2cmax(r__1,r__2);
  1010. } else if (salfai == 0.f) {
  1011. /* If insignificant underflow in ALPHAI, then make the */
  1012. /* conjugate eigenvalue real. */
  1013. if (alphai[jc] < 0.f && jc > 1) {
  1014. alphai[jc - 1] = 0.f;
  1015. } else if (alphai[jc] > 0.f && jc < *n) {
  1016. alphai[jc + 1] = 0.f;
  1017. }
  1018. }
  1019. /* Check for significant underflow in ALPHAR */
  1020. /* Computing MAX */
  1021. r__1 = safmin, r__2 = eps * absai, r__1 = f2cmax(r__1,r__2), r__2 = eps *
  1022. absb;
  1023. if (abs(salfar) < safmin && absar >= f2cmax(r__1,r__2)) {
  1024. ilimit = TRUE_;
  1025. /* Computing MAX */
  1026. /* Computing MAX */
  1027. r__3 = onepls * safmin, r__4 = anrm2 * absar;
  1028. r__1 = scale, r__2 = onepls * safmin / anrm1 / f2cmax(r__3,r__4);
  1029. scale = f2cmax(r__1,r__2);
  1030. }
  1031. /* Check for significant underflow in BETA */
  1032. /* Computing MAX */
  1033. r__1 = safmin, r__2 = eps * absar, r__1 = f2cmax(r__1,r__2), r__2 = eps *
  1034. absai;
  1035. if (abs(sbeta) < safmin && absb >= f2cmax(r__1,r__2)) {
  1036. ilimit = TRUE_;
  1037. /* Computing MAX */
  1038. /* Computing MAX */
  1039. r__3 = onepls * safmin, r__4 = bnrm2 * absb;
  1040. r__1 = scale, r__2 = onepls * safmin / bnrm1 / f2cmax(r__3,r__4);
  1041. scale = f2cmax(r__1,r__2);
  1042. }
  1043. /* Check for possible overflow when limiting scaling */
  1044. if (ilimit) {
  1045. /* Computing MAX */
  1046. r__1 = abs(salfar), r__2 = abs(salfai), r__1 = f2cmax(r__1,r__2),
  1047. r__2 = abs(sbeta);
  1048. temp = scale * safmin * f2cmax(r__1,r__2);
  1049. if (temp > 1.f) {
  1050. scale /= temp;
  1051. }
  1052. if (scale < 1.f) {
  1053. ilimit = FALSE_;
  1054. }
  1055. }
  1056. /* Recompute un-scaled ALPHAR, ALPHAI, BETA if necessary. */
  1057. if (ilimit) {
  1058. salfar = scale * alphar[jc] * anrm;
  1059. salfai = scale * alphai[jc] * anrm;
  1060. sbeta = scale * beta[jc] * bnrm;
  1061. }
  1062. alphar[jc] = salfar;
  1063. alphai[jc] = salfai;
  1064. beta[jc] = sbeta;
  1065. /* L110: */
  1066. }
  1067. L120:
  1068. work[1] = (real) lwkopt;
  1069. return;
  1070. /* End of SGEGV */
  1071. } /* sgegv_ */