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.

zgegs.c 26 kB

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