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.

dlarrd.c 44 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  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 DLARRD 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 DLARRD + dependencies */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarrd.
  496. f"> */
  497. /* > [TGZ]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarrd.
  499. f"> */
  500. /* > [ZIP]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarrd.
  502. f"> */
  503. /* > [TXT]</a> */
  504. /* > \endhtmlonly */
  505. /* Definition: */
  506. /* =========== */
  507. /* SUBROUTINE DLARRD( 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. /* DOUBLE PRECISION PIVMIN, RELTOL, VL, VU, WL, WU */
  514. /* INTEGER IBLOCK( * ), INDEXW( * ), */
  515. /* $ ISPLIT( * ), IWORK( * ) */
  516. /* DOUBLE PRECISION D( * ), E( * ), E2( * ), */
  517. /* $ GERS( * ), W( * ), WERR( * ), WORK( * ) */
  518. /* > \par Purpose: */
  519. /* ============= */
  520. /* > */
  521. /* > \verbatim */
  522. /* > */
  523. /* > DLARRD computes the eigenvalues of a symmetric tridiagonal */
  524. /* > matrix T to suitable accuracy. This is an auxiliary code to be */
  525. /* > called from DSTEMR. */
  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 DOUBLE PRECISION */
  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 DOUBLE PRECISION */
  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 DOUBLE PRECISION 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 DOUBLE PRECISION */
  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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION */
  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 DOUBLE PRECISION array, dimension (N) */
  677. /* > On exit, the first M elements of W will contain the */
  678. /* > eigenvalue approximations. DLARRD 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 DOUBLE PRECISION 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 DOUBLE PRECISION */
  695. /* > \endverbatim */
  696. /* > */
  697. /* > \param[out] WU */
  698. /* > \verbatim */
  699. /* > WU is DOUBLE PRECISION */
  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 DLAEBZ 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. (DLARRD 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 DOUBLE PRECISION 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 DOUBLE PRECISION, 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 dlarrd_(char *range, char *order, integer *n, doublereal
  800. *vl, doublereal *vu, integer *il, integer *iu, doublereal *gers,
  801. doublereal *reltol, doublereal *d__, doublereal *e, doublereal *e2,
  802. doublereal *pivmin, integer *nsplit, integer *isplit, integer *m,
  803. doublereal *w, doublereal *werr, doublereal *wl, doublereal *wu,
  804. integer *iblock, integer *indexw, doublereal *work, integer *iwork,
  805. integer *info)
  806. {
  807. /* System generated locals */
  808. integer i__1, i__2, i__3;
  809. doublereal d__1, d__2;
  810. /* Local variables */
  811. integer iend, jblk, ioff, iout, itmp1, itmp2, i__, j, jdisc;
  812. extern logical lsame_(char *, char *);
  813. integer iinfo;
  814. doublereal atoli;
  815. integer iwoff, itmax;
  816. doublereal wkill, rtoli, uflow, tnorm;
  817. integer ib, ie, je, nb;
  818. doublereal gl;
  819. integer im, in;
  820. extern doublereal dlamch_(char *);
  821. doublereal gu;
  822. integer ibegin, iw;
  823. extern /* Subroutine */ void dlaebz_(integer *, integer *, integer *,
  824. integer *, integer *, integer *, doublereal *, doublereal *,
  825. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  826. doublereal *, doublereal *, integer *, integer *, doublereal *,
  827. integer *, integer *);
  828. integer irange, idiscl, idumma[1];
  829. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  830. integer *, integer *, ftnlen, ftnlen);
  831. integer idiscu;
  832. logical ncnvrg, toofew;
  833. integer jee;
  834. doublereal eps;
  835. integer nwl;
  836. doublereal wlu, wul;
  837. integer nwu;
  838. doublereal tmp1, tmp2;
  839. /* -- LAPACK auxiliary routine (version 3.7.1) -- */
  840. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  841. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  842. /* June 2016 */
  843. /* ===================================================================== */
  844. /* Parameter adjustments */
  845. --iwork;
  846. --work;
  847. --indexw;
  848. --iblock;
  849. --werr;
  850. --w;
  851. --isplit;
  852. --e2;
  853. --e;
  854. --d__;
  855. --gers;
  856. /* Function Body */
  857. *info = 0;
  858. /* Quick return if possible */
  859. if (*n <= 0) {
  860. return;
  861. }
  862. /* Decode RANGE */
  863. if (lsame_(range, "A")) {
  864. irange = 1;
  865. } else if (lsame_(range, "V")) {
  866. irange = 2;
  867. } else if (lsame_(range, "I")) {
  868. irange = 3;
  869. } else {
  870. irange = 0;
  871. }
  872. /* Check for Errors */
  873. if (irange <= 0) {
  874. *info = -1;
  875. } else if (! (lsame_(order, "B") || lsame_(order,
  876. "E"))) {
  877. *info = -2;
  878. } else if (*n < 0) {
  879. *info = -3;
  880. } else if (irange == 2) {
  881. if (*vl >= *vu) {
  882. *info = -5;
  883. }
  884. } else if (irange == 3 && (*il < 1 || *il > f2cmax(1,*n))) {
  885. *info = -6;
  886. } else if (irange == 3 && (*iu < f2cmin(*n,*il) || *iu > *n)) {
  887. *info = -7;
  888. }
  889. if (*info != 0) {
  890. return;
  891. }
  892. /* Initialize error flags */
  893. *info = 0;
  894. ncnvrg = FALSE_;
  895. toofew = FALSE_;
  896. /* Quick return if possible */
  897. *m = 0;
  898. if (*n == 0) {
  899. return;
  900. }
  901. /* Simplification: */
  902. if (irange == 3 && *il == 1 && *iu == *n) {
  903. irange = 1;
  904. }
  905. /* Get machine constants */
  906. eps = dlamch_("P");
  907. uflow = dlamch_("U");
  908. /* Special Case when N=1 */
  909. /* Treat case of 1x1 matrix for quick return */
  910. if (*n == 1) {
  911. if (irange == 1 || irange == 2 && d__[1] > *vl && d__[1] <= *vu ||
  912. irange == 3 && *il == 1 && *iu == 1) {
  913. *m = 1;
  914. w[1] = d__[1];
  915. /* The computation error of the eigenvalue is zero */
  916. werr[1] = 0.;
  917. iblock[1] = 1;
  918. indexw[1] = 1;
  919. }
  920. return;
  921. }
  922. /* NB is the minimum vector length for vector bisection, or 0 */
  923. /* if only scalar is to be done. */
  924. nb = ilaenv_(&c__1, "DSTEBZ", " ", n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
  925. ftnlen)1);
  926. if (nb <= 1) {
  927. nb = 0;
  928. }
  929. /* Find global spectral radius */
  930. gl = d__[1];
  931. gu = d__[1];
  932. i__1 = *n;
  933. for (i__ = 1; i__ <= i__1; ++i__) {
  934. /* Computing MIN */
  935. d__1 = gl, d__2 = gers[(i__ << 1) - 1];
  936. gl = f2cmin(d__1,d__2);
  937. /* Computing MAX */
  938. d__1 = gu, d__2 = gers[i__ * 2];
  939. gu = f2cmax(d__1,d__2);
  940. /* L5: */
  941. }
  942. /* Compute global Gerschgorin bounds and spectral diameter */
  943. /* Computing MAX */
  944. d__1 = abs(gl), d__2 = abs(gu);
  945. tnorm = f2cmax(d__1,d__2);
  946. gl = gl - tnorm * 2. * eps * *n - *pivmin * 4.;
  947. gu = gu + tnorm * 2. * eps * *n + *pivmin * 4.;
  948. /* [JAN/28/2009] remove the line below since SPDIAM variable not use */
  949. /* SPDIAM = GU - GL */
  950. /* Input arguments for DLAEBZ: */
  951. /* The relative tolerance. An interval (a,b] lies within */
  952. /* "relative tolerance" if b-a < RELTOL*f2cmax(|a|,|b|), */
  953. rtoli = *reltol;
  954. /* Set the absolute tolerance for interval convergence to zero to force */
  955. /* interval convergence based on relative size of the interval. */
  956. /* This is dangerous because intervals might not converge when RELTOL is */
  957. /* small. But at least a very small number should be selected so that for */
  958. /* strongly graded matrices, the code can get relatively accurate */
  959. /* eigenvalues. */
  960. atoli = uflow * 4. + *pivmin * 4.;
  961. if (irange == 3) {
  962. /* RANGE='I': Compute an interval containing eigenvalues */
  963. /* IL through IU. The initial interval [GL,GU] from the global */
  964. /* Gerschgorin bounds GL and GU is refined by DLAEBZ. */
  965. itmax = (integer) ((log(tnorm + *pivmin) - log(*pivmin)) / log(2.)) +
  966. 2;
  967. work[*n + 1] = gl;
  968. work[*n + 2] = gl;
  969. work[*n + 3] = gu;
  970. work[*n + 4] = gu;
  971. work[*n + 5] = gl;
  972. work[*n + 6] = gu;
  973. iwork[1] = -1;
  974. iwork[2] = -1;
  975. iwork[3] = *n + 1;
  976. iwork[4] = *n + 1;
  977. iwork[5] = *il - 1;
  978. iwork[6] = *iu;
  979. dlaebz_(&c__3, &itmax, n, &c__2, &c__2, &nb, &atoli, &rtoli, pivmin, &
  980. d__[1], &e[1], &e2[1], &iwork[5], &work[*n + 1], &work[*n + 5]
  981. , &iout, &iwork[1], &w[1], &iblock[1], &iinfo);
  982. if (iinfo != 0) {
  983. *info = iinfo;
  984. return;
  985. }
  986. /* On exit, output intervals may not be ordered by ascending negcount */
  987. if (iwork[6] == *iu) {
  988. *wl = work[*n + 1];
  989. wlu = work[*n + 3];
  990. nwl = iwork[1];
  991. *wu = work[*n + 4];
  992. wul = work[*n + 2];
  993. nwu = iwork[4];
  994. } else {
  995. *wl = work[*n + 2];
  996. wlu = work[*n + 4];
  997. nwl = iwork[2];
  998. *wu = work[*n + 3];
  999. wul = work[*n + 1];
  1000. nwu = iwork[3];
  1001. }
  1002. /* On exit, the interval [WL, WLU] contains a value with negcount NWL, */
  1003. /* and [WUL, WU] contains a value with negcount NWU. */
  1004. if (nwl < 0 || nwl >= *n || nwu < 1 || nwu > *n) {
  1005. *info = 4;
  1006. return;
  1007. }
  1008. } else if (irange == 2) {
  1009. *wl = *vl;
  1010. *wu = *vu;
  1011. } else if (irange == 1) {
  1012. *wl = gl;
  1013. *wu = gu;
  1014. }
  1015. /* Find Eigenvalues -- Loop Over blocks and recompute NWL and NWU. */
  1016. /* NWL accumulates the number of eigenvalues .le. WL, */
  1017. /* NWU accumulates the number of eigenvalues .le. WU */
  1018. *m = 0;
  1019. iend = 0;
  1020. *info = 0;
  1021. nwl = 0;
  1022. nwu = 0;
  1023. i__1 = *nsplit;
  1024. for (jblk = 1; jblk <= i__1; ++jblk) {
  1025. ioff = iend;
  1026. ibegin = ioff + 1;
  1027. iend = isplit[jblk];
  1028. in = iend - ioff;
  1029. if (in == 1) {
  1030. /* 1x1 block */
  1031. if (*wl >= d__[ibegin] - *pivmin) {
  1032. ++nwl;
  1033. }
  1034. if (*wu >= d__[ibegin] - *pivmin) {
  1035. ++nwu;
  1036. }
  1037. if (irange == 1 || *wl < d__[ibegin] - *pivmin && *wu >= d__[
  1038. ibegin] - *pivmin) {
  1039. ++(*m);
  1040. w[*m] = d__[ibegin];
  1041. werr[*m] = 0.;
  1042. /* The gap for a single block doesn't matter for the later */
  1043. /* algorithm and is assigned an arbitrary large value */
  1044. iblock[*m] = jblk;
  1045. indexw[*m] = 1;
  1046. }
  1047. /* Disabled 2x2 case because of a failure on the following matrix */
  1048. /* RANGE = 'I', IL = IU = 4 */
  1049. /* Original Tridiagonal, d = [ */
  1050. /* -0.150102010615740E+00 */
  1051. /* -0.849897989384260E+00 */
  1052. /* -0.128208148052635E-15 */
  1053. /* 0.128257718286320E-15 */
  1054. /* ]; */
  1055. /* e = [ */
  1056. /* -0.357171383266986E+00 */
  1057. /* -0.180411241501588E-15 */
  1058. /* -0.175152352710251E-15 */
  1059. /* ]; */
  1060. /* ELSE IF( IN.EQ.2 ) THEN */
  1061. /* * 2x2 block */
  1062. /* DISC = SQRT( (HALF*(D(IBEGIN)-D(IEND)))**2 + E(IBEGIN)**2 ) */
  1063. /* TMP1 = HALF*(D(IBEGIN)+D(IEND)) */
  1064. /* L1 = TMP1 - DISC */
  1065. /* IF( WL.GE. L1-PIVMIN ) */
  1066. /* $ NWL = NWL + 1 */
  1067. /* IF( WU.GE. L1-PIVMIN ) */
  1068. /* $ NWU = NWU + 1 */
  1069. /* IF( IRANGE.EQ.ALLRNG .OR. ( WL.LT.L1-PIVMIN .AND. WU.GE. */
  1070. /* $ L1-PIVMIN ) ) THEN */
  1071. /* M = M + 1 */
  1072. /* W( M ) = L1 */
  1073. /* * The uncertainty of eigenvalues of a 2x2 matrix is very small */
  1074. /* WERR( M ) = EPS * ABS( W( M ) ) * TWO */
  1075. /* IBLOCK( M ) = JBLK */
  1076. /* INDEXW( M ) = 1 */
  1077. /* ENDIF */
  1078. /* L2 = TMP1 + DISC */
  1079. /* IF( WL.GE. L2-PIVMIN ) */
  1080. /* $ NWL = NWL + 1 */
  1081. /* IF( WU.GE. L2-PIVMIN ) */
  1082. /* $ NWU = NWU + 1 */
  1083. /* IF( IRANGE.EQ.ALLRNG .OR. ( WL.LT.L2-PIVMIN .AND. WU.GE. */
  1084. /* $ L2-PIVMIN ) ) THEN */
  1085. /* M = M + 1 */
  1086. /* W( M ) = L2 */
  1087. /* * The uncertainty of eigenvalues of a 2x2 matrix is very small */
  1088. /* WERR( M ) = EPS * ABS( W( M ) ) * TWO */
  1089. /* IBLOCK( M ) = JBLK */
  1090. /* INDEXW( M ) = 2 */
  1091. /* ENDIF */
  1092. } else {
  1093. /* General Case - block of size IN >= 2 */
  1094. /* Compute local Gerschgorin interval and use it as the initial */
  1095. /* interval for DLAEBZ */
  1096. gu = d__[ibegin];
  1097. gl = d__[ibegin];
  1098. tmp1 = 0.;
  1099. i__2 = iend;
  1100. for (j = ibegin; j <= i__2; ++j) {
  1101. /* Computing MIN */
  1102. d__1 = gl, d__2 = gers[(j << 1) - 1];
  1103. gl = f2cmin(d__1,d__2);
  1104. /* Computing MAX */
  1105. d__1 = gu, d__2 = gers[j * 2];
  1106. gu = f2cmax(d__1,d__2);
  1107. /* L40: */
  1108. }
  1109. /* [JAN/28/2009] */
  1110. /* change SPDIAM by TNORM in lines 2 and 3 thereafter */
  1111. /* line 1: remove computation of SPDIAM (not useful anymore) */
  1112. /* SPDIAM = GU - GL */
  1113. /* GL = GL - FUDGE*SPDIAM*EPS*IN - FUDGE*PIVMIN */
  1114. /* GU = GU + FUDGE*SPDIAM*EPS*IN + FUDGE*PIVMIN */
  1115. gl = gl - tnorm * 2. * eps * in - *pivmin * 2.;
  1116. gu = gu + tnorm * 2. * eps * in + *pivmin * 2.;
  1117. if (irange > 1) {
  1118. if (gu < *wl) {
  1119. /* the local block contains none of the wanted eigenvalues */
  1120. nwl += in;
  1121. nwu += in;
  1122. goto L70;
  1123. }
  1124. /* refine search interval if possible, only range (WL,WU] matters */
  1125. gl = f2cmax(gl,*wl);
  1126. gu = f2cmin(gu,*wu);
  1127. if (gl >= gu) {
  1128. goto L70;
  1129. }
  1130. }
  1131. /* Find negcount of initial interval boundaries GL and GU */
  1132. work[*n + 1] = gl;
  1133. work[*n + in + 1] = gu;
  1134. dlaebz_(&c__1, &c__0, &in, &in, &c__1, &nb, &atoli, &rtoli,
  1135. pivmin, &d__[ibegin], &e[ibegin], &e2[ibegin], idumma, &
  1136. work[*n + 1], &work[*n + (in << 1) + 1], &im, &iwork[1], &
  1137. w[*m + 1], &iblock[*m + 1], &iinfo);
  1138. if (iinfo != 0) {
  1139. *info = iinfo;
  1140. return;
  1141. }
  1142. nwl += iwork[1];
  1143. nwu += iwork[in + 1];
  1144. iwoff = *m - iwork[1];
  1145. /* Compute Eigenvalues */
  1146. itmax = (integer) ((log(gu - gl + *pivmin) - log(*pivmin)) / log(
  1147. 2.)) + 2;
  1148. dlaebz_(&c__2, &itmax, &in, &in, &c__1, &nb, &atoli, &rtoli,
  1149. pivmin, &d__[ibegin], &e[ibegin], &e2[ibegin], idumma, &
  1150. work[*n + 1], &work[*n + (in << 1) + 1], &iout, &iwork[1],
  1151. &w[*m + 1], &iblock[*m + 1], &iinfo);
  1152. if (iinfo != 0) {
  1153. *info = iinfo;
  1154. return;
  1155. }
  1156. /* Copy eigenvalues into W and IBLOCK */
  1157. /* Use -JBLK for block number for unconverged eigenvalues. */
  1158. /* Loop over the number of output intervals from DLAEBZ */
  1159. i__2 = iout;
  1160. for (j = 1; j <= i__2; ++j) {
  1161. /* eigenvalue approximation is middle point of interval */
  1162. tmp1 = (work[j + *n] + work[j + in + *n]) * .5;
  1163. /* semi length of error interval */
  1164. tmp2 = (d__1 = work[j + *n] - work[j + in + *n], abs(d__1)) *
  1165. .5;
  1166. if (j > iout - iinfo) {
  1167. /* Flag non-convergence. */
  1168. ncnvrg = TRUE_;
  1169. ib = -jblk;
  1170. } else {
  1171. ib = jblk;
  1172. }
  1173. i__3 = iwork[j + in] + iwoff;
  1174. for (je = iwork[j] + 1 + iwoff; je <= i__3; ++je) {
  1175. w[je] = tmp1;
  1176. werr[je] = tmp2;
  1177. indexw[je] = je - iwoff;
  1178. iblock[je] = ib;
  1179. /* L50: */
  1180. }
  1181. /* L60: */
  1182. }
  1183. *m += im;
  1184. }
  1185. L70:
  1186. ;
  1187. }
  1188. /* If RANGE='I', then (WL,WU) contains eigenvalues NWL+1,...,NWU */
  1189. /* If NWL+1 < IL or NWU > IU, discard extra eigenvalues. */
  1190. if (irange == 3) {
  1191. idiscl = *il - 1 - nwl;
  1192. idiscu = nwu - *iu;
  1193. if (idiscl > 0) {
  1194. im = 0;
  1195. i__1 = *m;
  1196. for (je = 1; je <= i__1; ++je) {
  1197. /* Remove some of the smallest eigenvalues from the left so that */
  1198. /* at the end IDISCL =0. Move all eigenvalues up to the left. */
  1199. if (w[je] <= wlu && idiscl > 0) {
  1200. --idiscl;
  1201. } else {
  1202. ++im;
  1203. w[im] = w[je];
  1204. werr[im] = werr[je];
  1205. indexw[im] = indexw[je];
  1206. iblock[im] = iblock[je];
  1207. }
  1208. /* L80: */
  1209. }
  1210. *m = im;
  1211. }
  1212. if (idiscu > 0) {
  1213. /* Remove some of the largest eigenvalues from the right so that */
  1214. /* at the end IDISCU =0. Move all eigenvalues up to the left. */
  1215. im = *m + 1;
  1216. for (je = *m; je >= 1; --je) {
  1217. if (w[je] >= wul && idiscu > 0) {
  1218. --idiscu;
  1219. } else {
  1220. --im;
  1221. w[im] = w[je];
  1222. werr[im] = werr[je];
  1223. indexw[im] = indexw[je];
  1224. iblock[im] = iblock[je];
  1225. }
  1226. /* L81: */
  1227. }
  1228. jee = 0;
  1229. i__1 = *m;
  1230. for (je = im; je <= i__1; ++je) {
  1231. ++jee;
  1232. w[jee] = w[je];
  1233. werr[jee] = werr[je];
  1234. indexw[jee] = indexw[je];
  1235. iblock[jee] = iblock[je];
  1236. /* L82: */
  1237. }
  1238. *m = *m - im + 1;
  1239. }
  1240. if (idiscl > 0 || idiscu > 0) {
  1241. /* Code to deal with effects of bad arithmetic. (If N(w) is */
  1242. /* monotone non-decreasing, this should never happen.) */
  1243. /* Some low eigenvalues to be discarded are not in (WL,WLU], */
  1244. /* or high eigenvalues to be discarded are not in (WUL,WU] */
  1245. /* so just kill off the smallest IDISCL/largest IDISCU */
  1246. /* eigenvalues, by marking the corresponding IBLOCK = 0 */
  1247. if (idiscl > 0) {
  1248. wkill = *wu;
  1249. i__1 = idiscl;
  1250. for (jdisc = 1; jdisc <= i__1; ++jdisc) {
  1251. iw = 0;
  1252. i__2 = *m;
  1253. for (je = 1; je <= i__2; ++je) {
  1254. if (iblock[je] != 0 && (w[je] < wkill || iw == 0)) {
  1255. iw = je;
  1256. wkill = w[je];
  1257. }
  1258. /* L90: */
  1259. }
  1260. iblock[iw] = 0;
  1261. /* L100: */
  1262. }
  1263. }
  1264. if (idiscu > 0) {
  1265. wkill = *wl;
  1266. i__1 = idiscu;
  1267. for (jdisc = 1; jdisc <= i__1; ++jdisc) {
  1268. iw = 0;
  1269. i__2 = *m;
  1270. for (je = 1; je <= i__2; ++je) {
  1271. if (iblock[je] != 0 && (w[je] >= wkill || iw == 0)) {
  1272. iw = je;
  1273. wkill = w[je];
  1274. }
  1275. /* L110: */
  1276. }
  1277. iblock[iw] = 0;
  1278. /* L120: */
  1279. }
  1280. }
  1281. /* Now erase all eigenvalues with IBLOCK set to zero */
  1282. im = 0;
  1283. i__1 = *m;
  1284. for (je = 1; je <= i__1; ++je) {
  1285. if (iblock[je] != 0) {
  1286. ++im;
  1287. w[im] = w[je];
  1288. werr[im] = werr[je];
  1289. indexw[im] = indexw[je];
  1290. iblock[im] = iblock[je];
  1291. }
  1292. /* L130: */
  1293. }
  1294. *m = im;
  1295. }
  1296. if (idiscl < 0 || idiscu < 0) {
  1297. toofew = TRUE_;
  1298. }
  1299. }
  1300. if (irange == 1 && *m != *n || irange == 3 && *m != *iu - *il + 1) {
  1301. toofew = TRUE_;
  1302. }
  1303. /* If ORDER='B', do nothing the eigenvalues are already sorted by */
  1304. /* block. */
  1305. /* If ORDER='E', sort the eigenvalues from smallest to largest */
  1306. if (lsame_(order, "E") && *nsplit > 1) {
  1307. i__1 = *m - 1;
  1308. for (je = 1; je <= i__1; ++je) {
  1309. ie = 0;
  1310. tmp1 = w[je];
  1311. i__2 = *m;
  1312. for (j = je + 1; j <= i__2; ++j) {
  1313. if (w[j] < tmp1) {
  1314. ie = j;
  1315. tmp1 = w[j];
  1316. }
  1317. /* L140: */
  1318. }
  1319. if (ie != 0) {
  1320. tmp2 = werr[ie];
  1321. itmp1 = iblock[ie];
  1322. itmp2 = indexw[ie];
  1323. w[ie] = w[je];
  1324. werr[ie] = werr[je];
  1325. iblock[ie] = iblock[je];
  1326. indexw[ie] = indexw[je];
  1327. w[je] = tmp1;
  1328. werr[je] = tmp2;
  1329. iblock[je] = itmp1;
  1330. indexw[je] = itmp2;
  1331. }
  1332. /* L150: */
  1333. }
  1334. }
  1335. *info = 0;
  1336. if (ncnvrg) {
  1337. ++(*info);
  1338. }
  1339. if (toofew) {
  1340. *info += 2;
  1341. }
  1342. return;
  1343. /* End of DLARRD */
  1344. } /* dlarrd_ */