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.

cheevx.c 30 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static integer c__1 = 1;
  363. static integer c_n1 = -1;
  364. /* > \brief <b> CHEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE mat
  365. rices</b> */
  366. /* =========== DOCUMENTATION =========== */
  367. /* Online html documentation available at */
  368. /* http://www.netlib.org/lapack/explore-html/ */
  369. /* > \htmlonly */
  370. /* > Download CHEEVX + dependencies */
  371. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheevx.
  372. f"> */
  373. /* > [TGZ]</a> */
  374. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheevx.
  375. f"> */
  376. /* > [ZIP]</a> */
  377. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheevx.
  378. f"> */
  379. /* > [TXT]</a> */
  380. /* > \endhtmlonly */
  381. /* Definition: */
  382. /* =========== */
  383. /* SUBROUTINE CHEEVX( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, */
  384. /* ABSTOL, M, W, Z, LDZ, WORK, LWORK, RWORK, */
  385. /* IWORK, IFAIL, INFO ) */
  386. /* CHARACTER JOBZ, RANGE, UPLO */
  387. /* INTEGER IL, INFO, IU, LDA, LDZ, LWORK, M, N */
  388. /* REAL ABSTOL, VL, VU */
  389. /* INTEGER IFAIL( * ), IWORK( * ) */
  390. /* REAL RWORK( * ), W( * ) */
  391. /* COMPLEX A( LDA, * ), WORK( * ), Z( LDZ, * ) */
  392. /* > \par Purpose: */
  393. /* ============= */
  394. /* > */
  395. /* > \verbatim */
  396. /* > */
  397. /* > CHEEVX computes selected eigenvalues and, optionally, eigenvectors */
  398. /* > of a complex Hermitian matrix A. Eigenvalues and eigenvectors can */
  399. /* > be selected by specifying either a range of values or a range of */
  400. /* > indices for the desired eigenvalues. */
  401. /* > \endverbatim */
  402. /* Arguments: */
  403. /* ========== */
  404. /* > \param[in] JOBZ */
  405. /* > \verbatim */
  406. /* > JOBZ is CHARACTER*1 */
  407. /* > = 'N': Compute eigenvalues only; */
  408. /* > = 'V': Compute eigenvalues and eigenvectors. */
  409. /* > \endverbatim */
  410. /* > */
  411. /* > \param[in] RANGE */
  412. /* > \verbatim */
  413. /* > RANGE is CHARACTER*1 */
  414. /* > = 'A': all eigenvalues will be found. */
  415. /* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
  416. /* > will be found. */
  417. /* > = 'I': the IL-th through IU-th eigenvalues will be found. */
  418. /* > \endverbatim */
  419. /* > */
  420. /* > \param[in] UPLO */
  421. /* > \verbatim */
  422. /* > UPLO is CHARACTER*1 */
  423. /* > = 'U': Upper triangle of A is stored; */
  424. /* > = 'L': Lower triangle of A is stored. */
  425. /* > \endverbatim */
  426. /* > */
  427. /* > \param[in] N */
  428. /* > \verbatim */
  429. /* > N is INTEGER */
  430. /* > The order of the matrix A. N >= 0. */
  431. /* > \endverbatim */
  432. /* > */
  433. /* > \param[in,out] A */
  434. /* > \verbatim */
  435. /* > A is COMPLEX array, dimension (LDA, N) */
  436. /* > On entry, the Hermitian matrix A. If UPLO = 'U', the */
  437. /* > leading N-by-N upper triangular part of A contains the */
  438. /* > upper triangular part of the matrix A. If UPLO = 'L', */
  439. /* > the leading N-by-N lower triangular part of A contains */
  440. /* > the lower triangular part of the matrix A. */
  441. /* > On exit, the lower triangle (if UPLO='L') or the upper */
  442. /* > triangle (if UPLO='U') of A, including the diagonal, is */
  443. /* > destroyed. */
  444. /* > \endverbatim */
  445. /* > */
  446. /* > \param[in] LDA */
  447. /* > \verbatim */
  448. /* > LDA is INTEGER */
  449. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  450. /* > \endverbatim */
  451. /* > */
  452. /* > \param[in] VL */
  453. /* > \verbatim */
  454. /* > VL is REAL */
  455. /* > If RANGE='V', the lower bound of the interval to */
  456. /* > be searched for eigenvalues. VL < VU. */
  457. /* > Not referenced if RANGE = 'A' or 'I'. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in] VU */
  461. /* > \verbatim */
  462. /* > VU is REAL */
  463. /* > If RANGE='V', the upper bound of the interval to */
  464. /* > be searched for eigenvalues. VL < VU. */
  465. /* > Not referenced if RANGE = 'A' or 'I'. */
  466. /* > \endverbatim */
  467. /* > */
  468. /* > \param[in] IL */
  469. /* > \verbatim */
  470. /* > IL is INTEGER */
  471. /* > If RANGE='I', the index of the */
  472. /* > smallest eigenvalue to be returned. */
  473. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  474. /* > Not referenced if RANGE = 'A' or 'V'. */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[in] IU */
  478. /* > \verbatim */
  479. /* > IU is INTEGER */
  480. /* > If RANGE='I', the index of the */
  481. /* > largest eigenvalue to be returned. */
  482. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  483. /* > Not referenced if RANGE = 'A' or 'V'. */
  484. /* > \endverbatim */
  485. /* > */
  486. /* > \param[in] ABSTOL */
  487. /* > \verbatim */
  488. /* > ABSTOL is REAL */
  489. /* > The absolute error tolerance for the eigenvalues. */
  490. /* > An approximate eigenvalue is accepted as converged */
  491. /* > when it is determined to lie in an interval [a,b] */
  492. /* > of width less than or equal to */
  493. /* > */
  494. /* > ABSTOL + EPS * f2cmax( |a|,|b| ) , */
  495. /* > */
  496. /* > where EPS is the machine precision. If ABSTOL is less than */
  497. /* > or equal to zero, then EPS*|T| will be used in its place, */
  498. /* > where |T| is the 1-norm of the tridiagonal matrix obtained */
  499. /* > by reducing A to tridiagonal form. */
  500. /* > */
  501. /* > Eigenvalues will be computed most accurately when ABSTOL is */
  502. /* > set to twice the underflow threshold 2*SLAMCH('S'), not zero. */
  503. /* > If this routine returns with INFO>0, indicating that some */
  504. /* > eigenvectors did not converge, try setting ABSTOL to */
  505. /* > 2*SLAMCH('S'). */
  506. /* > */
  507. /* > See "Computing Small Singular Values of Bidiagonal Matrices */
  508. /* > with Guaranteed High Relative Accuracy," by Demmel and */
  509. /* > Kahan, LAPACK Working Note #3. */
  510. /* > \endverbatim */
  511. /* > */
  512. /* > \param[out] M */
  513. /* > \verbatim */
  514. /* > M is INTEGER */
  515. /* > The total number of eigenvalues found. 0 <= M <= N. */
  516. /* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  517. /* > \endverbatim */
  518. /* > */
  519. /* > \param[out] W */
  520. /* > \verbatim */
  521. /* > W is REAL array, dimension (N) */
  522. /* > On normal exit, the first M elements contain the selected */
  523. /* > eigenvalues in ascending order. */
  524. /* > \endverbatim */
  525. /* > */
  526. /* > \param[out] Z */
  527. /* > \verbatim */
  528. /* > Z is COMPLEX array, dimension (LDZ, f2cmax(1,M)) */
  529. /* > If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  530. /* > contain the orthonormal eigenvectors of the matrix A */
  531. /* > corresponding to the selected eigenvalues, with the i-th */
  532. /* > column of Z holding the eigenvector associated with W(i). */
  533. /* > If an eigenvector fails to converge, then that column of Z */
  534. /* > contains the latest approximation to the eigenvector, and the */
  535. /* > index of the eigenvector is returned in IFAIL. */
  536. /* > If JOBZ = 'N', then Z is not referenced. */
  537. /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
  538. /* > supplied in the array Z; if RANGE = 'V', the exact value of M */
  539. /* > is not known in advance and an upper bound must be used. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[in] LDZ */
  543. /* > \verbatim */
  544. /* > LDZ is INTEGER */
  545. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  546. /* > JOBZ = 'V', LDZ >= f2cmax(1,N). */
  547. /* > \endverbatim */
  548. /* > */
  549. /* > \param[out] WORK */
  550. /* > \verbatim */
  551. /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
  552. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] LWORK */
  556. /* > \verbatim */
  557. /* > LWORK is INTEGER */
  558. /* > The length of the array WORK. LWORK >= 1, when N <= 1; */
  559. /* > otherwise 2*N. */
  560. /* > For optimal efficiency, LWORK >= (NB+1)*N, */
  561. /* > where NB is the f2cmax of the blocksize for CHETRD and for */
  562. /* > CUNMTR as returned by ILAENV. */
  563. /* > */
  564. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  565. /* > only calculates the optimal size of the WORK array, returns */
  566. /* > this value as the first entry of the WORK array, and no error */
  567. /* > message related to LWORK is issued by XERBLA. */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[out] RWORK */
  571. /* > \verbatim */
  572. /* > RWORK is REAL array, dimension (7*N) */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[out] IWORK */
  576. /* > \verbatim */
  577. /* > IWORK is INTEGER array, dimension (5*N) */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[out] IFAIL */
  581. /* > \verbatim */
  582. /* > IFAIL is INTEGER array, dimension (N) */
  583. /* > If JOBZ = 'V', then if INFO = 0, the first M elements of */
  584. /* > IFAIL are zero. If INFO > 0, then IFAIL contains the */
  585. /* > indices of the eigenvectors that failed to converge. */
  586. /* > If JOBZ = 'N', then IFAIL is not referenced. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[out] INFO */
  590. /* > \verbatim */
  591. /* > INFO is INTEGER */
  592. /* > = 0: successful exit */
  593. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  594. /* > > 0: if INFO = i, then i eigenvectors failed to converge. */
  595. /* > Their indices are stored in array IFAIL. */
  596. /* > \endverbatim */
  597. /* Authors: */
  598. /* ======== */
  599. /* > \author Univ. of Tennessee */
  600. /* > \author Univ. of California Berkeley */
  601. /* > \author Univ. of Colorado Denver */
  602. /* > \author NAG Ltd. */
  603. /* > \date June 2016 */
  604. /* > \ingroup complexHEeigen */
  605. /* ===================================================================== */
  606. /* Subroutine */ int cheevx_(char *jobz, char *range, char *uplo, integer *n,
  607. complex *a, integer *lda, real *vl, real *vu, integer *il, integer *
  608. iu, real *abstol, integer *m, real *w, complex *z__, integer *ldz,
  609. complex *work, integer *lwork, real *rwork, integer *iwork, integer *
  610. ifail, integer *info)
  611. {
  612. /* System generated locals */
  613. integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
  614. real r__1, r__2;
  615. /* Local variables */
  616. integer indd, inde;
  617. real anrm;
  618. integer imax;
  619. real rmin, rmax;
  620. logical test;
  621. integer itmp1, i__, j, indee;
  622. real sigma;
  623. extern logical lsame_(char *, char *);
  624. integer iinfo;
  625. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
  626. char order[1];
  627. extern /* Subroutine */ int cswap_(integer *, complex *, integer *,
  628. complex *, integer *);
  629. logical lower;
  630. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  631. integer *);
  632. logical wantz;
  633. integer nb, jj;
  634. extern real clanhe_(char *, char *, integer *, complex *, integer *, real
  635. *);
  636. logical alleig, indeig;
  637. integer iscale, indibl;
  638. logical valeig;
  639. extern real slamch_(char *);
  640. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  641. *), chetrd_(char *, integer *, complex *, integer *, real *, real
  642. *, complex *, complex *, integer *, integer *), clacpy_(
  643. char *, integer *, integer *, complex *, integer *, complex *,
  644. integer *);
  645. real safmin;
  646. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  647. integer *, integer *, ftnlen, ftnlen);
  648. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  649. real abstll, bignum;
  650. integer indiwk, indisp, indtau;
  651. extern /* Subroutine */ int cstein_(integer *, real *, real *, integer *,
  652. real *, integer *, integer *, complex *, integer *, real *,
  653. integer *, integer *, integer *);
  654. integer indrwk, indwrk, lwkmin;
  655. extern /* Subroutine */ int csteqr_(char *, integer *, real *, real *,
  656. complex *, integer *, real *, integer *), cungtr_(char *,
  657. integer *, complex *, integer *, complex *, complex *, integer *,
  658. integer *), ssterf_(integer *, real *, real *, integer *),
  659. cunmtr_(char *, char *, char *, integer *, integer *, complex *,
  660. integer *, complex *, complex *, integer *, complex *, integer *,
  661. integer *);
  662. integer nsplit, llwork;
  663. real smlnum;
  664. extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *,
  665. real *, integer *, integer *, real *, real *, real *, integer *,
  666. integer *, real *, integer *, integer *, real *, integer *,
  667. integer *);
  668. integer lwkopt;
  669. logical lquery;
  670. real eps, vll, vuu, tmp1;
  671. /* -- LAPACK driver routine (version 3.7.0) -- */
  672. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  673. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  674. /* June 2016 */
  675. /* ===================================================================== */
  676. /* Test the input parameters. */
  677. /* Parameter adjustments */
  678. a_dim1 = *lda;
  679. a_offset = 1 + a_dim1 * 1;
  680. a -= a_offset;
  681. --w;
  682. z_dim1 = *ldz;
  683. z_offset = 1 + z_dim1 * 1;
  684. z__ -= z_offset;
  685. --work;
  686. --rwork;
  687. --iwork;
  688. --ifail;
  689. /* Function Body */
  690. lower = lsame_(uplo, "L");
  691. wantz = lsame_(jobz, "V");
  692. alleig = lsame_(range, "A");
  693. valeig = lsame_(range, "V");
  694. indeig = lsame_(range, "I");
  695. lquery = *lwork == -1;
  696. *info = 0;
  697. if (! (wantz || lsame_(jobz, "N"))) {
  698. *info = -1;
  699. } else if (! (alleig || valeig || indeig)) {
  700. *info = -2;
  701. } else if (! (lower || lsame_(uplo, "U"))) {
  702. *info = -3;
  703. } else if (*n < 0) {
  704. *info = -4;
  705. } else if (*lda < f2cmax(1,*n)) {
  706. *info = -6;
  707. } else {
  708. if (valeig) {
  709. if (*n > 0 && *vu <= *vl) {
  710. *info = -8;
  711. }
  712. } else if (indeig) {
  713. if (*il < 1 || *il > f2cmax(1,*n)) {
  714. *info = -9;
  715. } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
  716. *info = -10;
  717. }
  718. }
  719. }
  720. if (*info == 0) {
  721. if (*ldz < 1 || wantz && *ldz < *n) {
  722. *info = -15;
  723. }
  724. }
  725. if (*info == 0) {
  726. if (*n <= 1) {
  727. lwkmin = 1;
  728. work[1].r = (real) lwkmin, work[1].i = 0.f;
  729. } else {
  730. lwkmin = *n << 1;
  731. nb = ilaenv_(&c__1, "CHETRD", uplo, n, &c_n1, &c_n1, &c_n1, (
  732. ftnlen)6, (ftnlen)1);
  733. /* Computing MAX */
  734. i__1 = nb, i__2 = ilaenv_(&c__1, "CUNMTR", uplo, n, &c_n1, &c_n1,
  735. &c_n1, (ftnlen)6, (ftnlen)1);
  736. nb = f2cmax(i__1,i__2);
  737. /* Computing MAX */
  738. i__1 = 1, i__2 = (nb + 1) * *n;
  739. lwkopt = f2cmax(i__1,i__2);
  740. work[1].r = (real) lwkopt, work[1].i = 0.f;
  741. }
  742. if (*lwork < lwkmin && ! lquery) {
  743. *info = -17;
  744. }
  745. }
  746. if (*info != 0) {
  747. i__1 = -(*info);
  748. xerbla_("CHEEVX", &i__1, (ftnlen)6);
  749. return 0;
  750. } else if (lquery) {
  751. return 0;
  752. }
  753. /* Quick return if possible */
  754. *m = 0;
  755. if (*n == 0) {
  756. return 0;
  757. }
  758. if (*n == 1) {
  759. if (alleig || indeig) {
  760. *m = 1;
  761. i__1 = a_dim1 + 1;
  762. w[1] = a[i__1].r;
  763. } else if (valeig) {
  764. i__1 = a_dim1 + 1;
  765. i__2 = a_dim1 + 1;
  766. if (*vl < a[i__1].r && *vu >= a[i__2].r) {
  767. *m = 1;
  768. i__1 = a_dim1 + 1;
  769. w[1] = a[i__1].r;
  770. }
  771. }
  772. if (wantz) {
  773. i__1 = z_dim1 + 1;
  774. z__[i__1].r = 1.f, z__[i__1].i = 0.f;
  775. }
  776. return 0;
  777. }
  778. /* Get machine constants. */
  779. safmin = slamch_("Safe minimum");
  780. eps = slamch_("Precision");
  781. smlnum = safmin / eps;
  782. bignum = 1.f / smlnum;
  783. rmin = sqrt(smlnum);
  784. /* Computing MIN */
  785. r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
  786. rmax = f2cmin(r__1,r__2);
  787. /* Scale matrix to allowable range, if necessary. */
  788. iscale = 0;
  789. abstll = *abstol;
  790. if (valeig) {
  791. vll = *vl;
  792. vuu = *vu;
  793. }
  794. anrm = clanhe_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
  795. if (anrm > 0.f && anrm < rmin) {
  796. iscale = 1;
  797. sigma = rmin / anrm;
  798. } else if (anrm > rmax) {
  799. iscale = 1;
  800. sigma = rmax / anrm;
  801. }
  802. if (iscale == 1) {
  803. if (lower) {
  804. i__1 = *n;
  805. for (j = 1; j <= i__1; ++j) {
  806. i__2 = *n - j + 1;
  807. csscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
  808. /* L10: */
  809. }
  810. } else {
  811. i__1 = *n;
  812. for (j = 1; j <= i__1; ++j) {
  813. csscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
  814. /* L20: */
  815. }
  816. }
  817. if (*abstol > 0.f) {
  818. abstll = *abstol * sigma;
  819. }
  820. if (valeig) {
  821. vll = *vl * sigma;
  822. vuu = *vu * sigma;
  823. }
  824. }
  825. /* Call CHETRD to reduce Hermitian matrix to tridiagonal form. */
  826. indd = 1;
  827. inde = indd + *n;
  828. indrwk = inde + *n;
  829. indtau = 1;
  830. indwrk = indtau + *n;
  831. llwork = *lwork - indwrk + 1;
  832. chetrd_(uplo, n, &a[a_offset], lda, &rwork[indd], &rwork[inde], &work[
  833. indtau], &work[indwrk], &llwork, &iinfo);
  834. /* If all eigenvalues are desired and ABSTOL is less than or equal to */
  835. /* zero, then call SSTERF or CUNGTR and CSTEQR. If this fails for */
  836. /* some eigenvalue, then try SSTEBZ. */
  837. test = FALSE_;
  838. if (indeig) {
  839. if (*il == 1 && *iu == *n) {
  840. test = TRUE_;
  841. }
  842. }
  843. if ((alleig || test) && *abstol <= 0.f) {
  844. scopy_(n, &rwork[indd], &c__1, &w[1], &c__1);
  845. indee = indrwk + (*n << 1);
  846. if (! wantz) {
  847. i__1 = *n - 1;
  848. scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
  849. ssterf_(n, &w[1], &rwork[indee], info);
  850. } else {
  851. clacpy_("A", n, n, &a[a_offset], lda, &z__[z_offset], ldz);
  852. cungtr_(uplo, n, &z__[z_offset], ldz, &work[indtau], &work[indwrk]
  853. , &llwork, &iinfo);
  854. i__1 = *n - 1;
  855. scopy_(&i__1, &rwork[inde], &c__1, &rwork[indee], &c__1);
  856. csteqr_(jobz, n, &w[1], &rwork[indee], &z__[z_offset], ldz, &
  857. rwork[indrwk], info);
  858. if (*info == 0) {
  859. i__1 = *n;
  860. for (i__ = 1; i__ <= i__1; ++i__) {
  861. ifail[i__] = 0;
  862. /* L30: */
  863. }
  864. }
  865. }
  866. if (*info == 0) {
  867. *m = *n;
  868. goto L40;
  869. }
  870. *info = 0;
  871. }
  872. /* Otherwise, call SSTEBZ and, if eigenvectors are desired, CSTEIN. */
  873. if (wantz) {
  874. *(unsigned char *)order = 'B';
  875. } else {
  876. *(unsigned char *)order = 'E';
  877. }
  878. indibl = 1;
  879. indisp = indibl + *n;
  880. indiwk = indisp + *n;
  881. sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indd], &
  882. rwork[inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
  883. rwork[indrwk], &iwork[indiwk], info);
  884. if (wantz) {
  885. cstein_(n, &rwork[indd], &rwork[inde], m, &w[1], &iwork[indibl], &
  886. iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
  887. indiwk], &ifail[1], info);
  888. /* Apply unitary matrix used in reduction to tridiagonal */
  889. /* form to eigenvectors returned by CSTEIN. */
  890. cunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
  891. z_offset], ldz, &work[indwrk], &llwork, &iinfo);
  892. }
  893. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  894. L40:
  895. if (iscale == 1) {
  896. if (*info == 0) {
  897. imax = *m;
  898. } else {
  899. imax = *info - 1;
  900. }
  901. r__1 = 1.f / sigma;
  902. sscal_(&imax, &r__1, &w[1], &c__1);
  903. }
  904. /* If eigenvalues are not in order, then sort them, along with */
  905. /* eigenvectors. */
  906. if (wantz) {
  907. i__1 = *m - 1;
  908. for (j = 1; j <= i__1; ++j) {
  909. i__ = 0;
  910. tmp1 = w[j];
  911. i__2 = *m;
  912. for (jj = j + 1; jj <= i__2; ++jj) {
  913. if (w[jj] < tmp1) {
  914. i__ = jj;
  915. tmp1 = w[jj];
  916. }
  917. /* L50: */
  918. }
  919. if (i__ != 0) {
  920. itmp1 = iwork[indibl + i__ - 1];
  921. w[i__] = w[j];
  922. iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
  923. w[j] = tmp1;
  924. iwork[indibl + j - 1] = itmp1;
  925. cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  926. &c__1);
  927. if (*info != 0) {
  928. itmp1 = ifail[i__];
  929. ifail[i__] = ifail[j];
  930. ifail[j] = itmp1;
  931. }
  932. }
  933. /* L60: */
  934. }
  935. }
  936. /* Set WORK(1) to optimal complex workspace size. */
  937. work[1].r = (real) lwkopt, work[1].i = 0.f;
  938. return 0;
  939. /* End of CHEEVX */
  940. } /* cheevx_ */