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