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.

sggevx.c 39 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  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 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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static integer c__1 = 1;
  236. static integer c__0 = 0;
  237. static real c_b57 = 0.f;
  238. static real c_b58 = 1.f;
  239. /* > \brief <b> SGGEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE mat
  240. rices</b> */
  241. /* =========== DOCUMENTATION =========== */
  242. /* Online html documentation available at */
  243. /* http://www.netlib.org/lapack/explore-html/ */
  244. /* > \htmlonly */
  245. /* > Download SGGEVX + dependencies */
  246. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggevx.
  247. f"> */
  248. /* > [TGZ]</a> */
  249. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggevx.
  250. f"> */
  251. /* > [ZIP]</a> */
  252. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggevx.
  253. f"> */
  254. /* > [TXT]</a> */
  255. /* > \endhtmlonly */
  256. /* Definition: */
  257. /* =========== */
  258. /* SUBROUTINE SGGEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, B, LDB, */
  259. /* ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, ILO, */
  260. /* IHI, LSCALE, RSCALE, ABNRM, BBNRM, RCONDE, */
  261. /* RCONDV, WORK, LWORK, IWORK, BWORK, INFO ) */
  262. /* CHARACTER BALANC, JOBVL, JOBVR, SENSE */
  263. /* INTEGER IHI, ILO, INFO, LDA, LDB, LDVL, LDVR, LWORK, N */
  264. /* REAL ABNRM, BBNRM */
  265. /* LOGICAL BWORK( * ) */
  266. /* INTEGER IWORK( * ) */
  267. /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  268. /* $ B( LDB, * ), BETA( * ), LSCALE( * ), */
  269. /* $ RCONDE( * ), RCONDV( * ), RSCALE( * ), */
  270. /* $ VL( LDVL, * ), VR( LDVR, * ), WORK( * ) */
  271. /* > \par Purpose: */
  272. /* ============= */
  273. /* > */
  274. /* > \verbatim */
  275. /* > */
  276. /* > SGGEVX computes for a pair of N-by-N real nonsymmetric matrices (A,B) */
  277. /* > the generalized eigenvalues, and optionally, the left and/or right */
  278. /* > generalized eigenvectors. */
  279. /* > */
  280. /* > Optionally also, it computes a balancing transformation to improve */
  281. /* > the conditioning of the eigenvalues and eigenvectors (ILO, IHI, */
  282. /* > LSCALE, RSCALE, ABNRM, and BBNRM), reciprocal condition numbers for */
  283. /* > the eigenvalues (RCONDE), and reciprocal condition numbers for the */
  284. /* > right eigenvectors (RCONDV). */
  285. /* > */
  286. /* > A generalized eigenvalue for a pair of matrices (A,B) is a scalar */
  287. /* > lambda or a ratio alpha/beta = lambda, such that A - lambda*B is */
  288. /* > singular. It is usually represented as the pair (alpha,beta), as */
  289. /* > there is a reasonable interpretation for beta=0, and even for both */
  290. /* > being zero. */
  291. /* > */
  292. /* > The right eigenvector v(j) corresponding to the eigenvalue lambda(j) */
  293. /* > of (A,B) satisfies */
  294. /* > */
  295. /* > A * v(j) = lambda(j) * B * v(j) . */
  296. /* > */
  297. /* > The left eigenvector u(j) corresponding to the eigenvalue lambda(j) */
  298. /* > of (A,B) satisfies */
  299. /* > */
  300. /* > u(j)**H * A = lambda(j) * u(j)**H * B. */
  301. /* > */
  302. /* > where u(j)**H is the conjugate-transpose of u(j). */
  303. /* > */
  304. /* > \endverbatim */
  305. /* Arguments: */
  306. /* ========== */
  307. /* > \param[in] BALANC */
  308. /* > \verbatim */
  309. /* > BALANC is CHARACTER*1 */
  310. /* > Specifies the balance option to be performed. */
  311. /* > = 'N': do not diagonally scale or permute; */
  312. /* > = 'P': permute only; */
  313. /* > = 'S': scale only; */
  314. /* > = 'B': both permute and scale. */
  315. /* > Computed reciprocal condition numbers will be for the */
  316. /* > matrices after permuting and/or balancing. Permuting does */
  317. /* > not change condition numbers (in exact arithmetic), but */
  318. /* > balancing does. */
  319. /* > \endverbatim */
  320. /* > */
  321. /* > \param[in] JOBVL */
  322. /* > \verbatim */
  323. /* > JOBVL is CHARACTER*1 */
  324. /* > = 'N': do not compute the left generalized eigenvectors; */
  325. /* > = 'V': compute the left generalized eigenvectors. */
  326. /* > \endverbatim */
  327. /* > */
  328. /* > \param[in] JOBVR */
  329. /* > \verbatim */
  330. /* > JOBVR is CHARACTER*1 */
  331. /* > = 'N': do not compute the right generalized eigenvectors; */
  332. /* > = 'V': compute the right generalized eigenvectors. */
  333. /* > \endverbatim */
  334. /* > */
  335. /* > \param[in] SENSE */
  336. /* > \verbatim */
  337. /* > SENSE is CHARACTER*1 */
  338. /* > Determines which reciprocal condition numbers are computed. */
  339. /* > = 'N': none are computed; */
  340. /* > = 'E': computed for eigenvalues only; */
  341. /* > = 'V': computed for eigenvectors only; */
  342. /* > = 'B': computed for eigenvalues and eigenvectors. */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[in] N */
  346. /* > \verbatim */
  347. /* > N is INTEGER */
  348. /* > The order of the matrices A, B, VL, and VR. N >= 0. */
  349. /* > \endverbatim */
  350. /* > */
  351. /* > \param[in,out] A */
  352. /* > \verbatim */
  353. /* > A is REAL array, dimension (LDA, N) */
  354. /* > On entry, the matrix A in the pair (A,B). */
  355. /* > On exit, A has been overwritten. If JOBVL='V' or JOBVR='V' */
  356. /* > or both, then A contains the first part of the real Schur */
  357. /* > form of the "balanced" versions of the input A and B. */
  358. /* > \endverbatim */
  359. /* > */
  360. /* > \param[in] LDA */
  361. /* > \verbatim */
  362. /* > LDA is INTEGER */
  363. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  364. /* > \endverbatim */
  365. /* > */
  366. /* > \param[in,out] B */
  367. /* > \verbatim */
  368. /* > B is REAL array, dimension (LDB, N) */
  369. /* > On entry, the matrix B in the pair (A,B). */
  370. /* > On exit, B has been overwritten. If JOBVL='V' or JOBVR='V' */
  371. /* > or both, then B contains the second part of the real Schur */
  372. /* > form of the "balanced" versions of the input A and B. */
  373. /* > \endverbatim */
  374. /* > */
  375. /* > \param[in] LDB */
  376. /* > \verbatim */
  377. /* > LDB is INTEGER */
  378. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  379. /* > \endverbatim */
  380. /* > */
  381. /* > \param[out] ALPHAR */
  382. /* > \verbatim */
  383. /* > ALPHAR is REAL array, dimension (N) */
  384. /* > \endverbatim */
  385. /* > */
  386. /* > \param[out] ALPHAI */
  387. /* > \verbatim */
  388. /* > ALPHAI is REAL array, dimension (N) */
  389. /* > \endverbatim */
  390. /* > */
  391. /* > \param[out] BETA */
  392. /* > \verbatim */
  393. /* > BETA is REAL array, dimension (N) */
  394. /* > On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
  395. /* > be the generalized eigenvalues. If ALPHAI(j) is zero, then */
  396. /* > the j-th eigenvalue is real; if positive, then the j-th and */
  397. /* > (j+1)-st eigenvalues are a complex conjugate pair, with */
  398. /* > ALPHAI(j+1) negative. */
  399. /* > */
  400. /* > Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
  401. /* > may easily over- or underflow, and BETA(j) may even be zero. */
  402. /* > Thus, the user should avoid naively computing the ratio */
  403. /* > ALPHA/BETA. However, ALPHAR and ALPHAI will be always less */
  404. /* > than and usually comparable with norm(A) in magnitude, and */
  405. /* > BETA always less than and usually comparable with norm(B). */
  406. /* > \endverbatim */
  407. /* > */
  408. /* > \param[out] VL */
  409. /* > \verbatim */
  410. /* > VL is REAL array, dimension (LDVL,N) */
  411. /* > If JOBVL = 'V', the left eigenvectors u(j) are stored one */
  412. /* > after another in the columns of VL, in the same order as */
  413. /* > their eigenvalues. If the j-th eigenvalue is real, then */
  414. /* > u(j) = VL(:,j), the j-th column of VL. If the j-th and */
  415. /* > (j+1)-th eigenvalues form a complex conjugate pair, then */
  416. /* > u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1). */
  417. /* > Each eigenvector will be scaled so the largest component have */
  418. /* > abs(real part) + abs(imag. part) = 1. */
  419. /* > Not referenced if JOBVL = 'N'. */
  420. /* > \endverbatim */
  421. /* > */
  422. /* > \param[in] LDVL */
  423. /* > \verbatim */
  424. /* > LDVL is INTEGER */
  425. /* > The leading dimension of the matrix VL. LDVL >= 1, and */
  426. /* > if JOBVL = 'V', LDVL >= N. */
  427. /* > \endverbatim */
  428. /* > */
  429. /* > \param[out] VR */
  430. /* > \verbatim */
  431. /* > VR is REAL array, dimension (LDVR,N) */
  432. /* > If JOBVR = 'V', the right eigenvectors v(j) are stored one */
  433. /* > after another in the columns of VR, in the same order as */
  434. /* > their eigenvalues. If the j-th eigenvalue is real, then */
  435. /* > v(j) = VR(:,j), the j-th column of VR. If the j-th and */
  436. /* > (j+1)-th eigenvalues form a complex conjugate pair, then */
  437. /* > v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1). */
  438. /* > Each eigenvector will be scaled so the largest component have */
  439. /* > abs(real part) + abs(imag. part) = 1. */
  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] ILO */
  451. /* > \verbatim */
  452. /* > ILO is INTEGER */
  453. /* > \endverbatim */
  454. /* > */
  455. /* > \param[out] IHI */
  456. /* > \verbatim */
  457. /* > IHI is INTEGER */
  458. /* > ILO and IHI are integer values such that on exit */
  459. /* > A(i,j) = 0 and B(i,j) = 0 if i > j and */
  460. /* > j = 1,...,ILO-1 or i = IHI+1,...,N. */
  461. /* > If BALANC = 'N' or 'S', ILO = 1 and IHI = N. */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[out] LSCALE */
  465. /* > \verbatim */
  466. /* > LSCALE is REAL array, dimension (N) */
  467. /* > Details of the permutations and scaling factors applied */
  468. /* > to the left side of A and B. If PL(j) is the index of the */
  469. /* > row interchanged with row j, and DL(j) is the scaling */
  470. /* > factor applied to row j, then */
  471. /* > LSCALE(j) = PL(j) for j = 1,...,ILO-1 */
  472. /* > = DL(j) for j = ILO,...,IHI */
  473. /* > = PL(j) for j = IHI+1,...,N. */
  474. /* > The order in which the interchanges are made is N to IHI+1, */
  475. /* > then 1 to ILO-1. */
  476. /* > \endverbatim */
  477. /* > */
  478. /* > \param[out] RSCALE */
  479. /* > \verbatim */
  480. /* > RSCALE is REAL array, dimension (N) */
  481. /* > Details of the permutations and scaling factors applied */
  482. /* > to the right side of A and B. If PR(j) is the index of the */
  483. /* > column interchanged with column j, and DR(j) is the scaling */
  484. /* > factor applied to column j, then */
  485. /* > RSCALE(j) = PR(j) for j = 1,...,ILO-1 */
  486. /* > = DR(j) for j = ILO,...,IHI */
  487. /* > = PR(j) for j = IHI+1,...,N */
  488. /* > The order in which the interchanges are made is N to IHI+1, */
  489. /* > then 1 to ILO-1. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[out] ABNRM */
  493. /* > \verbatim */
  494. /* > ABNRM is REAL */
  495. /* > The one-norm of the balanced matrix A. */
  496. /* > \endverbatim */
  497. /* > */
  498. /* > \param[out] BBNRM */
  499. /* > \verbatim */
  500. /* > BBNRM is REAL */
  501. /* > The one-norm of the balanced matrix B. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[out] RCONDE */
  505. /* > \verbatim */
  506. /* > RCONDE is REAL array, dimension (N) */
  507. /* > If SENSE = 'E' or 'B', the reciprocal condition numbers of */
  508. /* > the eigenvalues, stored in consecutive elements of the array. */
  509. /* > For a complex conjugate pair of eigenvalues two consecutive */
  510. /* > elements of RCONDE are set to the same value. Thus RCONDE(j), */
  511. /* > RCONDV(j), and the j-th columns of VL and VR all correspond */
  512. /* > to the j-th eigenpair. */
  513. /* > If SENSE = 'N' or 'V', RCONDE is not referenced. */
  514. /* > \endverbatim */
  515. /* > */
  516. /* > \param[out] RCONDV */
  517. /* > \verbatim */
  518. /* > RCONDV is REAL array, dimension (N) */
  519. /* > If SENSE = 'V' or 'B', the estimated reciprocal condition */
  520. /* > numbers of the eigenvectors, stored in consecutive elements */
  521. /* > of the array. For a complex eigenvector two consecutive */
  522. /* > elements of RCONDV are set to the same value. If the */
  523. /* > eigenvalues cannot be reordered to compute RCONDV(j), */
  524. /* > RCONDV(j) is set to 0; this can only occur when the true */
  525. /* > value would be very small anyway. */
  526. /* > If SENSE = 'N' or 'E', RCONDV is not referenced. */
  527. /* > \endverbatim */
  528. /* > */
  529. /* > \param[out] WORK */
  530. /* > \verbatim */
  531. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  532. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[in] LWORK */
  536. /* > \verbatim */
  537. /* > LWORK is INTEGER */
  538. /* > The dimension of the array WORK. LWORK >= f2cmax(1,2*N). */
  539. /* > If BALANC = 'S' or 'B', or JOBVL = 'V', or JOBVR = 'V', */
  540. /* > LWORK >= f2cmax(1,6*N). */
  541. /* > If SENSE = 'E', LWORK >= f2cmax(1,10*N). */
  542. /* > If SENSE = 'V' or 'B', LWORK >= 2*N*N+8*N+16. */
  543. /* > */
  544. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  545. /* > only calculates the optimal size of the WORK array, returns */
  546. /* > this value as the first entry of the WORK array, and no error */
  547. /* > message related to LWORK is issued by XERBLA. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[out] IWORK */
  551. /* > \verbatim */
  552. /* > IWORK is INTEGER array, dimension (N+6) */
  553. /* > If SENSE = 'E', IWORK is not referenced. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[out] BWORK */
  557. /* > \verbatim */
  558. /* > BWORK is LOGICAL array, dimension (N) */
  559. /* > If SENSE = 'N', BWORK is not referenced. */
  560. /* > \endverbatim */
  561. /* > */
  562. /* > \param[out] INFO */
  563. /* > \verbatim */
  564. /* > INFO is INTEGER */
  565. /* > = 0: successful exit */
  566. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  567. /* > = 1,...,N: */
  568. /* > The QZ iteration failed. No eigenvectors have been */
  569. /* > calculated, but ALPHAR(j), ALPHAI(j), and BETA(j) */
  570. /* > should be correct for j=INFO+1,...,N. */
  571. /* > > N: =N+1: other than QZ iteration failed in SHGEQZ. */
  572. /* > =N+2: error return from STGEVC. */
  573. /* > \endverbatim */
  574. /* Authors: */
  575. /* ======== */
  576. /* > \author Univ. of Tennessee */
  577. /* > \author Univ. of California Berkeley */
  578. /* > \author Univ. of Colorado Denver */
  579. /* > \author NAG Ltd. */
  580. /* > \date April 2012 */
  581. /* > \ingroup realGEeigen */
  582. /* > \par Further Details: */
  583. /* ===================== */
  584. /* > */
  585. /* > \verbatim */
  586. /* > */
  587. /* > Balancing a matrix pair (A,B) includes, first, permuting rows and */
  588. /* > columns to isolate eigenvalues, second, applying diagonal similarity */
  589. /* > transformation to the rows and columns to make the rows and columns */
  590. /* > as close in norm as possible. The computed reciprocal condition */
  591. /* > numbers correspond to the balanced matrix. Permuting rows and columns */
  592. /* > will not change the condition numbers (in exact arithmetic) but */
  593. /* > diagonal scaling will. For further explanation of balancing, see */
  594. /* > section 4.11.1.2 of LAPACK Users' Guide. */
  595. /* > */
  596. /* > An approximate error bound on the chordal distance between the i-th */
  597. /* > computed generalized eigenvalue w and the corresponding exact */
  598. /* > eigenvalue lambda is */
  599. /* > */
  600. /* > chord(w, lambda) <= EPS * norm(ABNRM, BBNRM) / RCONDE(I) */
  601. /* > */
  602. /* > An approximate error bound for the angle between the i-th computed */
  603. /* > eigenvector VL(i) or VR(i) is given by */
  604. /* > */
  605. /* > EPS * norm(ABNRM, BBNRM) / DIF(i). */
  606. /* > */
  607. /* > For further explanation of the reciprocal condition numbers RCONDE */
  608. /* > and RCONDV, see section 4.11 of LAPACK User's Guide. */
  609. /* > \endverbatim */
  610. /* > */
  611. /* ===================================================================== */
  612. /* Subroutine */ void sggevx_(char *balanc, char *jobvl, char *jobvr, char *
  613. sense, integer *n, real *a, integer *lda, real *b, integer *ldb, real
  614. *alphar, real *alphai, real *beta, real *vl, integer *ldvl, real *vr,
  615. integer *ldvr, integer *ilo, integer *ihi, real *lscale, real *rscale,
  616. real *abnrm, real *bbnrm, real *rconde, real *rcondv, real *work,
  617. integer *lwork, integer *iwork, logical *bwork, integer *info)
  618. {
  619. /* System generated locals */
  620. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  621. vr_offset, i__1, i__2;
  622. real r__1, r__2, r__3, r__4;
  623. /* Local variables */
  624. logical pair;
  625. real anrm, bnrm;
  626. integer ierr, itau;
  627. real temp;
  628. logical ilvl, ilvr;
  629. integer iwrk, iwrk1, i__, j, m;
  630. extern logical lsame_(char *, char *);
  631. integer icols;
  632. logical noscl;
  633. integer irows, jc;
  634. extern /* Subroutine */ void slabad_(real *, real *);
  635. integer in, mm, jr;
  636. extern /* Subroutine */ void sggbak_(char *, char *, integer *, integer *,
  637. integer *, real *, real *, integer *, real *, integer *, integer *
  638. ), sggbal_(char *, integer *, real *, integer *,
  639. real *, integer *, integer *, integer *, real *, real *, real *,
  640. integer *);
  641. logical ilascl, ilbscl;
  642. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  643. extern void sgghrd_(
  644. char *, char *, integer *, integer *, integer *, real *, integer *
  645. , real *, integer *, real *, integer *, real *, integer *,
  646. integer *);
  647. logical ldumma[1];
  648. char chtemp[1];
  649. real bignum;
  650. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  651. real *, integer *, integer *, real *, integer *, integer *);
  652. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  653. integer *, integer *, ftnlen, ftnlen);
  654. extern real slamch_(char *);
  655. integer ijobvl;
  656. extern real slange_(char *, integer *, integer *, real *, integer *, real
  657. *);
  658. extern /* Subroutine */ void sgeqrf_(integer *, integer *, real *, integer
  659. *, real *, real *, integer *, integer *);
  660. integer ijobvr;
  661. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  662. integer *, real *, integer *);
  663. logical wantsb;
  664. extern /* Subroutine */ void slaset_(char *, integer *, integer *, real *,
  665. real *, real *, integer *);
  666. real anrmto;
  667. logical wantse;
  668. real bnrmto;
  669. extern /* Subroutine */ void shgeqz_(char *, char *, char *, integer *,
  670. integer *, integer *, real *, integer *, real *, integer *, real *
  671. , real *, real *, real *, integer *, real *, integer *, real *,
  672. integer *, integer *), stgevc_(char *,
  673. char *, logical *, integer *, real *, integer *, real *, integer *
  674. , real *, integer *, real *, integer *, integer *, integer *,
  675. real *, integer *), stgsna_(char *, char *,
  676. logical *, integer *, real *, integer *, real *, integer *, real *
  677. , integer *, real *, integer *, real *, real *, integer *,
  678. integer *, real *, integer *, integer *, integer *);
  679. integer minwrk, maxwrk;
  680. logical wantsn;
  681. real smlnum;
  682. extern /* Subroutine */ void sorgqr_(integer *, integer *, integer *, real
  683. *, integer *, real *, real *, integer *, integer *);
  684. logical lquery, wantsv;
  685. extern /* Subroutine */ void sormqr_(char *, char *, integer *, integer *,
  686. integer *, real *, integer *, real *, real *, integer *, real *,
  687. integer *, integer *);
  688. real eps;
  689. logical ilv;
  690. /* -- LAPACK driver routine (version 3.7.0) -- */
  691. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  692. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  693. /* April 2012 */
  694. /* ===================================================================== */
  695. /* Decode the input arguments */
  696. /* Parameter adjustments */
  697. a_dim1 = *lda;
  698. a_offset = 1 + a_dim1 * 1;
  699. a -= a_offset;
  700. b_dim1 = *ldb;
  701. b_offset = 1 + b_dim1 * 1;
  702. b -= b_offset;
  703. --alphar;
  704. --alphai;
  705. --beta;
  706. vl_dim1 = *ldvl;
  707. vl_offset = 1 + vl_dim1 * 1;
  708. vl -= vl_offset;
  709. vr_dim1 = *ldvr;
  710. vr_offset = 1 + vr_dim1 * 1;
  711. vr -= vr_offset;
  712. --lscale;
  713. --rscale;
  714. --rconde;
  715. --rcondv;
  716. --work;
  717. --iwork;
  718. --bwork;
  719. /* Function Body */
  720. if (lsame_(jobvl, "N")) {
  721. ijobvl = 1;
  722. ilvl = FALSE_;
  723. } else if (lsame_(jobvl, "V")) {
  724. ijobvl = 2;
  725. ilvl = TRUE_;
  726. } else {
  727. ijobvl = -1;
  728. ilvl = FALSE_;
  729. }
  730. if (lsame_(jobvr, "N")) {
  731. ijobvr = 1;
  732. ilvr = FALSE_;
  733. } else if (lsame_(jobvr, "V")) {
  734. ijobvr = 2;
  735. ilvr = TRUE_;
  736. } else {
  737. ijobvr = -1;
  738. ilvr = FALSE_;
  739. }
  740. ilv = ilvl || ilvr;
  741. noscl = lsame_(balanc, "N") || lsame_(balanc, "P");
  742. wantsn = lsame_(sense, "N");
  743. wantse = lsame_(sense, "E");
  744. wantsv = lsame_(sense, "V");
  745. wantsb = lsame_(sense, "B");
  746. /* Test the input arguments */
  747. *info = 0;
  748. lquery = *lwork == -1;
  749. if (! (noscl || lsame_(balanc, "S") || lsame_(
  750. balanc, "B"))) {
  751. *info = -1;
  752. } else if (ijobvl <= 0) {
  753. *info = -2;
  754. } else if (ijobvr <= 0) {
  755. *info = -3;
  756. } else if (! (wantsn || wantse || wantsb || wantsv)) {
  757. *info = -4;
  758. } else if (*n < 0) {
  759. *info = -5;
  760. } else if (*lda < f2cmax(1,*n)) {
  761. *info = -7;
  762. } else if (*ldb < f2cmax(1,*n)) {
  763. *info = -9;
  764. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  765. *info = -14;
  766. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  767. *info = -16;
  768. }
  769. /* Compute workspace */
  770. /* (Note: Comments in the code beginning "Workspace:" describe the */
  771. /* minimal amount of workspace needed at that point in the code, */
  772. /* as well as the preferred amount for good performance. */
  773. /* NB refers to the optimal block size for the immediately */
  774. /* following subroutine, as returned by ILAENV. The workspace is */
  775. /* computed assuming ILO = 1 and IHI = N, the worst case.) */
  776. if (*info == 0) {
  777. if (*n == 0) {
  778. minwrk = 1;
  779. maxwrk = 1;
  780. } else {
  781. if (noscl && ! ilv) {
  782. minwrk = *n << 1;
  783. } else {
  784. minwrk = *n * 6;
  785. }
  786. if (wantse) {
  787. minwrk = *n * 10;
  788. } else if (wantsv || wantsb) {
  789. minwrk = (*n << 1) * (*n + 4) + 16;
  790. }
  791. maxwrk = minwrk;
  792. /* Computing MAX */
  793. i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "SGEQRF", " ", n, &
  794. c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  795. maxwrk = f2cmax(i__1,i__2);
  796. /* Computing MAX */
  797. i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "SORMQR", " ", n, &
  798. c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  799. maxwrk = f2cmax(i__1,i__2);
  800. if (ilvl) {
  801. /* Computing MAX */
  802. i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "SORGQR",
  803. " ", n, &c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  804. maxwrk = f2cmax(i__1,i__2);
  805. }
  806. }
  807. work[1] = (real) maxwrk;
  808. if (*lwork < minwrk && ! lquery) {
  809. *info = -26;
  810. }
  811. }
  812. if (*info != 0) {
  813. i__1 = -(*info);
  814. xerbla_("SGGEVX", &i__1, (ftnlen)6);
  815. return;
  816. } else if (lquery) {
  817. return;
  818. }
  819. /* Quick return if possible */
  820. if (*n == 0) {
  821. return;
  822. }
  823. /* Get machine constants */
  824. eps = slamch_("P");
  825. smlnum = slamch_("S");
  826. bignum = 1.f / smlnum;
  827. slabad_(&smlnum, &bignum);
  828. smlnum = sqrt(smlnum) / eps;
  829. bignum = 1.f / smlnum;
  830. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  831. anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
  832. ilascl = FALSE_;
  833. if (anrm > 0.f && anrm < smlnum) {
  834. anrmto = smlnum;
  835. ilascl = TRUE_;
  836. } else if (anrm > bignum) {
  837. anrmto = bignum;
  838. ilascl = TRUE_;
  839. }
  840. if (ilascl) {
  841. slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  842. ierr);
  843. }
  844. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  845. bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
  846. ilbscl = FALSE_;
  847. if (bnrm > 0.f && bnrm < smlnum) {
  848. bnrmto = smlnum;
  849. ilbscl = TRUE_;
  850. } else if (bnrm > bignum) {
  851. bnrmto = bignum;
  852. ilbscl = TRUE_;
  853. }
  854. if (ilbscl) {
  855. slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  856. ierr);
  857. }
  858. /* Permute and/or balance the matrix pair (A,B) */
  859. /* (Workspace: need 6*N if BALANC = 'S' or 'B', 1 otherwise) */
  860. sggbal_(balanc, n, &a[a_offset], lda, &b[b_offset], ldb, ilo, ihi, &
  861. lscale[1], &rscale[1], &work[1], &ierr);
  862. /* Compute ABNRM and BBNRM */
  863. *abnrm = slange_("1", n, n, &a[a_offset], lda, &work[1]);
  864. if (ilascl) {
  865. work[1] = *abnrm;
  866. slascl_("G", &c__0, &c__0, &anrmto, &anrm, &c__1, &c__1, &work[1], &
  867. c__1, &ierr);
  868. *abnrm = work[1];
  869. }
  870. *bbnrm = slange_("1", n, n, &b[b_offset], ldb, &work[1]);
  871. if (ilbscl) {
  872. work[1] = *bbnrm;
  873. slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, &c__1, &c__1, &work[1], &
  874. c__1, &ierr);
  875. *bbnrm = work[1];
  876. }
  877. /* Reduce B to triangular form (QR decomposition of B) */
  878. /* (Workspace: need N, prefer N*NB ) */
  879. irows = *ihi + 1 - *ilo;
  880. if (ilv || ! wantsn) {
  881. icols = *n + 1 - *ilo;
  882. } else {
  883. icols = irows;
  884. }
  885. itau = 1;
  886. iwrk = itau + irows;
  887. i__1 = *lwork + 1 - iwrk;
  888. sgeqrf_(&irows, &icols, &b[*ilo + *ilo * b_dim1], ldb, &work[itau], &work[
  889. iwrk], &i__1, &ierr);
  890. /* Apply the orthogonal transformation to A */
  891. /* (Workspace: need N, prefer N*NB) */
  892. i__1 = *lwork + 1 - iwrk;
  893. sormqr_("L", "T", &irows, &icols, &irows, &b[*ilo + *ilo * b_dim1], ldb, &
  894. work[itau], &a[*ilo + *ilo * a_dim1], lda, &work[iwrk], &i__1, &
  895. ierr);
  896. /* Initialize VL and/or VR */
  897. /* (Workspace: need N, prefer N*NB) */
  898. if (ilvl) {
  899. slaset_("Full", n, n, &c_b57, &c_b58, &vl[vl_offset], ldvl)
  900. ;
  901. if (irows > 1) {
  902. i__1 = irows - 1;
  903. i__2 = irows - 1;
  904. slacpy_("L", &i__1, &i__2, &b[*ilo + 1 + *ilo * b_dim1], ldb, &vl[
  905. *ilo + 1 + *ilo * vl_dim1], ldvl);
  906. }
  907. i__1 = *lwork + 1 - iwrk;
  908. sorgqr_(&irows, &irows, &irows, &vl[*ilo + *ilo * vl_dim1], ldvl, &
  909. work[itau], &work[iwrk], &i__1, &ierr);
  910. }
  911. if (ilvr) {
  912. slaset_("Full", n, n, &c_b57, &c_b58, &vr[vr_offset], ldvr)
  913. ;
  914. }
  915. /* Reduce to generalized Hessenberg form */
  916. /* (Workspace: none needed) */
  917. if (ilv || ! wantsn) {
  918. /* Eigenvectors requested -- work on whole matrix. */
  919. sgghrd_(jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset],
  920. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
  921. } else {
  922. sgghrd_("N", "N", &irows, &c__1, &irows, &a[*ilo + *ilo * a_dim1],
  923. lda, &b[*ilo + *ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  924. vr_offset], ldvr, &ierr);
  925. }
  926. /* Perform QZ algorithm (Compute eigenvalues, and optionally, the */
  927. /* Schur forms and Schur vectors) */
  928. /* (Workspace: need N) */
  929. if (ilv || ! wantsn) {
  930. *(unsigned char *)chtemp = 'S';
  931. } else {
  932. *(unsigned char *)chtemp = 'E';
  933. }
  934. shgeqz_(chtemp, jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset]
  935. , ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset], ldvl, &
  936. vr[vr_offset], ldvr, &work[1], lwork, &ierr);
  937. if (ierr != 0) {
  938. if (ierr > 0 && ierr <= *n) {
  939. *info = ierr;
  940. } else if (ierr > *n && ierr <= *n << 1) {
  941. *info = ierr - *n;
  942. } else {
  943. *info = *n + 1;
  944. }
  945. goto L130;
  946. }
  947. /* Compute Eigenvectors and estimate condition numbers if desired */
  948. /* (Workspace: STGEVC: need 6*N */
  949. /* STGSNA: need 2*N*(N+2)+16 if SENSE = 'V' or 'B', */
  950. /* need N otherwise ) */
  951. if (ilv || ! wantsn) {
  952. if (ilv) {
  953. if (ilvl) {
  954. if (ilvr) {
  955. *(unsigned char *)chtemp = 'B';
  956. } else {
  957. *(unsigned char *)chtemp = 'L';
  958. }
  959. } else {
  960. *(unsigned char *)chtemp = 'R';
  961. }
  962. stgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset],
  963. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &
  964. work[1], &ierr);
  965. if (ierr != 0) {
  966. *info = *n + 2;
  967. goto L130;
  968. }
  969. }
  970. if (! wantsn) {
  971. /* compute eigenvectors (STGEVC) and estimate condition */
  972. /* numbers (STGSNA). Note that the definition of the condition */
  973. /* number is not invariant under transformation (u,v) to */
  974. /* (Q*u, Z*v), where (u,v) are eigenvectors of the generalized */
  975. /* Schur form (S,T), Q and Z are orthogonal matrices. In order */
  976. /* to avoid using extra 2*N*N workspace, we have to recalculate */
  977. /* eigenvectors and estimate one condition numbers at a time. */
  978. pair = FALSE_;
  979. i__1 = *n;
  980. for (i__ = 1; i__ <= i__1; ++i__) {
  981. if (pair) {
  982. pair = FALSE_;
  983. goto L20;
  984. }
  985. mm = 1;
  986. if (i__ < *n) {
  987. if (a[i__ + 1 + i__ * a_dim1] != 0.f) {
  988. pair = TRUE_;
  989. mm = 2;
  990. }
  991. }
  992. i__2 = *n;
  993. for (j = 1; j <= i__2; ++j) {
  994. bwork[j] = FALSE_;
  995. /* L10: */
  996. }
  997. if (mm == 1) {
  998. bwork[i__] = TRUE_;
  999. } else if (mm == 2) {
  1000. bwork[i__] = TRUE_;
  1001. bwork[i__ + 1] = TRUE_;
  1002. }
  1003. iwrk = mm * *n + 1;
  1004. iwrk1 = iwrk + mm * *n;
  1005. /* Compute a pair of left and right eigenvectors. */
  1006. /* (compute workspace: need up to 4*N + 6*N) */
  1007. if (wantse || wantsb) {
  1008. stgevc_("B", "S", &bwork[1], n, &a[a_offset], lda, &b[
  1009. b_offset], ldb, &work[1], n, &work[iwrk], n, &mm,
  1010. &m, &work[iwrk1], &ierr);
  1011. if (ierr != 0) {
  1012. *info = *n + 2;
  1013. goto L130;
  1014. }
  1015. }
  1016. i__2 = *lwork - iwrk1 + 1;
  1017. stgsna_(sense, "S", &bwork[1], n, &a[a_offset], lda, &b[
  1018. b_offset], ldb, &work[1], n, &work[iwrk], n, &rconde[
  1019. i__], &rcondv[i__], &mm, &m, &work[iwrk1], &i__2, &
  1020. iwork[1], &ierr);
  1021. L20:
  1022. ;
  1023. }
  1024. }
  1025. }
  1026. /* Undo balancing on VL and VR and normalization */
  1027. /* (Workspace: none needed) */
  1028. if (ilvl) {
  1029. sggbak_(balanc, "L", n, ilo, ihi, &lscale[1], &rscale[1], n, &vl[
  1030. vl_offset], ldvl, &ierr);
  1031. i__1 = *n;
  1032. for (jc = 1; jc <= i__1; ++jc) {
  1033. if (alphai[jc] < 0.f) {
  1034. goto L70;
  1035. }
  1036. temp = 0.f;
  1037. if (alphai[jc] == 0.f) {
  1038. i__2 = *n;
  1039. for (jr = 1; jr <= i__2; ++jr) {
  1040. /* Computing MAX */
  1041. r__2 = temp, r__3 = (r__1 = vl[jr + jc * vl_dim1], abs(
  1042. r__1));
  1043. temp = f2cmax(r__2,r__3);
  1044. /* L30: */
  1045. }
  1046. } else {
  1047. i__2 = *n;
  1048. for (jr = 1; jr <= i__2; ++jr) {
  1049. /* Computing MAX */
  1050. r__3 = temp, r__4 = (r__1 = vl[jr + jc * vl_dim1], abs(
  1051. r__1)) + (r__2 = vl[jr + (jc + 1) * vl_dim1], abs(
  1052. r__2));
  1053. temp = f2cmax(r__3,r__4);
  1054. /* L40: */
  1055. }
  1056. }
  1057. if (temp < smlnum) {
  1058. goto L70;
  1059. }
  1060. temp = 1.f / temp;
  1061. if (alphai[jc] == 0.f) {
  1062. i__2 = *n;
  1063. for (jr = 1; jr <= i__2; ++jr) {
  1064. vl[jr + jc * vl_dim1] *= temp;
  1065. /* L50: */
  1066. }
  1067. } else {
  1068. i__2 = *n;
  1069. for (jr = 1; jr <= i__2; ++jr) {
  1070. vl[jr + jc * vl_dim1] *= temp;
  1071. vl[jr + (jc + 1) * vl_dim1] *= temp;
  1072. /* L60: */
  1073. }
  1074. }
  1075. L70:
  1076. ;
  1077. }
  1078. }
  1079. if (ilvr) {
  1080. sggbak_(balanc, "R", n, ilo, ihi, &lscale[1], &rscale[1], n, &vr[
  1081. vr_offset], ldvr, &ierr);
  1082. i__1 = *n;
  1083. for (jc = 1; jc <= i__1; ++jc) {
  1084. if (alphai[jc] < 0.f) {
  1085. goto L120;
  1086. }
  1087. temp = 0.f;
  1088. if (alphai[jc] == 0.f) {
  1089. i__2 = *n;
  1090. for (jr = 1; jr <= i__2; ++jr) {
  1091. /* Computing MAX */
  1092. r__2 = temp, r__3 = (r__1 = vr[jr + jc * vr_dim1], abs(
  1093. r__1));
  1094. temp = f2cmax(r__2,r__3);
  1095. /* L80: */
  1096. }
  1097. } else {
  1098. i__2 = *n;
  1099. for (jr = 1; jr <= i__2; ++jr) {
  1100. /* Computing MAX */
  1101. r__3 = temp, r__4 = (r__1 = vr[jr + jc * vr_dim1], abs(
  1102. r__1)) + (r__2 = vr[jr + (jc + 1) * vr_dim1], abs(
  1103. r__2));
  1104. temp = f2cmax(r__3,r__4);
  1105. /* L90: */
  1106. }
  1107. }
  1108. if (temp < smlnum) {
  1109. goto L120;
  1110. }
  1111. temp = 1.f / temp;
  1112. if (alphai[jc] == 0.f) {
  1113. i__2 = *n;
  1114. for (jr = 1; jr <= i__2; ++jr) {
  1115. vr[jr + jc * vr_dim1] *= temp;
  1116. /* L100: */
  1117. }
  1118. } else {
  1119. i__2 = *n;
  1120. for (jr = 1; jr <= i__2; ++jr) {
  1121. vr[jr + jc * vr_dim1] *= temp;
  1122. vr[jr + (jc + 1) * vr_dim1] *= temp;
  1123. /* L110: */
  1124. }
  1125. }
  1126. L120:
  1127. ;
  1128. }
  1129. }
  1130. /* Undo scaling if necessary */
  1131. L130:
  1132. if (ilascl) {
  1133. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  1134. ierr);
  1135. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  1136. ierr);
  1137. }
  1138. if (ilbscl) {
  1139. slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  1140. ierr);
  1141. }
  1142. work[1] = (real) maxwrk;
  1143. return;
  1144. /* End of SGGEVX */
  1145. } /* sggevx_ */