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.

sgees.c 30 kB

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