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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #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]);}
  173. #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]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #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++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #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]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #define F2C_proc_par_types 1
  240. /* -- translated by f2c (version 20000121).
  241. You must link the resulting object file with the libraries:
  242. -lf2c -lm (in that order)
  243. */
  244. /* Table of constant values */
  245. static integer c__1 = 1;
  246. static integer c_n1 = -1;
  247. static real c_b36 = 0.f;
  248. static real c_b37 = 1.f;
  249. /* > \brief <b> SGEGS computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matr
  250. ices</b> */
  251. /* =========== DOCUMENTATION =========== */
  252. /* Online html documentation available at */
  253. /* http://www.netlib.org/lapack/explore-html/ */
  254. /* > \htmlonly */
  255. /* > Download SGEGS + dependencies */
  256. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgegs.f
  257. "> */
  258. /* > [TGZ]</a> */
  259. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgegs.f
  260. "> */
  261. /* > [ZIP]</a> */
  262. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgegs.f
  263. "> */
  264. /* > [TXT]</a> */
  265. /* > \endhtmlonly */
  266. /* Definition: */
  267. /* =========== */
  268. /* SUBROUTINE SGEGS( JOBVSL, JOBVSR, N, A, LDA, B, LDB, ALPHAR, */
  269. /* ALPHAI, BETA, VSL, LDVSL, VSR, LDVSR, WORK, */
  270. /* LWORK, INFO ) */
  271. /* CHARACTER JOBVSL, JOBVSR */
  272. /* INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N */
  273. /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  274. /* $ B( LDB, * ), BETA( * ), VSL( LDVSL, * ), */
  275. /* $ VSR( LDVSR, * ), WORK( * ) */
  276. /* > \par Purpose: */
  277. /* ============= */
  278. /* > */
  279. /* > \verbatim */
  280. /* > */
  281. /* > This routine is deprecated and has been replaced by routine SGGES. */
  282. /* > */
  283. /* > SGEGS computes the eigenvalues, real Schur form, and, optionally, */
  284. /* > left and or/right Schur vectors of a real matrix pair (A,B). */
  285. /* > Given two square matrices A and B, the generalized real Schur */
  286. /* > factorization has the form */
  287. /* > */
  288. /* > A = Q*S*Z**T, B = Q*T*Z**T */
  289. /* > */
  290. /* > where Q and Z are orthogonal matrices, T is upper triangular, and S */
  291. /* > is an upper quasi-triangular matrix with 1-by-1 and 2-by-2 diagonal */
  292. /* > blocks, the 2-by-2 blocks corresponding to complex conjugate pairs */
  293. /* > of eigenvalues of (A,B). The columns of Q are the left Schur vectors */
  294. /* > and the columns of Z are the right Schur vectors. */
  295. /* > */
  296. /* > If only the eigenvalues of (A,B) are needed, the driver routine */
  297. /* > SGEGV should be used instead. See SGEGV for a description of the */
  298. /* > eigenvalues of the generalized nonsymmetric eigenvalue problem */
  299. /* > (GNEP). */
  300. /* > \endverbatim */
  301. /* Arguments: */
  302. /* ========== */
  303. /* > \param[in] JOBVSL */
  304. /* > \verbatim */
  305. /* > JOBVSL is CHARACTER*1 */
  306. /* > = 'N': do not compute the left Schur vectors; */
  307. /* > = 'V': compute the left Schur vectors (returned in VSL). */
  308. /* > \endverbatim */
  309. /* > */
  310. /* > \param[in] JOBVSR */
  311. /* > \verbatim */
  312. /* > JOBVSR is CHARACTER*1 */
  313. /* > = 'N': do not compute the right Schur vectors; */
  314. /* > = 'V': compute the right Schur vectors (returned in VSR). */
  315. /* > \endverbatim */
  316. /* > */
  317. /* > \param[in] N */
  318. /* > \verbatim */
  319. /* > N is INTEGER */
  320. /* > The order of the matrices A, B, VSL, and VSR. N >= 0. */
  321. /* > \endverbatim */
  322. /* > */
  323. /* > \param[in,out] A */
  324. /* > \verbatim */
  325. /* > A is REAL array, dimension (LDA, N) */
  326. /* > On entry, the matrix A. */
  327. /* > On exit, the upper quasi-triangular matrix S from the */
  328. /* > generalized real Schur factorization. */
  329. /* > \endverbatim */
  330. /* > */
  331. /* > \param[in] LDA */
  332. /* > \verbatim */
  333. /* > LDA is INTEGER */
  334. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  335. /* > \endverbatim */
  336. /* > */
  337. /* > \param[in,out] B */
  338. /* > \verbatim */
  339. /* > B is REAL array, dimension (LDB, N) */
  340. /* > On entry, the matrix B. */
  341. /* > On exit, the upper triangular matrix T from the generalized */
  342. /* > real Schur factorization. */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[in] LDB */
  346. /* > \verbatim */
  347. /* > LDB is INTEGER */
  348. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  349. /* > \endverbatim */
  350. /* > */
  351. /* > \param[out] ALPHAR */
  352. /* > \verbatim */
  353. /* > ALPHAR is REAL array, dimension (N) */
  354. /* > The real parts of each scalar alpha defining an eigenvalue */
  355. /* > of GNEP. */
  356. /* > \endverbatim */
  357. /* > */
  358. /* > \param[out] ALPHAI */
  359. /* > \verbatim */
  360. /* > ALPHAI is REAL array, dimension (N) */
  361. /* > The imaginary parts of each scalar alpha defining an */
  362. /* > eigenvalue of GNEP. If ALPHAI(j) is zero, then the j-th */
  363. /* > eigenvalue is real; if positive, then the j-th and (j+1)-st */
  364. /* > eigenvalues are a complex conjugate pair, with */
  365. /* > ALPHAI(j+1) = -ALPHAI(j). */
  366. /* > \endverbatim */
  367. /* > */
  368. /* > \param[out] BETA */
  369. /* > \verbatim */
  370. /* > BETA is REAL array, dimension (N) */
  371. /* > The scalars beta that define the eigenvalues of GNEP. */
  372. /* > Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
  373. /* > beta = BETA(j) represent the j-th eigenvalue of the matrix */
  374. /* > pair (A,B), in one of the forms lambda = alpha/beta or */
  375. /* > mu = beta/alpha. Since either lambda or mu may overflow, */
  376. /* > they should not, in general, be computed. */
  377. /* > \endverbatim */
  378. /* > */
  379. /* > \param[out] VSL */
  380. /* > \verbatim */
  381. /* > VSL is REAL array, dimension (LDVSL,N) */
  382. /* > If JOBVSL = 'V', the matrix of left Schur vectors Q. */
  383. /* > Not referenced if JOBVSL = 'N'. */
  384. /* > \endverbatim */
  385. /* > */
  386. /* > \param[in] LDVSL */
  387. /* > \verbatim */
  388. /* > LDVSL is INTEGER */
  389. /* > The leading dimension of the matrix VSL. LDVSL >=1, and */
  390. /* > if JOBVSL = 'V', LDVSL >= N. */
  391. /* > \endverbatim */
  392. /* > */
  393. /* > \param[out] VSR */
  394. /* > \verbatim */
  395. /* > VSR is REAL array, dimension (LDVSR,N) */
  396. /* > If JOBVSR = 'V', the matrix of right Schur vectors Z. */
  397. /* > Not referenced if JOBVSR = 'N'. */
  398. /* > \endverbatim */
  399. /* > */
  400. /* > \param[in] LDVSR */
  401. /* > \verbatim */
  402. /* > LDVSR is INTEGER */
  403. /* > The leading dimension of the matrix VSR. LDVSR >= 1, and */
  404. /* > if JOBVSR = 'V', LDVSR >= N. */
  405. /* > \endverbatim */
  406. /* > */
  407. /* > \param[out] WORK */
  408. /* > \verbatim */
  409. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  410. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  411. /* > \endverbatim */
  412. /* > */
  413. /* > \param[in] LWORK */
  414. /* > \verbatim */
  415. /* > LWORK is INTEGER */
  416. /* > The dimension of the array WORK. LWORK >= f2cmax(1,4*N). */
  417. /* > For good performance, LWORK must generally be larger. */
  418. /* > To compute the optimal value of LWORK, call ILAENV to get */
  419. /* > blocksizes (for SGEQRF, SORMQR, and SORGQR.) Then compute: */
  420. /* > NB -- MAX of the blocksizes for SGEQRF, SORMQR, and SORGQR */
  421. /* > The optimal LWORK is 2*N + N*(NB+1). */
  422. /* > */
  423. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  424. /* > only calculates the optimal size of the WORK array, returns */
  425. /* > this value as the first entry of the WORK array, and no error */
  426. /* > message related to LWORK is issued by XERBLA. */
  427. /* > \endverbatim */
  428. /* > */
  429. /* > \param[out] INFO */
  430. /* > \verbatim */
  431. /* > INFO is INTEGER */
  432. /* > = 0: successful exit */
  433. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  434. /* > = 1,...,N: */
  435. /* > The QZ iteration failed. (A,B) are not in Schur */
  436. /* > form, but ALPHAR(j), ALPHAI(j), and BETA(j) should */
  437. /* > be correct for j=INFO+1,...,N. */
  438. /* > > N: errors that usually indicate LAPACK problems: */
  439. /* > =N+1: error return from SGGBAL */
  440. /* > =N+2: error return from SGEQRF */
  441. /* > =N+3: error return from SORMQR */
  442. /* > =N+4: error return from SORGQR */
  443. /* > =N+5: error return from SGGHRD */
  444. /* > =N+6: error return from SHGEQZ (other than failed */
  445. /* > iteration) */
  446. /* > =N+7: error return from SGGBAK (computing VSL) */
  447. /* > =N+8: error return from SGGBAK (computing VSR) */
  448. /* > =N+9: error return from SLASCL (various places) */
  449. /* > \endverbatim */
  450. /* Authors: */
  451. /* ======== */
  452. /* > \author Univ. of Tennessee */
  453. /* > \author Univ. of California Berkeley */
  454. /* > \author Univ. of Colorado Denver */
  455. /* > \author NAG Ltd. */
  456. /* > \date December 2016 */
  457. /* > \ingroup realGEeigen */
  458. /* ===================================================================== */
  459. /* Subroutine */ void sgegs_(char *jobvsl, char *jobvsr, integer *n, real *a,
  460. integer *lda, real *b, integer *ldb, real *alphar, real *alphai, real
  461. *beta, real *vsl, integer *ldvsl, real *vsr, integer *ldvsr, real *
  462. work, integer *lwork, integer *info)
  463. {
  464. /* System generated locals */
  465. integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
  466. vsr_dim1, vsr_offset, i__1, i__2;
  467. /* Local variables */
  468. real anrm, bnrm;
  469. integer itau, lopt;
  470. extern logical lsame_(char *, char *);
  471. integer ileft, iinfo, icols;
  472. logical ilvsl;
  473. integer iwork;
  474. logical ilvsr;
  475. integer irows, nb;
  476. extern /* Subroutine */ void sggbak_(char *, char *, integer *, integer *,
  477. integer *, real *, real *, integer *, real *, integer *, integer *
  478. ), sggbal_(char *, integer *, real *, integer *,
  479. real *, integer *, integer *, integer *, real *, real *, real *,
  480. integer *);
  481. logical ilascl, ilbscl;
  482. extern real slamch_(char *), slange_(char *, integer *, integer *,
  483. real *, integer *, real *);
  484. real safmin;
  485. extern /* Subroutine */ void sgghrd_(char *, char *, integer *, integer *,
  486. integer *, real *, integer *, real *, integer *, real *, integer *
  487. , real *, integer *, integer *);
  488. extern int xerbla_(char *, integer *, ftnlen);
  489. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  490. integer *, integer *, ftnlen, ftnlen);
  491. real bignum;
  492. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  493. real *, integer *, integer *, real *, integer *, integer *);
  494. integer ijobvl, iright;
  495. extern /* Subroutine */ void sgeqrf_(integer *, integer *, real *, integer
  496. *, real *, real *, integer *, integer *);
  497. integer ijobvr;
  498. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  499. integer *, real *, integer *), slaset_(char *, integer *,
  500. integer *, real *, real *, real *, integer *);
  501. real anrmto;
  502. integer lwkmin, nb1, nb2, nb3;
  503. real bnrmto;
  504. extern /* Subroutine */ void shgeqz_(char *, char *, char *, integer *,
  505. integer *, integer *, real *, integer *, real *, integer *, real *
  506. , real *, real *, real *, integer *, real *, integer *, real *,
  507. integer *, integer *);
  508. real smlnum;
  509. extern /* Subroutine */ void sorgqr_(integer *, integer *, integer *, real
  510. *, integer *, real *, real *, integer *, integer *);
  511. integer lwkopt;
  512. logical lquery;
  513. extern /* Subroutine */ void sormqr_(char *, char *, integer *, integer *,
  514. integer *, real *, integer *, real *, real *, integer *, real *,
  515. integer *, integer *);
  516. integer ihi, ilo;
  517. real eps;
  518. /* -- LAPACK driver routine (version 3.7.0) -- */
  519. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  520. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  521. /* December 2016 */
  522. /* ===================================================================== */
  523. /* Decode the input arguments */
  524. /* Parameter adjustments */
  525. a_dim1 = *lda;
  526. a_offset = 1 + a_dim1 * 1;
  527. a -= a_offset;
  528. b_dim1 = *ldb;
  529. b_offset = 1 + b_dim1 * 1;
  530. b -= b_offset;
  531. --alphar;
  532. --alphai;
  533. --beta;
  534. vsl_dim1 = *ldvsl;
  535. vsl_offset = 1 + vsl_dim1 * 1;
  536. vsl -= vsl_offset;
  537. vsr_dim1 = *ldvsr;
  538. vsr_offset = 1 + vsr_dim1 * 1;
  539. vsr -= vsr_offset;
  540. --work;
  541. /* Function Body */
  542. if (lsame_(jobvsl, "N")) {
  543. ijobvl = 1;
  544. ilvsl = FALSE_;
  545. } else if (lsame_(jobvsl, "V")) {
  546. ijobvl = 2;
  547. ilvsl = TRUE_;
  548. } else {
  549. ijobvl = -1;
  550. ilvsl = FALSE_;
  551. }
  552. if (lsame_(jobvsr, "N")) {
  553. ijobvr = 1;
  554. ilvsr = FALSE_;
  555. } else if (lsame_(jobvsr, "V")) {
  556. ijobvr = 2;
  557. ilvsr = TRUE_;
  558. } else {
  559. ijobvr = -1;
  560. ilvsr = FALSE_;
  561. }
  562. /* Test the input arguments */
  563. /* Computing MAX */
  564. i__1 = *n << 2;
  565. lwkmin = f2cmax(i__1,1);
  566. lwkopt = lwkmin;
  567. work[1] = (real) lwkopt;
  568. lquery = *lwork == -1;
  569. *info = 0;
  570. if (ijobvl <= 0) {
  571. *info = -1;
  572. } else if (ijobvr <= 0) {
  573. *info = -2;
  574. } else if (*n < 0) {
  575. *info = -3;
  576. } else if (*lda < f2cmax(1,*n)) {
  577. *info = -5;
  578. } else if (*ldb < f2cmax(1,*n)) {
  579. *info = -7;
  580. } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
  581. *info = -12;
  582. } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
  583. *info = -14;
  584. } else if (*lwork < lwkmin && ! lquery) {
  585. *info = -16;
  586. }
  587. if (*info == 0) {
  588. nb1 = ilaenv_(&c__1, "SGEQRF", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
  589. ftnlen)1);
  590. nb2 = ilaenv_(&c__1, "SORMQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  591. ftnlen)1);
  592. nb3 = ilaenv_(&c__1, "SORGQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  593. ftnlen)1);
  594. /* Computing MAX */
  595. i__1 = f2cmax(nb1,nb2);
  596. nb = f2cmax(i__1,nb3);
  597. lopt = (*n << 1) + *n * (nb + 1);
  598. work[1] = (real) lopt;
  599. }
  600. if (*info != 0) {
  601. i__1 = -(*info);
  602. xerbla_("SGEGS ", &i__1, 6);
  603. return;
  604. } else if (lquery) {
  605. return;
  606. }
  607. /* Quick return if possible */
  608. if (*n == 0) {
  609. return;
  610. }
  611. /* Get machine constants */
  612. eps = slamch_("E") * slamch_("B");
  613. safmin = slamch_("S");
  614. smlnum = *n * safmin / eps;
  615. bignum = 1.f / smlnum;
  616. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  617. anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
  618. ilascl = FALSE_;
  619. if (anrm > 0.f && anrm < smlnum) {
  620. anrmto = smlnum;
  621. ilascl = TRUE_;
  622. } else if (anrm > bignum) {
  623. anrmto = bignum;
  624. ilascl = TRUE_;
  625. }
  626. if (ilascl) {
  627. slascl_("G", &c_n1, &c_n1, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  628. iinfo);
  629. if (iinfo != 0) {
  630. *info = *n + 9;
  631. return;
  632. }
  633. }
  634. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  635. bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
  636. ilbscl = FALSE_;
  637. if (bnrm > 0.f && bnrm < smlnum) {
  638. bnrmto = smlnum;
  639. ilbscl = TRUE_;
  640. } else if (bnrm > bignum) {
  641. bnrmto = bignum;
  642. ilbscl = TRUE_;
  643. }
  644. if (ilbscl) {
  645. slascl_("G", &c_n1, &c_n1, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  646. iinfo);
  647. if (iinfo != 0) {
  648. *info = *n + 9;
  649. return;
  650. }
  651. }
  652. /* Permute the matrix to make it more nearly triangular */
  653. /* Workspace layout: (2*N words -- "work..." not actually used) */
  654. /* left_permutation, right_permutation, work... */
  655. ileft = 1;
  656. iright = *n + 1;
  657. iwork = iright + *n;
  658. sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  659. ileft], &work[iright], &work[iwork], &iinfo);
  660. if (iinfo != 0) {
  661. *info = *n + 1;
  662. goto L10;
  663. }
  664. /* Reduce B to triangular form, and initialize VSL and/or VSR */
  665. /* Workspace layout: ("work..." must have at least N words) */
  666. /* left_permutation, right_permutation, tau, work... */
  667. irows = ihi + 1 - ilo;
  668. icols = *n + 1 - ilo;
  669. itau = iwork;
  670. iwork = itau + irows;
  671. i__1 = *lwork + 1 - iwork;
  672. sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  673. iwork], &i__1, &iinfo);
  674. if (iinfo >= 0) {
  675. /* Computing MAX */
  676. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  677. lwkopt = f2cmax(i__1,i__2);
  678. }
  679. if (iinfo != 0) {
  680. *info = *n + 2;
  681. goto L10;
  682. }
  683. i__1 = *lwork + 1 - iwork;
  684. sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  685. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  686. iinfo);
  687. if (iinfo >= 0) {
  688. /* Computing MAX */
  689. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  690. lwkopt = f2cmax(i__1,i__2);
  691. }
  692. if (iinfo != 0) {
  693. *info = *n + 3;
  694. goto L10;
  695. }
  696. if (ilvsl) {
  697. slaset_("Full", n, n, &c_b36, &c_b37, &vsl[vsl_offset], ldvsl);
  698. i__1 = irows - 1;
  699. i__2 = irows - 1;
  700. slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ilo
  701. + 1 + ilo * vsl_dim1], ldvsl);
  702. i__1 = *lwork + 1 - iwork;
  703. sorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
  704. work[itau], &work[iwork], &i__1, &iinfo);
  705. if (iinfo >= 0) {
  706. /* Computing MAX */
  707. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  708. lwkopt = f2cmax(i__1,i__2);
  709. }
  710. if (iinfo != 0) {
  711. *info = *n + 4;
  712. goto L10;
  713. }
  714. }
  715. if (ilvsr) {
  716. slaset_("Full", n, n, &c_b36, &c_b37, &vsr[vsr_offset], ldvsr);
  717. }
  718. /* Reduce to generalized Hessenberg form */
  719. sgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  720. ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &iinfo);
  721. if (iinfo != 0) {
  722. *info = *n + 5;
  723. goto L10;
  724. }
  725. /* Perform QZ algorithm, computing Schur vectors if desired */
  726. /* Workspace layout: ("work..." must have at least 1 word) */
  727. /* left_permutation, right_permutation, work... */
  728. iwork = itau;
  729. i__1 = *lwork + 1 - iwork;
  730. shgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  731. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
  732. , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwork], &i__1, &iinfo);
  733. if (iinfo >= 0) {
  734. /* Computing MAX */
  735. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  736. lwkopt = f2cmax(i__1,i__2);
  737. }
  738. if (iinfo != 0) {
  739. if (iinfo > 0 && iinfo <= *n) {
  740. *info = iinfo;
  741. } else if (iinfo > *n && iinfo <= *n << 1) {
  742. *info = iinfo - *n;
  743. } else {
  744. *info = *n + 6;
  745. }
  746. goto L10;
  747. }
  748. /* Apply permutation to VSL and VSR */
  749. if (ilvsl) {
  750. sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
  751. vsl_offset], ldvsl, &iinfo);
  752. if (iinfo != 0) {
  753. *info = *n + 7;
  754. goto L10;
  755. }
  756. }
  757. if (ilvsr) {
  758. sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
  759. vsr_offset], ldvsr, &iinfo);
  760. if (iinfo != 0) {
  761. *info = *n + 8;
  762. goto L10;
  763. }
  764. }
  765. /* Undo scaling */
  766. if (ilascl) {
  767. slascl_("H", &c_n1, &c_n1, &anrmto, &anrm, n, n, &a[a_offset], lda, &
  768. iinfo);
  769. if (iinfo != 0) {
  770. *info = *n + 9;
  771. return;
  772. }
  773. slascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  774. iinfo);
  775. if (iinfo != 0) {
  776. *info = *n + 9;
  777. return;
  778. }
  779. slascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  780. iinfo);
  781. if (iinfo != 0) {
  782. *info = *n + 9;
  783. return;
  784. }
  785. }
  786. if (ilbscl) {
  787. slascl_("U", &c_n1, &c_n1, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
  788. iinfo);
  789. if (iinfo != 0) {
  790. *info = *n + 9;
  791. return;
  792. }
  793. slascl_("G", &c_n1, &c_n1, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  794. iinfo);
  795. if (iinfo != 0) {
  796. *info = *n + 9;
  797. return;
  798. }
  799. }
  800. L10:
  801. work[1] = (real) lwkopt;
  802. return;
  803. /* End of SGEGS */
  804. } /* sgegs_ */