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.

cheevr.c 38 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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__10 = 10;
  363. static integer c__1 = 1;
  364. static integer c__2 = 2;
  365. static integer c__3 = 3;
  366. static integer c__4 = 4;
  367. static integer c_n1 = -1;
  368. /* > \brief <b> CHEEVR computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE mat
  369. rices</b> */
  370. /* =========== DOCUMENTATION =========== */
  371. /* Online html documentation available at */
  372. /* http://www.netlib.org/lapack/explore-html/ */
  373. /* > \htmlonly */
  374. /* > Download CHEEVR + dependencies */
  375. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheevr.
  376. f"> */
  377. /* > [TGZ]</a> */
  378. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheevr.
  379. f"> */
  380. /* > [ZIP]</a> */
  381. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheevr.
  382. f"> */
  383. /* > [TXT]</a> */
  384. /* > \endhtmlonly */
  385. /* Definition: */
  386. /* =========== */
  387. /* SUBROUTINE CHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, */
  388. /* ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK, */
  389. /* RWORK, LRWORK, IWORK, LIWORK, INFO ) */
  390. /* CHARACTER JOBZ, RANGE, UPLO */
  391. /* INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK, */
  392. /* $ M, N */
  393. /* REAL ABSTOL, VL, VU */
  394. /* INTEGER ISUPPZ( * ), IWORK( * ) */
  395. /* REAL RWORK( * ), W( * ) */
  396. /* COMPLEX A( LDA, * ), WORK( * ), Z( LDZ, * ) */
  397. /* > \par Purpose: */
  398. /* ============= */
  399. /* > */
  400. /* > \verbatim */
  401. /* > */
  402. /* > CHEEVR computes selected eigenvalues and, optionally, eigenvectors */
  403. /* > of a complex Hermitian matrix A. Eigenvalues and eigenvectors can */
  404. /* > be selected by specifying either a range of values or a range of */
  405. /* > indices for the desired eigenvalues. */
  406. /* > */
  407. /* > CHEEVR first reduces the matrix A to tridiagonal form T with a call */
  408. /* > to CHETRD. Then, whenever possible, CHEEVR calls CSTEMR to compute */
  409. /* > the eigenspectrum using Relatively Robust Representations. CSTEMR */
  410. /* > computes eigenvalues by the dqds algorithm, while orthogonal */
  411. /* > eigenvectors are computed from various "good" L D L^T representations */
  412. /* > (also known as Relatively Robust Representations). Gram-Schmidt */
  413. /* > orthogonalization is avoided as far as possible. More specifically, */
  414. /* > the various steps of the algorithm are as follows. */
  415. /* > */
  416. /* > For each unreduced block (submatrix) of T, */
  417. /* > (a) Compute T - sigma I = L D L^T, so that L and D */
  418. /* > define all the wanted eigenvalues to high relative accuracy. */
  419. /* > This means that small relative changes in the entries of D and L */
  420. /* > cause only small relative changes in the eigenvalues and */
  421. /* > eigenvectors. The standard (unfactored) representation of the */
  422. /* > tridiagonal matrix T does not have this property in general. */
  423. /* > (b) Compute the eigenvalues to suitable accuracy. */
  424. /* > If the eigenvectors are desired, the algorithm attains full */
  425. /* > accuracy of the computed eigenvalues only right before */
  426. /* > the corresponding vectors have to be computed, see steps c) and d). */
  427. /* > (c) For each cluster of close eigenvalues, select a new */
  428. /* > shift close to the cluster, find a new factorization, and refine */
  429. /* > the shifted eigenvalues to suitable accuracy. */
  430. /* > (d) For each eigenvalue with a large enough relative separation compute */
  431. /* > the corresponding eigenvector by forming a rank revealing twisted */
  432. /* > factorization. Go back to (c) for any clusters that remain. */
  433. /* > */
  434. /* > The desired accuracy of the output can be specified by the input */
  435. /* > parameter ABSTOL. */
  436. /* > */
  437. /* > For more details, see DSTEMR's documentation and: */
  438. /* > - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
  439. /* > to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
  440. /* > Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
  441. /* > - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
  442. /* > Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
  443. /* > 2004. Also LAPACK Working Note 154. */
  444. /* > - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
  445. /* > tridiagonal eigenvalue/eigenvector problem", */
  446. /* > Computer Science Division Technical Report No. UCB/CSD-97-971, */
  447. /* > UC Berkeley, May 1997. */
  448. /* > */
  449. /* > */
  450. /* > Note 1 : CHEEVR calls CSTEMR when the full spectrum is requested */
  451. /* > on machines which conform to the ieee-754 floating point standard. */
  452. /* > CHEEVR calls SSTEBZ and CSTEIN on non-ieee machines and */
  453. /* > when partial spectrum requests are made. */
  454. /* > */
  455. /* > Normal execution of CSTEMR may create NaNs and infinities and */
  456. /* > hence may abort due to a floating point exception in environments */
  457. /* > which do not handle NaNs and infinities in the ieee standard default */
  458. /* > manner. */
  459. /* > \endverbatim */
  460. /* Arguments: */
  461. /* ========== */
  462. /* > \param[in] JOBZ */
  463. /* > \verbatim */
  464. /* > JOBZ is CHARACTER*1 */
  465. /* > = 'N': Compute eigenvalues only; */
  466. /* > = 'V': Compute eigenvalues and eigenvectors. */
  467. /* > \endverbatim */
  468. /* > */
  469. /* > \param[in] RANGE */
  470. /* > \verbatim */
  471. /* > RANGE is CHARACTER*1 */
  472. /* > = 'A': all eigenvalues will be found. */
  473. /* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
  474. /* > will be found. */
  475. /* > = 'I': the IL-th through IU-th eigenvalues will be found. */
  476. /* > For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and */
  477. /* > CSTEIN are called */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[in] UPLO */
  481. /* > \verbatim */
  482. /* > UPLO is CHARACTER*1 */
  483. /* > = 'U': Upper triangle of A is stored; */
  484. /* > = 'L': Lower triangle of A is stored. */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[in] N */
  488. /* > \verbatim */
  489. /* > N is INTEGER */
  490. /* > The order of the matrix A. N >= 0. */
  491. /* > \endverbatim */
  492. /* > */
  493. /* > \param[in,out] A */
  494. /* > \verbatim */
  495. /* > A is COMPLEX array, dimension (LDA, N) */
  496. /* > On entry, the Hermitian matrix A. If UPLO = 'U', the */
  497. /* > leading N-by-N upper triangular part of A contains the */
  498. /* > upper triangular part of the matrix A. If UPLO = 'L', */
  499. /* > the leading N-by-N lower triangular part of A contains */
  500. /* > the lower triangular part of the matrix A. */
  501. /* > On exit, the lower triangle (if UPLO='L') or the upper */
  502. /* > triangle (if UPLO='U') of A, including the diagonal, is */
  503. /* > destroyed. */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[in] LDA */
  507. /* > \verbatim */
  508. /* > LDA is INTEGER */
  509. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  510. /* > \endverbatim */
  511. /* > */
  512. /* > \param[in] VL */
  513. /* > \verbatim */
  514. /* > VL is REAL */
  515. /* > If RANGE='V', the lower bound of the interval to */
  516. /* > be searched for eigenvalues. VL < VU. */
  517. /* > Not referenced if RANGE = 'A' or 'I'. */
  518. /* > \endverbatim */
  519. /* > */
  520. /* > \param[in] VU */
  521. /* > \verbatim */
  522. /* > VU is REAL */
  523. /* > If RANGE='V', the upper bound of the interval to */
  524. /* > be searched for eigenvalues. VL < VU. */
  525. /* > Not referenced if RANGE = 'A' or 'I'. */
  526. /* > \endverbatim */
  527. /* > */
  528. /* > \param[in] IL */
  529. /* > \verbatim */
  530. /* > IL is INTEGER */
  531. /* > If RANGE='I', the index of the */
  532. /* > smallest eigenvalue to be returned. */
  533. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  534. /* > Not referenced if RANGE = 'A' or 'V'. */
  535. /* > \endverbatim */
  536. /* > */
  537. /* > \param[in] IU */
  538. /* > \verbatim */
  539. /* > IU is INTEGER */
  540. /* > If RANGE='I', the index of the */
  541. /* > largest eigenvalue to be returned. */
  542. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  543. /* > Not referenced if RANGE = 'A' or 'V'. */
  544. /* > \endverbatim */
  545. /* > */
  546. /* > \param[in] ABSTOL */
  547. /* > \verbatim */
  548. /* > ABSTOL is REAL */
  549. /* > The absolute error tolerance for the eigenvalues. */
  550. /* > An approximate eigenvalue is accepted as converged */
  551. /* > when it is determined to lie in an interval [a,b] */
  552. /* > of width less than or equal to */
  553. /* > */
  554. /* > ABSTOL + EPS * f2cmax( |a|,|b| ) , */
  555. /* > */
  556. /* > where EPS is the machine precision. If ABSTOL is less than */
  557. /* > or equal to zero, then EPS*|T| will be used in its place, */
  558. /* > where |T| is the 1-norm of the tridiagonal matrix obtained */
  559. /* > by reducing A to tridiagonal form. */
  560. /* > */
  561. /* > See "Computing Small Singular Values of Bidiagonal Matrices */
  562. /* > with Guaranteed High Relative Accuracy," by Demmel and */
  563. /* > Kahan, LAPACK Working Note #3. */
  564. /* > */
  565. /* > If high relative accuracy is important, set ABSTOL to */
  566. /* > SLAMCH( 'Safe minimum' ). Doing so will guarantee that */
  567. /* > eigenvalues are computed to high relative accuracy when */
  568. /* > possible in future releases. The current code does not */
  569. /* > make any guarantees about high relative accuracy, but */
  570. /* > future releases will. See J. Barlow and J. Demmel, */
  571. /* > "Computing Accurate Eigensystems of Scaled Diagonally */
  572. /* > Dominant Matrices", LAPACK Working Note #7, for a discussion */
  573. /* > of which matrices define their eigenvalues to high relative */
  574. /* > accuracy. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[out] M */
  578. /* > \verbatim */
  579. /* > M is INTEGER */
  580. /* > The total number of eigenvalues found. 0 <= M <= N. */
  581. /* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[out] W */
  585. /* > \verbatim */
  586. /* > W is REAL array, dimension (N) */
  587. /* > The first M elements contain the selected eigenvalues in */
  588. /* > ascending order. */
  589. /* > \endverbatim */
  590. /* > */
  591. /* > \param[out] Z */
  592. /* > \verbatim */
  593. /* > Z is COMPLEX array, dimension (LDZ, f2cmax(1,M)) */
  594. /* > If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  595. /* > contain the orthonormal eigenvectors of the matrix A */
  596. /* > corresponding to the selected eigenvalues, with the i-th */
  597. /* > column of Z holding the eigenvector associated with W(i). */
  598. /* > If JOBZ = 'N', then Z is not referenced. */
  599. /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
  600. /* > supplied in the array Z; if RANGE = 'V', the exact value of M */
  601. /* > is not known in advance and an upper bound must be used. */
  602. /* > \endverbatim */
  603. /* > */
  604. /* > \param[in] LDZ */
  605. /* > \verbatim */
  606. /* > LDZ is INTEGER */
  607. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  608. /* > JOBZ = 'V', LDZ >= f2cmax(1,N). */
  609. /* > \endverbatim */
  610. /* > */
  611. /* > \param[out] ISUPPZ */
  612. /* > \verbatim */
  613. /* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
  614. /* > The support of the eigenvectors in Z, i.e., the indices */
  615. /* > indicating the nonzero elements in Z. The i-th eigenvector */
  616. /* > is nonzero only in elements ISUPPZ( 2*i-1 ) through */
  617. /* > ISUPPZ( 2*i ). This is an output of CSTEMR (tridiagonal */
  618. /* > matrix). The support of the eigenvectors of A is typically */
  619. /* > 1:N because of the unitary transformations applied by CUNMTR. */
  620. /* > Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[out] WORK */
  624. /* > \verbatim */
  625. /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
  626. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  627. /* > \endverbatim */
  628. /* > */
  629. /* > \param[in] LWORK */
  630. /* > \verbatim */
  631. /* > LWORK is INTEGER */
  632. /* > The length of the array WORK. LWORK >= f2cmax(1,2*N). */
  633. /* > For optimal efficiency, LWORK >= (NB+1)*N, */
  634. /* > where NB is the f2cmax of the blocksize for CHETRD and for */
  635. /* > CUNMTR as returned by ILAENV. */
  636. /* > */
  637. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  638. /* > only calculates the optimal sizes of the WORK, RWORK and */
  639. /* > IWORK arrays, returns these values as the first entries of */
  640. /* > the WORK, RWORK and IWORK arrays, and no error message */
  641. /* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
  642. /* > \endverbatim */
  643. /* > */
  644. /* > \param[out] RWORK */
  645. /* > \verbatim */
  646. /* > RWORK is REAL array, dimension (MAX(1,LRWORK)) */
  647. /* > On exit, if INFO = 0, RWORK(1) returns the optimal */
  648. /* > (and minimal) LRWORK. */
  649. /* > \endverbatim */
  650. /* > */
  651. /* > \param[in] LRWORK */
  652. /* > \verbatim */
  653. /* > LRWORK is INTEGER */
  654. /* > The length of the array RWORK. LRWORK >= f2cmax(1,24*N). */
  655. /* > */
  656. /* > If LRWORK = -1, then a workspace query is assumed; the */
  657. /* > routine only calculates the optimal sizes of the WORK, RWORK */
  658. /* > and IWORK arrays, returns these values as the first entries */
  659. /* > of the WORK, RWORK and IWORK arrays, and no error message */
  660. /* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
  661. /* > \endverbatim */
  662. /* > */
  663. /* > \param[out] IWORK */
  664. /* > \verbatim */
  665. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  666. /* > On exit, if INFO = 0, IWORK(1) returns the optimal */
  667. /* > (and minimal) LIWORK. */
  668. /* > \endverbatim */
  669. /* > */
  670. /* > \param[in] LIWORK */
  671. /* > \verbatim */
  672. /* > LIWORK is INTEGER */
  673. /* > The dimension of the array IWORK. LIWORK >= f2cmax(1,10*N). */
  674. /* > */
  675. /* > If LIWORK = -1, then a workspace query is assumed; the */
  676. /* > routine only calculates the optimal sizes of the WORK, RWORK */
  677. /* > and IWORK arrays, returns these values as the first entries */
  678. /* > of the WORK, RWORK and IWORK arrays, and no error message */
  679. /* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
  680. /* > \endverbatim */
  681. /* > */
  682. /* > \param[out] INFO */
  683. /* > \verbatim */
  684. /* > INFO is INTEGER */
  685. /* > = 0: successful exit */
  686. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  687. /* > > 0: Internal error */
  688. /* > \endverbatim */
  689. /* Authors: */
  690. /* ======== */
  691. /* > \author Univ. of Tennessee */
  692. /* > \author Univ. of California Berkeley */
  693. /* > \author Univ. of Colorado Denver */
  694. /* > \author NAG Ltd. */
  695. /* > \date June 2016 */
  696. /* > \ingroup complexHEeigen */
  697. /* > \par Contributors: */
  698. /* ================== */
  699. /* > */
  700. /* > Inderjit Dhillon, IBM Almaden, USA \n */
  701. /* > Osni Marques, LBNL/NERSC, USA \n */
  702. /* > Ken Stanley, Computer Science Division, University of */
  703. /* > California at Berkeley, USA \n */
  704. /* > Jason Riedy, Computer Science Division, University of */
  705. /* > California at Berkeley, USA \n */
  706. /* > */
  707. /* ===================================================================== */
  708. /* Subroutine */ int cheevr_(char *jobz, char *range, char *uplo, integer *n,
  709. complex *a, integer *lda, real *vl, real *vu, integer *il, integer *
  710. iu, real *abstol, integer *m, real *w, complex *z__, integer *ldz,
  711. integer *isuppz, complex *work, integer *lwork, real *rwork, integer *
  712. lrwork, integer *iwork, integer *liwork, integer *info)
  713. {
  714. /* System generated locals */
  715. integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
  716. real r__1, r__2;
  717. /* Local variables */
  718. real anrm;
  719. integer imax;
  720. real rmin, rmax;
  721. logical test;
  722. integer itmp1, i__, j, indrd, indre;
  723. real sigma;
  724. extern logical lsame_(char *, char *);
  725. integer iinfo;
  726. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
  727. char order[1];
  728. integer indwk;
  729. extern /* Subroutine */ int cswap_(integer *, complex *, integer *,
  730. complex *, integer *);
  731. integer lwmin;
  732. logical lower;
  733. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  734. integer *);
  735. logical wantz;
  736. integer nb, jj;
  737. logical alleig, indeig;
  738. integer iscale, ieeeok, indibl, indrdd, indifl, indree;
  739. logical valeig;
  740. extern real slamch_(char *);
  741. extern /* Subroutine */ int chetrd_(char *, integer *, complex *, integer
  742. *, real *, real *, complex *, complex *, integer *, integer *), csscal_(integer *, real *, complex *, integer *);
  743. real safmin;
  744. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  745. integer *, integer *, ftnlen, ftnlen);
  746. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  747. real abstll, bignum;
  748. integer indtau, indisp;
  749. extern /* Subroutine */ int cstein_(integer *, real *, real *, integer *,
  750. real *, integer *, integer *, complex *, integer *, real *,
  751. integer *, integer *, integer *);
  752. integer indiwo, indwkn;
  753. extern real clansy_(char *, char *, integer *, complex *, integer *, real
  754. *);
  755. extern /* Subroutine */ int cstemr_(char *, char *, integer *, real *,
  756. real *, real *, real *, integer *, integer *, integer *, real *,
  757. complex *, integer *, integer *, integer *, logical *, real *,
  758. integer *, integer *, integer *, integer *);
  759. integer indrwk, liwmin;
  760. logical tryrac;
  761. extern /* Subroutine */ int ssterf_(integer *, real *, real *, integer *);
  762. integer lrwmin, llwrkn, llwork, nsplit;
  763. real smlnum;
  764. extern /* Subroutine */ int cunmtr_(char *, char *, char *, integer *,
  765. integer *, complex *, integer *, complex *, complex *, integer *,
  766. complex *, integer *, integer *), sstebz_(
  767. char *, char *, integer *, real *, real *, integer *, integer *,
  768. real *, real *, real *, integer *, integer *, real *, integer *,
  769. integer *, real *, integer *, integer *);
  770. logical lquery;
  771. integer lwkopt;
  772. real eps, vll, vuu;
  773. integer llrwork;
  774. real tmp1;
  775. /* -- LAPACK driver routine (version 3.7.0) -- */
  776. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  777. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  778. /* June 2016 */
  779. /* ===================================================================== */
  780. /* Test the input parameters. */
  781. /* Parameter adjustments */
  782. a_dim1 = *lda;
  783. a_offset = 1 + a_dim1 * 1;
  784. a -= a_offset;
  785. --w;
  786. z_dim1 = *ldz;
  787. z_offset = 1 + z_dim1 * 1;
  788. z__ -= z_offset;
  789. --isuppz;
  790. --work;
  791. --rwork;
  792. --iwork;
  793. /* Function Body */
  794. ieeeok = ilaenv_(&c__10, "CHEEVR", "N", &c__1, &c__2, &c__3, &c__4, (
  795. ftnlen)6, (ftnlen)1);
  796. lower = lsame_(uplo, "L");
  797. wantz = lsame_(jobz, "V");
  798. alleig = lsame_(range, "A");
  799. valeig = lsame_(range, "V");
  800. indeig = lsame_(range, "I");
  801. lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
  802. /* Computing MAX */
  803. i__1 = 1, i__2 = *n * 24;
  804. lrwmin = f2cmax(i__1,i__2);
  805. /* Computing MAX */
  806. i__1 = 1, i__2 = *n * 10;
  807. liwmin = f2cmax(i__1,i__2);
  808. /* Computing MAX */
  809. i__1 = 1, i__2 = *n << 1;
  810. lwmin = f2cmax(i__1,i__2);
  811. *info = 0;
  812. if (! (wantz || lsame_(jobz, "N"))) {
  813. *info = -1;
  814. } else if (! (alleig || valeig || indeig)) {
  815. *info = -2;
  816. } else if (! (lower || lsame_(uplo, "U"))) {
  817. *info = -3;
  818. } else if (*n < 0) {
  819. *info = -4;
  820. } else if (*lda < f2cmax(1,*n)) {
  821. *info = -6;
  822. } else {
  823. if (valeig) {
  824. if (*n > 0 && *vu <= *vl) {
  825. *info = -8;
  826. }
  827. } else if (indeig) {
  828. if (*il < 1 || *il > f2cmax(1,*n)) {
  829. *info = -9;
  830. } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
  831. *info = -10;
  832. }
  833. }
  834. }
  835. if (*info == 0) {
  836. if (*ldz < 1 || wantz && *ldz < *n) {
  837. *info = -15;
  838. }
  839. }
  840. if (*info == 0) {
  841. nb = ilaenv_(&c__1, "CHETRD", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6,
  842. (ftnlen)1);
  843. /* Computing MAX */
  844. i__1 = nb, i__2 = ilaenv_(&c__1, "CUNMTR", uplo, n, &c_n1, &c_n1, &
  845. c_n1, (ftnlen)6, (ftnlen)1);
  846. nb = f2cmax(i__1,i__2);
  847. /* Computing MAX */
  848. i__1 = (nb + 1) * *n;
  849. lwkopt = f2cmax(i__1,lwmin);
  850. work[1].r = (real) lwkopt, work[1].i = 0.f;
  851. rwork[1] = (real) lrwmin;
  852. iwork[1] = liwmin;
  853. if (*lwork < lwmin && ! lquery) {
  854. *info = -18;
  855. } else if (*lrwork < lrwmin && ! lquery) {
  856. *info = -20;
  857. } else if (*liwork < liwmin && ! lquery) {
  858. *info = -22;
  859. }
  860. }
  861. if (*info != 0) {
  862. i__1 = -(*info);
  863. xerbla_("CHEEVR", &i__1, (ftnlen)6);
  864. return 0;
  865. } else if (lquery) {
  866. return 0;
  867. }
  868. /* Quick return if possible */
  869. *m = 0;
  870. if (*n == 0) {
  871. work[1].r = 1.f, work[1].i = 0.f;
  872. return 0;
  873. }
  874. if (*n == 1) {
  875. work[1].r = 2.f, work[1].i = 0.f;
  876. if (alleig || indeig) {
  877. *m = 1;
  878. i__1 = a_dim1 + 1;
  879. w[1] = a[i__1].r;
  880. } else {
  881. i__1 = a_dim1 + 1;
  882. i__2 = a_dim1 + 1;
  883. if (*vl < a[i__1].r && *vu >= a[i__2].r) {
  884. *m = 1;
  885. i__1 = a_dim1 + 1;
  886. w[1] = a[i__1].r;
  887. }
  888. }
  889. if (wantz) {
  890. i__1 = z_dim1 + 1;
  891. z__[i__1].r = 1.f, z__[i__1].i = 0.f;
  892. isuppz[1] = 1;
  893. isuppz[2] = 1;
  894. }
  895. return 0;
  896. }
  897. /* Get machine constants. */
  898. safmin = slamch_("Safe minimum");
  899. eps = slamch_("Precision");
  900. smlnum = safmin / eps;
  901. bignum = 1.f / smlnum;
  902. rmin = sqrt(smlnum);
  903. /* Computing MIN */
  904. r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
  905. rmax = f2cmin(r__1,r__2);
  906. /* Scale matrix to allowable range, if necessary. */
  907. iscale = 0;
  908. abstll = *abstol;
  909. if (valeig) {
  910. vll = *vl;
  911. vuu = *vu;
  912. }
  913. anrm = clansy_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
  914. if (anrm > 0.f && anrm < rmin) {
  915. iscale = 1;
  916. sigma = rmin / anrm;
  917. } else if (anrm > rmax) {
  918. iscale = 1;
  919. sigma = rmax / anrm;
  920. }
  921. if (iscale == 1) {
  922. if (lower) {
  923. i__1 = *n;
  924. for (j = 1; j <= i__1; ++j) {
  925. i__2 = *n - j + 1;
  926. csscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
  927. /* L10: */
  928. }
  929. } else {
  930. i__1 = *n;
  931. for (j = 1; j <= i__1; ++j) {
  932. csscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
  933. /* L20: */
  934. }
  935. }
  936. if (*abstol > 0.f) {
  937. abstll = *abstol * sigma;
  938. }
  939. if (valeig) {
  940. vll = *vl * sigma;
  941. vuu = *vu * sigma;
  942. }
  943. }
  944. /* Initialize indices into workspaces. Note: The IWORK indices are */
  945. /* used only if SSTERF or CSTEMR fail. */
  946. /* WORK(INDTAU:INDTAU+N-1) stores the complex scalar factors of the */
  947. /* elementary reflectors used in CHETRD. */
  948. indtau = 1;
  949. /* INDWK is the starting offset of the remaining complex workspace, */
  950. /* and LLWORK is the remaining complex workspace size. */
  951. indwk = indtau + *n;
  952. llwork = *lwork - indwk + 1;
  953. /* RWORK(INDRD:INDRD+N-1) stores the real tridiagonal's diagonal */
  954. /* entries. */
  955. indrd = 1;
  956. /* RWORK(INDRE:INDRE+N-1) stores the off-diagonal entries of the */
  957. /* tridiagonal matrix from CHETRD. */
  958. indre = indrd + *n;
  959. /* RWORK(INDRDD:INDRDD+N-1) is a copy of the diagonal entries over */
  960. /* -written by CSTEMR (the SSTERF path copies the diagonal to W). */
  961. indrdd = indre + *n;
  962. /* RWORK(INDREE:INDREE+N-1) is a copy of the off-diagonal entries over */
  963. /* -written while computing the eigenvalues in SSTERF and CSTEMR. */
  964. indree = indrdd + *n;
  965. /* INDRWK is the starting offset of the left-over real workspace, and */
  966. /* LLRWORK is the remaining workspace size. */
  967. indrwk = indree + *n;
  968. llrwork = *lrwork - indrwk + 1;
  969. /* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and */
  970. /* stores the block indices of each of the M<=N eigenvalues. */
  971. indibl = 1;
  972. /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and */
  973. /* stores the starting and finishing indices of each block. */
  974. indisp = indibl + *n;
  975. /* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
  976. /* that corresponding to eigenvectors that fail to converge in */
  977. /* SSTEIN. This information is discarded; if any fail, the driver */
  978. /* returns INFO > 0. */
  979. indifl = indisp + *n;
  980. /* INDIWO is the offset of the remaining integer workspace. */
  981. indiwo = indifl + *n;
  982. /* Call CHETRD to reduce Hermitian matrix to tridiagonal form. */
  983. chetrd_(uplo, n, &a[a_offset], lda, &rwork[indrd], &rwork[indre], &work[
  984. indtau], &work[indwk], &llwork, &iinfo);
  985. /* If all eigenvalues are desired */
  986. /* then call SSTERF or CSTEMR and CUNMTR. */
  987. test = FALSE_;
  988. if (indeig) {
  989. if (*il == 1 && *iu == *n) {
  990. test = TRUE_;
  991. }
  992. }
  993. if ((alleig || test) && ieeeok == 1) {
  994. if (! wantz) {
  995. scopy_(n, &rwork[indrd], &c__1, &w[1], &c__1);
  996. i__1 = *n - 1;
  997. scopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
  998. ssterf_(n, &w[1], &rwork[indree], info);
  999. } else {
  1000. i__1 = *n - 1;
  1001. scopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
  1002. scopy_(n, &rwork[indrd], &c__1, &rwork[indrdd], &c__1);
  1003. if (*abstol <= *n * 2.f * eps) {
  1004. tryrac = TRUE_;
  1005. } else {
  1006. tryrac = FALSE_;
  1007. }
  1008. cstemr_(jobz, "A", n, &rwork[indrdd], &rwork[indree], vl, vu, il,
  1009. iu, m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac,
  1010. &rwork[indrwk], &llrwork, &iwork[1], liwork, info);
  1011. /* Apply unitary matrix used in reduction to tridiagonal */
  1012. /* form to eigenvectors returned by CSTEMR. */
  1013. if (wantz && *info == 0) {
  1014. indwkn = indwk;
  1015. llwrkn = *lwork - indwkn + 1;
  1016. cunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau]
  1017. , &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
  1018. }
  1019. }
  1020. if (*info == 0) {
  1021. *m = *n;
  1022. goto L30;
  1023. }
  1024. *info = 0;
  1025. }
  1026. /* Otherwise, call SSTEBZ and, if eigenvectors are desired, CSTEIN. */
  1027. /* Also call SSTEBZ and CSTEIN if CSTEMR fails. */
  1028. if (wantz) {
  1029. *(unsigned char *)order = 'B';
  1030. } else {
  1031. *(unsigned char *)order = 'E';
  1032. }
  1033. sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indrd], &
  1034. rwork[indre], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
  1035. rwork[indrwk], &iwork[indiwo], info);
  1036. if (wantz) {
  1037. cstein_(n, &rwork[indrd], &rwork[indre], m, &w[1], &iwork[indibl], &
  1038. iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
  1039. indiwo], &iwork[indifl], info);
  1040. /* Apply unitary matrix used in reduction to tridiagonal */
  1041. /* form to eigenvectors returned by CSTEIN. */
  1042. indwkn = indwk;
  1043. llwrkn = *lwork - indwkn + 1;
  1044. cunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
  1045. z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
  1046. }
  1047. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  1048. L30:
  1049. if (iscale == 1) {
  1050. if (*info == 0) {
  1051. imax = *m;
  1052. } else {
  1053. imax = *info - 1;
  1054. }
  1055. r__1 = 1.f / sigma;
  1056. sscal_(&imax, &r__1, &w[1], &c__1);
  1057. }
  1058. /* If eigenvalues are not in order, then sort them, along with */
  1059. /* eigenvectors. */
  1060. if (wantz) {
  1061. i__1 = *m - 1;
  1062. for (j = 1; j <= i__1; ++j) {
  1063. i__ = 0;
  1064. tmp1 = w[j];
  1065. i__2 = *m;
  1066. for (jj = j + 1; jj <= i__2; ++jj) {
  1067. if (w[jj] < tmp1) {
  1068. i__ = jj;
  1069. tmp1 = w[jj];
  1070. }
  1071. /* L40: */
  1072. }
  1073. if (i__ != 0) {
  1074. itmp1 = iwork[indibl + i__ - 1];
  1075. w[i__] = w[j];
  1076. iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
  1077. w[j] = tmp1;
  1078. iwork[indibl + j - 1] = itmp1;
  1079. cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  1080. &c__1);
  1081. }
  1082. /* L50: */
  1083. }
  1084. }
  1085. /* Set WORK(1) to optimal workspace size. */
  1086. work[1].r = (real) lwkopt, work[1].i = 0.f;
  1087. rwork[1] = (real) lrwmin;
  1088. iwork[1] = liwmin;
  1089. return 0;
  1090. /* End of CHEEVR */
  1091. } /* cheevr_ */