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 27 kB

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