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.

sggesx.c 37 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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. /* procedure parameter types for -A and -C++ */
  231. #ifdef __cplusplus
  232. typedef logical (*L_fp)(...);
  233. #else
  234. typedef logical (*L_fp)();
  235. #endif
  236. /* -- translated by f2c (version 20000121).
  237. You must link the resulting object file with the libraries:
  238. -lf2c -lm (in that order)
  239. */
  240. /* Table of constant values */
  241. static integer c__1 = 1;
  242. static integer c__0 = 0;
  243. static integer c_n1 = -1;
  244. static real c_b42 = 0.f;
  245. static real c_b43 = 1.f;
  246. /* > \brief <b> SGGESX computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors
  247. for GE matrices</b> */
  248. /* =========== DOCUMENTATION =========== */
  249. /* Online html documentation available at */
  250. /* http://www.netlib.org/lapack/explore-html/ */
  251. /* > \htmlonly */
  252. /* > Download SGGESX + dependencies */
  253. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggesx.
  254. f"> */
  255. /* > [TGZ]</a> */
  256. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggesx.
  257. f"> */
  258. /* > [ZIP]</a> */
  259. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggesx.
  260. f"> */
  261. /* > [TXT]</a> */
  262. /* > \endhtmlonly */
  263. /* Definition: */
  264. /* =========== */
  265. /* SUBROUTINE SGGESX( JOBVSL, JOBVSR, SORT, SELCTG, SENSE, N, A, LDA, */
  266. /* B, LDB, SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL, */
  267. /* VSR, LDVSR, RCONDE, RCONDV, WORK, LWORK, IWORK, */
  268. /* LIWORK, BWORK, INFO ) */
  269. /* CHARACTER JOBVSL, JOBVSR, SENSE, SORT */
  270. /* INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LIWORK, LWORK, N, */
  271. /* $ SDIM */
  272. /* LOGICAL BWORK( * ) */
  273. /* INTEGER IWORK( * ) */
  274. /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  275. /* $ B( LDB, * ), BETA( * ), RCONDE( 2 ), */
  276. /* $ RCONDV( 2 ), VSL( LDVSL, * ), VSR( LDVSR, * ), */
  277. /* $ WORK( * ) */
  278. /* LOGICAL SELCTG */
  279. /* EXTERNAL SELCTG */
  280. /* > \par Purpose: */
  281. /* ============= */
  282. /* > */
  283. /* > \verbatim */
  284. /* > */
  285. /* > SGGESX computes for a pair of N-by-N real nonsymmetric matrices */
  286. /* > (A,B), the generalized eigenvalues, the real Schur form (S,T), and, */
  287. /* > optionally, the left and/or right matrices of Schur vectors (VSL and */
  288. /* > VSR). This gives the generalized Schur factorization */
  289. /* > */
  290. /* > (A,B) = ( (VSL) S (VSR)**T, (VSL) T (VSR)**T ) */
  291. /* > */
  292. /* > Optionally, it also orders the eigenvalues so that a selected cluster */
  293. /* > of eigenvalues appears in the leading diagonal blocks of the upper */
  294. /* > quasi-triangular matrix S and the upper triangular matrix T; computes */
  295. /* > a reciprocal condition number for the average of the selected */
  296. /* > eigenvalues (RCONDE); and computes a reciprocal condition number for */
  297. /* > the right and left deflating subspaces corresponding to the selected */
  298. /* > eigenvalues (RCONDV). The leading columns of VSL and VSR then form */
  299. /* > an orthonormal basis for the corresponding left and right eigenspaces */
  300. /* > (deflating subspaces). */
  301. /* > */
  302. /* > A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */
  303. /* > or a ratio alpha/beta = w, such that A - w*B is singular. It is */
  304. /* > usually represented as the pair (alpha,beta), as there is a */
  305. /* > reasonable interpretation for beta=0 or for both being zero. */
  306. /* > */
  307. /* > A pair of matrices (S,T) is in generalized real Schur form if T is */
  308. /* > upper triangular with non-negative diagonal and S is block upper */
  309. /* > triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond */
  310. /* > to real generalized eigenvalues, while 2-by-2 blocks of S will be */
  311. /* > "standardized" by making the corresponding elements of T have the */
  312. /* > form: */
  313. /* > [ a 0 ] */
  314. /* > [ 0 b ] */
  315. /* > */
  316. /* > and the pair of corresponding 2-by-2 blocks in S and T will have a */
  317. /* > complex conjugate pair of generalized eigenvalues. */
  318. /* > */
  319. /* > \endverbatim */
  320. /* Arguments: */
  321. /* ========== */
  322. /* > \param[in] JOBVSL */
  323. /* > \verbatim */
  324. /* > JOBVSL is CHARACTER*1 */
  325. /* > = 'N': do not compute the left Schur vectors; */
  326. /* > = 'V': compute the left Schur vectors. */
  327. /* > \endverbatim */
  328. /* > */
  329. /* > \param[in] JOBVSR */
  330. /* > \verbatim */
  331. /* > JOBVSR is CHARACTER*1 */
  332. /* > = 'N': do not compute the right Schur vectors; */
  333. /* > = 'V': compute the right Schur vectors. */
  334. /* > \endverbatim */
  335. /* > */
  336. /* > \param[in] SORT */
  337. /* > \verbatim */
  338. /* > SORT is CHARACTER*1 */
  339. /* > Specifies whether or not to order the eigenvalues on the */
  340. /* > diagonal of the generalized Schur form. */
  341. /* > = 'N': Eigenvalues are not ordered; */
  342. /* > = 'S': Eigenvalues are ordered (see SELCTG). */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[in] SELCTG */
  346. /* > \verbatim */
  347. /* > SELCTG is a LOGICAL FUNCTION of three REAL arguments */
  348. /* > SELCTG must be declared EXTERNAL in the calling subroutine. */
  349. /* > If SORT = 'N', SELCTG is not referenced. */
  350. /* > If SORT = 'S', SELCTG is used to select eigenvalues to sort */
  351. /* > to the top left of the Schur form. */
  352. /* > An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if */
  353. /* > SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either */
  354. /* > one of a complex conjugate pair of eigenvalues is selected, */
  355. /* > then both complex eigenvalues are selected. */
  356. /* > Note that a selected complex eigenvalue may no longer satisfy */
  357. /* > SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) = .TRUE. after ordering, */
  358. /* > since ordering may change the value of complex eigenvalues */
  359. /* > (especially if the eigenvalue is ill-conditioned), in this */
  360. /* > case INFO is set to N+3. */
  361. /* > \endverbatim */
  362. /* > */
  363. /* > \param[in] SENSE */
  364. /* > \verbatim */
  365. /* > SENSE is CHARACTER*1 */
  366. /* > Determines which reciprocal condition numbers are computed. */
  367. /* > = 'N': None are computed; */
  368. /* > = 'E': Computed for average of selected eigenvalues only; */
  369. /* > = 'V': Computed for selected deflating subspaces only; */
  370. /* > = 'B': Computed for both. */
  371. /* > If SENSE = 'E', 'V', or 'B', SORT must equal 'S'. */
  372. /* > \endverbatim */
  373. /* > */
  374. /* > \param[in] N */
  375. /* > \verbatim */
  376. /* > N is INTEGER */
  377. /* > The order of the matrices A, B, VSL, and VSR. N >= 0. */
  378. /* > \endverbatim */
  379. /* > */
  380. /* > \param[in,out] A */
  381. /* > \verbatim */
  382. /* > A is REAL array, dimension (LDA, N) */
  383. /* > On entry, the first of the pair of matrices. */
  384. /* > On exit, A has been overwritten by its generalized Schur */
  385. /* > form S. */
  386. /* > \endverbatim */
  387. /* > */
  388. /* > \param[in] LDA */
  389. /* > \verbatim */
  390. /* > LDA is INTEGER */
  391. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  392. /* > \endverbatim */
  393. /* > */
  394. /* > \param[in,out] B */
  395. /* > \verbatim */
  396. /* > B is REAL array, dimension (LDB, N) */
  397. /* > On entry, the second of the pair of matrices. */
  398. /* > On exit, B has been overwritten by its generalized Schur */
  399. /* > form T. */
  400. /* > \endverbatim */
  401. /* > */
  402. /* > \param[in] LDB */
  403. /* > \verbatim */
  404. /* > LDB is INTEGER */
  405. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  406. /* > \endverbatim */
  407. /* > */
  408. /* > \param[out] SDIM */
  409. /* > \verbatim */
  410. /* > SDIM is INTEGER */
  411. /* > If SORT = 'N', SDIM = 0. */
  412. /* > If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
  413. /* > for which SELCTG is true. (Complex conjugate pairs for which */
  414. /* > SELCTG is true for either eigenvalue count as 2.) */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[out] ALPHAR */
  418. /* > \verbatim */
  419. /* > ALPHAR is REAL array, dimension (N) */
  420. /* > \endverbatim */
  421. /* > */
  422. /* > \param[out] ALPHAI */
  423. /* > \verbatim */
  424. /* > ALPHAI is REAL array, dimension (N) */
  425. /* > \endverbatim */
  426. /* > */
  427. /* > \param[out] BETA */
  428. /* > \verbatim */
  429. /* > BETA is REAL array, dimension (N) */
  430. /* > On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
  431. /* > be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i */
  432. /* > and BETA(j),j=1,...,N are the diagonals of the complex Schur */
  433. /* > form (S,T) that would result if the 2-by-2 diagonal blocks of */
  434. /* > the real Schur form of (A,B) were further reduced to */
  435. /* > triangular form using 2-by-2 complex unitary transformations. */
  436. /* > If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
  437. /* > positive, then the j-th and (j+1)-st eigenvalues are a */
  438. /* > complex conjugate pair, with ALPHAI(j+1) negative. */
  439. /* > */
  440. /* > Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
  441. /* > may easily over- or underflow, and BETA(j) may even be zero. */
  442. /* > Thus, the user should avoid naively computing the ratio. */
  443. /* > However, ALPHAR and ALPHAI will be always less than and */
  444. /* > usually comparable with norm(A) in magnitude, and BETA always */
  445. /* > less than and usually comparable with norm(B). */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[out] VSL */
  449. /* > \verbatim */
  450. /* > VSL is REAL array, dimension (LDVSL,N) */
  451. /* > If JOBVSL = 'V', VSL will contain the left Schur vectors. */
  452. /* > Not referenced if JOBVSL = 'N'. */
  453. /* > \endverbatim */
  454. /* > */
  455. /* > \param[in] LDVSL */
  456. /* > \verbatim */
  457. /* > LDVSL is INTEGER */
  458. /* > The leading dimension of the matrix VSL. LDVSL >=1, and */
  459. /* > if JOBVSL = 'V', LDVSL >= N. */
  460. /* > \endverbatim */
  461. /* > */
  462. /* > \param[out] VSR */
  463. /* > \verbatim */
  464. /* > VSR is REAL array, dimension (LDVSR,N) */
  465. /* > If JOBVSR = 'V', VSR will contain the right Schur vectors. */
  466. /* > Not referenced if JOBVSR = 'N'. */
  467. /* > \endverbatim */
  468. /* > */
  469. /* > \param[in] LDVSR */
  470. /* > \verbatim */
  471. /* > LDVSR is INTEGER */
  472. /* > The leading dimension of the matrix VSR. LDVSR >= 1, and */
  473. /* > if JOBVSR = 'V', LDVSR >= N. */
  474. /* > \endverbatim */
  475. /* > */
  476. /* > \param[out] RCONDE */
  477. /* > \verbatim */
  478. /* > RCONDE is REAL array, dimension ( 2 ) */
  479. /* > If SENSE = 'E' or 'B', RCONDE(1) and RCONDE(2) contain the */
  480. /* > reciprocal condition numbers for the average of the selected */
  481. /* > eigenvalues. */
  482. /* > Not referenced if SENSE = 'N' or 'V'. */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[out] RCONDV */
  486. /* > \verbatim */
  487. /* > RCONDV is REAL array, dimension ( 2 ) */
  488. /* > If SENSE = 'V' or 'B', RCONDV(1) and RCONDV(2) contain the */
  489. /* > reciprocal condition numbers for the selected deflating */
  490. /* > subspaces. */
  491. /* > Not referenced if SENSE = 'N' or 'E'. */
  492. /* > \endverbatim */
  493. /* > */
  494. /* > \param[out] WORK */
  495. /* > \verbatim */
  496. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  497. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  498. /* > \endverbatim */
  499. /* > */
  500. /* > \param[in] LWORK */
  501. /* > \verbatim */
  502. /* > LWORK is INTEGER */
  503. /* > The dimension of the array WORK. */
  504. /* > If N = 0, LWORK >= 1, else if SENSE = 'E', 'V', or 'B', */
  505. /* > LWORK >= f2cmax( 8*N, 6*N+16, 2*SDIM*(N-SDIM) ), else */
  506. /* > LWORK >= f2cmax( 8*N, 6*N+16 ). */
  507. /* > Note that 2*SDIM*(N-SDIM) <= N*N/2. */
  508. /* > Note also that an error is only returned if */
  509. /* > LWORK < f2cmax( 8*N, 6*N+16), but if SENSE = 'E' or 'V' or 'B' */
  510. /* > this may not be large enough. */
  511. /* > */
  512. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  513. /* > only calculates the bound on the optimal size of the WORK */
  514. /* > array and the minimum size of the IWORK array, returns these */
  515. /* > values as the first entries of the WORK and IWORK arrays, and */
  516. /* > no error message related to LWORK or LIWORK is issued by */
  517. /* > XERBLA. */
  518. /* > \endverbatim */
  519. /* > */
  520. /* > \param[out] IWORK */
  521. /* > \verbatim */
  522. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  523. /* > On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK. */
  524. /* > \endverbatim */
  525. /* > */
  526. /* > \param[in] LIWORK */
  527. /* > \verbatim */
  528. /* > LIWORK is INTEGER */
  529. /* > The dimension of the array IWORK. */
  530. /* > If SENSE = 'N' or N = 0, LIWORK >= 1, otherwise */
  531. /* > LIWORK >= N+6. */
  532. /* > */
  533. /* > If LIWORK = -1, then a workspace query is assumed; the */
  534. /* > routine only calculates the bound on the optimal size of the */
  535. /* > WORK array and the minimum size of the IWORK array, returns */
  536. /* > these values as the first entries of the WORK and IWORK */
  537. /* > arrays, and no error message related to LWORK or LIWORK is */
  538. /* > issued by XERBLA. */
  539. /* > \endverbatim */
  540. /* > */
  541. /* > \param[out] BWORK */
  542. /* > \verbatim */
  543. /* > BWORK is LOGICAL array, dimension (N) */
  544. /* > Not referenced if SORT = 'N'. */
  545. /* > \endverbatim */
  546. /* > */
  547. /* > \param[out] INFO */
  548. /* > \verbatim */
  549. /* > INFO is INTEGER */
  550. /* > = 0: successful exit */
  551. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  552. /* > = 1,...,N: */
  553. /* > The QZ iteration failed. (A,B) are not in Schur */
  554. /* > form, but ALPHAR(j), ALPHAI(j), and BETA(j) should */
  555. /* > be correct for j=INFO+1,...,N. */
  556. /* > > N: =N+1: other than QZ iteration failed in SHGEQZ */
  557. /* > =N+2: after reordering, roundoff changed values of */
  558. /* > some complex eigenvalues so that leading */
  559. /* > eigenvalues in the Generalized Schur form no */
  560. /* > longer satisfy SELCTG=.TRUE. This could also */
  561. /* > be caused due to scaling. */
  562. /* > =N+3: reordering failed in STGSEN. */
  563. /* > \endverbatim */
  564. /* Authors: */
  565. /* ======== */
  566. /* > \author Univ. of Tennessee */
  567. /* > \author Univ. of California Berkeley */
  568. /* > \author Univ. of Colorado Denver */
  569. /* > \author NAG Ltd. */
  570. /* > \date June 2017 */
  571. /* > \ingroup realGEeigen */
  572. /* > \par Further Details: */
  573. /* ===================== */
  574. /* > */
  575. /* > \verbatim */
  576. /* > */
  577. /* > An approximate (asymptotic) bound on the average absolute error of */
  578. /* > the selected eigenvalues is */
  579. /* > */
  580. /* > EPS * norm((A, B)) / RCONDE( 1 ). */
  581. /* > */
  582. /* > An approximate (asymptotic) bound on the maximum angular error in */
  583. /* > the computed deflating subspaces is */
  584. /* > */
  585. /* > EPS * norm((A, B)) / RCONDV( 2 ). */
  586. /* > */
  587. /* > See LAPACK User's Guide, section 4.11 for more information. */
  588. /* > \endverbatim */
  589. /* > */
  590. /* ===================================================================== */
  591. /* Subroutine */ void sggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp
  592. selctg, char *sense, integer *n, real *a, integer *lda, real *b,
  593. integer *ldb, integer *sdim, real *alphar, real *alphai, real *beta,
  594. real *vsl, integer *ldvsl, real *vsr, integer *ldvsr, real *rconde,
  595. real *rcondv, real *work, integer *lwork, integer *iwork, integer *
  596. liwork, logical *bwork, integer *info)
  597. {
  598. /* System generated locals */
  599. integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
  600. vsr_dim1, vsr_offset, i__1, i__2;
  601. real r__1;
  602. /* Local variables */
  603. integer ijob;
  604. real anrm, bnrm;
  605. integer ierr, itau, iwrk, lwrk, i__;
  606. extern logical lsame_(char *, char *);
  607. integer ileft, icols;
  608. logical cursl, ilvsl, ilvsr;
  609. integer irows;
  610. logical lst2sl;
  611. extern /* Subroutine */ void slabad_(real *, real *);
  612. integer ip;
  613. real pl;
  614. extern /* Subroutine */ void sggbak_(char *, char *, integer *, integer *,
  615. integer *, real *, real *, integer *, real *, integer *, integer *
  616. ), sggbal_(char *, integer *, real *, integer *,
  617. real *, integer *, integer *, integer *, real *, real *, real *,
  618. integer *);
  619. real pr;
  620. logical ilascl, ilbscl;
  621. extern real slamch_(char *), slange_(char *, integer *, integer *,
  622. real *, integer *, real *);
  623. real safmin;
  624. extern /* Subroutine */ void sgghrd_(char *, char *, integer *, integer *,
  625. integer *, real *, integer *, real *, integer *, real *, integer *
  626. , real *, integer *, integer *);
  627. real safmax;
  628. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  629. real bignum;
  630. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  631. real *, integer *, integer *, real *, integer *, integer *);
  632. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  633. integer *, integer *, ftnlen, ftnlen);
  634. integer ijobvl, iright;
  635. extern /* Subroutine */ void sgeqrf_(integer *, integer *, real *, integer
  636. *, real *, real *, integer *, integer *);
  637. integer ijobvr;
  638. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  639. integer *, real *, integer *);
  640. logical wantsb, wantse, lastsl;
  641. integer liwmin;
  642. real anrmto, bnrmto;
  643. integer minwrk, maxwrk;
  644. logical wantsn;
  645. real smlnum;
  646. extern /* Subroutine */ void shgeqz_(char *, char *, char *, integer *,
  647. integer *, integer *, real *, integer *, real *, integer *, real *
  648. , real *, real *, real *, integer *, real *, integer *, real *,
  649. integer *, integer *), slaset_(char *,
  650. integer *, integer *, real *, real *, real *, integer *),
  651. sorgqr_(integer *, integer *, integer *, real *, integer *, real *
  652. , real *, integer *, integer *), stgsen_(integer *, logical *,
  653. logical *, logical *, integer *, real *, integer *, real *,
  654. integer *, real *, real *, real *, real *, integer *, real *,
  655. integer *, integer *, real *, real *, real *, real *, integer *,
  656. integer *, integer *, integer *);
  657. logical wantst, lquery, wantsv;
  658. extern /* Subroutine */ void sormqr_(char *, char *, integer *, integer *,
  659. integer *, real *, integer *, real *, real *, integer *, real *,
  660. integer *, integer *);
  661. real dif[2];
  662. integer ihi, ilo;
  663. real eps;
  664. /* -- LAPACK driver routine (version 3.7.1) -- */
  665. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  666. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  667. /* June 2017 */
  668. /* ===================================================================== */
  669. /* Decode the input arguments */
  670. /* Parameter adjustments */
  671. a_dim1 = *lda;
  672. a_offset = 1 + a_dim1 * 1;
  673. a -= a_offset;
  674. b_dim1 = *ldb;
  675. b_offset = 1 + b_dim1 * 1;
  676. b -= b_offset;
  677. --alphar;
  678. --alphai;
  679. --beta;
  680. vsl_dim1 = *ldvsl;
  681. vsl_offset = 1 + vsl_dim1 * 1;
  682. vsl -= vsl_offset;
  683. vsr_dim1 = *ldvsr;
  684. vsr_offset = 1 + vsr_dim1 * 1;
  685. vsr -= vsr_offset;
  686. --rconde;
  687. --rcondv;
  688. --work;
  689. --iwork;
  690. --bwork;
  691. /* Function Body */
  692. if (lsame_(jobvsl, "N")) {
  693. ijobvl = 1;
  694. ilvsl = FALSE_;
  695. } else if (lsame_(jobvsl, "V")) {
  696. ijobvl = 2;
  697. ilvsl = TRUE_;
  698. } else {
  699. ijobvl = -1;
  700. ilvsl = FALSE_;
  701. }
  702. if (lsame_(jobvsr, "N")) {
  703. ijobvr = 1;
  704. ilvsr = FALSE_;
  705. } else if (lsame_(jobvsr, "V")) {
  706. ijobvr = 2;
  707. ilvsr = TRUE_;
  708. } else {
  709. ijobvr = -1;
  710. ilvsr = FALSE_;
  711. }
  712. wantst = lsame_(sort, "S");
  713. wantsn = lsame_(sense, "N");
  714. wantse = lsame_(sense, "E");
  715. wantsv = lsame_(sense, "V");
  716. wantsb = lsame_(sense, "B");
  717. lquery = *lwork == -1 || *liwork == -1;
  718. if (wantsn) {
  719. ijob = 0;
  720. } else if (wantse) {
  721. ijob = 1;
  722. } else if (wantsv) {
  723. ijob = 2;
  724. } else if (wantsb) {
  725. ijob = 4;
  726. }
  727. /* Test the input arguments */
  728. *info = 0;
  729. if (ijobvl <= 0) {
  730. *info = -1;
  731. } else if (ijobvr <= 0) {
  732. *info = -2;
  733. } else if (! wantst && ! lsame_(sort, "N")) {
  734. *info = -3;
  735. } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && !
  736. wantsn) {
  737. *info = -5;
  738. } else if (*n < 0) {
  739. *info = -6;
  740. } else if (*lda < f2cmax(1,*n)) {
  741. *info = -8;
  742. } else if (*ldb < f2cmax(1,*n)) {
  743. *info = -10;
  744. } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
  745. *info = -16;
  746. } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
  747. *info = -18;
  748. }
  749. /* Compute workspace */
  750. /* (Note: Comments in the code beginning "Workspace:" describe the */
  751. /* minimal amount of workspace needed at that point in the code, */
  752. /* as well as the preferred amount for good performance. */
  753. /* NB refers to the optimal block size for the immediately */
  754. /* following subroutine, as returned by ILAENV.) */
  755. if (*info == 0) {
  756. if (*n > 0) {
  757. /* Computing MAX */
  758. i__1 = *n << 3, i__2 = *n * 6 + 16;
  759. minwrk = f2cmax(i__1,i__2);
  760. maxwrk = minwrk - *n + *n * ilaenv_(&c__1, "SGEQRF", " ", n, &
  761. c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  762. /* Computing MAX */
  763. i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SORMQR",
  764. " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
  765. maxwrk = f2cmax(i__1,i__2);
  766. if (ilvsl) {
  767. /* Computing MAX */
  768. i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SOR"
  769. "GQR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
  770. maxwrk = f2cmax(i__1,i__2);
  771. }
  772. lwrk = maxwrk;
  773. if (ijob >= 1) {
  774. /* Computing MAX */
  775. i__1 = lwrk, i__2 = *n * *n / 2;
  776. lwrk = f2cmax(i__1,i__2);
  777. }
  778. } else {
  779. minwrk = 1;
  780. maxwrk = 1;
  781. lwrk = 1;
  782. }
  783. work[1] = (real) lwrk;
  784. if (wantsn || *n == 0) {
  785. liwmin = 1;
  786. } else {
  787. liwmin = *n + 6;
  788. }
  789. iwork[1] = liwmin;
  790. if (*lwork < minwrk && ! lquery) {
  791. *info = -22;
  792. } else if (*liwork < liwmin && ! lquery) {
  793. *info = -24;
  794. }
  795. }
  796. if (*info != 0) {
  797. i__1 = -(*info);
  798. xerbla_("SGGESX", &i__1, (ftnlen)6);
  799. return;
  800. } else if (lquery) {
  801. return;
  802. }
  803. /* Quick return if possible */
  804. if (*n == 0) {
  805. *sdim = 0;
  806. return;
  807. }
  808. /* Get machine constants */
  809. eps = slamch_("P");
  810. safmin = slamch_("S");
  811. safmax = 1.f / safmin;
  812. slabad_(&safmin, &safmax);
  813. smlnum = sqrt(safmin) / eps;
  814. bignum = 1.f / smlnum;
  815. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  816. anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
  817. ilascl = FALSE_;
  818. if (anrm > 0.f && anrm < smlnum) {
  819. anrmto = smlnum;
  820. ilascl = TRUE_;
  821. } else if (anrm > bignum) {
  822. anrmto = bignum;
  823. ilascl = TRUE_;
  824. }
  825. if (ilascl) {
  826. slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  827. ierr);
  828. }
  829. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  830. bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
  831. ilbscl = FALSE_;
  832. if (bnrm > 0.f && bnrm < smlnum) {
  833. bnrmto = smlnum;
  834. ilbscl = TRUE_;
  835. } else if (bnrm > bignum) {
  836. bnrmto = bignum;
  837. ilbscl = TRUE_;
  838. }
  839. if (ilbscl) {
  840. slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  841. ierr);
  842. }
  843. /* Permute the matrix to make it more nearly triangular */
  844. /* (Workspace: need 6*N + 2*N for permutation parameters) */
  845. ileft = 1;
  846. iright = *n + 1;
  847. iwrk = iright + *n;
  848. sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  849. ileft], &work[iright], &work[iwrk], &ierr);
  850. /* Reduce B to triangular form (QR decomposition of B) */
  851. /* (Workspace: need N, prefer N*NB) */
  852. irows = ihi + 1 - ilo;
  853. icols = *n + 1 - ilo;
  854. itau = iwrk;
  855. iwrk = itau + irows;
  856. i__1 = *lwork + 1 - iwrk;
  857. sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  858. iwrk], &i__1, &ierr);
  859. /* Apply the orthogonal transformation to matrix A */
  860. /* (Workspace: need N, prefer N*NB) */
  861. i__1 = *lwork + 1 - iwrk;
  862. sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  863. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
  864. ierr);
  865. /* Initialize VSL */
  866. /* (Workspace: need N, prefer N*NB) */
  867. if (ilvsl) {
  868. slaset_("Full", n, n, &c_b42, &c_b43, &vsl[vsl_offset], ldvsl);
  869. if (irows > 1) {
  870. i__1 = irows - 1;
  871. i__2 = irows - 1;
  872. slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
  873. ilo + 1 + ilo * vsl_dim1], ldvsl);
  874. }
  875. i__1 = *lwork + 1 - iwrk;
  876. sorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
  877. work[itau], &work[iwrk], &i__1, &ierr);
  878. }
  879. /* Initialize VSR */
  880. if (ilvsr) {
  881. slaset_("Full", n, n, &c_b42, &c_b43, &vsr[vsr_offset], ldvsr);
  882. }
  883. /* Reduce to generalized Hessenberg form */
  884. /* (Workspace: none needed) */
  885. sgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  886. ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
  887. *sdim = 0;
  888. /* Perform QZ algorithm, computing Schur vectors if desired */
  889. /* (Workspace: need N) */
  890. iwrk = itau;
  891. i__1 = *lwork + 1 - iwrk;
  892. shgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  893. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
  894. , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &ierr);
  895. if (ierr != 0) {
  896. if (ierr > 0 && ierr <= *n) {
  897. *info = ierr;
  898. } else if (ierr > *n && ierr <= *n << 1) {
  899. *info = ierr - *n;
  900. } else {
  901. *info = *n + 1;
  902. }
  903. goto L50;
  904. }
  905. /* Sort eigenvalues ALPHA/BETA and compute the reciprocal of */
  906. /* condition number(s) */
  907. /* (Workspace: If IJOB >= 1, need MAX( 8*(N+1), 2*SDIM*(N-SDIM) ) */
  908. /* otherwise, need 8*(N+1) ) */
  909. if (wantst) {
  910. /* Undo scaling on eigenvalues before SELCTGing */
  911. if (ilascl) {
  912. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1],
  913. n, &ierr);
  914. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1],
  915. n, &ierr);
  916. }
  917. if (ilbscl) {
  918. slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n,
  919. &ierr);
  920. }
  921. /* Select eigenvalues */
  922. i__1 = *n;
  923. for (i__ = 1; i__ <= i__1; ++i__) {
  924. bwork[i__] = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
  925. /* L10: */
  926. }
  927. /* Reorder eigenvalues, transform Generalized Schur vectors, and */
  928. /* compute reciprocal condition numbers */
  929. i__1 = *lwork - iwrk + 1;
  930. stgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
  931. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[
  932. vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pl, &pr,
  933. dif, &work[iwrk], &i__1, &iwork[1], liwork, &ierr);
  934. if (ijob >= 1) {
  935. /* Computing MAX */
  936. i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim);
  937. maxwrk = f2cmax(i__1,i__2);
  938. }
  939. if (ierr == -22) {
  940. /* not enough real workspace */
  941. *info = -22;
  942. } else {
  943. if (ijob == 1 || ijob == 4) {
  944. rconde[1] = pl;
  945. rconde[2] = pr;
  946. }
  947. if (ijob == 2 || ijob == 4) {
  948. rcondv[1] = dif[0];
  949. rcondv[2] = dif[1];
  950. }
  951. if (ierr == 1) {
  952. *info = *n + 3;
  953. }
  954. }
  955. }
  956. /* Apply permutation to VSL and VSR */
  957. /* (Workspace: none needed) */
  958. if (ilvsl) {
  959. sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
  960. vsl_offset], ldvsl, &ierr);
  961. }
  962. if (ilvsr) {
  963. sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
  964. vsr_offset], ldvsr, &ierr);
  965. }
  966. /* Check if unscaling would cause over/underflow, if so, rescale */
  967. /* (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of */
  968. /* B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I) */
  969. if (ilascl) {
  970. i__1 = *n;
  971. for (i__ = 1; i__ <= i__1; ++i__) {
  972. if (alphai[i__] != 0.f) {
  973. if (alphar[i__] / safmax > anrmto / anrm || safmin / alphar[
  974. i__] > anrm / anrmto) {
  975. work[1] = (r__1 = a[i__ + i__ * a_dim1] / alphar[i__],
  976. abs(r__1));
  977. beta[i__] *= work[1];
  978. alphar[i__] *= work[1];
  979. alphai[i__] *= work[1];
  980. } else if (alphai[i__] / safmax > anrmto / anrm || safmin /
  981. alphai[i__] > anrm / anrmto) {
  982. work[1] = (r__1 = a[i__ + (i__ + 1) * a_dim1] / alphai[
  983. i__], abs(r__1));
  984. beta[i__] *= work[1];
  985. alphar[i__] *= work[1];
  986. alphai[i__] *= work[1];
  987. }
  988. }
  989. /* L20: */
  990. }
  991. }
  992. if (ilbscl) {
  993. i__1 = *n;
  994. for (i__ = 1; i__ <= i__1; ++i__) {
  995. if (alphai[i__] != 0.f) {
  996. if (beta[i__] / safmax > bnrmto / bnrm || safmin / beta[i__]
  997. > bnrm / bnrmto) {
  998. work[1] = (r__1 = b[i__ + i__ * b_dim1] / beta[i__], abs(
  999. r__1));
  1000. beta[i__] *= work[1];
  1001. alphar[i__] *= work[1];
  1002. alphai[i__] *= work[1];
  1003. }
  1004. }
  1005. /* L25: */
  1006. }
  1007. }
  1008. /* Undo scaling */
  1009. if (ilascl) {
  1010. slascl_("H", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
  1011. ierr);
  1012. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  1013. ierr);
  1014. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  1015. ierr);
  1016. }
  1017. if (ilbscl) {
  1018. slascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
  1019. ierr);
  1020. slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  1021. ierr);
  1022. }
  1023. if (wantst) {
  1024. /* Check if reordering is correct */
  1025. lastsl = TRUE_;
  1026. lst2sl = TRUE_;
  1027. *sdim = 0;
  1028. ip = 0;
  1029. i__1 = *n;
  1030. for (i__ = 1; i__ <= i__1; ++i__) {
  1031. cursl = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
  1032. if (alphai[i__] == 0.f) {
  1033. if (cursl) {
  1034. ++(*sdim);
  1035. }
  1036. ip = 0;
  1037. if (cursl && ! lastsl) {
  1038. *info = *n + 2;
  1039. }
  1040. } else {
  1041. if (ip == 1) {
  1042. /* Last eigenvalue of conjugate pair */
  1043. cursl = cursl || lastsl;
  1044. lastsl = cursl;
  1045. if (cursl) {
  1046. *sdim += 2;
  1047. }
  1048. ip = -1;
  1049. if (cursl && ! lst2sl) {
  1050. *info = *n + 2;
  1051. }
  1052. } else {
  1053. /* First eigenvalue of conjugate pair */
  1054. ip = 1;
  1055. }
  1056. }
  1057. lst2sl = lastsl;
  1058. lastsl = cursl;
  1059. /* L40: */
  1060. }
  1061. }
  1062. L50:
  1063. work[1] = (real) maxwrk;
  1064. iwork[1] = liwmin;
  1065. return;
  1066. /* End of SGGESX */
  1067. } /* sggesx_ */