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.

slarre.c 47 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  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 SLARRE 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 SLARRE + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarre.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarre.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarre.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE SLARRE( 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. /* REAL PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU */
  512. /* INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ), */
  513. /* $ INDEXW( * ) */
  514. /* REAL 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, SLARRE 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. /* > SSTEMR 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 SLASQ2) to */
  531. /* > conpute all and then discard any unwanted one. */
  532. /* > As an added benefit, SLARRE 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 REAL */
  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', SLARRE computes bounds on the desired */
  560. /* > part of the spectrum. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in,out] VU */
  564. /* > \verbatim */
  565. /* > VU is REAL */
  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', SLARRE 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 REAL 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 REAL 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 REAL 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 REAL */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[in] RTOL2 */
  624. /* > \verbatim */
  625. /* > RTOL2 is REAL */
  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 REAL */
  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 REAL 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 ( SLARRE may use the */
  666. /* > remaining N-M elements as workspace). */
  667. /* > \endverbatim */
  668. /* > */
  669. /* > \param[out] WERR */
  670. /* > \verbatim */
  671. /* > WERR is REAL 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 REAL 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 REAL 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 REAL */
  711. /* > The minimum pivot in the Sturm sequence for T. */
  712. /* > \endverbatim */
  713. /* > */
  714. /* > \param[out] WORK */
  715. /* > \verbatim */
  716. /* > WORK is REAL 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 SLARRE. */
  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 SLARRD. */
  736. /* > = 2: No base representation could be found in MAXTRY iterations. */
  737. /* > Increasing MAXTRY and recompilation might be a remedy. */
  738. /* > =-3: Problem in SLARRB when computing the refined root */
  739. /* > representation for SLASQ2. */
  740. /* > =-4: Problem in SLARRB when preforming bisection on the */
  741. /* > desired part of the spectrum. */
  742. /* > =-5: Problem in SLASQ2. */
  743. /* > =-6: Problem in SLASQ2. */
  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 slarre_(char *range, integer *n, real *vl, real *vu,
  773. integer *il, integer *iu, real *d__, real *e, real *e2, real *rtol1,
  774. real *rtol2, real *spltol, integer *nsplit, integer *isplit, integer *
  775. m, real *w, real *werr, real *wgap, integer *iblock, integer *indexw,
  776. real *gers, real *pivmin, real *work, integer *iwork, integer *info)
  777. {
  778. /* System generated locals */
  779. integer i__1, i__2;
  780. real r__1, r__2, r__3;
  781. /* Local variables */
  782. real eabs;
  783. integer iend, jblk;
  784. real eold;
  785. integer indl;
  786. real dmax__, emax;
  787. integer wend, idum, indu;
  788. real rtol;
  789. integer i__, j, iseed[4];
  790. real avgap, sigma;
  791. extern logical lsame_(char *, char *);
  792. integer iinfo;
  793. logical norep;
  794. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  795. integer *);
  796. real s1, s2;
  797. extern /* Subroutine */ void slasq2_(integer *, real *, integer *);
  798. integer mb;
  799. real gl;
  800. integer in, mm;
  801. real gu;
  802. integer ibegin;
  803. logical forceb;
  804. integer irange;
  805. real sgndef;
  806. extern real slamch_(char *);
  807. integer wbegin;
  808. real safmin, spdiam;
  809. extern /* Subroutine */ void slarra_(integer *, real *, real *, real *,
  810. real *, real *, integer *, integer *, integer *);
  811. logical usedqd;
  812. real clwdth, isleft;
  813. extern /* Subroutine */ void slarrb_(integer *, real *, real *, integer *,
  814. integer *, real *, real *, integer *, real *, real *, real *,
  815. real *, integer *, real *, real *, integer *, integer *), slarrc_(
  816. char *, integer *, real *, real *, real *, real *, real *,
  817. integer *, integer *, integer *, integer *), slarrd_(char
  818. *, char *, integer *, real *, real *, integer *, integer *, real *
  819. , real *, real *, real *, real *, real *, integer *, integer *,
  820. integer *, real *, real *, real *, real *, integer *, integer *,
  821. real *, integer *, integer *), slarrk_(integer *,
  822. integer *, real *, real *, real *, real *, real *, real *, real *,
  823. real *, integer *);
  824. real isrght, bsrtol, dpivot;
  825. extern /* Subroutine */ void slarnv_(integer *, integer *, integer *, real
  826. *);
  827. integer cnt;
  828. real eps, tau, tmp, rtl;
  829. integer cnt1, cnt2;
  830. real tmp1;
  831. /* -- LAPACK auxiliary routine (version 3.8.0) -- */
  832. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  833. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  834. /* June 2016 */
  835. /* ===================================================================== */
  836. /* Parameter adjustments */
  837. --iwork;
  838. --work;
  839. --gers;
  840. --indexw;
  841. --iblock;
  842. --wgap;
  843. --werr;
  844. --w;
  845. --isplit;
  846. --e2;
  847. --e;
  848. --d__;
  849. /* Function Body */
  850. *info = 0;
  851. /* Quick return if possible */
  852. if (*n <= 0) {
  853. return;
  854. }
  855. /* Decode RANGE */
  856. if (lsame_(range, "A")) {
  857. irange = 1;
  858. } else if (lsame_(range, "V")) {
  859. irange = 3;
  860. } else if (lsame_(range, "I")) {
  861. irange = 2;
  862. }
  863. *m = 0;
  864. /* Get machine constants */
  865. safmin = slamch_("S");
  866. eps = slamch_("P");
  867. /* Set parameters */
  868. rtl = eps * 100.f;
  869. /* If one were ever to ask for less initial precision in BSRTOL, */
  870. /* one should keep in mind that for the subset case, the extremal */
  871. /* eigenvalues must be at least as accurate as the current setting */
  872. /* (eigenvalues in the middle need not as much accuracy) */
  873. bsrtol = sqrt(eps) * 5e-4f;
  874. /* Treat case of 1x1 matrix for quick return */
  875. if (*n == 1) {
  876. if (irange == 1 || irange == 3 && d__[1] > *vl && d__[1] <= *vu ||
  877. irange == 2 && *il == 1 && *iu == 1) {
  878. *m = 1;
  879. w[1] = d__[1];
  880. /* The computation error of the eigenvalue is zero */
  881. werr[1] = 0.f;
  882. wgap[1] = 0.f;
  883. iblock[1] = 1;
  884. indexw[1] = 1;
  885. gers[1] = d__[1];
  886. gers[2] = d__[1];
  887. }
  888. /* store the shift for the initial RRR, which is zero in this case */
  889. e[1] = 0.f;
  890. return;
  891. }
  892. /* General case: tridiagonal matrix of order > 1 */
  893. /* Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter. */
  894. /* Compute maximum off-diagonal entry and pivmin. */
  895. gl = d__[1];
  896. gu = d__[1];
  897. eold = 0.f;
  898. emax = 0.f;
  899. e[*n] = 0.f;
  900. i__1 = *n;
  901. for (i__ = 1; i__ <= i__1; ++i__) {
  902. werr[i__] = 0.f;
  903. wgap[i__] = 0.f;
  904. eabs = (r__1 = e[i__], abs(r__1));
  905. if (eabs >= emax) {
  906. emax = eabs;
  907. }
  908. tmp1 = eabs + eold;
  909. gers[(i__ << 1) - 1] = d__[i__] - tmp1;
  910. /* Computing MIN */
  911. r__1 = gl, r__2 = gers[(i__ << 1) - 1];
  912. gl = f2cmin(r__1,r__2);
  913. gers[i__ * 2] = d__[i__] + tmp1;
  914. /* Computing MAX */
  915. r__1 = gu, r__2 = gers[i__ * 2];
  916. gu = f2cmax(r__1,r__2);
  917. eold = eabs;
  918. /* L5: */
  919. }
  920. /* The minimum pivot allowed in the Sturm sequence for T */
  921. /* Computing MAX */
  922. /* Computing 2nd power */
  923. r__3 = emax;
  924. r__1 = 1.f, r__2 = r__3 * r__3;
  925. *pivmin = safmin * f2cmax(r__1,r__2);
  926. /* Compute spectral diameter. The Gerschgorin bounds give an */
  927. /* estimate that is wrong by at most a factor of SQRT(2) */
  928. spdiam = gu - gl;
  929. /* Compute splitting points */
  930. slarra_(n, &d__[1], &e[1], &e2[1], spltol, &spdiam, nsplit, &isplit[1], &
  931. iinfo);
  932. /* Can force use of bisection instead of faster DQDS. */
  933. /* Option left in the code for future multisection work. */
  934. forceb = FALSE_;
  935. /* Initialize USEDQD, DQDS should be used for ALLRNG unless someone */
  936. /* explicitly wants bisection. */
  937. usedqd = irange == 1 && ! forceb;
  938. if (irange == 1 && ! forceb) {
  939. /* Set interval [VL,VU] that contains all eigenvalues */
  940. *vl = gl;
  941. *vu = gu;
  942. } else {
  943. /* We call SLARRD to find crude approximations to the eigenvalues */
  944. /* in the desired range. In case IRANGE = INDRNG, we also obtain the */
  945. /* interval (VL,VU] that contains all the wanted eigenvalues. */
  946. /* An interval [LEFT,RIGHT] has converged if */
  947. /* RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT)) */
  948. /* SLARRD needs a WORK of size 4*N, IWORK of size 3*N */
  949. slarrd_(range, "B", n, vl, vu, il, iu, &gers[1], &bsrtol, &d__[1], &e[
  950. 1], &e2[1], pivmin, nsplit, &isplit[1], &mm, &w[1], &werr[1],
  951. vl, vu, &iblock[1], &indexw[1], &work[1], &iwork[1], &iinfo);
  952. if (iinfo != 0) {
  953. *info = -1;
  954. return;
  955. }
  956. /* Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0 */
  957. i__1 = *n;
  958. for (i__ = mm + 1; i__ <= i__1; ++i__) {
  959. w[i__] = 0.f;
  960. werr[i__] = 0.f;
  961. iblock[i__] = 0;
  962. indexw[i__] = 0;
  963. /* L14: */
  964. }
  965. }
  966. /* ** */
  967. /* Loop over unreduced blocks */
  968. ibegin = 1;
  969. wbegin = 1;
  970. i__1 = *nsplit;
  971. for (jblk = 1; jblk <= i__1; ++jblk) {
  972. iend = isplit[jblk];
  973. in = iend - ibegin + 1;
  974. /* 1 X 1 block */
  975. if (in == 1) {
  976. if (irange == 1 || irange == 3 && d__[ibegin] > *vl && d__[ibegin]
  977. <= *vu || irange == 2 && iblock[wbegin] == jblk) {
  978. ++(*m);
  979. w[*m] = d__[ibegin];
  980. werr[*m] = 0.f;
  981. /* The gap for a single block doesn't matter for the later */
  982. /* algorithm and is assigned an arbitrary large value */
  983. wgap[*m] = 0.f;
  984. iblock[*m] = jblk;
  985. indexw[*m] = 1;
  986. ++wbegin;
  987. }
  988. /* E( IEND ) holds the shift for the initial RRR */
  989. e[iend] = 0.f;
  990. ibegin = iend + 1;
  991. goto L170;
  992. }
  993. /* Blocks of size larger than 1x1 */
  994. /* E( IEND ) will hold the shift for the initial RRR, for now set it =0 */
  995. e[iend] = 0.f;
  996. /* Find local outer bounds GL,GU for the block */
  997. gl = d__[ibegin];
  998. gu = d__[ibegin];
  999. i__2 = iend;
  1000. for (i__ = ibegin; i__ <= i__2; ++i__) {
  1001. /* Computing MIN */
  1002. r__1 = gers[(i__ << 1) - 1];
  1003. gl = f2cmin(r__1,gl);
  1004. /* Computing MAX */
  1005. r__1 = gers[i__ * 2];
  1006. gu = f2cmax(r__1,gu);
  1007. /* L15: */
  1008. }
  1009. spdiam = gu - gl;
  1010. if (! (irange == 1 && ! forceb)) {
  1011. /* Count the number of eigenvalues in the current block. */
  1012. mb = 0;
  1013. i__2 = mm;
  1014. for (i__ = wbegin; i__ <= i__2; ++i__) {
  1015. if (iblock[i__] == jblk) {
  1016. ++mb;
  1017. } else {
  1018. goto L21;
  1019. }
  1020. /* L20: */
  1021. }
  1022. L21:
  1023. if (mb == 0) {
  1024. /* No eigenvalue in the current block lies in the desired range */
  1025. /* E( IEND ) holds the shift for the initial RRR */
  1026. e[iend] = 0.f;
  1027. ibegin = iend + 1;
  1028. goto L170;
  1029. } else {
  1030. /* Decide whether dqds or bisection is more efficient */
  1031. usedqd = (real) mb > in * .5f && ! forceb;
  1032. wend = wbegin + mb - 1;
  1033. /* Calculate gaps for the current block */
  1034. /* In later stages, when representations for individual */
  1035. /* eigenvalues are different, we use SIGMA = E( IEND ). */
  1036. sigma = 0.f;
  1037. i__2 = wend - 1;
  1038. for (i__ = wbegin; i__ <= i__2; ++i__) {
  1039. /* Computing MAX */
  1040. r__1 = 0.f, r__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] +
  1041. werr[i__]);
  1042. wgap[i__] = f2cmax(r__1,r__2);
  1043. /* L30: */
  1044. }
  1045. /* Computing MAX */
  1046. r__1 = 0.f, r__2 = *vu - sigma - (w[wend] + werr[wend]);
  1047. wgap[wend] = f2cmax(r__1,r__2);
  1048. /* Find local index of the first and last desired evalue. */
  1049. indl = indexw[wbegin];
  1050. indu = indexw[wend];
  1051. }
  1052. }
  1053. if (irange == 1 && ! forceb || usedqd) {
  1054. /* Case of DQDS */
  1055. /* Find approximations to the extremal eigenvalues of the block */
  1056. slarrk_(&in, &c__1, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
  1057. rtl, &tmp, &tmp1, &iinfo);
  1058. if (iinfo != 0) {
  1059. *info = -1;
  1060. return;
  1061. }
  1062. /* Computing MAX */
  1063. r__2 = gl, r__3 = tmp - tmp1 - eps * 100.f * (r__1 = tmp - tmp1,
  1064. abs(r__1));
  1065. isleft = f2cmax(r__2,r__3);
  1066. slarrk_(&in, &in, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
  1067. rtl, &tmp, &tmp1, &iinfo);
  1068. if (iinfo != 0) {
  1069. *info = -1;
  1070. return;
  1071. }
  1072. /* Computing MIN */
  1073. r__2 = gu, r__3 = tmp + tmp1 + eps * 100.f * (r__1 = tmp + tmp1,
  1074. abs(r__1));
  1075. isrght = f2cmin(r__2,r__3);
  1076. /* Improve the estimate of the spectral diameter */
  1077. spdiam = isrght - isleft;
  1078. } else {
  1079. /* Case of bisection */
  1080. /* Find approximations to the wanted extremal eigenvalues */
  1081. /* Computing MAX */
  1082. r__2 = gl, r__3 = w[wbegin] - werr[wbegin] - eps * 100.f * (r__1 =
  1083. w[wbegin] - werr[wbegin], abs(r__1));
  1084. isleft = f2cmax(r__2,r__3);
  1085. /* Computing MIN */
  1086. r__2 = gu, r__3 = w[wend] + werr[wend] + eps * 100.f * (r__1 = w[
  1087. wend] + werr[wend], abs(r__1));
  1088. isrght = f2cmin(r__2,r__3);
  1089. }
  1090. /* Decide whether the base representation for the current block */
  1091. /* L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I */
  1092. /* should be on the left or the right end of the current block. */
  1093. /* The strategy is to shift to the end which is "more populated" */
  1094. /* Furthermore, decide whether to use DQDS for the computation of */
  1095. /* the eigenvalue approximations at the end of SLARRE or bisection. */
  1096. /* dqds is chosen if all eigenvalues are desired or the number of */
  1097. /* eigenvalues to be computed is large compared to the blocksize. */
  1098. if (irange == 1 && ! forceb) {
  1099. /* If all the eigenvalues have to be computed, we use dqd */
  1100. usedqd = TRUE_;
  1101. /* INDL is the local index of the first eigenvalue to compute */
  1102. indl = 1;
  1103. indu = in;
  1104. /* MB = number of eigenvalues to compute */
  1105. mb = in;
  1106. wend = wbegin + mb - 1;
  1107. /* Define 1/4 and 3/4 points of the spectrum */
  1108. s1 = isleft + spdiam * .25f;
  1109. s2 = isrght - spdiam * .25f;
  1110. } else {
  1111. /* SLARRD has computed IBLOCK and INDEXW for each eigenvalue */
  1112. /* approximation. */
  1113. /* choose sigma */
  1114. if (usedqd) {
  1115. s1 = isleft + spdiam * .25f;
  1116. s2 = isrght - spdiam * .25f;
  1117. } else {
  1118. tmp = f2cmin(isrght,*vu) - f2cmax(isleft,*vl);
  1119. s1 = f2cmax(isleft,*vl) + tmp * .25f;
  1120. s2 = f2cmin(isrght,*vu) - tmp * .25f;
  1121. }
  1122. }
  1123. /* Compute the negcount at the 1/4 and 3/4 points */
  1124. if (mb > 1) {
  1125. slarrc_("T", &in, &s1, &s2, &d__[ibegin], &e[ibegin], pivmin, &
  1126. cnt, &cnt1, &cnt2, &iinfo);
  1127. }
  1128. if (mb == 1) {
  1129. sigma = gl;
  1130. sgndef = 1.f;
  1131. } else if (cnt1 - indl >= indu - cnt2) {
  1132. if (irange == 1 && ! forceb) {
  1133. sigma = f2cmax(isleft,gl);
  1134. } else if (usedqd) {
  1135. /* use Gerschgorin bound as shift to get pos def matrix */
  1136. /* for dqds */
  1137. sigma = isleft;
  1138. } else {
  1139. /* use approximation of the first desired eigenvalue of the */
  1140. /* block as shift */
  1141. sigma = f2cmax(isleft,*vl);
  1142. }
  1143. sgndef = 1.f;
  1144. } else {
  1145. if (irange == 1 && ! forceb) {
  1146. sigma = f2cmin(isrght,gu);
  1147. } else if (usedqd) {
  1148. /* use Gerschgorin bound as shift to get neg def matrix */
  1149. /* for dqds */
  1150. sigma = isrght;
  1151. } else {
  1152. /* use approximation of the first desired eigenvalue of the */
  1153. /* block as shift */
  1154. sigma = f2cmin(isrght,*vu);
  1155. }
  1156. sgndef = -1.f;
  1157. }
  1158. /* An initial SIGMA has been chosen that will be used for computing */
  1159. /* T - SIGMA I = L D L^T */
  1160. /* Define the increment TAU of the shift in case the initial shift */
  1161. /* needs to be refined to obtain a factorization with not too much */
  1162. /* element growth. */
  1163. if (usedqd) {
  1164. /* The initial SIGMA was to the outer end of the spectrum */
  1165. /* the matrix is definite and we need not retreat. */
  1166. tau = spdiam * eps * *n + *pivmin * 2.f;
  1167. /* Computing MAX */
  1168. r__1 = tau, r__2 = eps * 2.f * abs(sigma);
  1169. tau = f2cmax(r__1,r__2);
  1170. } else {
  1171. if (mb > 1) {
  1172. clwdth = w[wend] + werr[wend] - w[wbegin] - werr[wbegin];
  1173. avgap = (r__1 = clwdth / (real) (wend - wbegin), abs(r__1));
  1174. if (sgndef == 1.f) {
  1175. /* Computing MAX */
  1176. r__1 = wgap[wbegin];
  1177. tau = f2cmax(r__1,avgap) * .5f;
  1178. /* Computing MAX */
  1179. r__1 = tau, r__2 = werr[wbegin];
  1180. tau = f2cmax(r__1,r__2);
  1181. } else {
  1182. /* Computing MAX */
  1183. r__1 = wgap[wend - 1];
  1184. tau = f2cmax(r__1,avgap) * .5f;
  1185. /* Computing MAX */
  1186. r__1 = tau, r__2 = werr[wend];
  1187. tau = f2cmax(r__1,r__2);
  1188. }
  1189. } else {
  1190. tau = werr[wbegin];
  1191. }
  1192. }
  1193. for (idum = 1; idum <= 6; ++idum) {
  1194. /* Compute L D L^T factorization of tridiagonal matrix T - sigma I. */
  1195. /* Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of */
  1196. /* pivots in WORK(2*IN+1:3*IN) */
  1197. dpivot = d__[ibegin] - sigma;
  1198. work[1] = dpivot;
  1199. dmax__ = abs(work[1]);
  1200. j = ibegin;
  1201. i__2 = in - 1;
  1202. for (i__ = 1; i__ <= i__2; ++i__) {
  1203. work[(in << 1) + i__] = 1.f / work[i__];
  1204. tmp = e[j] * work[(in << 1) + i__];
  1205. work[in + i__] = tmp;
  1206. dpivot = d__[j + 1] - sigma - tmp * e[j];
  1207. work[i__ + 1] = dpivot;
  1208. /* Computing MAX */
  1209. r__1 = dmax__, r__2 = abs(dpivot);
  1210. dmax__ = f2cmax(r__1,r__2);
  1211. ++j;
  1212. /* L70: */
  1213. }
  1214. /* check for element growth */
  1215. if (dmax__ > spdiam * 64.f) {
  1216. norep = TRUE_;
  1217. } else {
  1218. norep = FALSE_;
  1219. }
  1220. if (usedqd && ! norep) {
  1221. /* Ensure the definiteness of the representation */
  1222. /* All entries of D (of L D L^T) must have the same sign */
  1223. i__2 = in;
  1224. for (i__ = 1; i__ <= i__2; ++i__) {
  1225. tmp = sgndef * work[i__];
  1226. if (tmp < 0.f) {
  1227. norep = TRUE_;
  1228. }
  1229. /* L71: */
  1230. }
  1231. }
  1232. if (norep) {
  1233. /* Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin */
  1234. /* shift which makes the matrix definite. So we should end up */
  1235. /* here really only in the case of IRANGE = VALRNG or INDRNG. */
  1236. if (idum == 5) {
  1237. if (sgndef == 1.f) {
  1238. /* The fudged Gerschgorin shift should succeed */
  1239. sigma = gl - spdiam * 2.f * eps * *n - *pivmin * 4.f;
  1240. } else {
  1241. sigma = gu + spdiam * 2.f * eps * *n + *pivmin * 4.f;
  1242. }
  1243. } else {
  1244. sigma -= sgndef * tau;
  1245. tau *= 2.f;
  1246. }
  1247. } else {
  1248. /* an initial RRR is found */
  1249. goto L83;
  1250. }
  1251. /* L80: */
  1252. }
  1253. /* if the program reaches this point, no base representation could be */
  1254. /* found in MAXTRY iterations. */
  1255. *info = 2;
  1256. return;
  1257. L83:
  1258. /* At this point, we have found an initial base representation */
  1259. /* T - SIGMA I = L D L^T with not too much element growth. */
  1260. /* Store the shift. */
  1261. e[iend] = sigma;
  1262. /* Store D and L. */
  1263. scopy_(&in, &work[1], &c__1, &d__[ibegin], &c__1);
  1264. i__2 = in - 1;
  1265. scopy_(&i__2, &work[in + 1], &c__1, &e[ibegin], &c__1);
  1266. if (mb > 1) {
  1267. /* Perturb each entry of the base representation by a small */
  1268. /* (but random) relative amount to overcome difficulties with */
  1269. /* glued matrices. */
  1270. for (i__ = 1; i__ <= 4; ++i__) {
  1271. iseed[i__ - 1] = 1;
  1272. /* L122: */
  1273. }
  1274. i__2 = (in << 1) - 1;
  1275. slarnv_(&c__2, iseed, &i__2, &work[1]);
  1276. i__2 = in - 1;
  1277. for (i__ = 1; i__ <= i__2; ++i__) {
  1278. d__[ibegin + i__ - 1] *= eps * 4.f * work[i__] + 1.f;
  1279. e[ibegin + i__ - 1] *= eps * 4.f * work[in + i__] + 1.f;
  1280. /* L125: */
  1281. }
  1282. d__[iend] *= eps * 4.f * work[in] + 1.f;
  1283. }
  1284. /* Don't update the Gerschgorin intervals because keeping track */
  1285. /* of the updates would be too much work in SLARRV. */
  1286. /* We update W instead and use it to locate the proper Gerschgorin */
  1287. /* intervals. */
  1288. /* Compute the required eigenvalues of L D L' by bisection or dqds */
  1289. if (! usedqd) {
  1290. /* If SLARRD has been used, shift the eigenvalue approximations */
  1291. /* according to their representation. This is necessary for */
  1292. /* a uniform SLARRV since dqds computes eigenvalues of the */
  1293. /* shifted representation. In SLARRV, W will always hold the */
  1294. /* UNshifted eigenvalue approximation. */
  1295. i__2 = wend;
  1296. for (j = wbegin; j <= i__2; ++j) {
  1297. w[j] -= sigma;
  1298. werr[j] += (r__1 = w[j], abs(r__1)) * eps;
  1299. /* L134: */
  1300. }
  1301. /* call SLARRB to reduce eigenvalue error of the approximations */
  1302. /* from SLARRD */
  1303. i__2 = iend - 1;
  1304. for (i__ = ibegin; i__ <= i__2; ++i__) {
  1305. /* Computing 2nd power */
  1306. r__1 = e[i__];
  1307. work[i__] = d__[i__] * (r__1 * r__1);
  1308. /* L135: */
  1309. }
  1310. /* use bisection to find EV from INDL to INDU */
  1311. i__2 = indl - 1;
  1312. slarrb_(&in, &d__[ibegin], &work[ibegin], &indl, &indu, rtol1,
  1313. rtol2, &i__2, &w[wbegin], &wgap[wbegin], &werr[wbegin], &
  1314. work[(*n << 1) + 1], &iwork[1], pivmin, &spdiam, &in, &
  1315. iinfo);
  1316. if (iinfo != 0) {
  1317. *info = -4;
  1318. return;
  1319. }
  1320. /* SLARRB computes all gaps correctly except for the last one */
  1321. /* Record distance to VU/GU */
  1322. /* Computing MAX */
  1323. r__1 = 0.f, r__2 = *vu - sigma - (w[wend] + werr[wend]);
  1324. wgap[wend] = f2cmax(r__1,r__2);
  1325. i__2 = indu;
  1326. for (i__ = indl; i__ <= i__2; ++i__) {
  1327. ++(*m);
  1328. iblock[*m] = jblk;
  1329. indexw[*m] = i__;
  1330. /* L138: */
  1331. }
  1332. } else {
  1333. /* Call dqds to get all eigs (and then possibly delete unwanted */
  1334. /* eigenvalues). */
  1335. /* Note that dqds finds the eigenvalues of the L D L^T representation */
  1336. /* of T to high relative accuracy. High relative accuracy */
  1337. /* might be lost when the shift of the RRR is subtracted to obtain */
  1338. /* the eigenvalues of T. However, T is not guaranteed to define its */
  1339. /* eigenvalues to high relative accuracy anyway. */
  1340. /* Set RTOL to the order of the tolerance used in SLASQ2 */
  1341. /* This is an ESTIMATED error, the worst case bound is 4*N*EPS */
  1342. /* which is usually too large and requires unnecessary work to be */
  1343. /* done by bisection when computing the eigenvectors */
  1344. rtol = log((real) in) * 4.f * eps;
  1345. j = ibegin;
  1346. i__2 = in - 1;
  1347. for (i__ = 1; i__ <= i__2; ++i__) {
  1348. work[(i__ << 1) - 1] = (r__1 = d__[j], abs(r__1));
  1349. work[i__ * 2] = e[j] * e[j] * work[(i__ << 1) - 1];
  1350. ++j;
  1351. /* L140: */
  1352. }
  1353. work[(in << 1) - 1] = (r__1 = d__[iend], abs(r__1));
  1354. work[in * 2] = 0.f;
  1355. slasq2_(&in, &work[1], &iinfo);
  1356. if (iinfo != 0) {
  1357. /* If IINFO = -5 then an index is part of a tight cluster */
  1358. /* and should be changed. The index is in IWORK(1) and the */
  1359. /* gap is in WORK(N+1) */
  1360. *info = -5;
  1361. return;
  1362. } else {
  1363. /* Test that all eigenvalues are positive as expected */
  1364. i__2 = in;
  1365. for (i__ = 1; i__ <= i__2; ++i__) {
  1366. if (work[i__] < 0.f) {
  1367. *info = -6;
  1368. return;
  1369. }
  1370. /* L149: */
  1371. }
  1372. }
  1373. if (sgndef > 0.f) {
  1374. i__2 = indu;
  1375. for (i__ = indl; i__ <= i__2; ++i__) {
  1376. ++(*m);
  1377. w[*m] = work[in - i__ + 1];
  1378. iblock[*m] = jblk;
  1379. indexw[*m] = i__;
  1380. /* L150: */
  1381. }
  1382. } else {
  1383. i__2 = indu;
  1384. for (i__ = indl; i__ <= i__2; ++i__) {
  1385. ++(*m);
  1386. w[*m] = -work[i__];
  1387. iblock[*m] = jblk;
  1388. indexw[*m] = i__;
  1389. /* L160: */
  1390. }
  1391. }
  1392. i__2 = *m;
  1393. for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
  1394. /* the value of RTOL below should be the tolerance in SLASQ2 */
  1395. werr[i__] = rtol * (r__1 = w[i__], abs(r__1));
  1396. /* L165: */
  1397. }
  1398. i__2 = *m - 1;
  1399. for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
  1400. /* compute the right gap between the intervals */
  1401. /* Computing MAX */
  1402. r__1 = 0.f, r__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] +
  1403. werr[i__]);
  1404. wgap[i__] = f2cmax(r__1,r__2);
  1405. /* L166: */
  1406. }
  1407. /* Computing MAX */
  1408. r__1 = 0.f, r__2 = *vu - sigma - (w[*m] + werr[*m]);
  1409. wgap[*m] = f2cmax(r__1,r__2);
  1410. }
  1411. /* proceed with next block */
  1412. ibegin = iend + 1;
  1413. wbegin = wend + 1;
  1414. L170:
  1415. ;
  1416. }
  1417. return;
  1418. /* end of SLARRE */
  1419. } /* slarre_ */