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