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.

dgeesx.c 38 kB

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