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.

shsein.c 25 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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 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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static logical c_false = FALSE_;
  236. static logical c_true = TRUE_;
  237. /* > \brief \b SHSEIN */
  238. /* =========== DOCUMENTATION =========== */
  239. /* Online html documentation available at */
  240. /* http://www.netlib.org/lapack/explore-html/ */
  241. /* > \htmlonly */
  242. /* > Download SHSEIN + dependencies */
  243. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/shsein.
  244. f"> */
  245. /* > [TGZ]</a> */
  246. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/shsein.
  247. f"> */
  248. /* > [ZIP]</a> */
  249. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/shsein.
  250. f"> */
  251. /* > [TXT]</a> */
  252. /* > \endhtmlonly */
  253. /* Definition: */
  254. /* =========== */
  255. /* SUBROUTINE SHSEIN( SIDE, EIGSRC, INITV, SELECT, N, H, LDH, WR, WI, */
  256. /* VL, LDVL, VR, LDVR, MM, M, WORK, IFAILL, */
  257. /* IFAILR, INFO ) */
  258. /* CHARACTER EIGSRC, INITV, SIDE */
  259. /* INTEGER INFO, LDH, LDVL, LDVR, M, MM, N */
  260. /* LOGICAL SELECT( * ) */
  261. /* INTEGER IFAILL( * ), IFAILR( * ) */
  262. /* REAL H( LDH, * ), VL( LDVL, * ), VR( LDVR, * ), */
  263. /* $ WI( * ), WORK( * ), WR( * ) */
  264. /* > \par Purpose: */
  265. /* ============= */
  266. /* > */
  267. /* > \verbatim */
  268. /* > */
  269. /* > SHSEIN uses inverse iteration to find specified right and/or left */
  270. /* > eigenvectors of a real upper Hessenberg matrix H. */
  271. /* > */
  272. /* > The right eigenvector x and the left eigenvector y of the matrix H */
  273. /* > corresponding to an eigenvalue w are defined by: */
  274. /* > */
  275. /* > H * x = w * x, y**h * H = w * y**h */
  276. /* > */
  277. /* > where y**h denotes the conjugate transpose of the vector y. */
  278. /* > \endverbatim */
  279. /* Arguments: */
  280. /* ========== */
  281. /* > \param[in] SIDE */
  282. /* > \verbatim */
  283. /* > SIDE is CHARACTER*1 */
  284. /* > = 'R': compute right eigenvectors only; */
  285. /* > = 'L': compute left eigenvectors only; */
  286. /* > = 'B': compute both right and left eigenvectors. */
  287. /* > \endverbatim */
  288. /* > */
  289. /* > \param[in] EIGSRC */
  290. /* > \verbatim */
  291. /* > EIGSRC is CHARACTER*1 */
  292. /* > Specifies the source of eigenvalues supplied in (WR,WI): */
  293. /* > = 'Q': the eigenvalues were found using SHSEQR; thus, if */
  294. /* > H has zero subdiagonal elements, and so is */
  295. /* > block-triangular, then the j-th eigenvalue can be */
  296. /* > assumed to be an eigenvalue of the block containing */
  297. /* > the j-th row/column. This property allows SHSEIN to */
  298. /* > perform inverse iteration on just one diagonal block. */
  299. /* > = 'N': no assumptions are made on the correspondence */
  300. /* > between eigenvalues and diagonal blocks. In this */
  301. /* > case, SHSEIN must always perform inverse iteration */
  302. /* > using the whole matrix H. */
  303. /* > \endverbatim */
  304. /* > */
  305. /* > \param[in] INITV */
  306. /* > \verbatim */
  307. /* > INITV is CHARACTER*1 */
  308. /* > = 'N': no initial vectors are supplied; */
  309. /* > = 'U': user-supplied initial vectors are stored in the arrays */
  310. /* > VL and/or VR. */
  311. /* > \endverbatim */
  312. /* > */
  313. /* > \param[in,out] SELECT */
  314. /* > \verbatim */
  315. /* > SELECT is LOGICAL array, dimension (N) */
  316. /* > Specifies the eigenvectors to be computed. To select the */
  317. /* > real eigenvector corresponding to a real eigenvalue WR(j), */
  318. /* > SELECT(j) must be set to .TRUE.. To select the complex */
  319. /* > eigenvector corresponding to a complex eigenvalue */
  320. /* > (WR(j),WI(j)), with complex conjugate (WR(j+1),WI(j+1)), */
  321. /* > either SELECT(j) or SELECT(j+1) or both must be set to */
  322. /* > .TRUE.; then on exit SELECT(j) is .TRUE. and SELECT(j+1) is */
  323. /* > .FALSE.. */
  324. /* > \endverbatim */
  325. /* > */
  326. /* > \param[in] N */
  327. /* > \verbatim */
  328. /* > N is INTEGER */
  329. /* > The order of the matrix H. N >= 0. */
  330. /* > \endverbatim */
  331. /* > */
  332. /* > \param[in] H */
  333. /* > \verbatim */
  334. /* > H is REAL array, dimension (LDH,N) */
  335. /* > The upper Hessenberg matrix H. */
  336. /* > If a NaN is detected in H, the routine will return with INFO=-6. */
  337. /* > \endverbatim */
  338. /* > */
  339. /* > \param[in] LDH */
  340. /* > \verbatim */
  341. /* > LDH is INTEGER */
  342. /* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[in,out] WR */
  346. /* > \verbatim */
  347. /* > WR is REAL array, dimension (N) */
  348. /* > \endverbatim */
  349. /* > */
  350. /* > \param[in] WI */
  351. /* > \verbatim */
  352. /* > WI is REAL array, dimension (N) */
  353. /* > */
  354. /* > On entry, the real and imaginary parts of the eigenvalues of */
  355. /* > H; a complex conjugate pair of eigenvalues must be stored in */
  356. /* > consecutive elements of WR and WI. */
  357. /* > On exit, WR may have been altered since close eigenvalues */
  358. /* > are perturbed slightly in searching for independent */
  359. /* > eigenvectors. */
  360. /* > \endverbatim */
  361. /* > */
  362. /* > \param[in,out] VL */
  363. /* > \verbatim */
  364. /* > VL is REAL array, dimension (LDVL,MM) */
  365. /* > On entry, if INITV = 'U' and SIDE = 'L' or 'B', VL must */
  366. /* > contain starting vectors for the inverse iteration for the */
  367. /* > left eigenvectors; the starting vector for each eigenvector */
  368. /* > must be in the same column(s) in which the eigenvector will */
  369. /* > be stored. */
  370. /* > On exit, if SIDE = 'L' or 'B', the left eigenvectors */
  371. /* > specified by SELECT will be stored consecutively in the */
  372. /* > columns of VL, in the same order as their eigenvalues. A */
  373. /* > complex eigenvector corresponding to a complex eigenvalue is */
  374. /* > stored in two consecutive columns, the first holding the real */
  375. /* > part and the second the imaginary part. */
  376. /* > If SIDE = 'R', VL is not referenced. */
  377. /* > \endverbatim */
  378. /* > */
  379. /* > \param[in] LDVL */
  380. /* > \verbatim */
  381. /* > LDVL is INTEGER */
  382. /* > The leading dimension of the array VL. */
  383. /* > LDVL >= f2cmax(1,N) if SIDE = 'L' or 'B'; LDVL >= 1 otherwise. */
  384. /* > \endverbatim */
  385. /* > */
  386. /* > \param[in,out] VR */
  387. /* > \verbatim */
  388. /* > VR is REAL array, dimension (LDVR,MM) */
  389. /* > On entry, if INITV = 'U' and SIDE = 'R' or 'B', VR must */
  390. /* > contain starting vectors for the inverse iteration for the */
  391. /* > right eigenvectors; the starting vector for each eigenvector */
  392. /* > must be in the same column(s) in which the eigenvector will */
  393. /* > be stored. */
  394. /* > On exit, if SIDE = 'R' or 'B', the right eigenvectors */
  395. /* > specified by SELECT will be stored consecutively in the */
  396. /* > columns of VR, in the same order as their eigenvalues. A */
  397. /* > complex eigenvector corresponding to a complex eigenvalue is */
  398. /* > stored in two consecutive columns, the first holding the real */
  399. /* > part and the second the imaginary part. */
  400. /* > If SIDE = 'L', VR is not referenced. */
  401. /* > \endverbatim */
  402. /* > */
  403. /* > \param[in] LDVR */
  404. /* > \verbatim */
  405. /* > LDVR is INTEGER */
  406. /* > The leading dimension of the array VR. */
  407. /* > LDVR >= f2cmax(1,N) if SIDE = 'R' or 'B'; LDVR >= 1 otherwise. */
  408. /* > \endverbatim */
  409. /* > */
  410. /* > \param[in] MM */
  411. /* > \verbatim */
  412. /* > MM is INTEGER */
  413. /* > The number of columns in the arrays VL and/or VR. MM >= M. */
  414. /* > \endverbatim */
  415. /* > */
  416. /* > \param[out] M */
  417. /* > \verbatim */
  418. /* > M is INTEGER */
  419. /* > The number of columns in the arrays VL and/or VR required to */
  420. /* > store the eigenvectors; each selected real eigenvector */
  421. /* > occupies one column and each selected complex eigenvector */
  422. /* > occupies two columns. */
  423. /* > \endverbatim */
  424. /* > */
  425. /* > \param[out] WORK */
  426. /* > \verbatim */
  427. /* > WORK is REAL array, dimension ((N+2)*N) */
  428. /* > \endverbatim */
  429. /* > */
  430. /* > \param[out] IFAILL */
  431. /* > \verbatim */
  432. /* > IFAILL is INTEGER array, dimension (MM) */
  433. /* > If SIDE = 'L' or 'B', IFAILL(i) = j > 0 if the left */
  434. /* > eigenvector in the i-th column of VL (corresponding to the */
  435. /* > eigenvalue w(j)) failed to converge; IFAILL(i) = 0 if the */
  436. /* > eigenvector converged satisfactorily. If the i-th and (i+1)th */
  437. /* > columns of VL hold a complex eigenvector, then IFAILL(i) and */
  438. /* > IFAILL(i+1) are set to the same value. */
  439. /* > If SIDE = 'R', IFAILL is not referenced. */
  440. /* > \endverbatim */
  441. /* > */
  442. /* > \param[out] IFAILR */
  443. /* > \verbatim */
  444. /* > IFAILR is INTEGER array, dimension (MM) */
  445. /* > If SIDE = 'R' or 'B', IFAILR(i) = j > 0 if the right */
  446. /* > eigenvector in the i-th column of VR (corresponding to the */
  447. /* > eigenvalue w(j)) failed to converge; IFAILR(i) = 0 if the */
  448. /* > eigenvector converged satisfactorily. If the i-th and (i+1)th */
  449. /* > columns of VR hold a complex eigenvector, then IFAILR(i) and */
  450. /* > IFAILR(i+1) are set to the same value. */
  451. /* > If SIDE = 'L', IFAILR is not referenced. */
  452. /* > \endverbatim */
  453. /* > */
  454. /* > \param[out] INFO */
  455. /* > \verbatim */
  456. /* > INFO is INTEGER */
  457. /* > = 0: successful exit */
  458. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  459. /* > > 0: if INFO = i, i is the number of eigenvectors which */
  460. /* > failed to converge; see IFAILL and IFAILR for further */
  461. /* > details. */
  462. /* > \endverbatim */
  463. /* Authors: */
  464. /* ======== */
  465. /* > \author Univ. of Tennessee */
  466. /* > \author Univ. of California Berkeley */
  467. /* > \author Univ. of Colorado Denver */
  468. /* > \author NAG Ltd. */
  469. /* > \date December 2016 */
  470. /* > \ingroup realOTHERcomputational */
  471. /* > \par Further Details: */
  472. /* ===================== */
  473. /* > */
  474. /* > \verbatim */
  475. /* > */
  476. /* > Each eigenvector is normalized so that the element of largest */
  477. /* > magnitude has magnitude 1; here the magnitude of a complex number */
  478. /* > (x,y) is taken to be |x|+|y|. */
  479. /* > \endverbatim */
  480. /* > */
  481. /* ===================================================================== */
  482. /* Subroutine */ void shsein_(char *side, char *eigsrc, char *initv, logical *
  483. select, integer *n, real *h__, integer *ldh, real *wr, real *wi, real
  484. *vl, integer *ldvl, real *vr, integer *ldvr, integer *mm, integer *m,
  485. real *work, integer *ifaill, integer *ifailr, integer *info)
  486. {
  487. /* System generated locals */
  488. integer h_dim1, h_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
  489. i__2;
  490. real r__1, r__2;
  491. /* Local variables */
  492. logical pair;
  493. real unfl;
  494. integer i__, k;
  495. extern logical lsame_(char *, char *);
  496. integer iinfo;
  497. logical leftv, bothv;
  498. real hnorm;
  499. integer kl, kr;
  500. extern real slamch_(char *);
  501. extern /* Subroutine */ void slaein_(logical *, logical *, integer *, real
  502. *, integer *, real *, real *, real *, real *, real *, integer *,
  503. real *, real *, real *, real *, integer *);
  504. extern int xerbla_(char *, integer *, ftnlen);
  505. real bignum;
  506. extern real slanhs_(char *, integer *, real *, integer *, real *);
  507. extern logical sisnan_(real *);
  508. logical noinit;
  509. integer ldwork;
  510. logical rightv, fromqr;
  511. real smlnum;
  512. integer kln, ksi;
  513. real wki;
  514. integer ksr;
  515. real ulp, wkr, eps3;
  516. /* -- LAPACK computational routine (version 3.7.0) -- */
  517. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  518. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  519. /* December 2016 */
  520. /* ===================================================================== */
  521. /* Decode and test the input parameters. */
  522. /* Parameter adjustments */
  523. --select;
  524. h_dim1 = *ldh;
  525. h_offset = 1 + h_dim1 * 1;
  526. h__ -= h_offset;
  527. --wr;
  528. --wi;
  529. vl_dim1 = *ldvl;
  530. vl_offset = 1 + vl_dim1 * 1;
  531. vl -= vl_offset;
  532. vr_dim1 = *ldvr;
  533. vr_offset = 1 + vr_dim1 * 1;
  534. vr -= vr_offset;
  535. --work;
  536. --ifaill;
  537. --ifailr;
  538. /* Function Body */
  539. bothv = lsame_(side, "B");
  540. rightv = lsame_(side, "R") || bothv;
  541. leftv = lsame_(side, "L") || bothv;
  542. fromqr = lsame_(eigsrc, "Q");
  543. noinit = lsame_(initv, "N");
  544. /* Set M to the number of columns required to store the selected */
  545. /* eigenvectors, and standardize the array SELECT. */
  546. *m = 0;
  547. pair = FALSE_;
  548. i__1 = *n;
  549. for (k = 1; k <= i__1; ++k) {
  550. if (pair) {
  551. pair = FALSE_;
  552. select[k] = FALSE_;
  553. } else {
  554. if (wi[k] == 0.f) {
  555. if (select[k]) {
  556. ++(*m);
  557. }
  558. } else {
  559. pair = TRUE_;
  560. if (select[k] || select[k + 1]) {
  561. select[k] = TRUE_;
  562. *m += 2;
  563. }
  564. }
  565. }
  566. /* L10: */
  567. }
  568. *info = 0;
  569. if (! rightv && ! leftv) {
  570. *info = -1;
  571. } else if (! fromqr && ! lsame_(eigsrc, "N")) {
  572. *info = -2;
  573. } else if (! noinit && ! lsame_(initv, "U")) {
  574. *info = -3;
  575. } else if (*n < 0) {
  576. *info = -5;
  577. } else if (*ldh < f2cmax(1,*n)) {
  578. *info = -7;
  579. } else if (*ldvl < 1 || leftv && *ldvl < *n) {
  580. *info = -11;
  581. } else if (*ldvr < 1 || rightv && *ldvr < *n) {
  582. *info = -13;
  583. } else if (*mm < *m) {
  584. *info = -14;
  585. }
  586. if (*info != 0) {
  587. i__1 = -(*info);
  588. xerbla_("SHSEIN", &i__1, (ftnlen)6);
  589. return;
  590. }
  591. /* Quick return if possible. */
  592. if (*n == 0) {
  593. return;
  594. }
  595. /* Set machine-dependent constants. */
  596. unfl = slamch_("Safe minimum");
  597. ulp = slamch_("Precision");
  598. smlnum = unfl * (*n / ulp);
  599. bignum = (1.f - ulp) / smlnum;
  600. ldwork = *n + 1;
  601. kl = 1;
  602. kln = 0;
  603. if (fromqr) {
  604. kr = 0;
  605. } else {
  606. kr = *n;
  607. }
  608. ksr = 1;
  609. i__1 = *n;
  610. for (k = 1; k <= i__1; ++k) {
  611. if (select[k]) {
  612. /* Compute eigenvector(s) corresponding to W(K). */
  613. if (fromqr) {
  614. /* If affiliation of eigenvalues is known, check whether */
  615. /* the matrix splits. */
  616. /* Determine KL and KR such that 1 <= KL <= K <= KR <= N */
  617. /* and H(KL,KL-1) and H(KR+1,KR) are zero (or KL = 1 or */
  618. /* KR = N). */
  619. /* Then inverse iteration can be performed with the */
  620. /* submatrix H(KL:N,KL:N) for a left eigenvector, and with */
  621. /* the submatrix H(1:KR,1:KR) for a right eigenvector. */
  622. i__2 = kl + 1;
  623. for (i__ = k; i__ >= i__2; --i__) {
  624. if (h__[i__ + (i__ - 1) * h_dim1] == 0.f) {
  625. goto L30;
  626. }
  627. /* L20: */
  628. }
  629. L30:
  630. kl = i__;
  631. if (k > kr) {
  632. i__2 = *n - 1;
  633. for (i__ = k; i__ <= i__2; ++i__) {
  634. if (h__[i__ + 1 + i__ * h_dim1] == 0.f) {
  635. goto L50;
  636. }
  637. /* L40: */
  638. }
  639. L50:
  640. kr = i__;
  641. }
  642. }
  643. if (kl != kln) {
  644. kln = kl;
  645. /* Compute infinity-norm of submatrix H(KL:KR,KL:KR) if it */
  646. /* has not ben computed before. */
  647. i__2 = kr - kl + 1;
  648. hnorm = slanhs_("I", &i__2, &h__[kl + kl * h_dim1], ldh, &
  649. work[1]);
  650. if (sisnan_(&hnorm)) {
  651. *info = -6;
  652. return;
  653. } else if (hnorm > 0.f) {
  654. eps3 = hnorm * ulp;
  655. } else {
  656. eps3 = smlnum;
  657. }
  658. }
  659. /* Perturb eigenvalue if it is close to any previous */
  660. /* selected eigenvalues affiliated to the submatrix */
  661. /* H(KL:KR,KL:KR). Close roots are modified by EPS3. */
  662. wkr = wr[k];
  663. wki = wi[k];
  664. L60:
  665. i__2 = kl;
  666. for (i__ = k - 1; i__ >= i__2; --i__) {
  667. if (select[i__] && (r__1 = wr[i__] - wkr, abs(r__1)) + (r__2 =
  668. wi[i__] - wki, abs(r__2)) < eps3) {
  669. wkr += eps3;
  670. goto L60;
  671. }
  672. /* L70: */
  673. }
  674. wr[k] = wkr;
  675. pair = wki != 0.f;
  676. if (pair) {
  677. ksi = ksr + 1;
  678. } else {
  679. ksi = ksr;
  680. }
  681. if (leftv) {
  682. /* Compute left eigenvector. */
  683. i__2 = *n - kl + 1;
  684. slaein_(&c_false, &noinit, &i__2, &h__[kl + kl * h_dim1], ldh,
  685. &wkr, &wki, &vl[kl + ksr * vl_dim1], &vl[kl + ksi *
  686. vl_dim1], &work[1], &ldwork, &work[*n * *n + *n + 1],
  687. &eps3, &smlnum, &bignum, &iinfo);
  688. if (iinfo > 0) {
  689. if (pair) {
  690. *info += 2;
  691. } else {
  692. ++(*info);
  693. }
  694. ifaill[ksr] = k;
  695. ifaill[ksi] = k;
  696. } else {
  697. ifaill[ksr] = 0;
  698. ifaill[ksi] = 0;
  699. }
  700. i__2 = kl - 1;
  701. for (i__ = 1; i__ <= i__2; ++i__) {
  702. vl[i__ + ksr * vl_dim1] = 0.f;
  703. /* L80: */
  704. }
  705. if (pair) {
  706. i__2 = kl - 1;
  707. for (i__ = 1; i__ <= i__2; ++i__) {
  708. vl[i__ + ksi * vl_dim1] = 0.f;
  709. /* L90: */
  710. }
  711. }
  712. }
  713. if (rightv) {
  714. /* Compute right eigenvector. */
  715. slaein_(&c_true, &noinit, &kr, &h__[h_offset], ldh, &wkr, &
  716. wki, &vr[ksr * vr_dim1 + 1], &vr[ksi * vr_dim1 + 1], &
  717. work[1], &ldwork, &work[*n * *n + *n + 1], &eps3, &
  718. smlnum, &bignum, &iinfo);
  719. if (iinfo > 0) {
  720. if (pair) {
  721. *info += 2;
  722. } else {
  723. ++(*info);
  724. }
  725. ifailr[ksr] = k;
  726. ifailr[ksi] = k;
  727. } else {
  728. ifailr[ksr] = 0;
  729. ifailr[ksi] = 0;
  730. }
  731. i__2 = *n;
  732. for (i__ = kr + 1; i__ <= i__2; ++i__) {
  733. vr[i__ + ksr * vr_dim1] = 0.f;
  734. /* L100: */
  735. }
  736. if (pair) {
  737. i__2 = *n;
  738. for (i__ = kr + 1; i__ <= i__2; ++i__) {
  739. vr[i__ + ksi * vr_dim1] = 0.f;
  740. /* L110: */
  741. }
  742. }
  743. }
  744. if (pair) {
  745. ksr += 2;
  746. } else {
  747. ++ksr;
  748. }
  749. }
  750. /* L120: */
  751. }
  752. return;
  753. /* End of SHSEIN */
  754. } /* shsein_ */