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.

dgeev.c 31 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #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++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #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]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static integer c__1 = 1;
  363. static integer c__0 = 0;
  364. static integer c_n1 = -1;
  365. /* > \brief <b> DGEEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matr
  366. ices</b> */
  367. /* =========== DOCUMENTATION =========== */
  368. /* Online html documentation available at */
  369. /* http://www.netlib.org/lapack/explore-html/ */
  370. /* > \htmlonly */
  371. /* > Download DGEEV + dependencies */
  372. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgeev.f
  373. "> */
  374. /* > [TGZ]</a> */
  375. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgeev.f
  376. "> */
  377. /* > [ZIP]</a> */
  378. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgeev.f
  379. "> */
  380. /* > [TXT]</a> */
  381. /* > \endhtmlonly */
  382. /* Definition: */
  383. /* =========== */
  384. /* SUBROUTINE DGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR, */
  385. /* LDVR, WORK, LWORK, INFO ) */
  386. /* CHARACTER JOBVL, JOBVR */
  387. /* INTEGER INFO, LDA, LDVL, LDVR, LWORK, N */
  388. /* DOUBLE PRECISION A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ), */
  389. /* $ WI( * ), WORK( * ), WR( * ) */
  390. /* > \par Purpose: */
  391. /* ============= */
  392. /* > */
  393. /* > \verbatim */
  394. /* > */
  395. /* > DGEEV computes for an N-by-N real nonsymmetric matrix A, the */
  396. /* > eigenvalues and, optionally, the left and/or right eigenvectors. */
  397. /* > */
  398. /* > The right eigenvector v(j) of A satisfies */
  399. /* > A * v(j) = lambda(j) * v(j) */
  400. /* > where lambda(j) is its eigenvalue. */
  401. /* > The left eigenvector u(j) of A satisfies */
  402. /* > u(j)**H * A = lambda(j) * u(j)**H */
  403. /* > where u(j)**H denotes the conjugate-transpose of u(j). */
  404. /* > */
  405. /* > The computed eigenvectors are normalized to have Euclidean norm */
  406. /* > equal to 1 and largest component real. */
  407. /* > \endverbatim */
  408. /* Arguments: */
  409. /* ========== */
  410. /* > \param[in] JOBVL */
  411. /* > \verbatim */
  412. /* > JOBVL is CHARACTER*1 */
  413. /* > = 'N': left eigenvectors of A are not computed; */
  414. /* > = 'V': left eigenvectors of A are computed. */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[in] JOBVR */
  418. /* > \verbatim */
  419. /* > JOBVR is CHARACTER*1 */
  420. /* > = 'N': right eigenvectors of A are not computed; */
  421. /* > = 'V': right eigenvectors of A are computed. */
  422. /* > \endverbatim */
  423. /* > */
  424. /* > \param[in] N */
  425. /* > \verbatim */
  426. /* > N is INTEGER */
  427. /* > The order of the matrix A. N >= 0. */
  428. /* > \endverbatim */
  429. /* > */
  430. /* > \param[in,out] A */
  431. /* > \verbatim */
  432. /* > A is DOUBLE PRECISION array, dimension (LDA,N) */
  433. /* > On entry, the N-by-N matrix A. */
  434. /* > On exit, A has been overwritten. */
  435. /* > \endverbatim */
  436. /* > */
  437. /* > \param[in] LDA */
  438. /* > \verbatim */
  439. /* > LDA is INTEGER */
  440. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[out] WR */
  444. /* > \verbatim */
  445. /* > WR is DOUBLE PRECISION array, dimension (N) */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[out] WI */
  449. /* > \verbatim */
  450. /* > WI is DOUBLE PRECISION array, dimension (N) */
  451. /* > WR and WI contain the real and imaginary parts, */
  452. /* > respectively, of the computed eigenvalues. Complex */
  453. /* > conjugate pairs of eigenvalues appear consecutively */
  454. /* > with the eigenvalue having the positive imaginary part */
  455. /* > first. */
  456. /* > \endverbatim */
  457. /* > */
  458. /* > \param[out] VL */
  459. /* > \verbatim */
  460. /* > VL is DOUBLE PRECISION array, dimension (LDVL,N) */
  461. /* > If JOBVL = 'V', the left eigenvectors u(j) are stored one */
  462. /* > after another in the columns of VL, in the same order */
  463. /* > as their eigenvalues. */
  464. /* > If JOBVL = 'N', VL is not referenced. */
  465. /* > If the j-th eigenvalue is real, then u(j) = VL(:,j), */
  466. /* > the j-th column of VL. */
  467. /* > If the j-th and (j+1)-st eigenvalues form a complex */
  468. /* > conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and */
  469. /* > u(j+1) = VL(:,j) - i*VL(:,j+1). */
  470. /* > \endverbatim */
  471. /* > */
  472. /* > \param[in] LDVL */
  473. /* > \verbatim */
  474. /* > LDVL is INTEGER */
  475. /* > The leading dimension of the array VL. LDVL >= 1; if */
  476. /* > JOBVL = 'V', LDVL >= N. */
  477. /* > \endverbatim */
  478. /* > */
  479. /* > \param[out] VR */
  480. /* > \verbatim */
  481. /* > VR is DOUBLE PRECISION array, dimension (LDVR,N) */
  482. /* > If JOBVR = 'V', the right eigenvectors v(j) are stored one */
  483. /* > after another in the columns of VR, in the same order */
  484. /* > as their eigenvalues. */
  485. /* > If JOBVR = 'N', VR is not referenced. */
  486. /* > If the j-th eigenvalue is real, then v(j) = VR(:,j), */
  487. /* > the j-th column of VR. */
  488. /* > If the j-th and (j+1)-st eigenvalues form a complex */
  489. /* > conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and */
  490. /* > v(j+1) = VR(:,j) - i*VR(:,j+1). */
  491. /* > \endverbatim */
  492. /* > */
  493. /* > \param[in] LDVR */
  494. /* > \verbatim */
  495. /* > LDVR is INTEGER */
  496. /* > The leading dimension of the array VR. LDVR >= 1; if */
  497. /* > JOBVR = 'V', LDVR >= N. */
  498. /* > \endverbatim */
  499. /* > */
  500. /* > \param[out] WORK */
  501. /* > \verbatim */
  502. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  503. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[in] LWORK */
  507. /* > \verbatim */
  508. /* > LWORK is INTEGER */
  509. /* > The dimension of the array WORK. LWORK >= f2cmax(1,3*N), and */
  510. /* > if JOBVL = 'V' or JOBVR = 'V', LWORK >= 4*N. For good */
  511. /* > performance, LWORK must generally be larger. */
  512. /* > */
  513. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  514. /* > only calculates the optimal size of the WORK array, returns */
  515. /* > this value as the first entry of the WORK array, and no error */
  516. /* > message related to LWORK is issued by XERBLA. */
  517. /* > \endverbatim */
  518. /* > */
  519. /* > \param[out] INFO */
  520. /* > \verbatim */
  521. /* > INFO is INTEGER */
  522. /* > = 0: successful exit */
  523. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  524. /* > > 0: if INFO = i, the QR algorithm failed to compute all the */
  525. /* > eigenvalues, and no eigenvectors have been computed; */
  526. /* > elements i+1:N of WR and WI contain eigenvalues which */
  527. /* > have converged. */
  528. /* > \endverbatim */
  529. /* Authors: */
  530. /* ======== */
  531. /* > \author Univ. of Tennessee */
  532. /* > \author Univ. of California Berkeley */
  533. /* > \author Univ. of Colorado Denver */
  534. /* > \author NAG Ltd. */
  535. /* > \date June 2016 */
  536. /* @precisions fortran d -> s */
  537. /* > \ingroup doubleGEeigen */
  538. /* ===================================================================== */
  539. /* Subroutine */ int dgeev_(char *jobvl, char *jobvr, integer *n, doublereal *
  540. a, integer *lda, doublereal *wr, doublereal *wi, doublereal *vl,
  541. integer *ldvl, doublereal *vr, integer *ldvr, doublereal *work,
  542. integer *lwork, integer *info)
  543. {
  544. /* System generated locals */
  545. integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  546. i__2, i__3;
  547. doublereal d__1, d__2;
  548. /* Local variables */
  549. integer ibal;
  550. char side[1];
  551. doublereal anrm;
  552. integer ierr, itau;
  553. extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
  554. doublereal *, integer *, doublereal *, doublereal *);
  555. integer iwrk, nout;
  556. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  557. integer i__, k;
  558. doublereal r__;
  559. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  560. integer *);
  561. extern logical lsame_(char *, char *);
  562. extern doublereal dlapy2_(doublereal *, doublereal *);
  563. extern /* Subroutine */ int dlabad_(doublereal *, doublereal *), dgebak_(
  564. char *, char *, integer *, integer *, integer *, doublereal *,
  565. integer *, doublereal *, integer *, integer *),
  566. dgebal_(char *, integer *, doublereal *, integer *, integer *,
  567. integer *, doublereal *, integer *);
  568. doublereal cs;
  569. logical scalea;
  570. extern doublereal dlamch_(char *);
  571. doublereal cscale;
  572. extern doublereal dlange_(char *, integer *, integer *, doublereal *,
  573. integer *, doublereal *);
  574. extern /* Subroutine */ int dgehrd_(integer *, integer *, integer *,
  575. doublereal *, integer *, doublereal *, doublereal *, integer *,
  576. integer *);
  577. doublereal sn;
  578. extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
  579. doublereal *, doublereal *, integer *, integer *, doublereal *,
  580. integer *, integer *);
  581. extern integer idamax_(integer *, doublereal *, integer *);
  582. extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
  583. doublereal *, integer *, doublereal *, integer *),
  584. dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  585. doublereal *), xerbla_(char *, integer *, ftnlen);
  586. logical select[1];
  587. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  588. integer *, integer *, ftnlen, ftnlen);
  589. doublereal bignum;
  590. extern /* Subroutine */ int dorghr_(integer *, integer *, integer *,
  591. doublereal *, integer *, doublereal *, doublereal *, integer *,
  592. integer *), dhseqr_(char *, char *, integer *, integer *, integer
  593. *, doublereal *, integer *, doublereal *, doublereal *,
  594. doublereal *, integer *, doublereal *, integer *, integer *);
  595. integer minwrk, maxwrk;
  596. logical wantvl;
  597. doublereal smlnum;
  598. integer hswork;
  599. logical lquery, wantvr;
  600. extern /* Subroutine */ int dtrevc3_(char *, char *, logical *, integer *,
  601. doublereal *, integer *, doublereal *, integer *, doublereal *,
  602. integer *, integer *, integer *, doublereal *, integer *, integer
  603. *);
  604. integer ihi;
  605. doublereal scl;
  606. integer ilo;
  607. doublereal dum[1], eps;
  608. integer lwork_trevc__;
  609. /* -- LAPACK driver routine (version 3.7.0) -- */
  610. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  611. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  612. /* June 2016 */
  613. /* ===================================================================== */
  614. /* Test the input arguments */
  615. /* Parameter adjustments */
  616. a_dim1 = *lda;
  617. a_offset = 1 + a_dim1 * 1;
  618. a -= a_offset;
  619. --wr;
  620. --wi;
  621. vl_dim1 = *ldvl;
  622. vl_offset = 1 + vl_dim1 * 1;
  623. vl -= vl_offset;
  624. vr_dim1 = *ldvr;
  625. vr_offset = 1 + vr_dim1 * 1;
  626. vr -= vr_offset;
  627. --work;
  628. /* Function Body */
  629. *info = 0;
  630. lquery = *lwork == -1;
  631. wantvl = lsame_(jobvl, "V");
  632. wantvr = lsame_(jobvr, "V");
  633. if (! wantvl && ! lsame_(jobvl, "N")) {
  634. *info = -1;
  635. } else if (! wantvr && ! lsame_(jobvr, "N")) {
  636. *info = -2;
  637. } else if (*n < 0) {
  638. *info = -3;
  639. } else if (*lda < f2cmax(1,*n)) {
  640. *info = -5;
  641. } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
  642. *info = -9;
  643. } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
  644. *info = -11;
  645. }
  646. /* Compute workspace */
  647. /* (Note: Comments in the code beginning "Workspace:" describe the */
  648. /* minimal amount of workspace needed at that point in the code, */
  649. /* as well as the preferred amount for good performance. */
  650. /* NB refers to the optimal block size for the immediately */
  651. /* following subroutine, as returned by ILAENV. */
  652. /* HSWORK refers to the workspace preferred by DHSEQR, as */
  653. /* calculated below. HSWORK is computed assuming ILO=1 and IHI=N, */
  654. /* the worst case.) */
  655. if (*info == 0) {
  656. if (*n == 0) {
  657. minwrk = 1;
  658. maxwrk = 1;
  659. } else {
  660. maxwrk = (*n << 1) + *n * ilaenv_(&c__1, "DGEHRD", " ", n, &c__1,
  661. n, &c__0, (ftnlen)6, (ftnlen)1);
  662. if (wantvl) {
  663. minwrk = *n << 2;
  664. /* Computing MAX */
  665. i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
  666. "DORGHR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)
  667. 1);
  668. maxwrk = f2cmax(i__1,i__2);
  669. dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
  670. 1], &vl[vl_offset], ldvl, &work[1], &c_n1, info);
  671. hswork = (integer) work[1];
  672. /* Computing MAX */
  673. i__1 = maxwrk, i__2 = *n + 1, i__1 = f2cmax(i__1,i__2), i__2 = *
  674. n + hswork;
  675. maxwrk = f2cmax(i__1,i__2);
  676. dtrevc3_("L", "B", select, n, &a[a_offset], lda, &vl[
  677. vl_offset], ldvl, &vr[vr_offset], ldvr, n, &nout, &
  678. work[1], &c_n1, &ierr);
  679. lwork_trevc__ = (integer) work[1];
  680. /* Computing MAX */
  681. i__1 = maxwrk, i__2 = *n + lwork_trevc__;
  682. maxwrk = f2cmax(i__1,i__2);
  683. /* Computing MAX */
  684. i__1 = maxwrk, i__2 = *n << 2;
  685. maxwrk = f2cmax(i__1,i__2);
  686. } else if (wantvr) {
  687. minwrk = *n << 2;
  688. /* Computing MAX */
  689. i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
  690. "DORGHR", " ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)
  691. 1);
  692. maxwrk = f2cmax(i__1,i__2);
  693. dhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
  694. 1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
  695. hswork = (integer) work[1];
  696. /* Computing MAX */
  697. i__1 = maxwrk, i__2 = *n + 1, i__1 = f2cmax(i__1,i__2), i__2 = *
  698. n + hswork;
  699. maxwrk = f2cmax(i__1,i__2);
  700. dtrevc3_("R", "B", select, n, &a[a_offset], lda, &vl[
  701. vl_offset], ldvl, &vr[vr_offset], ldvr, n, &nout, &
  702. work[1], &c_n1, &ierr);
  703. lwork_trevc__ = (integer) work[1];
  704. /* Computing MAX */
  705. i__1 = maxwrk, i__2 = *n + lwork_trevc__;
  706. maxwrk = f2cmax(i__1,i__2);
  707. /* Computing MAX */
  708. i__1 = maxwrk, i__2 = *n << 2;
  709. maxwrk = f2cmax(i__1,i__2);
  710. } else {
  711. minwrk = *n * 3;
  712. dhseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
  713. 1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
  714. hswork = (integer) work[1];
  715. /* Computing MAX */
  716. i__1 = maxwrk, i__2 = *n + 1, i__1 = f2cmax(i__1,i__2), i__2 = *
  717. n + hswork;
  718. maxwrk = f2cmax(i__1,i__2);
  719. }
  720. maxwrk = f2cmax(maxwrk,minwrk);
  721. }
  722. work[1] = (doublereal) maxwrk;
  723. if (*lwork < minwrk && ! lquery) {
  724. *info = -13;
  725. }
  726. }
  727. if (*info != 0) {
  728. i__1 = -(*info);
  729. xerbla_("DGEEV ", &i__1, (ftnlen)6);
  730. return 0;
  731. } else if (lquery) {
  732. return 0;
  733. }
  734. /* Quick return if possible */
  735. if (*n == 0) {
  736. return 0;
  737. }
  738. /* Get machine constants */
  739. eps = dlamch_("P");
  740. smlnum = dlamch_("S");
  741. bignum = 1. / smlnum;
  742. dlabad_(&smlnum, &bignum);
  743. smlnum = sqrt(smlnum) / eps;
  744. bignum = 1. / smlnum;
  745. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  746. anrm = dlange_("M", n, n, &a[a_offset], lda, dum);
  747. scalea = FALSE_;
  748. if (anrm > 0. && anrm < smlnum) {
  749. scalea = TRUE_;
  750. cscale = smlnum;
  751. } else if (anrm > bignum) {
  752. scalea = TRUE_;
  753. cscale = bignum;
  754. }
  755. if (scalea) {
  756. dlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
  757. ierr);
  758. }
  759. /* Balance the matrix */
  760. /* (Workspace: need N) */
  761. ibal = 1;
  762. dgebal_("B", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
  763. /* Reduce to upper Hessenberg form */
  764. /* (Workspace: need 3*N, prefer 2*N+N*NB) */
  765. itau = ibal + *n;
  766. iwrk = itau + *n;
  767. i__1 = *lwork - iwrk + 1;
  768. dgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
  769. &ierr);
  770. if (wantvl) {
  771. /* Want left eigenvectors */
  772. /* Copy Householder vectors to VL */
  773. *(unsigned char *)side = 'L';
  774. dlacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
  775. ;
  776. /* Generate orthogonal matrix in VL */
  777. /* (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB) */
  778. i__1 = *lwork - iwrk + 1;
  779. dorghr_(n, &ilo, &ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk],
  780. &i__1, &ierr);
  781. /* Perform QR iteration, accumulating Schur vectors in VL */
  782. /* (Workspace: need N+1, prefer N+HSWORK (see comments) ) */
  783. iwrk = itau;
  784. i__1 = *lwork - iwrk + 1;
  785. dhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
  786. vl[vl_offset], ldvl, &work[iwrk], &i__1, info);
  787. if (wantvr) {
  788. /* Want left and right eigenvectors */
  789. /* Copy Schur vectors to VR */
  790. *(unsigned char *)side = 'B';
  791. dlacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
  792. }
  793. } else if (wantvr) {
  794. /* Want right eigenvectors */
  795. /* Copy Householder vectors to VR */
  796. *(unsigned char *)side = 'R';
  797. dlacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
  798. ;
  799. /* Generate orthogonal matrix in VR */
  800. /* (Workspace: need 3*N-1, prefer 2*N+(N-1)*NB) */
  801. i__1 = *lwork - iwrk + 1;
  802. dorghr_(n, &ilo, &ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk],
  803. &i__1, &ierr);
  804. /* Perform QR iteration, accumulating Schur vectors in VR */
  805. /* (Workspace: need N+1, prefer N+HSWORK (see comments) ) */
  806. iwrk = itau;
  807. i__1 = *lwork - iwrk + 1;
  808. dhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
  809. vr[vr_offset], ldvr, &work[iwrk], &i__1, info);
  810. } else {
  811. /* Compute eigenvalues only */
  812. /* (Workspace: need N+1, prefer N+HSWORK (see comments) ) */
  813. iwrk = itau;
  814. i__1 = *lwork - iwrk + 1;
  815. dhseqr_("E", "N", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
  816. vr[vr_offset], ldvr, &work[iwrk], &i__1, info);
  817. }
  818. /* If INFO .NE. 0 from DHSEQR, then quit */
  819. if (*info != 0) {
  820. goto L50;
  821. }
  822. if (wantvl || wantvr) {
  823. /* Compute left and/or right eigenvectors */
  824. /* (Workspace: need 4*N, prefer N + N + 2*N*NB) */
  825. i__1 = *lwork - iwrk + 1;
  826. dtrevc3_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset],
  827. ldvl, &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &i__1, &
  828. ierr);
  829. }
  830. if (wantvl) {
  831. /* Undo balancing of left eigenvectors */
  832. /* (Workspace: need N) */
  833. dgebak_("B", "L", n, &ilo, &ihi, &work[ibal], n, &vl[vl_offset], ldvl,
  834. &ierr);
  835. /* Normalize left eigenvectors and make largest component real */
  836. i__1 = *n;
  837. for (i__ = 1; i__ <= i__1; ++i__) {
  838. if (wi[i__] == 0.) {
  839. scl = 1. / dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
  840. dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
  841. } else if (wi[i__] > 0.) {
  842. d__1 = dnrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
  843. d__2 = dnrm2_(n, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
  844. scl = 1. / dlapy2_(&d__1, &d__2);
  845. dscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
  846. dscal_(n, &scl, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
  847. i__2 = *n;
  848. for (k = 1; k <= i__2; ++k) {
  849. /* Computing 2nd power */
  850. d__1 = vl[k + i__ * vl_dim1];
  851. /* Computing 2nd power */
  852. d__2 = vl[k + (i__ + 1) * vl_dim1];
  853. work[iwrk + k - 1] = d__1 * d__1 + d__2 * d__2;
  854. /* L10: */
  855. }
  856. k = idamax_(n, &work[iwrk], &c__1);
  857. dlartg_(&vl[k + i__ * vl_dim1], &vl[k + (i__ + 1) * vl_dim1],
  858. &cs, &sn, &r__);
  859. drot_(n, &vl[i__ * vl_dim1 + 1], &c__1, &vl[(i__ + 1) *
  860. vl_dim1 + 1], &c__1, &cs, &sn);
  861. vl[k + (i__ + 1) * vl_dim1] = 0.;
  862. }
  863. /* L20: */
  864. }
  865. }
  866. if (wantvr) {
  867. /* Undo balancing of right eigenvectors */
  868. /* (Workspace: need N) */
  869. dgebak_("B", "R", n, &ilo, &ihi, &work[ibal], n, &vr[vr_offset], ldvr,
  870. &ierr);
  871. /* Normalize right eigenvectors and make largest component real */
  872. i__1 = *n;
  873. for (i__ = 1; i__ <= i__1; ++i__) {
  874. if (wi[i__] == 0.) {
  875. scl = 1. / dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
  876. dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
  877. } else if (wi[i__] > 0.) {
  878. d__1 = dnrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
  879. d__2 = dnrm2_(n, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
  880. scl = 1. / dlapy2_(&d__1, &d__2);
  881. dscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
  882. dscal_(n, &scl, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
  883. i__2 = *n;
  884. for (k = 1; k <= i__2; ++k) {
  885. /* Computing 2nd power */
  886. d__1 = vr[k + i__ * vr_dim1];
  887. /* Computing 2nd power */
  888. d__2 = vr[k + (i__ + 1) * vr_dim1];
  889. work[iwrk + k - 1] = d__1 * d__1 + d__2 * d__2;
  890. /* L30: */
  891. }
  892. k = idamax_(n, &work[iwrk], &c__1);
  893. dlartg_(&vr[k + i__ * vr_dim1], &vr[k + (i__ + 1) * vr_dim1],
  894. &cs, &sn, &r__);
  895. drot_(n, &vr[i__ * vr_dim1 + 1], &c__1, &vr[(i__ + 1) *
  896. vr_dim1 + 1], &c__1, &cs, &sn);
  897. vr[k + (i__ + 1) * vr_dim1] = 0.;
  898. }
  899. /* L40: */
  900. }
  901. }
  902. /* Undo scaling if necessary */
  903. L50:
  904. if (scalea) {
  905. i__1 = *n - *info;
  906. /* Computing MAX */
  907. i__3 = *n - *info;
  908. i__2 = f2cmax(i__3,1);
  909. dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[*info +
  910. 1], &i__2, &ierr);
  911. i__1 = *n - *info;
  912. /* Computing MAX */
  913. i__3 = *n - *info;
  914. i__2 = f2cmax(i__3,1);
  915. dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[*info +
  916. 1], &i__2, &ierr);
  917. if (*info > 0) {
  918. i__1 = ilo - 1;
  919. dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[1],
  920. n, &ierr);
  921. i__1 = ilo - 1;
  922. dlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[1],
  923. n, &ierr);
  924. }
  925. }
  926. work[1] = (doublereal) maxwrk;
  927. return 0;
  928. /* End of DGEEV */
  929. } /* dgeev_ */