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.

sgges.c 36 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #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++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #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]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c__1 = 1;
  381. static integer c__0 = 0;
  382. static integer c_n1 = -1;
  383. static real c_b38 = 0.f;
  384. static real c_b39 = 1.f;
  385. /* > \brief <b> SGGES computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors f
  386. or GE matrices</b> */
  387. /* =========== DOCUMENTATION =========== */
  388. /* Online html documentation available at */
  389. /* http://www.netlib.org/lapack/explore-html/ */
  390. /* > \htmlonly */
  391. /* > Download SGGES + dependencies */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgges.f
  393. "> */
  394. /* > [TGZ]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgges.f
  396. "> */
  397. /* > [ZIP]</a> */
  398. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgges.f
  399. "> */
  400. /* > [TXT]</a> */
  401. /* > \endhtmlonly */
  402. /* Definition: */
  403. /* =========== */
  404. /* SUBROUTINE SGGES( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B, LDB, */
  405. /* SDIM, ALPHAR, ALPHAI, BETA, VSL, LDVSL, VSR, */
  406. /* LDVSR, WORK, LWORK, BWORK, INFO ) */
  407. /* CHARACTER JOBVSL, JOBVSR, SORT */
  408. /* INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM */
  409. /* LOGICAL BWORK( * ) */
  410. /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  411. /* $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ), */
  412. /* $ VSR( LDVSR, * ), WORK( * ) */
  413. /* LOGICAL SELCTG */
  414. /* EXTERNAL SELCTG */
  415. /* > \par Purpose: */
  416. /* ============= */
  417. /* > */
  418. /* > \verbatim */
  419. /* > */
  420. /* > SGGES computes for a pair of N-by-N real nonsymmetric matrices (A,B), */
  421. /* > the generalized eigenvalues, the generalized real Schur form (S,T), */
  422. /* > optionally, the left and/or right matrices of Schur vectors (VSL and */
  423. /* > VSR). This gives the generalized Schur factorization */
  424. /* > */
  425. /* > (A,B) = ( (VSL)*S*(VSR)**T, (VSL)*T*(VSR)**T ) */
  426. /* > */
  427. /* > Optionally, it also orders the eigenvalues so that a selected cluster */
  428. /* > of eigenvalues appears in the leading diagonal blocks of the upper */
  429. /* > quasi-triangular matrix S and the upper triangular matrix T.The */
  430. /* > leading columns of VSL and VSR then form an orthonormal basis for the */
  431. /* > corresponding left and right eigenspaces (deflating subspaces). */
  432. /* > */
  433. /* > (If only the generalized eigenvalues are needed, use the driver */
  434. /* > SGGEV instead, which is faster.) */
  435. /* > */
  436. /* > A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */
  437. /* > or a ratio alpha/beta = w, such that A - w*B is singular. It is */
  438. /* > usually represented as the pair (alpha,beta), as there is a */
  439. /* > reasonable interpretation for beta=0 or both being zero. */
  440. /* > */
  441. /* > A pair of matrices (S,T) is in generalized real Schur form if T is */
  442. /* > upper triangular with non-negative diagonal and S is block upper */
  443. /* > triangular with 1-by-1 and 2-by-2 blocks. 1-by-1 blocks correspond */
  444. /* > to real generalized eigenvalues, while 2-by-2 blocks of S will be */
  445. /* > "standardized" by making the corresponding elements of T have the */
  446. /* > form: */
  447. /* > [ a 0 ] */
  448. /* > [ 0 b ] */
  449. /* > */
  450. /* > and the pair of corresponding 2-by-2 blocks in S and T will have a */
  451. /* > complex conjugate pair of generalized eigenvalues. */
  452. /* > */
  453. /* > \endverbatim */
  454. /* Arguments: */
  455. /* ========== */
  456. /* > \param[in] JOBVSL */
  457. /* > \verbatim */
  458. /* > JOBVSL is CHARACTER*1 */
  459. /* > = 'N': do not compute the left Schur vectors; */
  460. /* > = 'V': compute the left Schur vectors. */
  461. /* > \endverbatim */
  462. /* > */
  463. /* > \param[in] JOBVSR */
  464. /* > \verbatim */
  465. /* > JOBVSR is CHARACTER*1 */
  466. /* > = 'N': do not compute the right Schur vectors; */
  467. /* > = 'V': compute the right Schur vectors. */
  468. /* > \endverbatim */
  469. /* > */
  470. /* > \param[in] SORT */
  471. /* > \verbatim */
  472. /* > SORT is CHARACTER*1 */
  473. /* > Specifies whether or not to order the eigenvalues on the */
  474. /* > diagonal of the generalized Schur form. */
  475. /* > = 'N': Eigenvalues are not ordered; */
  476. /* > = 'S': Eigenvalues are ordered (see SELCTG); */
  477. /* > \endverbatim */
  478. /* > */
  479. /* > \param[in] SELCTG */
  480. /* > \verbatim */
  481. /* > SELCTG is a LOGICAL FUNCTION of three REAL arguments */
  482. /* > SELCTG must be declared EXTERNAL in the calling subroutine. */
  483. /* > If SORT = 'N', SELCTG is not referenced. */
  484. /* > If SORT = 'S', SELCTG is used to select eigenvalues to sort */
  485. /* > to the top left of the Schur form. */
  486. /* > An eigenvalue (ALPHAR(j)+ALPHAI(j))/BETA(j) is selected if */
  487. /* > SELCTG(ALPHAR(j),ALPHAI(j),BETA(j)) is true; i.e. if either */
  488. /* > one of a complex conjugate pair of eigenvalues is selected, */
  489. /* > then both complex eigenvalues are selected. */
  490. /* > */
  491. /* > Note that in the ill-conditioned case, a selected complex */
  492. /* > eigenvalue may no longer satisfy SELCTG(ALPHAR(j),ALPHAI(j), */
  493. /* > BETA(j)) = .TRUE. after ordering. INFO is to be set to N+2 */
  494. /* > in this case. */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[in] N */
  498. /* > \verbatim */
  499. /* > N is INTEGER */
  500. /* > The order of the matrices A, B, VSL, and VSR. N >= 0. */
  501. /* > \endverbatim */
  502. /* > */
  503. /* > \param[in,out] A */
  504. /* > \verbatim */
  505. /* > A is REAL array, dimension (LDA, N) */
  506. /* > On entry, the first of the pair of matrices. */
  507. /* > On exit, A has been overwritten by its generalized Schur */
  508. /* > form S. */
  509. /* > \endverbatim */
  510. /* > */
  511. /* > \param[in] LDA */
  512. /* > \verbatim */
  513. /* > LDA is INTEGER */
  514. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[in,out] B */
  518. /* > \verbatim */
  519. /* > B is REAL array, dimension (LDB, N) */
  520. /* > On entry, the second of the pair of matrices. */
  521. /* > On exit, B has been overwritten by its generalized Schur */
  522. /* > form T. */
  523. /* > \endverbatim */
  524. /* > */
  525. /* > \param[in] LDB */
  526. /* > \verbatim */
  527. /* > LDB is INTEGER */
  528. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  529. /* > \endverbatim */
  530. /* > */
  531. /* > \param[out] SDIM */
  532. /* > \verbatim */
  533. /* > SDIM is INTEGER */
  534. /* > If SORT = 'N', SDIM = 0. */
  535. /* > If SORT = 'S', SDIM = number of eigenvalues (after sorting) */
  536. /* > for which SELCTG is true. (Complex conjugate pairs for which */
  537. /* > SELCTG is true for either eigenvalue count as 2.) */
  538. /* > \endverbatim */
  539. /* > */
  540. /* > \param[out] ALPHAR */
  541. /* > \verbatim */
  542. /* > ALPHAR is REAL array, dimension (N) */
  543. /* > \endverbatim */
  544. /* > */
  545. /* > \param[out] ALPHAI */
  546. /* > \verbatim */
  547. /* > ALPHAI is REAL array, dimension (N) */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[out] BETA */
  551. /* > \verbatim */
  552. /* > BETA is REAL array, dimension (N) */
  553. /* > On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
  554. /* > be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i, */
  555. /* > and BETA(j),j=1,...,N are the diagonals of the complex Schur */
  556. /* > form (S,T) that would result if the 2-by-2 diagonal blocks of */
  557. /* > the real Schur form of (A,B) were further reduced to */
  558. /* > triangular form using 2-by-2 complex unitary transformations. */
  559. /* > If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
  560. /* > positive, then the j-th and (j+1)-st eigenvalues are a */
  561. /* > complex conjugate pair, with ALPHAI(j+1) negative. */
  562. /* > */
  563. /* > Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
  564. /* > may easily over- or underflow, and BETA(j) may even be zero. */
  565. /* > Thus, the user should avoid naively computing the ratio. */
  566. /* > However, ALPHAR and ALPHAI will be always less than and */
  567. /* > usually comparable with norm(A) in magnitude, and BETA always */
  568. /* > less than and usually comparable with norm(B). */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[out] VSL */
  572. /* > \verbatim */
  573. /* > VSL is REAL array, dimension (LDVSL,N) */
  574. /* > If JOBVSL = 'V', VSL will contain the left Schur vectors. */
  575. /* > Not referenced if JOBVSL = 'N'. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[in] LDVSL */
  579. /* > \verbatim */
  580. /* > LDVSL is INTEGER */
  581. /* > The leading dimension of the matrix VSL. LDVSL >=1, and */
  582. /* > if JOBVSL = 'V', LDVSL >= N. */
  583. /* > \endverbatim */
  584. /* > */
  585. /* > \param[out] VSR */
  586. /* > \verbatim */
  587. /* > VSR is REAL array, dimension (LDVSR,N) */
  588. /* > If JOBVSR = 'V', VSR will contain the right Schur vectors. */
  589. /* > Not referenced if JOBVSR = 'N'. */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[in] LDVSR */
  593. /* > \verbatim */
  594. /* > LDVSR is INTEGER */
  595. /* > The leading dimension of the matrix VSR. LDVSR >= 1, and */
  596. /* > if JOBVSR = 'V', LDVSR >= N. */
  597. /* > \endverbatim */
  598. /* > */
  599. /* > \param[out] WORK */
  600. /* > \verbatim */
  601. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  602. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  603. /* > \endverbatim */
  604. /* > */
  605. /* > \param[in] LWORK */
  606. /* > \verbatim */
  607. /* > LWORK is INTEGER */
  608. /* > The dimension of the array WORK. */
  609. /* > If N = 0, LWORK >= 1, else LWORK >= f2cmax(8*N,6*N+16). */
  610. /* > For good performance , LWORK must generally be larger. */
  611. /* > */
  612. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  613. /* > only calculates the optimal size of the WORK array, returns */
  614. /* > this value as the first entry of the WORK array, and no error */
  615. /* > message related to LWORK is issued by XERBLA. */
  616. /* > \endverbatim */
  617. /* > */
  618. /* > \param[out] BWORK */
  619. /* > \verbatim */
  620. /* > BWORK is LOGICAL array, dimension (N) */
  621. /* > Not referenced if SORT = 'N'. */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[out] INFO */
  625. /* > \verbatim */
  626. /* > INFO is INTEGER */
  627. /* > = 0: successful exit */
  628. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  629. /* > = 1,...,N: */
  630. /* > The QZ iteration failed. (A,B) are not in Schur */
  631. /* > form, but ALPHAR(j), ALPHAI(j), and BETA(j) should */
  632. /* > be correct for j=INFO+1,...,N. */
  633. /* > > N: =N+1: other than QZ iteration failed in SHGEQZ. */
  634. /* > =N+2: after reordering, roundoff changed values of */
  635. /* > some complex eigenvalues so that leading */
  636. /* > eigenvalues in the Generalized Schur form no */
  637. /* > longer satisfy SELCTG=.TRUE. This could also */
  638. /* > be caused due to scaling. */
  639. /* > =N+3: reordering failed in STGSEN. */
  640. /* > \endverbatim */
  641. /* Authors: */
  642. /* ======== */
  643. /* > \author Univ. of Tennessee */
  644. /* > \author Univ. of California Berkeley */
  645. /* > \author Univ. of Colorado Denver */
  646. /* > \author NAG Ltd. */
  647. /* > \date December 2016 */
  648. /* > \ingroup realGEeigen */
  649. /* ===================================================================== */
  650. /* Subroutine */ int sgges_(char *jobvsl, char *jobvsr, char *sort, L_fp
  651. selctg, integer *n, real *a, integer *lda, real *b, integer *ldb,
  652. integer *sdim, real *alphar, real *alphai, real *beta, real *vsl,
  653. integer *ldvsl, real *vsr, integer *ldvsr, real *work, integer *lwork,
  654. logical *bwork, integer *info)
  655. {
  656. /* System generated locals */
  657. integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
  658. vsr_dim1, vsr_offset, i__1, i__2;
  659. real r__1;
  660. /* Local variables */
  661. real anrm, bnrm;
  662. integer idum[1], ierr, itau, iwrk;
  663. real pvsl, pvsr;
  664. integer i__;
  665. extern logical lsame_(char *, char *);
  666. integer ileft, icols;
  667. logical cursl, ilvsl, ilvsr;
  668. integer irows;
  669. logical lst2sl;
  670. extern /* Subroutine */ int slabad_(real *, real *);
  671. integer ip;
  672. extern /* Subroutine */ int sggbak_(char *, char *, integer *, integer *,
  673. integer *, real *, real *, integer *, real *, integer *, integer *
  674. ), sggbal_(char *, integer *, real *, integer *,
  675. real *, integer *, integer *, integer *, real *, real *, real *,
  676. integer *);
  677. logical ilascl, ilbscl;
  678. extern real slamch_(char *), slange_(char *, integer *, integer *,
  679. real *, integer *, real *);
  680. real safmin;
  681. extern /* Subroutine */ int sgghrd_(char *, char *, integer *, integer *,
  682. integer *, real *, integer *, real *, integer *, real *, integer *
  683. , real *, integer *, integer *);
  684. real safmax;
  685. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  686. real bignum;
  687. extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
  688. real *, integer *, integer *, real *, integer *, integer *);
  689. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  690. integer *, integer *, ftnlen, ftnlen);
  691. integer ijobvl, iright;
  692. extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer
  693. *, real *, real *, integer *, integer *);
  694. integer ijobvr;
  695. extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *,
  696. integer *, real *, integer *), slaset_(char *, integer *,
  697. integer *, real *, real *, real *, integer *);
  698. real anrmto, bnrmto;
  699. logical lastsl;
  700. extern /* Subroutine */ int shgeqz_(char *, char *, char *, integer *,
  701. integer *, integer *, real *, integer *, real *, integer *, real *
  702. , real *, real *, real *, integer *, real *, integer *, real *,
  703. integer *, integer *), stgsen_(integer *,
  704. logical *, logical *, logical *, integer *, real *, integer *,
  705. real *, integer *, real *, real *, real *, real *, integer *,
  706. real *, integer *, integer *, real *, real *, real *, real *,
  707. integer *, integer *, integer *, integer *);
  708. integer minwrk, maxwrk;
  709. real smlnum;
  710. extern /* Subroutine */ int sorgqr_(integer *, integer *, integer *, real
  711. *, integer *, real *, real *, integer *, integer *);
  712. logical wantst, lquery;
  713. extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *,
  714. integer *, real *, integer *, real *, real *, integer *, real *,
  715. integer *, integer *);
  716. real dif[2];
  717. integer ihi, ilo;
  718. real eps;
  719. /* -- LAPACK driver routine (version 3.7.0) -- */
  720. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  721. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  722. /* December 2016 */
  723. /* ===================================================================== */
  724. /* Decode the input arguments */
  725. /* Parameter adjustments */
  726. a_dim1 = *lda;
  727. a_offset = 1 + a_dim1 * 1;
  728. a -= a_offset;
  729. b_dim1 = *ldb;
  730. b_offset = 1 + b_dim1 * 1;
  731. b -= b_offset;
  732. --alphar;
  733. --alphai;
  734. --beta;
  735. vsl_dim1 = *ldvsl;
  736. vsl_offset = 1 + vsl_dim1 * 1;
  737. vsl -= vsl_offset;
  738. vsr_dim1 = *ldvsr;
  739. vsr_offset = 1 + vsr_dim1 * 1;
  740. vsr -= vsr_offset;
  741. --work;
  742. --bwork;
  743. /* Function Body */
  744. if (lsame_(jobvsl, "N")) {
  745. ijobvl = 1;
  746. ilvsl = FALSE_;
  747. } else if (lsame_(jobvsl, "V")) {
  748. ijobvl = 2;
  749. ilvsl = TRUE_;
  750. } else {
  751. ijobvl = -1;
  752. ilvsl = FALSE_;
  753. }
  754. if (lsame_(jobvsr, "N")) {
  755. ijobvr = 1;
  756. ilvsr = FALSE_;
  757. } else if (lsame_(jobvsr, "V")) {
  758. ijobvr = 2;
  759. ilvsr = TRUE_;
  760. } else {
  761. ijobvr = -1;
  762. ilvsr = FALSE_;
  763. }
  764. wantst = lsame_(sort, "S");
  765. /* Test the input arguments */
  766. *info = 0;
  767. lquery = *lwork == -1;
  768. if (ijobvl <= 0) {
  769. *info = -1;
  770. } else if (ijobvr <= 0) {
  771. *info = -2;
  772. } else if (! wantst && ! lsame_(sort, "N")) {
  773. *info = -3;
  774. } else if (*n < 0) {
  775. *info = -5;
  776. } else if (*lda < f2cmax(1,*n)) {
  777. *info = -7;
  778. } else if (*ldb < f2cmax(1,*n)) {
  779. *info = -9;
  780. } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
  781. *info = -15;
  782. } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
  783. *info = -17;
  784. }
  785. /* Compute workspace */
  786. /* (Note: Comments in the code beginning "Workspace:" describe the */
  787. /* minimal amount of workspace needed at that point in the code, */
  788. /* as well as the preferred amount for good performance. */
  789. /* NB refers to the optimal block size for the immediately */
  790. /* following subroutine, as returned by ILAENV.) */
  791. if (*info == 0) {
  792. if (*n > 0) {
  793. /* Computing MAX */
  794. i__1 = *n << 3, i__2 = *n * 6 + 16;
  795. minwrk = f2cmax(i__1,i__2);
  796. maxwrk = minwrk - *n + *n * ilaenv_(&c__1, "SGEQRF", " ", n, &
  797. c__1, n, &c__0, (ftnlen)6, (ftnlen)1);
  798. /* Computing MAX */
  799. i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SORMQR",
  800. " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
  801. maxwrk = f2cmax(i__1,i__2);
  802. if (ilvsl) {
  803. /* Computing MAX */
  804. i__1 = maxwrk, i__2 = minwrk - *n + *n * ilaenv_(&c__1, "SOR"
  805. "GQR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
  806. maxwrk = f2cmax(i__1,i__2);
  807. }
  808. } else {
  809. minwrk = 1;
  810. maxwrk = 1;
  811. }
  812. work[1] = (real) maxwrk;
  813. if (*lwork < minwrk && ! lquery) {
  814. *info = -19;
  815. }
  816. }
  817. if (*info != 0) {
  818. i__1 = -(*info);
  819. xerbla_("SGGES ", &i__1, (ftnlen)5);
  820. return 0;
  821. } else if (lquery) {
  822. return 0;
  823. }
  824. /* Quick return if possible */
  825. if (*n == 0) {
  826. *sdim = 0;
  827. return 0;
  828. }
  829. /* Get machine constants */
  830. eps = slamch_("P");
  831. safmin = slamch_("S");
  832. safmax = 1.f / safmin;
  833. slabad_(&safmin, &safmax);
  834. smlnum = sqrt(safmin) / eps;
  835. bignum = 1.f / smlnum;
  836. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  837. anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
  838. ilascl = FALSE_;
  839. if (anrm > 0.f && anrm < smlnum) {
  840. anrmto = smlnum;
  841. ilascl = TRUE_;
  842. } else if (anrm > bignum) {
  843. anrmto = bignum;
  844. ilascl = TRUE_;
  845. }
  846. if (ilascl) {
  847. slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  848. ierr);
  849. }
  850. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  851. bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
  852. ilbscl = FALSE_;
  853. if (bnrm > 0.f && bnrm < smlnum) {
  854. bnrmto = smlnum;
  855. ilbscl = TRUE_;
  856. } else if (bnrm > bignum) {
  857. bnrmto = bignum;
  858. ilbscl = TRUE_;
  859. }
  860. if (ilbscl) {
  861. slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  862. ierr);
  863. }
  864. /* Permute the matrix to make it more nearly triangular */
  865. /* (Workspace: need 6*N + 2*N space for storing balancing factors) */
  866. ileft = 1;
  867. iright = *n + 1;
  868. iwrk = iright + *n;
  869. sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  870. ileft], &work[iright], &work[iwrk], &ierr);
  871. /* Reduce B to triangular form (QR decomposition of B) */
  872. /* (Workspace: need N, prefer N*NB) */
  873. irows = ihi + 1 - ilo;
  874. icols = *n + 1 - ilo;
  875. itau = iwrk;
  876. iwrk = itau + irows;
  877. i__1 = *lwork + 1 - iwrk;
  878. sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  879. iwrk], &i__1, &ierr);
  880. /* Apply the orthogonal transformation to matrix A */
  881. /* (Workspace: need N, prefer N*NB) */
  882. i__1 = *lwork + 1 - iwrk;
  883. sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  884. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
  885. ierr);
  886. /* Initialize VSL */
  887. /* (Workspace: need N, prefer N*NB) */
  888. if (ilvsl) {
  889. slaset_("Full", n, n, &c_b38, &c_b39, &vsl[vsl_offset], ldvsl);
  890. if (irows > 1) {
  891. i__1 = irows - 1;
  892. i__2 = irows - 1;
  893. slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[
  894. ilo + 1 + ilo * vsl_dim1], ldvsl);
  895. }
  896. i__1 = *lwork + 1 - iwrk;
  897. sorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
  898. work[itau], &work[iwrk], &i__1, &ierr);
  899. }
  900. /* Initialize VSR */
  901. if (ilvsr) {
  902. slaset_("Full", n, n, &c_b38, &c_b39, &vsr[vsr_offset], ldvsr);
  903. }
  904. /* Reduce to generalized Hessenberg form */
  905. /* (Workspace: none needed) */
  906. sgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  907. ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr);
  908. /* Perform QZ algorithm, computing Schur vectors if desired */
  909. /* (Workspace: need N) */
  910. iwrk = itau;
  911. i__1 = *lwork + 1 - iwrk;
  912. shgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  913. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
  914. , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &ierr);
  915. if (ierr != 0) {
  916. if (ierr > 0 && ierr <= *n) {
  917. *info = ierr;
  918. } else if (ierr > *n && ierr <= *n << 1) {
  919. *info = ierr - *n;
  920. } else {
  921. *info = *n + 1;
  922. }
  923. goto L40;
  924. }
  925. /* Sort eigenvalues ALPHA/BETA if desired */
  926. /* (Workspace: need 4*N+16 ) */
  927. *sdim = 0;
  928. if (wantst) {
  929. /* Undo scaling on eigenvalues before SELCTGing */
  930. if (ilascl) {
  931. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1],
  932. n, &ierr);
  933. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1],
  934. n, &ierr);
  935. }
  936. if (ilbscl) {
  937. slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n,
  938. &ierr);
  939. }
  940. /* Select eigenvalues */
  941. i__1 = *n;
  942. for (i__ = 1; i__ <= i__1; ++i__) {
  943. bwork[i__] = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
  944. /* L10: */
  945. }
  946. i__1 = *lwork - iwrk + 1;
  947. stgsen_(&c__0, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[
  948. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[
  949. vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pvsl, &
  950. pvsr, dif, &work[iwrk], &i__1, idum, &c__1, &ierr);
  951. if (ierr == 1) {
  952. *info = *n + 3;
  953. }
  954. }
  955. /* Apply back-permutation to VSL and VSR */
  956. /* (Workspace: none needed) */
  957. if (ilvsl) {
  958. sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
  959. vsl_offset], ldvsl, &ierr);
  960. }
  961. if (ilvsr) {
  962. sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
  963. vsr_offset], ldvsr, &ierr);
  964. }
  965. /* Check if unscaling would cause over/underflow, if so, rescale */
  966. /* (ALPHAR(I),ALPHAI(I),BETA(I)) so BETA(I) is on the order of */
  967. /* B(I,I) and ALPHAR(I) and ALPHAI(I) are on the order of A(I,I) */
  968. if (ilascl) {
  969. i__1 = *n;
  970. for (i__ = 1; i__ <= i__1; ++i__) {
  971. if (alphai[i__] != 0.f) {
  972. if (alphar[i__] / safmax > anrmto / anrm || safmin / alphar[
  973. i__] > anrm / anrmto) {
  974. work[1] = (r__1 = a[i__ + i__ * a_dim1] / alphar[i__],
  975. abs(r__1));
  976. beta[i__] *= work[1];
  977. alphar[i__] *= work[1];
  978. alphai[i__] *= work[1];
  979. } else if (alphai[i__] / safmax > anrmto / anrm || safmin /
  980. alphai[i__] > anrm / anrmto) {
  981. work[1] = (r__1 = a[i__ + (i__ + 1) * a_dim1] / alphai[
  982. i__], abs(r__1));
  983. beta[i__] *= work[1];
  984. alphar[i__] *= work[1];
  985. alphai[i__] *= work[1];
  986. }
  987. }
  988. /* L50: */
  989. }
  990. }
  991. if (ilbscl) {
  992. i__1 = *n;
  993. for (i__ = 1; i__ <= i__1; ++i__) {
  994. if (alphai[i__] != 0.f) {
  995. if (beta[i__] / safmax > bnrmto / bnrm || safmin / beta[i__]
  996. > bnrm / bnrmto) {
  997. work[1] = (r__1 = b[i__ + i__ * b_dim1] / beta[i__], abs(
  998. r__1));
  999. beta[i__] *= work[1];
  1000. alphar[i__] *= work[1];
  1001. alphai[i__] *= work[1];
  1002. }
  1003. }
  1004. /* L60: */
  1005. }
  1006. }
  1007. /* Undo scaling */
  1008. if (ilascl) {
  1009. slascl_("H", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, &
  1010. ierr);
  1011. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  1012. ierr);
  1013. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  1014. ierr);
  1015. }
  1016. if (ilbscl) {
  1017. slascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
  1018. ierr);
  1019. slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  1020. ierr);
  1021. }
  1022. if (wantst) {
  1023. /* Check if reordering is correct */
  1024. lastsl = TRUE_;
  1025. lst2sl = TRUE_;
  1026. *sdim = 0;
  1027. ip = 0;
  1028. i__1 = *n;
  1029. for (i__ = 1; i__ <= i__1; ++i__) {
  1030. cursl = (*selctg)(&alphar[i__], &alphai[i__], &beta[i__]);
  1031. if (alphai[i__] == 0.f) {
  1032. if (cursl) {
  1033. ++(*sdim);
  1034. }
  1035. ip = 0;
  1036. if (cursl && ! lastsl) {
  1037. *info = *n + 2;
  1038. }
  1039. } else {
  1040. if (ip == 1) {
  1041. /* Last eigenvalue of conjugate pair */
  1042. cursl = cursl || lastsl;
  1043. lastsl = cursl;
  1044. if (cursl) {
  1045. *sdim += 2;
  1046. }
  1047. ip = -1;
  1048. if (cursl && ! lst2sl) {
  1049. *info = *n + 2;
  1050. }
  1051. } else {
  1052. /* First eigenvalue of conjugate pair */
  1053. ip = 1;
  1054. }
  1055. }
  1056. lst2sl = lastsl;
  1057. lastsl = cursl;
  1058. /* L30: */
  1059. }
  1060. }
  1061. L40:
  1062. work[1] = (real) maxwrk;
  1063. return 0;
  1064. /* End of SGGES */
  1065. } /* sgges_ */