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.

dgegs.c 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  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 doublereal c_b36 = 0.;
  246. static doublereal c_b37 = 1.;
  247. /* > \brief <b> DGEEVX 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 DGEGS + dependencies */
  254. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgegs.f
  255. "> */
  256. /* > [TGZ]</a> */
  257. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgegs.f
  258. "> */
  259. /* > [ZIP]</a> */
  260. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgegs.f
  261. "> */
  262. /* > [TXT]</a> */
  263. /* > \endhtmlonly */
  264. /* Definition: */
  265. /* =========== */
  266. /* SUBROUTINE DGEGS( 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. /* DOUBLE PRECISION 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 DGGES. */
  280. /* > */
  281. /* > DGEGS 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. /* > DGEGV should be used instead. See DGEGV 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DGEQRF, DORMQR, and DORGQR.) Then compute: */
  418. /* > NB -- MAX of the blocksizes for DGEQRF, DORMQR, and DORGQR */
  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 DGGBAL */
  438. /* > =N+2: error return from DGEQRF */
  439. /* > =N+3: error return from DORMQR */
  440. /* > =N+4: error return from DORGQR */
  441. /* > =N+5: error return from DGGHRD */
  442. /* > =N+6: error return from DHGEQZ (other than failed */
  443. /* > iteration) */
  444. /* > =N+7: error return from DGGBAK (computing VSL) */
  445. /* > =N+8: error return from DGGBAK (computing VSR) */
  446. /* > =N+9: error return from DLASCL (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 doubleGEeigen */
  456. /* ===================================================================== */
  457. /* Subroutine */ void dgegs_(char *jobvsl, char *jobvsr, integer *n,
  458. doublereal *a, integer *lda, doublereal *b, integer *ldb, doublereal *
  459. alphar, doublereal *alphai, doublereal *beta, doublereal *vsl,
  460. integer *ldvsl, doublereal *vsr, integer *ldvsr, doublereal *work,
  461. integer *lwork, integer *info)
  462. {
  463. /* System generated locals */
  464. integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset,
  465. vsr_dim1, vsr_offset, i__1, i__2;
  466. /* Local variables */
  467. doublereal anrm, bnrm;
  468. integer itau, lopt;
  469. extern logical lsame_(char *, char *);
  470. integer ileft, iinfo, icols;
  471. logical ilvsl;
  472. integer iwork;
  473. logical ilvsr;
  474. integer irows;
  475. extern /* Subroutine */ void dggbak_(char *, char *, integer *, integer *,
  476. integer *, doublereal *, doublereal *, integer *, doublereal *,
  477. integer *, integer *);
  478. integer nb;
  479. extern /* Subroutine */ void dggbal_(char *, integer *, doublereal *,
  480. integer *, doublereal *, integer *, integer *, integer *,
  481. doublereal *, doublereal *, doublereal *, integer *);
  482. extern doublereal dlamch_(char *), dlange_(char *, integer *,
  483. integer *, doublereal *, integer *, doublereal *);
  484. extern /* Subroutine */ void dgghrd_(char *, char *, integer *, integer *,
  485. integer *, doublereal *, integer *, doublereal *, integer *,
  486. doublereal *, integer *, doublereal *, integer *, integer *), dlascl_(char *, integer *, integer *, doublereal
  487. *, doublereal *, integer *, integer *, doublereal *, integer *,
  488. integer *);
  489. logical ilascl, ilbscl;
  490. extern /* Subroutine */ void dgeqrf_(integer *, integer *, doublereal *,
  491. integer *, doublereal *, doublereal *, integer *, integer *),
  492. dlacpy_(char *, integer *, integer *, doublereal *, integer *,
  493. doublereal *, integer *);
  494. doublereal safmin;
  495. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  496. doublereal *, doublereal *, doublereal *, integer *);
  497. extern int xerbla_(char *, integer *, ftnlen);
  498. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  499. integer *, integer *, ftnlen, ftnlen);
  500. doublereal bignum;
  501. extern /* Subroutine */ void dhgeqz_(char *, char *, char *, integer *,
  502. integer *, integer *, doublereal *, integer *, doublereal *,
  503. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  504. integer *, doublereal *, integer *, doublereal *, integer *,
  505. integer *);
  506. integer ijobvl, iright, ijobvr;
  507. extern /* Subroutine */ void dorgqr_(integer *, integer *, integer *,
  508. doublereal *, integer *, doublereal *, doublereal *, integer *,
  509. integer *);
  510. doublereal anrmto;
  511. integer lwkmin, nb1, nb2, nb3;
  512. doublereal bnrmto;
  513. extern /* Subroutine */ void dormqr_(char *, char *, integer *, integer *,
  514. integer *, doublereal *, integer *, doublereal *, doublereal *,
  515. integer *, doublereal *, integer *, integer *);
  516. doublereal smlnum;
  517. integer lwkopt;
  518. logical lquery;
  519. integer ihi, ilo;
  520. doublereal eps;
  521. /* -- LAPACK driver routine (version 3.7.0) -- */
  522. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  523. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  524. /* December 2016 */
  525. /* ===================================================================== */
  526. /* Decode the input arguments */
  527. /* Parameter adjustments */
  528. a_dim1 = *lda;
  529. a_offset = 1 + a_dim1 * 1;
  530. a -= a_offset;
  531. b_dim1 = *ldb;
  532. b_offset = 1 + b_dim1 * 1;
  533. b -= b_offset;
  534. --alphar;
  535. --alphai;
  536. --beta;
  537. vsl_dim1 = *ldvsl;
  538. vsl_offset = 1 + vsl_dim1 * 1;
  539. vsl -= vsl_offset;
  540. vsr_dim1 = *ldvsr;
  541. vsr_offset = 1 + vsr_dim1 * 1;
  542. vsr -= vsr_offset;
  543. --work;
  544. /* Function Body */
  545. if (lsame_(jobvsl, "N")) {
  546. ijobvl = 1;
  547. ilvsl = FALSE_;
  548. } else if (lsame_(jobvsl, "V")) {
  549. ijobvl = 2;
  550. ilvsl = TRUE_;
  551. } else {
  552. ijobvl = -1;
  553. ilvsl = FALSE_;
  554. }
  555. if (lsame_(jobvsr, "N")) {
  556. ijobvr = 1;
  557. ilvsr = FALSE_;
  558. } else if (lsame_(jobvsr, "V")) {
  559. ijobvr = 2;
  560. ilvsr = TRUE_;
  561. } else {
  562. ijobvr = -1;
  563. ilvsr = FALSE_;
  564. }
  565. /* Test the input arguments */
  566. /* Computing MAX */
  567. i__1 = *n << 2;
  568. lwkmin = f2cmax(i__1,1);
  569. lwkopt = lwkmin;
  570. work[1] = (doublereal) lwkopt;
  571. lquery = *lwork == -1;
  572. *info = 0;
  573. if (ijobvl <= 0) {
  574. *info = -1;
  575. } else if (ijobvr <= 0) {
  576. *info = -2;
  577. } else if (*n < 0) {
  578. *info = -3;
  579. } else if (*lda < f2cmax(1,*n)) {
  580. *info = -5;
  581. } else if (*ldb < f2cmax(1,*n)) {
  582. *info = -7;
  583. } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) {
  584. *info = -12;
  585. } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) {
  586. *info = -14;
  587. } else if (*lwork < lwkmin && ! lquery) {
  588. *info = -16;
  589. }
  590. if (*info == 0) {
  591. nb1 = ilaenv_(&c__1, "DGEQRF", " ", n, n, &c_n1, &c_n1, (ftnlen)6, (
  592. ftnlen)1);
  593. nb2 = ilaenv_(&c__1, "DORMQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  594. ftnlen)1);
  595. nb3 = ilaenv_(&c__1, "DORGQR", " ", n, n, n, &c_n1, (ftnlen)6, (
  596. ftnlen)1);
  597. /* Computing MAX */
  598. i__1 = f2cmax(nb1,nb2);
  599. nb = f2cmax(i__1,nb3);
  600. lopt = (*n << 1) + *n * (nb + 1);
  601. work[1] = (doublereal) lopt;
  602. }
  603. if (*info != 0) {
  604. i__1 = -(*info);
  605. xerbla_("DGEGS ", &i__1, 6);
  606. return;
  607. } else if (lquery) {
  608. return;
  609. }
  610. /* Quick return if possible */
  611. if (*n == 0) {
  612. return;
  613. }
  614. /* Get machine constants */
  615. eps = dlamch_("E") * dlamch_("B");
  616. safmin = dlamch_("S");
  617. smlnum = *n * safmin / eps;
  618. bignum = 1. / smlnum;
  619. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  620. anrm = dlange_("M", n, n, &a[a_offset], lda, &work[1]);
  621. ilascl = FALSE_;
  622. if (anrm > 0. && anrm < smlnum) {
  623. anrmto = smlnum;
  624. ilascl = TRUE_;
  625. } else if (anrm > bignum) {
  626. anrmto = bignum;
  627. ilascl = TRUE_;
  628. }
  629. if (ilascl) {
  630. dlascl_("G", &c_n1, &c_n1, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  631. iinfo);
  632. if (iinfo != 0) {
  633. *info = *n + 9;
  634. return;
  635. }
  636. }
  637. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  638. bnrm = dlange_("M", n, n, &b[b_offset], ldb, &work[1]);
  639. ilbscl = FALSE_;
  640. if (bnrm > 0. && bnrm < smlnum) {
  641. bnrmto = smlnum;
  642. ilbscl = TRUE_;
  643. } else if (bnrm > bignum) {
  644. bnrmto = bignum;
  645. ilbscl = TRUE_;
  646. }
  647. if (ilbscl) {
  648. dlascl_("G", &c_n1, &c_n1, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  649. iinfo);
  650. if (iinfo != 0) {
  651. *info = *n + 9;
  652. return;
  653. }
  654. }
  655. /* Permute the matrix to make it more nearly triangular */
  656. /* Workspace layout: (2*N words -- "work..." not actually used) */
  657. /* left_permutation, right_permutation, work... */
  658. ileft = 1;
  659. iright = *n + 1;
  660. iwork = iright + *n;
  661. dggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  662. ileft], &work[iright], &work[iwork], &iinfo);
  663. if (iinfo != 0) {
  664. *info = *n + 1;
  665. goto L10;
  666. }
  667. /* Reduce B to triangular form, and initialize VSL and/or VSR */
  668. /* Workspace layout: ("work..." must have at least N words) */
  669. /* left_permutation, right_permutation, tau, work... */
  670. irows = ihi + 1 - ilo;
  671. icols = *n + 1 - ilo;
  672. itau = iwork;
  673. iwork = itau + irows;
  674. i__1 = *lwork + 1 - iwork;
  675. dgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  676. iwork], &i__1, &iinfo);
  677. if (iinfo >= 0) {
  678. /* Computing MAX */
  679. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  680. lwkopt = f2cmax(i__1,i__2);
  681. }
  682. if (iinfo != 0) {
  683. *info = *n + 2;
  684. goto L10;
  685. }
  686. i__1 = *lwork + 1 - iwork;
  687. dormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  688. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, &
  689. iinfo);
  690. if (iinfo >= 0) {
  691. /* Computing MAX */
  692. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  693. lwkopt = f2cmax(i__1,i__2);
  694. }
  695. if (iinfo != 0) {
  696. *info = *n + 3;
  697. goto L10;
  698. }
  699. if (ilvsl) {
  700. dlaset_("Full", n, n, &c_b36, &c_b37, &vsl[vsl_offset], ldvsl);
  701. i__1 = irows - 1;
  702. i__2 = irows - 1;
  703. dlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ilo
  704. + 1 + ilo * vsl_dim1], ldvsl);
  705. i__1 = *lwork + 1 - iwork;
  706. dorgqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, &
  707. work[itau], &work[iwork], &i__1, &iinfo);
  708. if (iinfo >= 0) {
  709. /* Computing MAX */
  710. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  711. lwkopt = f2cmax(i__1,i__2);
  712. }
  713. if (iinfo != 0) {
  714. *info = *n + 4;
  715. goto L10;
  716. }
  717. }
  718. if (ilvsr) {
  719. dlaset_("Full", n, n, &c_b36, &c_b37, &vsr[vsr_offset], ldvsr);
  720. }
  721. /* Reduce to generalized Hessenberg form */
  722. dgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  723. ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &iinfo);
  724. if (iinfo != 0) {
  725. *info = *n + 5;
  726. goto L10;
  727. }
  728. /* Perform QZ algorithm, computing Schur vectors if desired */
  729. /* Workspace layout: ("work..." must have at least 1 word) */
  730. /* left_permutation, right_permutation, work... */
  731. iwork = itau;
  732. i__1 = *lwork + 1 - iwork;
  733. dhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  734. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vsl[vsl_offset]
  735. , ldvsl, &vsr[vsr_offset], ldvsr, &work[iwork], &i__1, &iinfo);
  736. if (iinfo >= 0) {
  737. /* Computing MAX */
  738. i__1 = lwkopt, i__2 = (integer) work[iwork] + iwork - 1;
  739. lwkopt = f2cmax(i__1,i__2);
  740. }
  741. if (iinfo != 0) {
  742. if (iinfo > 0 && iinfo <= *n) {
  743. *info = iinfo;
  744. } else if (iinfo > *n && iinfo <= *n << 1) {
  745. *info = iinfo - *n;
  746. } else {
  747. *info = *n + 6;
  748. }
  749. goto L10;
  750. }
  751. /* Apply permutation to VSL and VSR */
  752. if (ilvsl) {
  753. dggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsl[
  754. vsl_offset], ldvsl, &iinfo);
  755. if (iinfo != 0) {
  756. *info = *n + 7;
  757. goto L10;
  758. }
  759. }
  760. if (ilvsr) {
  761. dggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &vsr[
  762. vsr_offset], ldvsr, &iinfo);
  763. if (iinfo != 0) {
  764. *info = *n + 8;
  765. goto L10;
  766. }
  767. }
  768. /* Undo scaling */
  769. if (ilascl) {
  770. dlascl_("H", &c_n1, &c_n1, &anrmto, &anrm, n, n, &a[a_offset], lda, &
  771. iinfo);
  772. if (iinfo != 0) {
  773. *info = *n + 9;
  774. return;
  775. }
  776. dlascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  777. iinfo);
  778. if (iinfo != 0) {
  779. *info = *n + 9;
  780. return;
  781. }
  782. dlascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  783. iinfo);
  784. if (iinfo != 0) {
  785. *info = *n + 9;
  786. return;
  787. }
  788. }
  789. if (ilbscl) {
  790. dlascl_("U", &c_n1, &c_n1, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, &
  791. iinfo);
  792. if (iinfo != 0) {
  793. *info = *n + 9;
  794. return;
  795. }
  796. dlascl_("G", &c_n1, &c_n1, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  797. iinfo);
  798. if (iinfo != 0) {
  799. *info = *n + 9;
  800. return;
  801. }
  802. }
  803. L10:
  804. work[1] = (doublereal) lwkopt;
  805. return;
  806. /* End of DGEGS */
  807. } /* dgegs_ */