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.

dlarre.c 47 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  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__2 = 2;
  486. /* > \brief \b DLARRE given the tridiagonal matrix T, sets small off-diagonal elements to zero and for each un
  487. reduced block Ti, finds base representations and eigenvalues. */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download DLARRE + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarre.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarre.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarre.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE DLARRE( RANGE, N, VL, VU, IL, IU, D, E, E2, */
  506. /* RTOL1, RTOL2, SPLTOL, NSPLIT, ISPLIT, M, */
  507. /* W, WERR, WGAP, IBLOCK, INDEXW, GERS, PIVMIN, */
  508. /* WORK, IWORK, INFO ) */
  509. /* CHARACTER RANGE */
  510. /* INTEGER IL, INFO, IU, M, N, NSPLIT */
  511. /* DOUBLE PRECISION PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU */
  512. /* INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ), */
  513. /* $ INDEXW( * ) */
  514. /* DOUBLE PRECISION D( * ), E( * ), E2( * ), GERS( * ), */
  515. /* $ W( * ),WERR( * ), WGAP( * ), WORK( * ) */
  516. /* > \par Purpose: */
  517. /* ============= */
  518. /* > */
  519. /* > \verbatim */
  520. /* > */
  521. /* > To find the desired eigenvalues of a given real symmetric */
  522. /* > tridiagonal matrix T, DLARRE sets any "small" off-diagonal */
  523. /* > elements to zero, and for each unreduced block T_i, it finds */
  524. /* > (a) a suitable shift at one end of the block's spectrum, */
  525. /* > (b) the base representation, T_i - sigma_i I = L_i D_i L_i^T, and */
  526. /* > (c) eigenvalues of each L_i D_i L_i^T. */
  527. /* > The representations and eigenvalues found are then used by */
  528. /* > DSTEMR to compute the eigenvectors of T. */
  529. /* > The accuracy varies depending on whether bisection is used to */
  530. /* > find a few eigenvalues or the dqds algorithm (subroutine DLASQ2) to */
  531. /* > conpute all and then discard any unwanted one. */
  532. /* > As an added benefit, DLARRE also outputs the n */
  533. /* > Gerschgorin intervals for the matrices L_i D_i L_i^T. */
  534. /* > \endverbatim */
  535. /* Arguments: */
  536. /* ========== */
  537. /* > \param[in] RANGE */
  538. /* > \verbatim */
  539. /* > RANGE is CHARACTER*1 */
  540. /* > = 'A': ("All") all eigenvalues will be found. */
  541. /* > = 'V': ("Value") all eigenvalues in the half-open interval */
  542. /* > (VL, VU] will be found. */
  543. /* > = 'I': ("Index") the IL-th through IU-th eigenvalues (of the */
  544. /* > entire matrix) will be found. */
  545. /* > \endverbatim */
  546. /* > */
  547. /* > \param[in] N */
  548. /* > \verbatim */
  549. /* > N is INTEGER */
  550. /* > The order of the matrix. N > 0. */
  551. /* > \endverbatim */
  552. /* > */
  553. /* > \param[in,out] VL */
  554. /* > \verbatim */
  555. /* > VL is DOUBLE PRECISION */
  556. /* > If RANGE='V', the lower bound for the eigenvalues. */
  557. /* > Eigenvalues less than or equal to VL, or greater than VU, */
  558. /* > will not be returned. VL < VU. */
  559. /* > If RANGE='I' or ='A', DLARRE computes bounds on the desired */
  560. /* > part of the spectrum. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in,out] VU */
  564. /* > \verbatim */
  565. /* > VU is DOUBLE PRECISION */
  566. /* > If RANGE='V', the upper bound for the eigenvalues. */
  567. /* > Eigenvalues less than or equal to VL, or greater than VU, */
  568. /* > will not be returned. VL < VU. */
  569. /* > If RANGE='I' or ='A', DLARRE computes bounds on the desired */
  570. /* > part of the spectrum. */
  571. /* > \endverbatim */
  572. /* > */
  573. /* > \param[in] IL */
  574. /* > \verbatim */
  575. /* > IL is INTEGER */
  576. /* > If RANGE='I', the index of the */
  577. /* > smallest eigenvalue to be returned. */
  578. /* > 1 <= IL <= IU <= N. */
  579. /* > \endverbatim */
  580. /* > */
  581. /* > \param[in] IU */
  582. /* > \verbatim */
  583. /* > IU is INTEGER */
  584. /* > If RANGE='I', the index of the */
  585. /* > largest eigenvalue to be returned. */
  586. /* > 1 <= IL <= IU <= N. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in,out] D */
  590. /* > \verbatim */
  591. /* > D is DOUBLE PRECISION array, dimension (N) */
  592. /* > On entry, the N diagonal elements of the tridiagonal */
  593. /* > matrix T. */
  594. /* > On exit, the N diagonal elements of the diagonal */
  595. /* > matrices D_i. */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[in,out] E */
  599. /* > \verbatim */
  600. /* > E is DOUBLE PRECISION array, dimension (N) */
  601. /* > On entry, the first (N-1) entries contain the subdiagonal */
  602. /* > elements of the tridiagonal matrix T; E(N) need not be set. */
  603. /* > On exit, E contains the subdiagonal elements of the unit */
  604. /* > bidiagonal matrices L_i. The entries E( ISPLIT( I ) ), */
  605. /* > 1 <= I <= NSPLIT, contain the base points sigma_i on output. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in,out] E2 */
  609. /* > \verbatim */
  610. /* > E2 is DOUBLE PRECISION array, dimension (N) */
  611. /* > On entry, the first (N-1) entries contain the SQUARES of the */
  612. /* > subdiagonal elements of the tridiagonal matrix T; */
  613. /* > E2(N) need not be set. */
  614. /* > On exit, the entries E2( ISPLIT( I ) ), */
  615. /* > 1 <= I <= NSPLIT, have been set to zero */
  616. /* > \endverbatim */
  617. /* > */
  618. /* > \param[in] RTOL1 */
  619. /* > \verbatim */
  620. /* > RTOL1 is DOUBLE PRECISION */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[in] RTOL2 */
  624. /* > \verbatim */
  625. /* > RTOL2 is DOUBLE PRECISION */
  626. /* > Parameters for bisection. */
  627. /* > An interval [LEFT,RIGHT] has converged if */
  628. /* > RIGHT-LEFT < MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
  629. /* > \endverbatim */
  630. /* > */
  631. /* > \param[in] SPLTOL */
  632. /* > \verbatim */
  633. /* > SPLTOL is DOUBLE PRECISION */
  634. /* > The threshold for splitting. */
  635. /* > \endverbatim */
  636. /* > */
  637. /* > \param[out] NSPLIT */
  638. /* > \verbatim */
  639. /* > NSPLIT is INTEGER */
  640. /* > The number of blocks T splits into. 1 <= NSPLIT <= N. */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[out] ISPLIT */
  644. /* > \verbatim */
  645. /* > ISPLIT is INTEGER array, dimension (N) */
  646. /* > The splitting points, at which T breaks up into blocks. */
  647. /* > The first block consists of rows/columns 1 to ISPLIT(1), */
  648. /* > the second of rows/columns ISPLIT(1)+1 through ISPLIT(2), */
  649. /* > etc., and the NSPLIT-th consists of rows/columns */
  650. /* > ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N. */
  651. /* > \endverbatim */
  652. /* > */
  653. /* > \param[out] M */
  654. /* > \verbatim */
  655. /* > M is INTEGER */
  656. /* > The total number of eigenvalues (of all L_i D_i L_i^T) */
  657. /* > found. */
  658. /* > \endverbatim */
  659. /* > */
  660. /* > \param[out] W */
  661. /* > \verbatim */
  662. /* > W is DOUBLE PRECISION array, dimension (N) */
  663. /* > The first M elements contain the eigenvalues. The */
  664. /* > eigenvalues of each of the blocks, L_i D_i L_i^T, are */
  665. /* > sorted in ascending order ( DLARRE may use the */
  666. /* > remaining N-M elements as workspace). */
  667. /* > \endverbatim */
  668. /* > */
  669. /* > \param[out] WERR */
  670. /* > \verbatim */
  671. /* > WERR is DOUBLE PRECISION array, dimension (N) */
  672. /* > The error bound on the corresponding eigenvalue in W. */
  673. /* > \endverbatim */
  674. /* > */
  675. /* > \param[out] WGAP */
  676. /* > \verbatim */
  677. /* > WGAP is DOUBLE PRECISION array, dimension (N) */
  678. /* > The separation from the right neighbor eigenvalue in W. */
  679. /* > The gap is only with respect to the eigenvalues of the same block */
  680. /* > as each block has its own representation tree. */
  681. /* > Exception: at the right end of a block we store the left gap */
  682. /* > \endverbatim */
  683. /* > */
  684. /* > \param[out] IBLOCK */
  685. /* > \verbatim */
  686. /* > IBLOCK is INTEGER array, dimension (N) */
  687. /* > The indices of the blocks (submatrices) associated with the */
  688. /* > corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
  689. /* > W(i) belongs to the first block from the top, =2 if W(i) */
  690. /* > belongs to the second block, etc. */
  691. /* > \endverbatim */
  692. /* > */
  693. /* > \param[out] INDEXW */
  694. /* > \verbatim */
  695. /* > INDEXW is INTEGER array, dimension (N) */
  696. /* > The indices of the eigenvalues within each block (submatrix); */
  697. /* > for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
  698. /* > i-th eigenvalue W(i) is the 10-th eigenvalue in block 2 */
  699. /* > \endverbatim */
  700. /* > */
  701. /* > \param[out] GERS */
  702. /* > \verbatim */
  703. /* > GERS is DOUBLE PRECISION array, dimension (2*N) */
  704. /* > The N Gerschgorin intervals (the i-th Gerschgorin interval */
  705. /* > is (GERS(2*i-1), GERS(2*i)). */
  706. /* > \endverbatim */
  707. /* > */
  708. /* > \param[out] PIVMIN */
  709. /* > \verbatim */
  710. /* > PIVMIN is DOUBLE PRECISION */
  711. /* > The minimum pivot in the Sturm sequence for T. */
  712. /* > \endverbatim */
  713. /* > */
  714. /* > \param[out] WORK */
  715. /* > \verbatim */
  716. /* > WORK is DOUBLE PRECISION array, dimension (6*N) */
  717. /* > Workspace. */
  718. /* > \endverbatim */
  719. /* > */
  720. /* > \param[out] IWORK */
  721. /* > \verbatim */
  722. /* > IWORK is INTEGER array, dimension (5*N) */
  723. /* > Workspace. */
  724. /* > \endverbatim */
  725. /* > */
  726. /* > \param[out] INFO */
  727. /* > \verbatim */
  728. /* > INFO is INTEGER */
  729. /* > = 0: successful exit */
  730. /* > > 0: A problem occurred in DLARRE. */
  731. /* > < 0: One of the called subroutines signaled an internal problem. */
  732. /* > Needs inspection of the corresponding parameter IINFO */
  733. /* > for further information. */
  734. /* > */
  735. /* > =-1: Problem in DLARRD. */
  736. /* > = 2: No base representation could be found in MAXTRY iterations. */
  737. /* > Increasing MAXTRY and recompilation might be a remedy. */
  738. /* > =-3: Problem in DLARRB when computing the refined root */
  739. /* > representation for DLASQ2. */
  740. /* > =-4: Problem in DLARRB when preforming bisection on the */
  741. /* > desired part of the spectrum. */
  742. /* > =-5: Problem in DLASQ2. */
  743. /* > =-6: Problem in DLASQ2. */
  744. /* > \endverbatim */
  745. /* Authors: */
  746. /* ======== */
  747. /* > \author Univ. of Tennessee */
  748. /* > \author Univ. of California Berkeley */
  749. /* > \author Univ. of Colorado Denver */
  750. /* > \author NAG Ltd. */
  751. /* > \date June 2016 */
  752. /* > \ingroup OTHERauxiliary */
  753. /* > \par Further Details: */
  754. /* ===================== */
  755. /* > */
  756. /* > \verbatim */
  757. /* > */
  758. /* > The base representations are required to suffer very little */
  759. /* > element growth and consequently define all their eigenvalues to */
  760. /* > high relative accuracy. */
  761. /* > \endverbatim */
  762. /* > \par Contributors: */
  763. /* ================== */
  764. /* > */
  765. /* > Beresford Parlett, University of California, Berkeley, USA \n */
  766. /* > Jim Demmel, University of California, Berkeley, USA \n */
  767. /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
  768. /* > Osni Marques, LBNL/NERSC, USA \n */
  769. /* > Christof Voemel, University of California, Berkeley, USA \n */
  770. /* > */
  771. /* ===================================================================== */
  772. /* Subroutine */ void dlarre_(char *range, integer *n, doublereal *vl,
  773. doublereal *vu, integer *il, integer *iu, doublereal *d__, doublereal
  774. *e, doublereal *e2, doublereal *rtol1, doublereal *rtol2, doublereal *
  775. spltol, integer *nsplit, integer *isplit, integer *m, doublereal *w,
  776. doublereal *werr, doublereal *wgap, integer *iblock, integer *indexw,
  777. doublereal *gers, doublereal *pivmin, doublereal *work, integer *
  778. iwork, integer *info)
  779. {
  780. /* System generated locals */
  781. integer i__1, i__2;
  782. doublereal d__1, d__2, d__3;
  783. /* Local variables */
  784. doublereal eabs;
  785. integer iend, jblk;
  786. doublereal eold;
  787. integer indl;
  788. doublereal dmax__, emax;
  789. integer wend, idum, indu;
  790. doublereal rtol;
  791. integer i__, j, iseed[4];
  792. doublereal avgap, sigma;
  793. extern logical lsame_(char *, char *);
  794. integer iinfo;
  795. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  796. doublereal *, integer *);
  797. logical norep;
  798. doublereal s1, s2;
  799. extern /* Subroutine */ void dlasq2_(integer *, doublereal *, integer *);
  800. integer mb;
  801. doublereal gl;
  802. integer in;
  803. extern doublereal dlamch_(char *);
  804. integer mm;
  805. doublereal gu;
  806. integer ibegin;
  807. logical forceb;
  808. integer irange;
  809. doublereal sgndef;
  810. extern /* Subroutine */ void dlarra_(integer *, doublereal *, doublereal *,
  811. doublereal *, doublereal *, doublereal *, integer *, integer *,
  812. integer *), dlarrb_(integer *, doublereal *, doublereal *,
  813. integer *, integer *, doublereal *, doublereal *, integer *,
  814. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  815. doublereal *, doublereal *, integer *, integer *), dlarrc_(char *
  816. , integer *, doublereal *, doublereal *, doublereal *, doublereal
  817. *, doublereal *, integer *, integer *, integer *, integer *);
  818. integer wbegin;
  819. doublereal safmin, spdiam;
  820. extern /* Subroutine */ void dlarrd_(char *, char *, integer *, doublereal
  821. *, doublereal *, integer *, integer *, doublereal *, doublereal *,
  822. doublereal *, doublereal *, doublereal *, doublereal *, integer *
  823. , integer *, integer *, doublereal *, doublereal *, doublereal *,
  824. doublereal *, integer *, integer *, doublereal *, integer *,
  825. integer *), dlarrk_(integer *, integer *,
  826. doublereal *, doublereal *, doublereal *, doublereal *,
  827. doublereal *, doublereal *, doublereal *, doublereal *, integer *)
  828. ;
  829. logical usedqd;
  830. doublereal clwdth, isleft;
  831. extern /* Subroutine */ void dlarnv_(integer *, integer *, integer *,
  832. doublereal *);
  833. doublereal isrght, bsrtol, dpivot;
  834. integer cnt;
  835. doublereal eps, tau, tmp, rtl;
  836. integer cnt1, cnt2;
  837. doublereal tmp1;
  838. /* -- LAPACK auxiliary routine (version 3.8.0) -- */
  839. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  840. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  841. /* June 2016 */
  842. /* ===================================================================== */
  843. /* Parameter adjustments */
  844. --iwork;
  845. --work;
  846. --gers;
  847. --indexw;
  848. --iblock;
  849. --wgap;
  850. --werr;
  851. --w;
  852. --isplit;
  853. --e2;
  854. --e;
  855. --d__;
  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 = 3;
  867. } else if (lsame_(range, "I")) {
  868. irange = 2;
  869. }
  870. *m = 0;
  871. /* Get machine constants */
  872. safmin = dlamch_("S");
  873. eps = dlamch_("P");
  874. /* Set parameters */
  875. rtl = sqrt(eps);
  876. bsrtol = sqrt(eps);
  877. /* Treat case of 1x1 matrix for quick return */
  878. if (*n == 1) {
  879. if (irange == 1 || irange == 3 && d__[1] > *vl && d__[1] <= *vu ||
  880. irange == 2 && *il == 1 && *iu == 1) {
  881. *m = 1;
  882. w[1] = d__[1];
  883. /* The computation error of the eigenvalue is zero */
  884. werr[1] = 0.;
  885. wgap[1] = 0.;
  886. iblock[1] = 1;
  887. indexw[1] = 1;
  888. gers[1] = d__[1];
  889. gers[2] = d__[1];
  890. }
  891. /* store the shift for the initial RRR, which is zero in this case */
  892. e[1] = 0.;
  893. return;
  894. }
  895. /* General case: tridiagonal matrix of order > 1 */
  896. /* Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter. */
  897. /* Compute maximum off-diagonal entry and pivmin. */
  898. gl = d__[1];
  899. gu = d__[1];
  900. eold = 0.;
  901. emax = 0.;
  902. e[*n] = 0.;
  903. i__1 = *n;
  904. for (i__ = 1; i__ <= i__1; ++i__) {
  905. werr[i__] = 0.;
  906. wgap[i__] = 0.;
  907. eabs = (d__1 = e[i__], abs(d__1));
  908. if (eabs >= emax) {
  909. emax = eabs;
  910. }
  911. tmp1 = eabs + eold;
  912. gers[(i__ << 1) - 1] = d__[i__] - tmp1;
  913. /* Computing MIN */
  914. d__1 = gl, d__2 = gers[(i__ << 1) - 1];
  915. gl = f2cmin(d__1,d__2);
  916. gers[i__ * 2] = d__[i__] + tmp1;
  917. /* Computing MAX */
  918. d__1 = gu, d__2 = gers[i__ * 2];
  919. gu = f2cmax(d__1,d__2);
  920. eold = eabs;
  921. /* L5: */
  922. }
  923. /* The minimum pivot allowed in the Sturm sequence for T */
  924. /* Computing MAX */
  925. /* Computing 2nd power */
  926. d__3 = emax;
  927. d__1 = 1., d__2 = d__3 * d__3;
  928. *pivmin = safmin * f2cmax(d__1,d__2);
  929. /* Compute spectral diameter. The Gerschgorin bounds give an */
  930. /* estimate that is wrong by at most a factor of SQRT(2) */
  931. spdiam = gu - gl;
  932. /* Compute splitting points */
  933. dlarra_(n, &d__[1], &e[1], &e2[1], spltol, &spdiam, nsplit, &isplit[1], &
  934. iinfo);
  935. /* Can force use of bisection instead of faster DQDS. */
  936. /* Option left in the code for future multisection work. */
  937. forceb = FALSE_;
  938. /* Initialize USEDQD, DQDS should be used for ALLRNG unless someone */
  939. /* explicitly wants bisection. */
  940. usedqd = irange == 1 && ! forceb;
  941. if (irange == 1 && ! forceb) {
  942. /* Set interval [VL,VU] that contains all eigenvalues */
  943. *vl = gl;
  944. *vu = gu;
  945. } else {
  946. /* We call DLARRD to find crude approximations to the eigenvalues */
  947. /* in the desired range. In case IRANGE = INDRNG, we also obtain the */
  948. /* interval (VL,VU] that contains all the wanted eigenvalues. */
  949. /* An interval [LEFT,RIGHT] has converged if */
  950. /* RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT)) */
  951. /* DLARRD needs a WORK of size 4*N, IWORK of size 3*N */
  952. dlarrd_(range, "B", n, vl, vu, il, iu, &gers[1], &bsrtol, &d__[1], &e[
  953. 1], &e2[1], pivmin, nsplit, &isplit[1], &mm, &w[1], &werr[1],
  954. vl, vu, &iblock[1], &indexw[1], &work[1], &iwork[1], &iinfo);
  955. if (iinfo != 0) {
  956. *info = -1;
  957. return;
  958. }
  959. /* Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0 */
  960. i__1 = *n;
  961. for (i__ = mm + 1; i__ <= i__1; ++i__) {
  962. w[i__] = 0.;
  963. werr[i__] = 0.;
  964. iblock[i__] = 0;
  965. indexw[i__] = 0;
  966. /* L14: */
  967. }
  968. }
  969. /* ** */
  970. /* Loop over unreduced blocks */
  971. ibegin = 1;
  972. wbegin = 1;
  973. i__1 = *nsplit;
  974. for (jblk = 1; jblk <= i__1; ++jblk) {
  975. iend = isplit[jblk];
  976. in = iend - ibegin + 1;
  977. /* 1 X 1 block */
  978. if (in == 1) {
  979. if (irange == 1 || irange == 3 && d__[ibegin] > *vl && d__[ibegin]
  980. <= *vu || irange == 2 && iblock[wbegin] == jblk) {
  981. ++(*m);
  982. w[*m] = d__[ibegin];
  983. werr[*m] = 0.;
  984. /* The gap for a single block doesn't matter for the later */
  985. /* algorithm and is assigned an arbitrary large value */
  986. wgap[*m] = 0.;
  987. iblock[*m] = jblk;
  988. indexw[*m] = 1;
  989. ++wbegin;
  990. }
  991. /* E( IEND ) holds the shift for the initial RRR */
  992. e[iend] = 0.;
  993. ibegin = iend + 1;
  994. goto L170;
  995. }
  996. /* Blocks of size larger than 1x1 */
  997. /* E( IEND ) will hold the shift for the initial RRR, for now set it =0 */
  998. e[iend] = 0.;
  999. /* Find local outer bounds GL,GU for the block */
  1000. gl = d__[ibegin];
  1001. gu = d__[ibegin];
  1002. i__2 = iend;
  1003. for (i__ = ibegin; i__ <= i__2; ++i__) {
  1004. /* Computing MIN */
  1005. d__1 = gers[(i__ << 1) - 1];
  1006. gl = f2cmin(d__1,gl);
  1007. /* Computing MAX */
  1008. d__1 = gers[i__ * 2];
  1009. gu = f2cmax(d__1,gu);
  1010. /* L15: */
  1011. }
  1012. spdiam = gu - gl;
  1013. if (! (irange == 1 && ! forceb)) {
  1014. /* Count the number of eigenvalues in the current block. */
  1015. mb = 0;
  1016. i__2 = mm;
  1017. for (i__ = wbegin; i__ <= i__2; ++i__) {
  1018. if (iblock[i__] == jblk) {
  1019. ++mb;
  1020. } else {
  1021. goto L21;
  1022. }
  1023. /* L20: */
  1024. }
  1025. L21:
  1026. if (mb == 0) {
  1027. /* No eigenvalue in the current block lies in the desired range */
  1028. /* E( IEND ) holds the shift for the initial RRR */
  1029. e[iend] = 0.;
  1030. ibegin = iend + 1;
  1031. goto L170;
  1032. } else {
  1033. /* Decide whether dqds or bisection is more efficient */
  1034. usedqd = (doublereal) mb > in * .5 && ! forceb;
  1035. wend = wbegin + mb - 1;
  1036. /* Calculate gaps for the current block */
  1037. /* In later stages, when representations for individual */
  1038. /* eigenvalues are different, we use SIGMA = E( IEND ). */
  1039. sigma = 0.;
  1040. i__2 = wend - 1;
  1041. for (i__ = wbegin; i__ <= i__2; ++i__) {
  1042. /* Computing MAX */
  1043. d__1 = 0., d__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] +
  1044. werr[i__]);
  1045. wgap[i__] = f2cmax(d__1,d__2);
  1046. /* L30: */
  1047. }
  1048. /* Computing MAX */
  1049. d__1 = 0., d__2 = *vu - sigma - (w[wend] + werr[wend]);
  1050. wgap[wend] = f2cmax(d__1,d__2);
  1051. /* Find local index of the first and last desired evalue. */
  1052. indl = indexw[wbegin];
  1053. indu = indexw[wend];
  1054. }
  1055. }
  1056. if (irange == 1 && ! forceb || usedqd) {
  1057. /* Case of DQDS */
  1058. /* Find approximations to the extremal eigenvalues of the block */
  1059. dlarrk_(&in, &c__1, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
  1060. rtl, &tmp, &tmp1, &iinfo);
  1061. if (iinfo != 0) {
  1062. *info = -1;
  1063. return;
  1064. }
  1065. /* Computing MAX */
  1066. d__2 = gl, d__3 = tmp - tmp1 - eps * 100. * (d__1 = tmp - tmp1,
  1067. abs(d__1));
  1068. isleft = f2cmax(d__2,d__3);
  1069. dlarrk_(&in, &in, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
  1070. rtl, &tmp, &tmp1, &iinfo);
  1071. if (iinfo != 0) {
  1072. *info = -1;
  1073. return;
  1074. }
  1075. /* Computing MIN */
  1076. d__2 = gu, d__3 = tmp + tmp1 + eps * 100. * (d__1 = tmp + tmp1,
  1077. abs(d__1));
  1078. isrght = f2cmin(d__2,d__3);
  1079. /* Improve the estimate of the spectral diameter */
  1080. spdiam = isrght - isleft;
  1081. } else {
  1082. /* Case of bisection */
  1083. /* Find approximations to the wanted extremal eigenvalues */
  1084. /* Computing MAX */
  1085. d__2 = gl, d__3 = w[wbegin] - werr[wbegin] - eps * 100. * (d__1 =
  1086. w[wbegin] - werr[wbegin], abs(d__1));
  1087. isleft = f2cmax(d__2,d__3);
  1088. /* Computing MIN */
  1089. d__2 = gu, d__3 = w[wend] + werr[wend] + eps * 100. * (d__1 = w[
  1090. wend] + werr[wend], abs(d__1));
  1091. isrght = f2cmin(d__2,d__3);
  1092. }
  1093. /* Decide whether the base representation for the current block */
  1094. /* L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I */
  1095. /* should be on the left or the right end of the current block. */
  1096. /* The strategy is to shift to the end which is "more populated" */
  1097. /* Furthermore, decide whether to use DQDS for the computation of */
  1098. /* the eigenvalue approximations at the end of DLARRE or bisection. */
  1099. /* dqds is chosen if all eigenvalues are desired or the number of */
  1100. /* eigenvalues to be computed is large compared to the blocksize. */
  1101. if (irange == 1 && ! forceb) {
  1102. /* If all the eigenvalues have to be computed, we use dqd */
  1103. usedqd = TRUE_;
  1104. /* INDL is the local index of the first eigenvalue to compute */
  1105. indl = 1;
  1106. indu = in;
  1107. /* MB = number of eigenvalues to compute */
  1108. mb = in;
  1109. wend = wbegin + mb - 1;
  1110. /* Define 1/4 and 3/4 points of the spectrum */
  1111. s1 = isleft + spdiam * .25;
  1112. s2 = isrght - spdiam * .25;
  1113. } else {
  1114. /* DLARRD has computed IBLOCK and INDEXW for each eigenvalue */
  1115. /* approximation. */
  1116. /* choose sigma */
  1117. if (usedqd) {
  1118. s1 = isleft + spdiam * .25;
  1119. s2 = isrght - spdiam * .25;
  1120. } else {
  1121. tmp = f2cmin(isrght,*vu) - f2cmax(isleft,*vl);
  1122. s1 = f2cmax(isleft,*vl) + tmp * .25;
  1123. s2 = f2cmin(isrght,*vu) - tmp * .25;
  1124. }
  1125. }
  1126. /* Compute the negcount at the 1/4 and 3/4 points */
  1127. if (mb > 1) {
  1128. dlarrc_("T", &in, &s1, &s2, &d__[ibegin], &e[ibegin], pivmin, &
  1129. cnt, &cnt1, &cnt2, &iinfo);
  1130. }
  1131. if (mb == 1) {
  1132. sigma = gl;
  1133. sgndef = 1.;
  1134. } else if (cnt1 - indl >= indu - cnt2) {
  1135. if (irange == 1 && ! forceb) {
  1136. sigma = f2cmax(isleft,gl);
  1137. } else if (usedqd) {
  1138. /* use Gerschgorin bound as shift to get pos def matrix */
  1139. /* for dqds */
  1140. sigma = isleft;
  1141. } else {
  1142. /* use approximation of the first desired eigenvalue of the */
  1143. /* block as shift */
  1144. sigma = f2cmax(isleft,*vl);
  1145. }
  1146. sgndef = 1.;
  1147. } else {
  1148. if (irange == 1 && ! forceb) {
  1149. sigma = f2cmin(isrght,gu);
  1150. } else if (usedqd) {
  1151. /* use Gerschgorin bound as shift to get neg def matrix */
  1152. /* for dqds */
  1153. sigma = isrght;
  1154. } else {
  1155. /* use approximation of the first desired eigenvalue of the */
  1156. /* block as shift */
  1157. sigma = f2cmin(isrght,*vu);
  1158. }
  1159. sgndef = -1.;
  1160. }
  1161. /* An initial SIGMA has been chosen that will be used for computing */
  1162. /* T - SIGMA I = L D L^T */
  1163. /* Define the increment TAU of the shift in case the initial shift */
  1164. /* needs to be refined to obtain a factorization with not too much */
  1165. /* element growth. */
  1166. if (usedqd) {
  1167. /* The initial SIGMA was to the outer end of the spectrum */
  1168. /* the matrix is definite and we need not retreat. */
  1169. tau = spdiam * eps * *n + *pivmin * 2.;
  1170. /* Computing MAX */
  1171. d__1 = tau, d__2 = eps * 2. * abs(sigma);
  1172. tau = f2cmax(d__1,d__2);
  1173. } else {
  1174. if (mb > 1) {
  1175. clwdth = w[wend] + werr[wend] - w[wbegin] - werr[wbegin];
  1176. avgap = (d__1 = clwdth / (doublereal) (wend - wbegin), abs(
  1177. d__1));
  1178. if (sgndef == 1.) {
  1179. /* Computing MAX */
  1180. d__1 = wgap[wbegin];
  1181. tau = f2cmax(d__1,avgap) * .5;
  1182. /* Computing MAX */
  1183. d__1 = tau, d__2 = werr[wbegin];
  1184. tau = f2cmax(d__1,d__2);
  1185. } else {
  1186. /* Computing MAX */
  1187. d__1 = wgap[wend - 1];
  1188. tau = f2cmax(d__1,avgap) * .5;
  1189. /* Computing MAX */
  1190. d__1 = tau, d__2 = werr[wend];
  1191. tau = f2cmax(d__1,d__2);
  1192. }
  1193. } else {
  1194. tau = werr[wbegin];
  1195. }
  1196. }
  1197. for (idum = 1; idum <= 6; ++idum) {
  1198. /* Compute L D L^T factorization of tridiagonal matrix T - sigma I. */
  1199. /* Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of */
  1200. /* pivots in WORK(2*IN+1:3*IN) */
  1201. dpivot = d__[ibegin] - sigma;
  1202. work[1] = dpivot;
  1203. dmax__ = abs(work[1]);
  1204. j = ibegin;
  1205. i__2 = in - 1;
  1206. for (i__ = 1; i__ <= i__2; ++i__) {
  1207. work[(in << 1) + i__] = 1. / work[i__];
  1208. tmp = e[j] * work[(in << 1) + i__];
  1209. work[in + i__] = tmp;
  1210. dpivot = d__[j + 1] - sigma - tmp * e[j];
  1211. work[i__ + 1] = dpivot;
  1212. /* Computing MAX */
  1213. d__1 = dmax__, d__2 = abs(dpivot);
  1214. dmax__ = f2cmax(d__1,d__2);
  1215. ++j;
  1216. /* L70: */
  1217. }
  1218. /* check for element growth */
  1219. if (dmax__ > spdiam * 64.) {
  1220. norep = TRUE_;
  1221. } else {
  1222. norep = FALSE_;
  1223. }
  1224. if (usedqd && ! norep) {
  1225. /* Ensure the definiteness of the representation */
  1226. /* All entries of D (of L D L^T) must have the same sign */
  1227. i__2 = in;
  1228. for (i__ = 1; i__ <= i__2; ++i__) {
  1229. tmp = sgndef * work[i__];
  1230. if (tmp < 0.) {
  1231. norep = TRUE_;
  1232. }
  1233. /* L71: */
  1234. }
  1235. }
  1236. if (norep) {
  1237. /* Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin */
  1238. /* shift which makes the matrix definite. So we should end up */
  1239. /* here really only in the case of IRANGE = VALRNG or INDRNG. */
  1240. if (idum == 5) {
  1241. if (sgndef == 1.) {
  1242. /* The fudged Gerschgorin shift should succeed */
  1243. sigma = gl - spdiam * 2. * eps * *n - *pivmin * 4.;
  1244. } else {
  1245. sigma = gu + spdiam * 2. * eps * *n + *pivmin * 4.;
  1246. }
  1247. } else {
  1248. sigma -= sgndef * tau;
  1249. tau *= 2.;
  1250. }
  1251. } else {
  1252. /* an initial RRR is found */
  1253. goto L83;
  1254. }
  1255. /* L80: */
  1256. }
  1257. /* if the program reaches this point, no base representation could be */
  1258. /* found in MAXTRY iterations. */
  1259. *info = 2;
  1260. return;
  1261. L83:
  1262. /* At this point, we have found an initial base representation */
  1263. /* T - SIGMA I = L D L^T with not too much element growth. */
  1264. /* Store the shift. */
  1265. e[iend] = sigma;
  1266. /* Store D and L. */
  1267. dcopy_(&in, &work[1], &c__1, &d__[ibegin], &c__1);
  1268. i__2 = in - 1;
  1269. dcopy_(&i__2, &work[in + 1], &c__1, &e[ibegin], &c__1);
  1270. if (mb > 1) {
  1271. /* Perturb each entry of the base representation by a small */
  1272. /* (but random) relative amount to overcome difficulties with */
  1273. /* glued matrices. */
  1274. for (i__ = 1; i__ <= 4; ++i__) {
  1275. iseed[i__ - 1] = 1;
  1276. /* L122: */
  1277. }
  1278. i__2 = (in << 1) - 1;
  1279. dlarnv_(&c__2, iseed, &i__2, &work[1]);
  1280. i__2 = in - 1;
  1281. for (i__ = 1; i__ <= i__2; ++i__) {
  1282. d__[ibegin + i__ - 1] *= eps * 8. * work[i__] + 1.;
  1283. e[ibegin + i__ - 1] *= eps * 8. * work[in + i__] + 1.;
  1284. /* L125: */
  1285. }
  1286. d__[iend] *= eps * 4. * work[in] + 1.;
  1287. }
  1288. /* Don't update the Gerschgorin intervals because keeping track */
  1289. /* of the updates would be too much work in DLARRV. */
  1290. /* We update W instead and use it to locate the proper Gerschgorin */
  1291. /* intervals. */
  1292. /* Compute the required eigenvalues of L D L' by bisection or dqds */
  1293. if (! usedqd) {
  1294. /* If DLARRD has been used, shift the eigenvalue approximations */
  1295. /* according to their representation. This is necessary for */
  1296. /* a uniform DLARRV since dqds computes eigenvalues of the */
  1297. /* shifted representation. In DLARRV, W will always hold the */
  1298. /* UNshifted eigenvalue approximation. */
  1299. i__2 = wend;
  1300. for (j = wbegin; j <= i__2; ++j) {
  1301. w[j] -= sigma;
  1302. werr[j] += (d__1 = w[j], abs(d__1)) * eps;
  1303. /* L134: */
  1304. }
  1305. /* call DLARRB to reduce eigenvalue error of the approximations */
  1306. /* from DLARRD */
  1307. i__2 = iend - 1;
  1308. for (i__ = ibegin; i__ <= i__2; ++i__) {
  1309. /* Computing 2nd power */
  1310. d__1 = e[i__];
  1311. work[i__] = d__[i__] * (d__1 * d__1);
  1312. /* L135: */
  1313. }
  1314. /* use bisection to find EV from INDL to INDU */
  1315. i__2 = indl - 1;
  1316. dlarrb_(&in, &d__[ibegin], &work[ibegin], &indl, &indu, rtol1,
  1317. rtol2, &i__2, &w[wbegin], &wgap[wbegin], &werr[wbegin], &
  1318. work[(*n << 1) + 1], &iwork[1], pivmin, &spdiam, &in, &
  1319. iinfo);
  1320. if (iinfo != 0) {
  1321. *info = -4;
  1322. return;
  1323. }
  1324. /* DLARRB computes all gaps correctly except for the last one */
  1325. /* Record distance to VU/GU */
  1326. /* Computing MAX */
  1327. d__1 = 0., d__2 = *vu - sigma - (w[wend] + werr[wend]);
  1328. wgap[wend] = f2cmax(d__1,d__2);
  1329. i__2 = indu;
  1330. for (i__ = indl; i__ <= i__2; ++i__) {
  1331. ++(*m);
  1332. iblock[*m] = jblk;
  1333. indexw[*m] = i__;
  1334. /* L138: */
  1335. }
  1336. } else {
  1337. /* Call dqds to get all eigs (and then possibly delete unwanted */
  1338. /* eigenvalues). */
  1339. /* Note that dqds finds the eigenvalues of the L D L^T representation */
  1340. /* of T to high relative accuracy. High relative accuracy */
  1341. /* might be lost when the shift of the RRR is subtracted to obtain */
  1342. /* the eigenvalues of T. However, T is not guaranteed to define its */
  1343. /* eigenvalues to high relative accuracy anyway. */
  1344. /* Set RTOL to the order of the tolerance used in DLASQ2 */
  1345. /* This is an ESTIMATED error, the worst case bound is 4*N*EPS */
  1346. /* which is usually too large and requires unnecessary work to be */
  1347. /* done by bisection when computing the eigenvectors */
  1348. rtol = log((doublereal) in) * 4. * eps;
  1349. j = ibegin;
  1350. i__2 = in - 1;
  1351. for (i__ = 1; i__ <= i__2; ++i__) {
  1352. work[(i__ << 1) - 1] = (d__1 = d__[j], abs(d__1));
  1353. work[i__ * 2] = e[j] * e[j] * work[(i__ << 1) - 1];
  1354. ++j;
  1355. /* L140: */
  1356. }
  1357. work[(in << 1) - 1] = (d__1 = d__[iend], abs(d__1));
  1358. work[in * 2] = 0.;
  1359. dlasq2_(&in, &work[1], &iinfo);
  1360. if (iinfo != 0) {
  1361. /* If IINFO = -5 then an index is part of a tight cluster */
  1362. /* and should be changed. The index is in IWORK(1) and the */
  1363. /* gap is in WORK(N+1) */
  1364. *info = -5;
  1365. return;
  1366. } else {
  1367. /* Test that all eigenvalues are positive as expected */
  1368. i__2 = in;
  1369. for (i__ = 1; i__ <= i__2; ++i__) {
  1370. if (work[i__] < 0.) {
  1371. *info = -6;
  1372. return;
  1373. }
  1374. /* L149: */
  1375. }
  1376. }
  1377. if (sgndef > 0.) {
  1378. i__2 = indu;
  1379. for (i__ = indl; i__ <= i__2; ++i__) {
  1380. ++(*m);
  1381. w[*m] = work[in - i__ + 1];
  1382. iblock[*m] = jblk;
  1383. indexw[*m] = i__;
  1384. /* L150: */
  1385. }
  1386. } else {
  1387. i__2 = indu;
  1388. for (i__ = indl; i__ <= i__2; ++i__) {
  1389. ++(*m);
  1390. w[*m] = -work[i__];
  1391. iblock[*m] = jblk;
  1392. indexw[*m] = i__;
  1393. /* L160: */
  1394. }
  1395. }
  1396. i__2 = *m;
  1397. for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
  1398. /* the value of RTOL below should be the tolerance in DLASQ2 */
  1399. werr[i__] = rtol * (d__1 = w[i__], abs(d__1));
  1400. /* L165: */
  1401. }
  1402. i__2 = *m - 1;
  1403. for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
  1404. /* compute the right gap between the intervals */
  1405. /* Computing MAX */
  1406. d__1 = 0., d__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] + werr[
  1407. i__]);
  1408. wgap[i__] = f2cmax(d__1,d__2);
  1409. /* L166: */
  1410. }
  1411. /* Computing MAX */
  1412. d__1 = 0., d__2 = *vu - sigma - (w[*m] + werr[*m]);
  1413. wgap[*m] = f2cmax(d__1,d__2);
  1414. }
  1415. /* proceed with next block */
  1416. ibegin = iend + 1;
  1417. wbegin = wend + 1;
  1418. L170:
  1419. ;
  1420. }
  1421. return;
  1422. /* end of DLARRE */
  1423. } /* dlarre_ */