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.

sgegs.c 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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 d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  191. #define d_log(x) (log(*(x)))
  192. #define d_mod(x, y) (fmod(*(x), *(y)))
  193. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  194. #define d_nint(x) u_nint(*(x))
  195. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  196. #define d_sign(a,b) u_sign(*(a),*(b))
  197. #define d_sin(x) (sin(*(x)))
  198. #define d_sinh(x) (sinh(*(x)))
  199. #define d_sqrt(x) (sqrt(*(x)))
  200. #define d_tan(x) (tan(*(x)))
  201. #define d_tanh(x) (tanh(*(x)))
  202. #define i_abs(x) abs(*(x))
  203. #define i_dnnt(x) ((integer)u_nint(*(x)))
  204. #define i_len(s, n) (n)
  205. #define i_nint(x) ((integer)u_nint(*(x)))
  206. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  207. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  208. #define pow_si(B,E) spow_ui(*(B),*(E))
  209. #define pow_di(B,E) dpow_ui(*(B),*(E))
  210. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  211. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  212. #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++ = ' '; }
  213. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  214. #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]; }
  215. #define sig_die(s, kill) { exit(1); }
  216. #define s_stop(s, n) {exit(0);}
  217. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  218. #define z_abs(z) (cabs(Cd(z)))
  219. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  220. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  221. #define myexit_() break;
  222. #define mycycle() continue;
  223. #define myceiling(w) {ceil(w)}
  224. #define myhuge(w) {HUGE_VAL}
  225. #define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  226. /* procedure parameter types for -A and -C++ */
  227. #define F2C_proc_par_types 1
  228. #ifdef __cplusplus
  229. typedef logical (*L_fp)(...);
  230. #else
  231. typedef logical (*L_fp)();
  232. #endif
  233. static float spow_ui(float x, integer n) {
  234. float pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static double dpow_ui(double x, integer n) {
  246. double pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex float cpow_ui(_Complex float x, integer n) {
  258. _Complex float pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static _Complex double zpow_ui(_Complex double x, integer n) {
  270. _Complex double pow=1.0; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x = 1/x;
  273. for(u = n; ; ) {
  274. if(u & 01) pow *= x;
  275. if(u >>= 1) x *= x;
  276. else break;
  277. }
  278. }
  279. return pow;
  280. }
  281. static integer pow_ii(integer x, integer n) {
  282. integer pow; unsigned long int u;
  283. if (n <= 0) {
  284. if (n == 0 || x == 1) pow = 1;
  285. else if (x != -1) pow = x == 0 ? 1/x : 0;
  286. else n = -n;
  287. }
  288. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  289. u = n;
  290. for(pow = 1; ; ) {
  291. if(u & 01) pow *= x;
  292. if(u >>= 1) x *= x;
  293. else break;
  294. }
  295. }
  296. return pow;
  297. }
  298. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  299. {
  300. double m; integer i, mi;
  301. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  302. if (w[i-1]>m) mi=i ,m=w[i-1];
  303. return mi-s+1;
  304. }
  305. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  306. {
  307. float m; integer i, mi;
  308. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  309. if (w[i-1]>m) mi=i ,m=w[i-1];
  310. return mi-s+1;
  311. }
  312. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  313. integer n = *n_, incx = *incx_, incy = *incy_, i;
  314. _Complex float zdotc = 0.0;
  315. if (incx == 1 && incy == 1) {
  316. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  317. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  318. }
  319. } else {
  320. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  321. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  322. }
  323. }
  324. pCf(z) = zdotc;
  325. }
  326. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  327. integer n = *n_, incx = *incx_, incy = *incy_, i;
  328. _Complex double zdotc = 0.0;
  329. if (incx == 1 && incy == 1) {
  330. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  331. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  332. }
  333. } else {
  334. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  335. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  336. }
  337. }
  338. pCd(z) = zdotc;
  339. }
  340. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  341. integer n = *n_, incx = *incx_, incy = *incy_, i;
  342. _Complex float zdotc = 0.0;
  343. if (incx == 1 && incy == 1) {
  344. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  345. zdotc += Cf(&x[i]) * Cf(&y[i]);
  346. }
  347. } else {
  348. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  349. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  350. }
  351. }
  352. pCf(z) = zdotc;
  353. }
  354. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  355. integer n = *n_, incx = *incx_, incy = *incy_, i;
  356. _Complex double zdotc = 0.0;
  357. if (incx == 1 && incy == 1) {
  358. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  359. zdotc += Cd(&x[i]) * Cd(&y[i]);
  360. }
  361. } else {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  364. }
  365. }
  366. pCd(z) = zdotc;
  367. }
  368. #endif
  369. /* -- translated by f2c (version 20000121).
  370. You must link the resulting object file with the libraries:
  371. -lf2c -lm (in that order)
  372. */
  373. /* Table of constant values */
  374. static integer c__1 = 1;
  375. static integer c_n1 = -1;
  376. static real c_b36 = 0.f;
  377. static real c_b37 = 1.f;
  378. /* > \brief <b> SGEGS computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matr
  379. ices</b> */
  380. /* =========== DOCUMENTATION =========== */
  381. /* Online html documentation available at */
  382. /* http://www.netlib.org/lapack/explore-html/ */
  383. /* > \htmlonly */
  384. /* > Download SGEGS + dependencies */
  385. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgegs.f
  386. "> */
  387. /* > [TGZ]</a> */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgegs.f
  389. "> */
  390. /* > [ZIP]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgegs.f
  392. "> */
  393. /* > [TXT]</a> */
  394. /* > \endhtmlonly */
  395. /* Definition: */
  396. /* =========== */
  397. /* SUBROUTINE SGEGS( JOBVSL, JOBVSR, N, A, LDA, B, LDB, ALPHAR, */
  398. /* ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, WORK, */
  399. /* LWORK, INFO ) */
  400. /* CHARACTER JOBVSL, JOBVSR */
  401. /* INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N */
  402. /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  403. /* $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ), */
  404. /* $ VSR( LDVSR, * ), WORK( * ) */
  405. /* > \par Purpose: */
  406. /* ============= */
  407. /* > */
  408. /* > \verbatim */
  409. /* > */
  410. /* > This routine is deprecated and has been replaced by routine SGGES. */
  411. /* > */
  412. /* > SGEGS computes the eigenvalues, real Schur form, and, optionally, */
  413. /* > left and or/right Schur vectors of a real matrix pair (A,B). */
  414. /* > Given two square matrices A and B, the generalized real Schur */
  415. /* > factorization has the form */
  416. /* > */
  417. /* > A = Q*S*Z**T, B = Q*T*Z**T */
  418. /* > */
  419. /* > where Q and Z are orthogonal matrices, T is upper triangular, and S */
  420. /* > is an upper quasi-triangular matrix with 1-by-1 and 2-by-2 diagonal */
  421. /* > blocks, the 2-by-2 blocks corresponding to complex conjugate pairs */
  422. /* > of eigenvalues of (A,B). The columns of Q are the left Schur vectors */
  423. /* > and the columns of Z are the right Schur vectors. */
  424. /* > */
  425. /* > If only the eigenvalues of (A,B) are needed, the driver routine */
  426. /* > SGEGV should be used instead. See SGEGV for a description of the */
  427. /* > eigenvalues of the generalized nonsymmetric eigenvalue problem */
  428. /* > (GNEP). */
  429. /* > \endverbatim */
  430. /* Arguments: */
  431. /* ========== */
  432. /* > \param[in] JOBVSL */
  433. /* > \verbatim */
  434. /* > JOBVSL is CHARACTER*1 */
  435. /* > = 'N': do not compute the left Schur vectors; */
  436. /* > = 'V': compute the left Schur vectors (returned in VSL). */
  437. /* > \endverbatim */
  438. /* > */
  439. /* > \param[in] JOBVSR */
  440. /* > \verbatim */
  441. /* > JOBVSR is CHARACTER*1 */
  442. /* > = 'N': do not compute the right Schur vectors; */
  443. /* > = 'V': compute the right Schur vectors (returned in VSR). */
  444. /* > \endverbatim */
  445. /* > */
  446. /* > \param[in] N */
  447. /* > \verbatim */
  448. /* > N is INTEGER */
  449. /* > The order of the matrices A, B, VSL, and VSR. N >= 0. */
  450. /* > \endverbatim */
  451. /* > */
  452. /* > \param[in,out] A */
  453. /* > \verbatim */
  454. /* > A is REAL array, dimension (LDA, N) */
  455. /* > On entry, the matrix A. */
  456. /* > On exit, the upper quasi-triangular matrix S from the */
  457. /* > generalized real Schur factorization. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in] LDA */
  461. /* > \verbatim */
  462. /* > LDA is INTEGER */
  463. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[in,out] B */
  467. /* > \verbatim */
  468. /* > B is REAL array, dimension (LDB, N) */
  469. /* > On entry, the matrix B. */
  470. /* > On exit, the upper triangular matrix T from the generalized */
  471. /* > real Schur factorization. */
  472. /* > \endverbatim */
  473. /* > */
  474. /* > \param[in] LDB */
  475. /* > \verbatim */
  476. /* > LDB is INTEGER */
  477. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[out] ALPHAR */
  481. /* > \verbatim */
  482. /* > ALPHAR is REAL array, dimension (N) */
  483. /* > The real parts of each scalar alpha defining an eigenvalue */
  484. /* > of GNEP. */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[out] ALPHAI */
  488. /* > \verbatim */
  489. /* > ALPHAI is REAL array, dimension (N) */
  490. /* > The imaginary parts of each scalar alpha defining an */
  491. /* > eigenvalue of GNEP. If ALPHAI(j) is zero, then the j-th */
  492. /* > eigenvalue is real; if positive, then the j-th and (j+1)-st */
  493. /* > eigenvalues are a complex conjugate pair, with */
  494. /* > ALPHAI(j+1) = -ALPHAI(j). */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[out] BETA */
  498. /* > \verbatim */
  499. /* > BETA is REAL array, dimension (N) */
  500. /* > The scalars beta that define the eigenvalues of GNEP. */
  501. /* > Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
  502. /* > beta = BETA(j) represent the j-th eigenvalue of the matrix */
  503. /* > pair (A,B), in one of the forms lambda = alpha/beta or */
  504. /* > mu = beta/alpha. Since either lambda or mu may overflow, */
  505. /* > they should not, in general, be computed. */
  506. /* > \endverbatim */
  507. /* > */
  508. /* > \param[out] VSL */
  509. /* > \verbatim */
  510. /* > VSL is REAL array, dimension (LDVSL,N) */
  511. /* > If JOBVSL = 'V', the matrix of left Schur vectors Q. */
  512. /* > Not referenced if JOBVSL = 'N'. */
  513. /* > \endverbatim */
  514. /* > */
  515. /* > \param[in] LDVSL */
  516. /* > \verbatim */
  517. /* > LDVSL is INTEGER */
  518. /* > The leading dimension of the matrix VSL. LDVSL >=1, and */
  519. /* > if JOBVSL = 'V', LDVSL >= N. */
  520. /* > \endverbatim */
  521. /* > */
  522. /* > \param[out] VSR */
  523. /* > \verbatim */
  524. /* > VSR is REAL array, dimension (LDVSR,N) */
  525. /* > If JOBVSR = 'V', the matrix of right Schur vectors Z. */
  526. /* > Not referenced if JOBVSR = 'N'. */
  527. /* > \endverbatim */
  528. /* > */
  529. /* > \param[in] LDVSR */
  530. /* > \verbatim */
  531. /* > LDVSR is INTEGER */
  532. /* > The leading dimension of the matrix VSR. LDVSR >= 1, and */
  533. /* > if JOBVSR = 'V', LDVSR >= N. */
  534. /* > \endverbatim */
  535. /* > */
  536. /* > \param[out] WORK */
  537. /* > \verbatim */
  538. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  539. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[in] LWORK */
  543. /* > \verbatim */
  544. /* > LWORK is INTEGER */
  545. /* > The dimension of the array WORK. LWORK >= f2cmax(1,4*N). */
  546. /* > For good performance, LWORK must generally be larger. */
  547. /* > To compute the optimal value of LWORK, call ILAENV to get */
  548. /* > blocksizes (for SGEQRF, SORMQR, and SORGQR.) Then compute: */
  549. /* > NB -- MAX of the blocksizes for SGEQRF, SORMQR, and SORGQR */
  550. /* > The optimal LWORK is 2*N + N*(NB+1). */
  551. /* > */
  552. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  553. /* > only calculates the optimal size of the WORK array, returns */
  554. /* > this value as the first entry of the WORK array, and no error */
  555. /* > message related to LWORK is issued by XERBLA. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[out] INFO */
  559. /* > \verbatim */
  560. /* > INFO is INTEGER */
  561. /* > = 0: successful exit */
  562. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  563. /* > = 1,...,N: */
  564. /* > The QZ iteration failed. (A,B) are not in Schur */
  565. /* > form, but ALPHAR(j), ALPHAI(j), and BETA(j) should */
  566. /* > be correct for j=INFO+1,...,N. */
  567. /* > > N: errors that usually indicate LAPACK problems: */
  568. /* > =N+1: error return from SGGBAL */
  569. /* > =N+2: error return from SGEQRF */
  570. /* > =N+3: error return from SORMQR */
  571. /* > =N+4: error return from SORGQR */
  572. /* > =N+5: error return from SGGHRD */
  573. /* > =N+6: error return from SHGEQZ (other than failed */
  574. /* > iteration) */
  575. /* > =N+7: error return from SGGBAK (computing VSL) */
  576. /* > =N+8: error return from SGGBAK (computing VSR) */
  577. /* > =N+9: error return from SLASCL (various places) */
  578. /* > \endverbatim */
  579. /* Authors: */
  580. /* ======== */
  581. /* > \author Univ. of Tennessee */
  582. /* > \author Univ. of California Berkeley */
  583. /* > \author Univ. of Colorado Denver */
  584. /* > \author NAG Ltd. */
  585. /* > \date December 2016 */
  586. /* > \ingroup realGEeigen */
  587. /* ===================================================================== */
  588. /* Subroutine */ int sgegs_(char *jobvsl, char *jobvsr, integer *n, real *a,
  589. integer *lda, real *b, integer *ldb, real *alphar, real *alphai, real
  590. *beta, real *vsl, integer *ldvsl, real *vsr, integer *ldvsr, real *
  591. work, integer *lwork, integer *info)
  592. {
  593. /* System generated locals */
  594. integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
  595. vsr_dim1, vsr_offset, i__1, i__2;
  596. /* Local variables */
  597. real anrm, bnrm;
  598. integer itau, lopt;
  599. extern logical lsame_(char *, char *);
  600. integer ileft, iinfo, icols;
  601. logical ilvsl;
  602. integer iwork;
  603. logical ilvsr;
  604. integer irows, nb;
  605. extern /* Subroutine */ int sggbak_(char *, char *, integer *, integer *,
  606. integer *, real *, real *, integer *, real *, integer *, integer *
  607. ), sggbal_(char *, integer *, real *, integer *,
  608. real *, integer *, integer *, integer *, real *, real *, real *,
  609. integer *);
  610. logical ilascl, ilbscl;
  611. extern real slamch_(char *), slange_(char *, integer *, integer *,
  612. real *, integer *, real *);
  613. real safmin;
  614. extern /* Subroutine */ int sgghrd_(char *, char *, integer *, integer *,
  615. integer *, real *, integer *, real *, integer *, real *, integer *
  616. , real *, integer *, integer *), xerbla_(char *,
  617. integer *);
  618. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  619. integer *, integer *, ftnlen, ftnlen);
  620. real bignum;
  621. extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
  622. real *, integer *, integer *, real *, integer *, integer *);
  623. integer ijobvl, iright;
  624. extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer
  625. *, real *, real *, integer *, integer *);
  626. integer ijobvr;
  627. extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *,
  628. integer *, real *, integer *), slaset_(char *, integer *,
  629. integer *, real *, real *, real *, integer *);
  630. real anrmto;
  631. integer lwkmin, nb1, nb2, nb3;
  632. real bnrmto;
  633. extern /* Subroutine */ int shgeqz_(char *, char *, char *, integer *,
  634. integer *, integer *, real *, integer *, real *, integer *, real *
  635. , real *, real *, real *, integer *, real *, integer *, real *,
  636. integer *, integer *);
  637. real smlnum;
  638. extern /* Subroutine */ int sorgqr_(integer *, integer *, integer *, real
  639. *, integer *, real *, real *, integer *, integer *);
  640. integer lwkopt;
  641. logical lquery;
  642. extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *,
  643. integer *, real *, integer *, real *, real *, integer *, real *,
  644. integer *, integer *);
  645. integer ihi, ilo;
  646. real eps;
  647. /* -- LAPACK driver routine (version 3.7.0) -- */
  648. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  649. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  650. /* December 2016 */
  651. /* ===================================================================== */
  652. /* Decode the input arguments */
  653. /* Parameter adjustments */
  654. a_dim1 = *lda;
  655. a_offset = 1 + a_dim1 * 1;
  656. a -= a_offset;
  657. b_dim1 = *ldb;
  658. b_offset = 1 + b_dim1 * 1;
  659. b -= b_offset;
  660. --alphar;
  661. --alphai;
  662. --beta;
  663. vsl_dim1 = *ldvsl;
  664. vsl_offset = 1 + vsl_dim1 * 1;
  665. vsl -= vsl_offset;
  666. vsr_dim1 = *ldvsr;
  667. vsr_offset = 1 + vsr_dim1 * 1;
  668. vsr -= vsr_offset;
  669. --work;
  670. /* Function Body */
  671. if (lsame_(jobvsl, "N")) {
  672. ijobvl = 1;
  673. ilvsl = FALSE_;
  674. } else if (lsame_(jobvsl, "V")) {
  675. ijobvl = 2;
  676. ilvsl = TRUE_;
  677. } else {
  678. ijobvl = -1;
  679. ilvsl = FALSE_;
  680. }
  681. if (lsame_(jobvsr, "N")) {
  682. ijobvr = 1;
  683. ilvsr = FALSE_;
  684. } else if (lsame_(jobvsr, "V")) {
  685. ijobvr = 2;
  686. ilvsr = TRUE_;
  687. } else {
  688. ijobvr = -1;
  689. ilvsr = FALSE_;
  690. }
  691. /* Test the input arguments */
  692. /* Computing MAX */
  693. i__1 = *n << 2;
  694. lwkmin = f2cmax(i__1,1);
  695. lwkopt = lwkmin;
  696. work[1] = (real) lwkopt;
  697. lquery = *lwork == -1;
  698. *info = 0;
  699. if (ijobvl <= 0) {
  700. *info = -1;
  701. } else if (ijobvr <= 0) {
  702. *info = -2;
  703. } else if (*n < 0) {
  704. *info = -3;
  705. } else if (*lda < f2cmax(1,*n)) {
  706. *info = -5;
  707. } else if (*ldb < f2cmax(1,*n)) {
  708. *info = -7;
  709. } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
  710. *info = -12;
  711. } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
  712. *info = -14;
  713. } else if (*lwork < lwkmin && ! lquery) {
  714. *info = -16;
  715. }
  716. if (*info == 0) {
  717. nb1 = ilaenv_(&c__1, "SGEQRF", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
  718. ftnlen)1);
  719. nb2 = ilaenv_(&c__1, "SORMQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  720. ftnlen)1);
  721. nb3 = ilaenv_(&c__1, "SORGQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  722. ftnlen)1);
  723. /* Computing MAX */
  724. i__1 = f2cmax(nb1,nb2);
  725. nb = f2cmax(i__1,nb3);
  726. lopt = (*n << 1) + *n * (nb + 1);
  727. work[1] = (real) lopt;
  728. }
  729. if (*info != 0) {
  730. i__1 = -(*info);
  731. xerbla_("SGEGS ", &i__1);
  732. return 0;
  733. } else if (lquery) {
  734. return 0;
  735. }
  736. /* Quick return if possible */
  737. if (*n == 0) {
  738. return 0;
  739. }
  740. /* Get machine constants */
  741. eps = slamch_("E") * slamch_("B");
  742. safmin = slamch_("S");
  743. smlnum = *n * safmin / eps;
  744. bignum = 1.f / smlnum;
  745. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  746. anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
  747. ilascl = FALSE_;
  748. if (anrm > 0.f && anrm < smlnum) {
  749. anrmto = smlnum;
  750. ilascl = TRUE_;
  751. } else if (anrm > bignum) {
  752. anrmto = bignum;
  753. ilascl = TRUE_;
  754. }
  755. if (ilascl) {
  756. slascl_("G", &c_n1, &c_n1, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  757. iinfo);
  758. if (iinfo != 0) {
  759. *info = *n + 9;
  760. return 0;
  761. }
  762. }
  763. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  764. bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
  765. ilbscl = FALSE_;
  766. if (bnrm > 0.f && bnrm < smlnum) {
  767. bnrmto = smlnum;
  768. ilbscl = TRUE_;
  769. } else if (bnrm > bignum) {
  770. bnrmto = bignum;
  771. ilbscl = TRUE_;
  772. }
  773. if (ilbscl) {
  774. slascl_("G", &c_n1, &c_n1, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  775. iinfo);
  776. if (iinfo != 0) {
  777. *info = *n + 9;
  778. return 0;
  779. }
  780. }
  781. /* Permute the matrix to make it more nearly triangular */
  782. /* Workspace layout: (2*N words -- "work..." not actually used) */
  783. /* left_permutation, right_permutation, work... */
  784. ileft = 1;
  785. iright = *n + 1;
  786. iwork = iright + *n;
  787. sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  788. ileft], &work[iright], &work[iwork], &iinfo);
  789. if (iinfo != 0) {
  790. *info = *n + 1;
  791. goto L10;
  792. }
  793. /* Reduce B to triangular form, and initialize VSL and/or VSR */
  794. /* Workspace layout: ("work..." must have at least N words) */
  795. /* left_permutation, right_permutation, tau, work... */
  796. irows = ihi + 1 - ilo;
  797. icols = *n + 1 - ilo;
  798. itau = iwork;
  799. iwork = itau + irows;
  800. i__1 = *lwork + 1 - iwork;
  801. sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  802. iwork], &i__1, &iinfo);
  803. if (iinfo >= 0) {
  804. /* Computing MAX */
  805. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  806. lwkopt = f2cmax(i__1,i__2);
  807. }
  808. if (iinfo != 0) {
  809. *info = *n + 2;
  810. goto L10;
  811. }
  812. i__1 = *lwork + 1 - iwork;
  813. sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  814. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  815. iinfo);
  816. if (iinfo >= 0) {
  817. /* Computing MAX */
  818. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  819. lwkopt = f2cmax(i__1,i__2);
  820. }
  821. if (iinfo != 0) {
  822. *info = *n + 3;
  823. goto L10;
  824. }
  825. if (ilvsl) {
  826. slaset_("Full", n, n, &c_b36, &c_b37, &vsl[vsl_offset], ldvsl);
  827. i__1 = irows - 1;
  828. i__2 = irows - 1;
  829. slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ilo
  830. + 1 + ilo * vsl_dim1], ldvsl);
  831. i__1 = *lwork + 1 - iwork;
  832. sorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
  833. work[itau], &work[iwork], &i__1, &iinfo);
  834. if (iinfo >= 0) {
  835. /* Computing MAX */
  836. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  837. lwkopt = f2cmax(i__1,i__2);
  838. }
  839. if (iinfo != 0) {
  840. *info = *n + 4;
  841. goto L10;
  842. }
  843. }
  844. if (ilvsr) {
  845. slaset_("Full", n, n, &c_b36, &c_b37, &vsr[vsr_offset], ldvsr);
  846. }
  847. /* Reduce to generalized Hessenberg form */
  848. sgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  849. ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &iinfo);
  850. if (iinfo != 0) {
  851. *info = *n + 5;
  852. goto L10;
  853. }
  854. /* Perform QZ algorithm, computing Schur vectors if desired */
  855. /* Workspace layout: ("work..." must have at least 1 word) */
  856. /* left_permutation, right_permutation, work... */
  857. iwork = itau;
  858. i__1 = *lwork + 1 - iwork;
  859. shgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  860. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
  861. , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwork], &i__1, &iinfo);
  862. if (iinfo >= 0) {
  863. /* Computing MAX */
  864. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  865. lwkopt = f2cmax(i__1,i__2);
  866. }
  867. if (iinfo != 0) {
  868. if (iinfo > 0 && iinfo <= *n) {
  869. *info = iinfo;
  870. } else if (iinfo > *n && iinfo <= *n << 1) {
  871. *info = iinfo - *n;
  872. } else {
  873. *info = *n + 6;
  874. }
  875. goto L10;
  876. }
  877. /* Apply permutation to VSL and VSR */
  878. if (ilvsl) {
  879. sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
  880. vsl_offset], ldvsl, &iinfo);
  881. if (iinfo != 0) {
  882. *info = *n + 7;
  883. goto L10;
  884. }
  885. }
  886. if (ilvsr) {
  887. sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
  888. vsr_offset], ldvsr, &iinfo);
  889. if (iinfo != 0) {
  890. *info = *n + 8;
  891. goto L10;
  892. }
  893. }
  894. /* Undo scaling */
  895. if (ilascl) {
  896. slascl_("H", &c_n1, &c_n1, &anrmto, &anrm, n, n, &a[a_offset], lda, &
  897. iinfo);
  898. if (iinfo != 0) {
  899. *info = *n + 9;
  900. return 0;
  901. }
  902. slascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  903. iinfo);
  904. if (iinfo != 0) {
  905. *info = *n + 9;
  906. return 0;
  907. }
  908. slascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  909. iinfo);
  910. if (iinfo != 0) {
  911. *info = *n + 9;
  912. return 0;
  913. }
  914. }
  915. if (ilbscl) {
  916. slascl_("U", &c_n1, &c_n1, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
  917. iinfo);
  918. if (iinfo != 0) {
  919. *info = *n + 9;
  920. return 0;
  921. }
  922. slascl_("G", &c_n1, &c_n1, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  923. iinfo);
  924. if (iinfo != 0) {
  925. *info = *n + 9;
  926. return 0;
  927. }
  928. }
  929. L10:
  930. work[1] = (real) lwkopt;
  931. return 0;
  932. /* End of SGEGS */
  933. } /* sgegs_ */