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.

slarrd.c 43 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__1 = 1;
  485. static integer c_n1 = -1;
  486. static integer c__3 = 3;
  487. static integer c__2 = 2;
  488. static integer c__0 = 0;
  489. /* > \brief \b SLARRD computes the eigenvalues of a symmetric tridiagonal matrix to suitable accuracy. */
  490. /* =========== DOCUMENTATION =========== */
  491. /* Online html documentation available at */
  492. /* http://www.netlib.org/lapack/explore-html/ */
  493. /* > \htmlonly */
  494. /* > Download SLARRD + dependencies */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarrd.
  496. f"> */
  497. /* > [TGZ]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarrd.
  499. f"> */
  500. /* > [ZIP]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarrd.
  502. f"> */
  503. /* > [TXT]</a> */
  504. /* > \endhtmlonly */
  505. /* Definition: */
  506. /* =========== */
  507. /* SUBROUTINE SLARRD( RANGE, ORDER, N, VL, VU, IL, IU, GERS, */
  508. /* RELTOL, D, E, E2, PIVMIN, NSPLIT, ISPLIT, */
  509. /* M, W, WERR, WL, WU, IBLOCK, INDEXW, */
  510. /* WORK, IWORK, INFO ) */
  511. /* CHARACTER ORDER, RANGE */
  512. /* INTEGER IL, INFO, IU, M, N, NSPLIT */
  513. /* REAL PIVMIN, RELTOL, VL, VU, WL, WU */
  514. /* INTEGER IBLOCK( * ), INDEXW( * ), */
  515. /* $ ISPLIT( * ), IWORK( * ) */
  516. /* REAL D( * ), E( * ), E2( * ), */
  517. /* $ GERS( * ), W( * ), WERR( * ), WORK( * ) */
  518. /* > \par Purpose: */
  519. /* ============= */
  520. /* > */
  521. /* > \verbatim */
  522. /* > */
  523. /* > SLARRD computes the eigenvalues of a symmetric tridiagonal */
  524. /* > matrix T to suitable accuracy. This is an auxiliary code to be */
  525. /* > called from SSTEMR. */
  526. /* > The user may ask for all eigenvalues, all eigenvalues */
  527. /* > in the half-open interval (VL, VU], or the IL-th through IU-th */
  528. /* > eigenvalues. */
  529. /* > */
  530. /* > To avoid overflow, the matrix must be scaled so that its */
  531. /* > largest element is no greater than overflow**(1/2) * underflow**(1/4) in absolute value, and for greatest
  532. */
  533. /* > accuracy, it should not be much smaller than that. */
  534. /* > */
  535. /* > See W. Kahan "Accurate Eigenvalues of a Symmetric Tridiagonal */
  536. /* > Matrix", Report CS41, Computer Science Dept., Stanford */
  537. /* > University, July 21, 1966. */
  538. /* > \endverbatim */
  539. /* Arguments: */
  540. /* ========== */
  541. /* > \param[in] RANGE */
  542. /* > \verbatim */
  543. /* > RANGE is CHARACTER*1 */
  544. /* > = 'A': ("All") all eigenvalues will be found. */
  545. /* > = 'V': ("Value") all eigenvalues in the half-open interval */
  546. /* > (VL, VU] will be found. */
  547. /* > = 'I': ("Index") the IL-th through IU-th eigenvalues (of the */
  548. /* > entire matrix) will be found. */
  549. /* > \endverbatim */
  550. /* > */
  551. /* > \param[in] ORDER */
  552. /* > \verbatim */
  553. /* > ORDER is CHARACTER*1 */
  554. /* > = 'B': ("By Block") the eigenvalues will be grouped by */
  555. /* > split-off block (see IBLOCK, ISPLIT) and */
  556. /* > ordered from smallest to largest within */
  557. /* > the block. */
  558. /* > = 'E': ("Entire matrix") */
  559. /* > the eigenvalues for the entire matrix */
  560. /* > will be ordered from smallest to */
  561. /* > largest. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[in] N */
  565. /* > \verbatim */
  566. /* > N is INTEGER */
  567. /* > The order of the tridiagonal matrix T. N >= 0. */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in] VL */
  571. /* > \verbatim */
  572. /* > VL is REAL */
  573. /* > If RANGE='V', the lower bound of the interval to */
  574. /* > be searched for eigenvalues. Eigenvalues less than or equal */
  575. /* > to VL, or greater than VU, will not be returned. VL < VU. */
  576. /* > Not referenced if RANGE = 'A' or 'I'. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[in] VU */
  580. /* > \verbatim */
  581. /* > VU is REAL */
  582. /* > If RANGE='V', the upper bound of the interval to */
  583. /* > be searched for eigenvalues. Eigenvalues less than or equal */
  584. /* > to VL, or greater than VU, will not be returned. VL < VU. */
  585. /* > Not referenced if RANGE = 'A' or 'I'. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] IL */
  589. /* > \verbatim */
  590. /* > IL is INTEGER */
  591. /* > If RANGE='I', the index of the */
  592. /* > smallest eigenvalue to be returned. */
  593. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  594. /* > Not referenced if RANGE = 'A' or 'V'. */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[in] IU */
  598. /* > \verbatim */
  599. /* > IU is INTEGER */
  600. /* > If RANGE='I', the index of the */
  601. /* > largest eigenvalue to be returned. */
  602. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  603. /* > Not referenced if RANGE = 'A' or 'V'. */
  604. /* > \endverbatim */
  605. /* > */
  606. /* > \param[in] GERS */
  607. /* > \verbatim */
  608. /* > GERS is REAL array, dimension (2*N) */
  609. /* > The N Gerschgorin intervals (the i-th Gerschgorin interval */
  610. /* > is (GERS(2*i-1), GERS(2*i)). */
  611. /* > \endverbatim */
  612. /* > */
  613. /* > \param[in] RELTOL */
  614. /* > \verbatim */
  615. /* > RELTOL is REAL */
  616. /* > The minimum relative width of an interval. When an interval */
  617. /* > is narrower than RELTOL times the larger (in */
  618. /* > magnitude) endpoint, then it is considered to be */
  619. /* > sufficiently small, i.e., converged. Note: this should */
  620. /* > always be at least radix*machine epsilon. */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[in] D */
  624. /* > \verbatim */
  625. /* > D is REAL array, dimension (N) */
  626. /* > The n diagonal elements of the tridiagonal matrix T. */
  627. /* > \endverbatim */
  628. /* > */
  629. /* > \param[in] E */
  630. /* > \verbatim */
  631. /* > E is REAL array, dimension (N-1) */
  632. /* > The (n-1) off-diagonal elements of the tridiagonal matrix T. */
  633. /* > \endverbatim */
  634. /* > */
  635. /* > \param[in] E2 */
  636. /* > \verbatim */
  637. /* > E2 is REAL array, dimension (N-1) */
  638. /* > The (n-1) squared off-diagonal elements of the tridiagonal matrix T. */
  639. /* > \endverbatim */
  640. /* > */
  641. /* > \param[in] PIVMIN */
  642. /* > \verbatim */
  643. /* > PIVMIN is REAL */
  644. /* > The minimum pivot allowed in the Sturm sequence for T. */
  645. /* > \endverbatim */
  646. /* > */
  647. /* > \param[in] NSPLIT */
  648. /* > \verbatim */
  649. /* > NSPLIT is INTEGER */
  650. /* > The number of diagonal blocks in the matrix T. */
  651. /* > 1 <= NSPLIT <= N. */
  652. /* > \endverbatim */
  653. /* > */
  654. /* > \param[in] ISPLIT */
  655. /* > \verbatim */
  656. /* > ISPLIT is INTEGER array, dimension (N) */
  657. /* > The splitting points, at which T breaks up into submatrices. */
  658. /* > The first submatrix consists of rows/columns 1 to ISPLIT(1), */
  659. /* > the second of rows/columns ISPLIT(1)+1 through ISPLIT(2), */
  660. /* > etc., and the NSPLIT-th consists of rows/columns */
  661. /* > ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N. */
  662. /* > (Only the first NSPLIT elements will actually be used, but */
  663. /* > since the user cannot know a priori what value NSPLIT will */
  664. /* > have, N words must be reserved for ISPLIT.) */
  665. /* > \endverbatim */
  666. /* > */
  667. /* > \param[out] M */
  668. /* > \verbatim */
  669. /* > M is INTEGER */
  670. /* > The actual number of eigenvalues found. 0 <= M <= N. */
  671. /* > (See also the description of INFO=2,3.) */
  672. /* > \endverbatim */
  673. /* > */
  674. /* > \param[out] W */
  675. /* > \verbatim */
  676. /* > W is REAL array, dimension (N) */
  677. /* > On exit, the first M elements of W will contain the */
  678. /* > eigenvalue approximations. SLARRD computes an interval */
  679. /* > I_j = (a_j, b_j] that includes eigenvalue j. The eigenvalue */
  680. /* > approximation is given as the interval midpoint */
  681. /* > W(j)= ( a_j + b_j)/2. The corresponding error is bounded by */
  682. /* > WERR(j) = abs( a_j - b_j)/2 */
  683. /* > \endverbatim */
  684. /* > */
  685. /* > \param[out] WERR */
  686. /* > \verbatim */
  687. /* > WERR is REAL array, dimension (N) */
  688. /* > The error bound on the corresponding eigenvalue approximation */
  689. /* > in W. */
  690. /* > \endverbatim */
  691. /* > */
  692. /* > \param[out] WL */
  693. /* > \verbatim */
  694. /* > WL is REAL */
  695. /* > \endverbatim */
  696. /* > */
  697. /* > \param[out] WU */
  698. /* > \verbatim */
  699. /* > WU is REAL */
  700. /* > The interval (WL, WU] contains all the wanted eigenvalues. */
  701. /* > If RANGE='V', then WL=VL and WU=VU. */
  702. /* > If RANGE='A', then WL and WU are the global Gerschgorin bounds */
  703. /* > on the spectrum. */
  704. /* > If RANGE='I', then WL and WU are computed by SLAEBZ from the */
  705. /* > index range specified. */
  706. /* > \endverbatim */
  707. /* > */
  708. /* > \param[out] IBLOCK */
  709. /* > \verbatim */
  710. /* > IBLOCK is INTEGER array, dimension (N) */
  711. /* > At each row/column j where E(j) is zero or small, the */
  712. /* > matrix T is considered to split into a block diagonal */
  713. /* > matrix. On exit, if INFO = 0, IBLOCK(i) specifies to which */
  714. /* > block (from 1 to the number of blocks) the eigenvalue W(i) */
  715. /* > belongs. (SLARRD may use the remaining N-M elements as */
  716. /* > workspace.) */
  717. /* > \endverbatim */
  718. /* > */
  719. /* > \param[out] INDEXW */
  720. /* > \verbatim */
  721. /* > INDEXW is INTEGER array, dimension (N) */
  722. /* > The indices of the eigenvalues within each block (submatrix); */
  723. /* > for example, INDEXW(i)= j and IBLOCK(i)=k imply that the */
  724. /* > i-th eigenvalue W(i) is the j-th eigenvalue in block k. */
  725. /* > \endverbatim */
  726. /* > */
  727. /* > \param[out] WORK */
  728. /* > \verbatim */
  729. /* > WORK is REAL array, dimension (4*N) */
  730. /* > \endverbatim */
  731. /* > */
  732. /* > \param[out] IWORK */
  733. /* > \verbatim */
  734. /* > IWORK is INTEGER array, dimension (3*N) */
  735. /* > \endverbatim */
  736. /* > */
  737. /* > \param[out] INFO */
  738. /* > \verbatim */
  739. /* > INFO is INTEGER */
  740. /* > = 0: successful exit */
  741. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  742. /* > > 0: some or all of the eigenvalues failed to converge or */
  743. /* > were not computed: */
  744. /* > =1 or 3: Bisection failed to converge for some */
  745. /* > eigenvalues; these eigenvalues are flagged by a */
  746. /* > negative block number. The effect is that the */
  747. /* > eigenvalues may not be as accurate as the */
  748. /* > absolute and relative tolerances. This is */
  749. /* > generally caused by unexpectedly inaccurate */
  750. /* > arithmetic. */
  751. /* > =2 or 3: RANGE='I' only: Not all of the eigenvalues */
  752. /* > IL:IU were found. */
  753. /* > Effect: M < IU+1-IL */
  754. /* > Cause: non-monotonic arithmetic, causing the */
  755. /* > Sturm sequence to be non-monotonic. */
  756. /* > Cure: recalculate, using RANGE='A', and pick */
  757. /* > out eigenvalues IL:IU. In some cases, */
  758. /* > increasing the PARAMETER "FUDGE" may */
  759. /* > make things work. */
  760. /* > = 4: RANGE='I', and the Gershgorin interval */
  761. /* > initially used was too small. No eigenvalues */
  762. /* > were computed. */
  763. /* > Probable cause: your machine has sloppy */
  764. /* > floating-point arithmetic. */
  765. /* > Cure: Increase the PARAMETER "FUDGE", */
  766. /* > recompile, and try again. */
  767. /* > \endverbatim */
  768. /* > \par Internal Parameters: */
  769. /* ========================= */
  770. /* > */
  771. /* > \verbatim */
  772. /* > FUDGE REAL, default = 2 */
  773. /* > A "fudge factor" to widen the Gershgorin intervals. Ideally, */
  774. /* > a value of 1 should work, but on machines with sloppy */
  775. /* > arithmetic, this needs to be larger. The default for */
  776. /* > publicly released versions should be large enough to handle */
  777. /* > the worst machine around. Note that this has no effect */
  778. /* > on accuracy of the solution. */
  779. /* > \endverbatim */
  780. /* > */
  781. /* > \par Contributors: */
  782. /* ================== */
  783. /* > */
  784. /* > W. Kahan, University of California, Berkeley, USA \n */
  785. /* > Beresford Parlett, University of California, Berkeley, USA \n */
  786. /* > Jim Demmel, University of California, Berkeley, USA \n */
  787. /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
  788. /* > Osni Marques, LBNL/NERSC, USA \n */
  789. /* > Christof Voemel, University of California, Berkeley, USA \n */
  790. /* Authors: */
  791. /* ======== */
  792. /* > \author Univ. of Tennessee */
  793. /* > \author Univ. of California Berkeley */
  794. /* > \author Univ. of Colorado Denver */
  795. /* > \author NAG Ltd. */
  796. /* > \date June 2016 */
  797. /* > \ingroup OTHERauxiliary */
  798. /* ===================================================================== */
  799. /* Subroutine */ void slarrd_(char *range, char *order, integer *n, real *vl,
  800. real *vu, integer *il, integer *iu, real *gers, real *reltol, real *
  801. d__, real *e, real *e2, real *pivmin, integer *nsplit, integer *
  802. isplit, integer *m, real *w, real *werr, real *wl, real *wu, integer *
  803. iblock, integer *indexw, real *work, integer *iwork, integer *info)
  804. {
  805. /* System generated locals */
  806. integer i__1, i__2, i__3;
  807. real r__1, r__2;
  808. /* Local variables */
  809. integer iend, jblk, ioff, iout, itmp1, itmp2, i__, j, jdisc;
  810. extern logical lsame_(char *, char *);
  811. integer iinfo;
  812. real atoli;
  813. integer iwoff, itmax;
  814. real wkill, rtoli, uflow, tnorm;
  815. integer ib, ie, je, nb;
  816. real gl;
  817. integer im, in;
  818. real gu;
  819. integer ibegin, iw, irange, idiscl;
  820. extern real slamch_(char *);
  821. integer idumma[1];
  822. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  823. integer *, integer *, ftnlen, ftnlen);
  824. integer idiscu;
  825. extern /* Subroutine */ void slaebz_(integer *, integer *, integer *,
  826. integer *, integer *, integer *, real *, real *, real *, real *,
  827. real *, real *, integer *, real *, real *, integer *, integer *,
  828. real *, integer *, integer *);
  829. logical ncnvrg, toofew;
  830. integer jee;
  831. real eps;
  832. integer nwl;
  833. real wlu, wul;
  834. integer nwu;
  835. real tmp1, tmp2;
  836. /* -- LAPACK auxiliary routine (version 3.7.1) -- */
  837. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  838. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  839. /* June 2016 */
  840. /* ===================================================================== */
  841. /* Parameter adjustments */
  842. --iwork;
  843. --work;
  844. --indexw;
  845. --iblock;
  846. --werr;
  847. --w;
  848. --isplit;
  849. --e2;
  850. --e;
  851. --d__;
  852. --gers;
  853. /* Function Body */
  854. *info = 0;
  855. /* Quick return if possible */
  856. if (*n <= 0) {
  857. return;
  858. }
  859. /* Decode RANGE */
  860. if (lsame_(range, "A")) {
  861. irange = 1;
  862. } else if (lsame_(range, "V")) {
  863. irange = 2;
  864. } else if (lsame_(range, "I")) {
  865. irange = 3;
  866. } else {
  867. irange = 0;
  868. }
  869. /* Check for Errors */
  870. if (irange <= 0) {
  871. *info = -1;
  872. } else if (! (lsame_(order, "B") || lsame_(order,
  873. "E"))) {
  874. *info = -2;
  875. } else if (*n < 0) {
  876. *info = -3;
  877. } else if (irange == 2) {
  878. if (*vl >= *vu) {
  879. *info = -5;
  880. }
  881. } else if (irange == 3 && (*il < 1 || *il > f2cmax(1,*n))) {
  882. *info = -6;
  883. } else if (irange == 3 && (*iu < f2cmin(*n,*il) || *iu > *n)) {
  884. *info = -7;
  885. }
  886. if (*info != 0) {
  887. return;
  888. }
  889. /* Initialize error flags */
  890. *info = 0;
  891. ncnvrg = FALSE_;
  892. toofew = FALSE_;
  893. /* Quick return if possible */
  894. *m = 0;
  895. if (*n == 0) {
  896. return;
  897. }
  898. /* Simplification: */
  899. if (irange == 3 && *il == 1 && *iu == *n) {
  900. irange = 1;
  901. }
  902. /* Get machine constants */
  903. eps = slamch_("P");
  904. uflow = slamch_("U");
  905. /* Special Case when N=1 */
  906. /* Treat case of 1x1 matrix for quick return */
  907. if (*n == 1) {
  908. if (irange == 1 || irange == 2 && d__[1] > *vl && d__[1] <= *vu ||
  909. irange == 3 && *il == 1 && *iu == 1) {
  910. *m = 1;
  911. w[1] = d__[1];
  912. /* The computation error of the eigenvalue is zero */
  913. werr[1] = 0.f;
  914. iblock[1] = 1;
  915. indexw[1] = 1;
  916. }
  917. return;
  918. }
  919. /* NB is the minimum vector length for vector bisection, or 0 */
  920. /* if only scalar is to be done. */
  921. nb = ilaenv_(&c__1, "SSTEBZ", " ", n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
  922. ftnlen)1);
  923. if (nb <= 1) {
  924. nb = 0;
  925. }
  926. /* Find global spectral radius */
  927. gl = d__[1];
  928. gu = d__[1];
  929. i__1 = *n;
  930. for (i__ = 1; i__ <= i__1; ++i__) {
  931. /* Computing MIN */
  932. r__1 = gl, r__2 = gers[(i__ << 1) - 1];
  933. gl = f2cmin(r__1,r__2);
  934. /* Computing MAX */
  935. r__1 = gu, r__2 = gers[i__ * 2];
  936. gu = f2cmax(r__1,r__2);
  937. /* L5: */
  938. }
  939. /* Compute global Gerschgorin bounds and spectral diameter */
  940. /* Computing MAX */
  941. r__1 = abs(gl), r__2 = abs(gu);
  942. tnorm = f2cmax(r__1,r__2);
  943. gl = gl - tnorm * 2.f * eps * *n - *pivmin * 4.f;
  944. gu = gu + tnorm * 2.f * eps * *n + *pivmin * 4.f;
  945. /* [JAN/28/2009] remove the line below since SPDIAM variable not use */
  946. /* SPDIAM = GU - GL */
  947. /* Input arguments for SLAEBZ: */
  948. /* The relative tolerance. An interval (a,b] lies within */
  949. /* "relative tolerance" if b-a < RELTOL*f2cmax(|a|,|b|), */
  950. rtoli = *reltol;
  951. /* Set the absolute tolerance for interval convergence to zero to force */
  952. /* interval convergence based on relative size of the interval. */
  953. /* This is dangerous because intervals might not converge when RELTOL is */
  954. /* small. But at least a very small number should be selected so that for */
  955. /* strongly graded matrices, the code can get relatively accurate */
  956. /* eigenvalues. */
  957. atoli = uflow * 4.f + *pivmin * 4.f;
  958. if (irange == 3) {
  959. /* RANGE='I': Compute an interval containing eigenvalues */
  960. /* IL through IU. The initial interval [GL,GU] from the global */
  961. /* Gerschgorin bounds GL and GU is refined by SLAEBZ. */
  962. itmax = (integer) ((log(tnorm + *pivmin) - log(*pivmin)) / log(2.f))
  963. + 2;
  964. work[*n + 1] = gl;
  965. work[*n + 2] = gl;
  966. work[*n + 3] = gu;
  967. work[*n + 4] = gu;
  968. work[*n + 5] = gl;
  969. work[*n + 6] = gu;
  970. iwork[1] = -1;
  971. iwork[2] = -1;
  972. iwork[3] = *n + 1;
  973. iwork[4] = *n + 1;
  974. iwork[5] = *il - 1;
  975. iwork[6] = *iu;
  976. slaebz_(&c__3, &itmax, n, &c__2, &c__2, &nb, &atoli, &rtoli, pivmin, &
  977. d__[1], &e[1], &e2[1], &iwork[5], &work[*n + 1], &work[*n + 5]
  978. , &iout, &iwork[1], &w[1], &iblock[1], &iinfo);
  979. if (iinfo != 0) {
  980. *info = iinfo;
  981. return;
  982. }
  983. /* On exit, output intervals may not be ordered by ascending negcount */
  984. if (iwork[6] == *iu) {
  985. *wl = work[*n + 1];
  986. wlu = work[*n + 3];
  987. nwl = iwork[1];
  988. *wu = work[*n + 4];
  989. wul = work[*n + 2];
  990. nwu = iwork[4];
  991. } else {
  992. *wl = work[*n + 2];
  993. wlu = work[*n + 4];
  994. nwl = iwork[2];
  995. *wu = work[*n + 3];
  996. wul = work[*n + 1];
  997. nwu = iwork[3];
  998. }
  999. /* On exit, the interval [WL, WLU] contains a value with negcount NWL, */
  1000. /* and [WUL, WU] contains a value with negcount NWU. */
  1001. if (nwl < 0 || nwl >= *n || nwu < 1 || nwu > *n) {
  1002. *info = 4;
  1003. return;
  1004. }
  1005. } else if (irange == 2) {
  1006. *wl = *vl;
  1007. *wu = *vu;
  1008. } else if (irange == 1) {
  1009. *wl = gl;
  1010. *wu = gu;
  1011. }
  1012. /* Find Eigenvalues -- Loop Over blocks and recompute NWL and NWU. */
  1013. /* NWL accumulates the number of eigenvalues .le. WL, */
  1014. /* NWU accumulates the number of eigenvalues .le. WU */
  1015. *m = 0;
  1016. iend = 0;
  1017. *info = 0;
  1018. nwl = 0;
  1019. nwu = 0;
  1020. i__1 = *nsplit;
  1021. for (jblk = 1; jblk <= i__1; ++jblk) {
  1022. ioff = iend;
  1023. ibegin = ioff + 1;
  1024. iend = isplit[jblk];
  1025. in = iend - ioff;
  1026. if (in == 1) {
  1027. /* 1x1 block */
  1028. if (*wl >= d__[ibegin] - *pivmin) {
  1029. ++nwl;
  1030. }
  1031. if (*wu >= d__[ibegin] - *pivmin) {
  1032. ++nwu;
  1033. }
  1034. if (irange == 1 || *wl < d__[ibegin] - *pivmin && *wu >= d__[
  1035. ibegin] - *pivmin) {
  1036. ++(*m);
  1037. w[*m] = d__[ibegin];
  1038. werr[*m] = 0.f;
  1039. /* The gap for a single block doesn't matter for the later */
  1040. /* algorithm and is assigned an arbitrary large value */
  1041. iblock[*m] = jblk;
  1042. indexw[*m] = 1;
  1043. }
  1044. /* Disabled 2x2 case because of a failure on the following matrix */
  1045. /* RANGE = 'I', IL = IU = 4 */
  1046. /* Original Tridiagonal, d = [ */
  1047. /* -0.150102010615740E+00 */
  1048. /* -0.849897989384260E+00 */
  1049. /* -0.128208148052635E-15 */
  1050. /* 0.128257718286320E-15 */
  1051. /* ]; */
  1052. /* e = [ */
  1053. /* -0.357171383266986E+00 */
  1054. /* -0.180411241501588E-15 */
  1055. /* -0.175152352710251E-15 */
  1056. /* ]; */
  1057. /* ELSE IF( IN.EQ.2 ) THEN */
  1058. /* * 2x2 block */
  1059. /* DISC = SQRT( (HALF*(D(IBEGIN)-D(IEND)))**2 + E(IBEGIN)**2 ) */
  1060. /* TMP1 = HALF*(D(IBEGIN)+D(IEND)) */
  1061. /* L1 = TMP1 - DISC */
  1062. /* IF( WL.GE. L1-PIVMIN ) */
  1063. /* $ NWL = NWL + 1 */
  1064. /* IF( WU.GE. L1-PIVMIN ) */
  1065. /* $ NWU = NWU + 1 */
  1066. /* IF( IRANGE.EQ.ALLRNG .OR. ( WL.LT.L1-PIVMIN .AND. WU.GE. */
  1067. /* $ L1-PIVMIN ) ) THEN */
  1068. /* M = M + 1 */
  1069. /* W( M ) = L1 */
  1070. /* * The uncertainty of eigenvalues of a 2x2 matrix is very small */
  1071. /* WERR( M ) = EPS * ABS( W( M ) ) * TWO */
  1072. /* IBLOCK( M ) = JBLK */
  1073. /* INDEXW( M ) = 1 */
  1074. /* ENDIF */
  1075. /* L2 = TMP1 + DISC */
  1076. /* IF( WL.GE. L2-PIVMIN ) */
  1077. /* $ NWL = NWL + 1 */
  1078. /* IF( WU.GE. L2-PIVMIN ) */
  1079. /* $ NWU = NWU + 1 */
  1080. /* IF( IRANGE.EQ.ALLRNG .OR. ( WL.LT.L2-PIVMIN .AND. WU.GE. */
  1081. /* $ L2-PIVMIN ) ) THEN */
  1082. /* M = M + 1 */
  1083. /* W( M ) = L2 */
  1084. /* * The uncertainty of eigenvalues of a 2x2 matrix is very small */
  1085. /* WERR( M ) = EPS * ABS( W( M ) ) * TWO */
  1086. /* IBLOCK( M ) = JBLK */
  1087. /* INDEXW( M ) = 2 */
  1088. /* ENDIF */
  1089. } else {
  1090. /* General Case - block of size IN >= 2 */
  1091. /* Compute local Gerschgorin interval and use it as the initial */
  1092. /* interval for SLAEBZ */
  1093. gu = d__[ibegin];
  1094. gl = d__[ibegin];
  1095. tmp1 = 0.f;
  1096. i__2 = iend;
  1097. for (j = ibegin; j <= i__2; ++j) {
  1098. /* Computing MIN */
  1099. r__1 = gl, r__2 = gers[(j << 1) - 1];
  1100. gl = f2cmin(r__1,r__2);
  1101. /* Computing MAX */
  1102. r__1 = gu, r__2 = gers[j * 2];
  1103. gu = f2cmax(r__1,r__2);
  1104. /* L40: */
  1105. }
  1106. /* [JAN/28/2009] */
  1107. /* change SPDIAM by TNORM in lines 2 and 3 thereafter */
  1108. /* line 1: remove computation of SPDIAM (not useful anymore) */
  1109. /* SPDIAM = GU - GL */
  1110. /* GL = GL - FUDGE*SPDIAM*EPS*IN - FUDGE*PIVMIN */
  1111. /* GU = GU + FUDGE*SPDIAM*EPS*IN + FUDGE*PIVMIN */
  1112. gl = gl - tnorm * 2.f * eps * in - *pivmin * 2.f;
  1113. gu = gu + tnorm * 2.f * eps * in + *pivmin * 2.f;
  1114. if (irange > 1) {
  1115. if (gu < *wl) {
  1116. /* the local block contains none of the wanted eigenvalues */
  1117. nwl += in;
  1118. nwu += in;
  1119. goto L70;
  1120. }
  1121. /* refine search interval if possible, only range (WL,WU] matters */
  1122. gl = f2cmax(gl,*wl);
  1123. gu = f2cmin(gu,*wu);
  1124. if (gl >= gu) {
  1125. goto L70;
  1126. }
  1127. }
  1128. /* Find negcount of initial interval boundaries GL and GU */
  1129. work[*n + 1] = gl;
  1130. work[*n + in + 1] = gu;
  1131. slaebz_(&c__1, &c__0, &in, &in, &c__1, &nb, &atoli, &rtoli,
  1132. pivmin, &d__[ibegin], &e[ibegin], &e2[ibegin], idumma, &
  1133. work[*n + 1], &work[*n + (in << 1) + 1], &im, &iwork[1], &
  1134. w[*m + 1], &iblock[*m + 1], &iinfo);
  1135. if (iinfo != 0) {
  1136. *info = iinfo;
  1137. return;
  1138. }
  1139. nwl += iwork[1];
  1140. nwu += iwork[in + 1];
  1141. iwoff = *m - iwork[1];
  1142. /* Compute Eigenvalues */
  1143. itmax = (integer) ((log(gu - gl + *pivmin) - log(*pivmin)) / log(
  1144. 2.f)) + 2;
  1145. slaebz_(&c__2, &itmax, &in, &in, &c__1, &nb, &atoli, &rtoli,
  1146. pivmin, &d__[ibegin], &e[ibegin], &e2[ibegin], idumma, &
  1147. work[*n + 1], &work[*n + (in << 1) + 1], &iout, &iwork[1],
  1148. &w[*m + 1], &iblock[*m + 1], &iinfo);
  1149. if (iinfo != 0) {
  1150. *info = iinfo;
  1151. return;
  1152. }
  1153. /* Copy eigenvalues into W and IBLOCK */
  1154. /* Use -JBLK for block number for unconverged eigenvalues. */
  1155. /* Loop over the number of output intervals from SLAEBZ */
  1156. i__2 = iout;
  1157. for (j = 1; j <= i__2; ++j) {
  1158. /* eigenvalue approximation is middle point of interval */
  1159. tmp1 = (work[j + *n] + work[j + in + *n]) * .5f;
  1160. /* semi length of error interval */
  1161. tmp2 = (r__1 = work[j + *n] - work[j + in + *n], abs(r__1)) *
  1162. .5f;
  1163. if (j > iout - iinfo) {
  1164. /* Flag non-convergence. */
  1165. ncnvrg = TRUE_;
  1166. ib = -jblk;
  1167. } else {
  1168. ib = jblk;
  1169. }
  1170. i__3 = iwork[j + in] + iwoff;
  1171. for (je = iwork[j] + 1 + iwoff; je <= i__3; ++je) {
  1172. w[je] = tmp1;
  1173. werr[je] = tmp2;
  1174. indexw[je] = je - iwoff;
  1175. iblock[je] = ib;
  1176. /* L50: */
  1177. }
  1178. /* L60: */
  1179. }
  1180. *m += im;
  1181. }
  1182. L70:
  1183. ;
  1184. }
  1185. /* If RANGE='I', then (WL,WU) contains eigenvalues NWL+1,...,NWU */
  1186. /* If NWL+1 < IL or NWU > IU, discard extra eigenvalues. */
  1187. if (irange == 3) {
  1188. idiscl = *il - 1 - nwl;
  1189. idiscu = nwu - *iu;
  1190. if (idiscl > 0) {
  1191. im = 0;
  1192. i__1 = *m;
  1193. for (je = 1; je <= i__1; ++je) {
  1194. /* Remove some of the smallest eigenvalues from the left so that */
  1195. /* at the end IDISCL =0. Move all eigenvalues up to the left. */
  1196. if (w[je] <= wlu && idiscl > 0) {
  1197. --idiscl;
  1198. } else {
  1199. ++im;
  1200. w[im] = w[je];
  1201. werr[im] = werr[je];
  1202. indexw[im] = indexw[je];
  1203. iblock[im] = iblock[je];
  1204. }
  1205. /* L80: */
  1206. }
  1207. *m = im;
  1208. }
  1209. if (idiscu > 0) {
  1210. /* Remove some of the largest eigenvalues from the right so that */
  1211. /* at the end IDISCU =0. Move all eigenvalues up to the left. */
  1212. im = *m + 1;
  1213. for (je = *m; je >= 1; --je) {
  1214. if (w[je] >= wul && idiscu > 0) {
  1215. --idiscu;
  1216. } else {
  1217. --im;
  1218. w[im] = w[je];
  1219. werr[im] = werr[je];
  1220. indexw[im] = indexw[je];
  1221. iblock[im] = iblock[je];
  1222. }
  1223. /* L81: */
  1224. }
  1225. jee = 0;
  1226. i__1 = *m;
  1227. for (je = im; je <= i__1; ++je) {
  1228. ++jee;
  1229. w[jee] = w[je];
  1230. werr[jee] = werr[je];
  1231. indexw[jee] = indexw[je];
  1232. iblock[jee] = iblock[je];
  1233. /* L82: */
  1234. }
  1235. *m = *m - im + 1;
  1236. }
  1237. if (idiscl > 0 || idiscu > 0) {
  1238. /* Code to deal with effects of bad arithmetic. (If N(w) is */
  1239. /* monotone non-decreasing, this should never happen.) */
  1240. /* Some low eigenvalues to be discarded are not in (WL,WLU], */
  1241. /* or high eigenvalues to be discarded are not in (WUL,WU] */
  1242. /* so just kill off the smallest IDISCL/largest IDISCU */
  1243. /* eigenvalues, by marking the corresponding IBLOCK = 0 */
  1244. if (idiscl > 0) {
  1245. wkill = *wu;
  1246. i__1 = idiscl;
  1247. for (jdisc = 1; jdisc <= i__1; ++jdisc) {
  1248. iw = 0;
  1249. i__2 = *m;
  1250. for (je = 1; je <= i__2; ++je) {
  1251. if (iblock[je] != 0 && (w[je] < wkill || iw == 0)) {
  1252. iw = je;
  1253. wkill = w[je];
  1254. }
  1255. /* L90: */
  1256. }
  1257. iblock[iw] = 0;
  1258. /* L100: */
  1259. }
  1260. }
  1261. if (idiscu > 0) {
  1262. wkill = *wl;
  1263. i__1 = idiscu;
  1264. for (jdisc = 1; jdisc <= i__1; ++jdisc) {
  1265. iw = 0;
  1266. i__2 = *m;
  1267. for (je = 1; je <= i__2; ++je) {
  1268. if (iblock[je] != 0 && (w[je] >= wkill || iw == 0)) {
  1269. iw = je;
  1270. wkill = w[je];
  1271. }
  1272. /* L110: */
  1273. }
  1274. iblock[iw] = 0;
  1275. /* L120: */
  1276. }
  1277. }
  1278. /* Now erase all eigenvalues with IBLOCK set to zero */
  1279. im = 0;
  1280. i__1 = *m;
  1281. for (je = 1; je <= i__1; ++je) {
  1282. if (iblock[je] != 0) {
  1283. ++im;
  1284. w[im] = w[je];
  1285. werr[im] = werr[je];
  1286. indexw[im] = indexw[je];
  1287. iblock[im] = iblock[je];
  1288. }
  1289. /* L130: */
  1290. }
  1291. *m = im;
  1292. }
  1293. if (idiscl < 0 || idiscu < 0) {
  1294. toofew = TRUE_;
  1295. }
  1296. }
  1297. if (irange == 1 && *m != *n || irange == 3 && *m != *iu - *il + 1) {
  1298. toofew = TRUE_;
  1299. }
  1300. /* If ORDER='B', do nothing the eigenvalues are already sorted by */
  1301. /* block. */
  1302. /* If ORDER='E', sort the eigenvalues from smallest to largest */
  1303. if (lsame_(order, "E") && *nsplit > 1) {
  1304. i__1 = *m - 1;
  1305. for (je = 1; je <= i__1; ++je) {
  1306. ie = 0;
  1307. tmp1 = w[je];
  1308. i__2 = *m;
  1309. for (j = je + 1; j <= i__2; ++j) {
  1310. if (w[j] < tmp1) {
  1311. ie = j;
  1312. tmp1 = w[j];
  1313. }
  1314. /* L140: */
  1315. }
  1316. if (ie != 0) {
  1317. tmp2 = werr[ie];
  1318. itmp1 = iblock[ie];
  1319. itmp2 = indexw[ie];
  1320. w[ie] = w[je];
  1321. werr[ie] = werr[je];
  1322. iblock[ie] = iblock[je];
  1323. indexw[ie] = indexw[je];
  1324. w[je] = tmp1;
  1325. werr[je] = tmp2;
  1326. iblock[je] = itmp1;
  1327. indexw[je] = itmp2;
  1328. }
  1329. /* L150: */
  1330. }
  1331. }
  1332. *info = 0;
  1333. if (ncnvrg) {
  1334. ++(*info);
  1335. }
  1336. if (toofew) {
  1337. *info += 2;
  1338. }
  1339. return;
  1340. /* End of SLARRD */
  1341. } /* slarrd_ */