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.

clarrv.c 55 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #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]);}
  173. #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]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #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++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #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]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  230. #define z_abs(z) (cabs(Cd(z)))
  231. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  232. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  233. #define myexit_() break;
  234. #define mycycle() continue;
  235. #define myceiling(w) {ceil(w)}
  236. #define myhuge(w) {HUGE_VAL}
  237. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  238. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  239. /* procedure parameter types for -A and -C++ */
  240. #define F2C_proc_par_types 1
  241. #ifdef __cplusplus
  242. typedef logical (*L_fp)(...);
  243. #else
  244. typedef logical (*L_fp)();
  245. #endif
  246. static float spow_ui(float x, integer n) {
  247. float pow=1.0; unsigned long int u;
  248. if(n != 0) {
  249. if(n < 0) n = -n, x = 1/x;
  250. for(u = n; ; ) {
  251. if(u & 01) pow *= x;
  252. if(u >>= 1) x *= x;
  253. else break;
  254. }
  255. }
  256. return pow;
  257. }
  258. static double dpow_ui(double x, integer n) {
  259. double pow=1.0; unsigned long int u;
  260. if(n != 0) {
  261. if(n < 0) n = -n, x = 1/x;
  262. for(u = n; ; ) {
  263. if(u & 01) pow *= x;
  264. if(u >>= 1) x *= x;
  265. else break;
  266. }
  267. }
  268. return pow;
  269. }
  270. #ifdef _MSC_VER
  271. static _Fcomplex cpow_ui(complex x, integer n) {
  272. complex pow={1.0,0.0}; unsigned long int u;
  273. if(n != 0) {
  274. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  275. for(u = n; ; ) {
  276. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  277. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  278. else break;
  279. }
  280. }
  281. _Fcomplex p={pow.r, pow.i};
  282. return p;
  283. }
  284. #else
  285. static _Complex float cpow_ui(_Complex float x, integer n) {
  286. _Complex float pow=1.0; unsigned long int u;
  287. if(n != 0) {
  288. if(n < 0) n = -n, x = 1/x;
  289. for(u = n; ; ) {
  290. if(u & 01) pow *= x;
  291. if(u >>= 1) x *= x;
  292. else break;
  293. }
  294. }
  295. return pow;
  296. }
  297. #endif
  298. #ifdef _MSC_VER
  299. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  300. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  301. if(n != 0) {
  302. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  303. for(u = n; ; ) {
  304. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  305. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  306. else break;
  307. }
  308. }
  309. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  310. return p;
  311. }
  312. #else
  313. static _Complex double zpow_ui(_Complex double x, integer n) {
  314. _Complex double pow=1.0; unsigned long int u;
  315. if(n != 0) {
  316. if(n < 0) n = -n, x = 1/x;
  317. for(u = n; ; ) {
  318. if(u & 01) pow *= x;
  319. if(u >>= 1) x *= x;
  320. else break;
  321. }
  322. }
  323. return pow;
  324. }
  325. #endif
  326. static integer pow_ii(integer x, integer n) {
  327. integer pow; unsigned long int u;
  328. if (n <= 0) {
  329. if (n == 0 || x == 1) pow = 1;
  330. else if (x != -1) pow = x == 0 ? 1/x : 0;
  331. else n = -n;
  332. }
  333. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  334. u = n;
  335. for(pow = 1; ; ) {
  336. if(u & 01) pow *= x;
  337. if(u >>= 1) x *= x;
  338. else break;
  339. }
  340. }
  341. return pow;
  342. }
  343. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  344. {
  345. double m; integer i, mi;
  346. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  347. if (w[i-1]>m) mi=i ,m=w[i-1];
  348. return mi-s+1;
  349. }
  350. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  351. {
  352. float m; integer i, mi;
  353. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  354. if (w[i-1]>m) mi=i ,m=w[i-1];
  355. return mi-s+1;
  356. }
  357. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  358. integer n = *n_, incx = *incx_, incy = *incy_, i;
  359. #ifdef _MSC_VER
  360. _Fcomplex zdotc = {0.0, 0.0};
  361. if (incx == 1 && incy == 1) {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  364. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  365. }
  366. } else {
  367. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  368. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  369. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  370. }
  371. }
  372. pCf(z) = zdotc;
  373. }
  374. #else
  375. _Complex float zdotc = 0.0;
  376. if (incx == 1 && incy == 1) {
  377. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  378. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  379. }
  380. } else {
  381. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  382. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  383. }
  384. }
  385. pCf(z) = zdotc;
  386. }
  387. #endif
  388. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  389. integer n = *n_, incx = *incx_, incy = *incy_, i;
  390. #ifdef _MSC_VER
  391. _Dcomplex zdotc = {0.0, 0.0};
  392. if (incx == 1 && incy == 1) {
  393. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  394. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  395. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  396. }
  397. } else {
  398. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  399. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  400. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  401. }
  402. }
  403. pCd(z) = zdotc;
  404. }
  405. #else
  406. _Complex double zdotc = 0.0;
  407. if (incx == 1 && incy == 1) {
  408. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  409. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  410. }
  411. } else {
  412. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  413. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  414. }
  415. }
  416. pCd(z) = zdotc;
  417. }
  418. #endif
  419. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  420. integer n = *n_, incx = *incx_, incy = *incy_, i;
  421. #ifdef _MSC_VER
  422. _Fcomplex zdotc = {0.0, 0.0};
  423. if (incx == 1 && incy == 1) {
  424. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  425. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  426. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  427. }
  428. } else {
  429. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  430. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  431. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  432. }
  433. }
  434. pCf(z) = zdotc;
  435. }
  436. #else
  437. _Complex float zdotc = 0.0;
  438. if (incx == 1 && incy == 1) {
  439. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  440. zdotc += Cf(&x[i]) * Cf(&y[i]);
  441. }
  442. } else {
  443. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  444. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  445. }
  446. }
  447. pCf(z) = zdotc;
  448. }
  449. #endif
  450. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  451. integer n = *n_, incx = *incx_, incy = *incy_, i;
  452. #ifdef _MSC_VER
  453. _Dcomplex zdotc = {0.0, 0.0};
  454. if (incx == 1 && incy == 1) {
  455. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  456. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  457. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  458. }
  459. } else {
  460. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  461. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  462. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  463. }
  464. }
  465. pCd(z) = zdotc;
  466. }
  467. #else
  468. _Complex double zdotc = 0.0;
  469. if (incx == 1 && incy == 1) {
  470. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  471. zdotc += Cd(&x[i]) * Cd(&y[i]);
  472. }
  473. } else {
  474. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  475. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  476. }
  477. }
  478. pCd(z) = zdotc;
  479. }
  480. #endif
  481. /* -- translated by f2c (version 20000121).
  482. You must link the resulting object file with the libraries:
  483. -lf2c -lm (in that order)
  484. */
  485. /* Table of constant values */
  486. static complex c_b1 = {0.f,0.f};
  487. static integer c__1 = 1;
  488. static integer c__2 = 2;
  489. static real c_b28 = 0.f;
  490. /* > \brief \b CLARRV computes the eigenvectors of the tridiagonal matrix T = L D LT given L, D and the eigenv
  491. alues of L D LT. */
  492. /* =========== DOCUMENTATION =========== */
  493. /* Online html documentation available at */
  494. /* http://www.netlib.org/lapack/explore-html/ */
  495. /* > \htmlonly */
  496. /* > Download CLARRV + dependencies */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clarrv.
  498. f"> */
  499. /* > [TGZ]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clarrv.
  501. f"> */
  502. /* > [ZIP]</a> */
  503. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clarrv.
  504. f"> */
  505. /* > [TXT]</a> */
  506. /* > \endhtmlonly */
  507. /* Definition: */
  508. /* =========== */
  509. /* SUBROUTINE CLARRV( N, VL, VU, D, L, PIVMIN, */
  510. /* ISPLIT, M, DOL, DOU, MINRGP, */
  511. /* RTOL1, RTOL2, W, WERR, WGAP, */
  512. /* IBLOCK, INDEXW, GERS, Z, LDZ, ISUPPZ, */
  513. /* WORK, IWORK, INFO ) */
  514. /* INTEGER DOL, DOU, INFO, LDZ, M, N */
  515. /* REAL MINRGP, PIVMIN, RTOL1, RTOL2, VL, VU */
  516. /* INTEGER IBLOCK( * ), INDEXW( * ), ISPLIT( * ), */
  517. /* $ ISUPPZ( * ), IWORK( * ) */
  518. /* REAL D( * ), GERS( * ), L( * ), W( * ), WERR( * ), */
  519. /* $ WGAP( * ), WORK( * ) */
  520. /* COMPLEX Z( LDZ, * ) */
  521. /* > \par Purpose: */
  522. /* ============= */
  523. /* > */
  524. /* > \verbatim */
  525. /* > */
  526. /* > CLARRV computes the eigenvectors of the tridiagonal matrix */
  527. /* > T = L D L**T given L, D and APPROXIMATIONS to the eigenvalues of L D L**T. */
  528. /* > The input eigenvalues should have been computed by SLARRE. */
  529. /* > \endverbatim */
  530. /* Arguments: */
  531. /* ========== */
  532. /* > \param[in] N */
  533. /* > \verbatim */
  534. /* > N is INTEGER */
  535. /* > The order of the matrix. N >= 0. */
  536. /* > \endverbatim */
  537. /* > */
  538. /* > \param[in] VL */
  539. /* > \verbatim */
  540. /* > VL is REAL */
  541. /* > Lower bound of the interval that contains the desired */
  542. /* > eigenvalues. VL < VU. Needed to compute gaps on the left or right */
  543. /* > end of the extremal eigenvalues in the desired RANGE. */
  544. /* > \endverbatim */
  545. /* > */
  546. /* > \param[in] VU */
  547. /* > \verbatim */
  548. /* > VU is REAL */
  549. /* > Upper bound of the interval that contains the desired */
  550. /* > eigenvalues. VL < VU. Needed to compute gaps on the left or right */
  551. /* > end of the extremal eigenvalues in the desired RANGE. */
  552. /* > \endverbatim */
  553. /* > */
  554. /* > \param[in,out] D */
  555. /* > \verbatim */
  556. /* > D is REAL array, dimension (N) */
  557. /* > On entry, the N diagonal elements of the diagonal matrix D. */
  558. /* > On exit, D may be overwritten. */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[in,out] L */
  562. /* > \verbatim */
  563. /* > L is REAL array, dimension (N) */
  564. /* > On entry, the (N-1) subdiagonal elements of the unit */
  565. /* > bidiagonal matrix L are in elements 1 to N-1 of L */
  566. /* > (if the matrix is not split.) At the end of each block */
  567. /* > is stored the corresponding shift as given by SLARRE. */
  568. /* > On exit, L is overwritten. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] PIVMIN */
  572. /* > \verbatim */
  573. /* > PIVMIN is REAL */
  574. /* > The minimum pivot allowed in the Sturm sequence. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in] ISPLIT */
  578. /* > \verbatim */
  579. /* > ISPLIT is INTEGER array, dimension (N) */
  580. /* > The splitting points, at which T breaks up into blocks. */
  581. /* > The first block consists of rows/columns 1 to */
  582. /* > ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */
  583. /* > through ISPLIT( 2 ), etc. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in] M */
  587. /* > \verbatim */
  588. /* > M is INTEGER */
  589. /* > The total number of input eigenvalues. 0 <= M <= N. */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[in] DOL */
  593. /* > \verbatim */
  594. /* > DOL is INTEGER */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[in] DOU */
  598. /* > \verbatim */
  599. /* > DOU is INTEGER */
  600. /* > If the user wants to compute only selected eigenvectors from all */
  601. /* > the eigenvalues supplied, he can specify an index range DOL:DOU. */
  602. /* > Or else the setting DOL=1, DOU=M should be applied. */
  603. /* > Note that DOL and DOU refer to the order in which the eigenvalues */
  604. /* > are stored in W. */
  605. /* > If the user wants to compute only selected eigenpairs, then */
  606. /* > the columns DOL-1 to DOU+1 of the eigenvector space Z contain the */
  607. /* > computed eigenvectors. All other columns of Z are set to zero. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in] MINRGP */
  611. /* > \verbatim */
  612. /* > MINRGP is REAL */
  613. /* > \endverbatim */
  614. /* > */
  615. /* > \param[in] RTOL1 */
  616. /* > \verbatim */
  617. /* > RTOL1 is REAL */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[in] RTOL2 */
  621. /* > \verbatim */
  622. /* > RTOL2 is REAL */
  623. /* > Parameters for bisection. */
  624. /* > An interval [LEFT,RIGHT] has converged if */
  625. /* > RIGHT-LEFT < MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
  626. /* > \endverbatim */
  627. /* > */
  628. /* > \param[in,out] W */
  629. /* > \verbatim */
  630. /* > W is REAL array, dimension (N) */
  631. /* > The first M elements of W contain the APPROXIMATE eigenvalues for */
  632. /* > which eigenvectors are to be computed. The eigenvalues */
  633. /* > should be grouped by split-off block and ordered from */
  634. /* > smallest to largest within the block ( The output array */
  635. /* > W from SLARRE is expected here ). Furthermore, they are with */
  636. /* > respect to the shift of the corresponding root representation */
  637. /* > for their block. On exit, W holds the eigenvalues of the */
  638. /* > UNshifted matrix. */
  639. /* > \endverbatim */
  640. /* > */
  641. /* > \param[in,out] WERR */
  642. /* > \verbatim */
  643. /* > WERR is REAL array, dimension (N) */
  644. /* > The first M elements contain the semiwidth of the uncertainty */
  645. /* > interval of the corresponding eigenvalue in W */
  646. /* > \endverbatim */
  647. /* > */
  648. /* > \param[in,out] WGAP */
  649. /* > \verbatim */
  650. /* > WGAP is REAL array, dimension (N) */
  651. /* > The separation from the right neighbor eigenvalue in W. */
  652. /* > \endverbatim */
  653. /* > */
  654. /* > \param[in] IBLOCK */
  655. /* > \verbatim */
  656. /* > IBLOCK is INTEGER array, dimension (N) */
  657. /* > The indices of the blocks (submatrices) associated with the */
  658. /* > corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
  659. /* > W(i) belongs to the first block from the top, =2 if W(i) */
  660. /* > belongs to the second block, etc. */
  661. /* > \endverbatim */
  662. /* > */
  663. /* > \param[in] INDEXW */
  664. /* > \verbatim */
  665. /* > INDEXW is INTEGER array, dimension (N) */
  666. /* > The indices of the eigenvalues within each block (submatrix); */
  667. /* > for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
  668. /* > i-th eigenvalue W(i) is the 10-th eigenvalue in the second block. */
  669. /* > \endverbatim */
  670. /* > */
  671. /* > \param[in] GERS */
  672. /* > \verbatim */
  673. /* > GERS is REAL array, dimension (2*N) */
  674. /* > The N Gerschgorin intervals (the i-th Gerschgorin interval */
  675. /* > is (GERS(2*i-1), GERS(2*i)). The Gerschgorin intervals should */
  676. /* > be computed from the original UNshifted matrix. */
  677. /* > \endverbatim */
  678. /* > */
  679. /* > \param[out] Z */
  680. /* > \verbatim */
  681. /* > Z is COMPLEX array, dimension (LDZ, f2cmax(1,M) ) */
  682. /* > If INFO = 0, the first M columns of Z contain the */
  683. /* > orthonormal eigenvectors of the matrix T */
  684. /* > corresponding to the input eigenvalues, with the i-th */
  685. /* > column of Z holding the eigenvector associated with W(i). */
  686. /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
  687. /* > supplied in the array Z. */
  688. /* > \endverbatim */
  689. /* > */
  690. /* > \param[in] LDZ */
  691. /* > \verbatim */
  692. /* > LDZ is INTEGER */
  693. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  694. /* > JOBZ = 'V', LDZ >= f2cmax(1,N). */
  695. /* > \endverbatim */
  696. /* > */
  697. /* > \param[out] ISUPPZ */
  698. /* > \verbatim */
  699. /* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
  700. /* > The support of the eigenvectors in Z, i.e., the indices */
  701. /* > indicating the nonzero elements in Z. The I-th eigenvector */
  702. /* > is nonzero only in elements ISUPPZ( 2*I-1 ) through */
  703. /* > ISUPPZ( 2*I ). */
  704. /* > \endverbatim */
  705. /* > */
  706. /* > \param[out] WORK */
  707. /* > \verbatim */
  708. /* > WORK is REAL array, dimension (12*N) */
  709. /* > \endverbatim */
  710. /* > */
  711. /* > \param[out] IWORK */
  712. /* > \verbatim */
  713. /* > IWORK is INTEGER array, dimension (7*N) */
  714. /* > \endverbatim */
  715. /* > */
  716. /* > \param[out] INFO */
  717. /* > \verbatim */
  718. /* > INFO is INTEGER */
  719. /* > = 0: successful exit */
  720. /* > */
  721. /* > > 0: A problem occurred in CLARRV. */
  722. /* > < 0: One of the called subroutines signaled an internal problem. */
  723. /* > Needs inspection of the corresponding parameter IINFO */
  724. /* > for further information. */
  725. /* > */
  726. /* > =-1: Problem in SLARRB when refining a child's eigenvalues. */
  727. /* > =-2: Problem in SLARRF when computing the RRR of a child. */
  728. /* > When a child is inside a tight cluster, it can be difficult */
  729. /* > to find an RRR. A partial remedy from the user's point of */
  730. /* > view is to make the parameter MINRGP smaller and recompile. */
  731. /* > However, as the orthogonality of the computed vectors is */
  732. /* > proportional to 1/MINRGP, the user should be aware that */
  733. /* > he might be trading in precision when he decreases MINRGP. */
  734. /* > =-3: Problem in SLARRB when refining a single eigenvalue */
  735. /* > after the Rayleigh correction was rejected. */
  736. /* > = 5: The Rayleigh Quotient Iteration failed to converge to */
  737. /* > full accuracy in MAXITR steps. */
  738. /* > \endverbatim */
  739. /* Authors: */
  740. /* ======== */
  741. /* > \author Univ. of Tennessee */
  742. /* > \author Univ. of California Berkeley */
  743. /* > \author Univ. of Colorado Denver */
  744. /* > \author NAG Ltd. */
  745. /* > \date June 2016 */
  746. /* > \ingroup complexOTHERauxiliary */
  747. /* > \par Contributors: */
  748. /* ================== */
  749. /* > */
  750. /* > Beresford Parlett, University of California, Berkeley, USA \n */
  751. /* > Jim Demmel, University of California, Berkeley, USA \n */
  752. /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
  753. /* > Osni Marques, LBNL/NERSC, USA \n */
  754. /* > Christof Voemel, University of California, Berkeley, USA */
  755. /* ===================================================================== */
  756. /* Subroutine */ int clarrv_(integer *n, real *vl, real *vu, real *d__, real *
  757. l, real *pivmin, integer *isplit, integer *m, integer *dol, integer *
  758. dou, real *minrgp, real *rtol1, real *rtol2, real *w, real *werr,
  759. real *wgap, integer *iblock, integer *indexw, real *gers, complex *
  760. z__, integer *ldz, integer *isuppz, real *work, integer *iwork,
  761. integer *info)
  762. {
  763. /* System generated locals */
  764. integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  765. real r__1, r__2;
  766. complex q__1;
  767. logical L__1;
  768. /* Local variables */
  769. integer iend, jblk;
  770. real lgap;
  771. integer done;
  772. real rgap, left;
  773. integer wend, iter;
  774. real bstw;
  775. integer minwsize, itmp1, i__, j, k, p, q, indld;
  776. real fudge;
  777. integer idone;
  778. real sigma;
  779. integer iinfo, iindr;
  780. real resid;
  781. logical eskip;
  782. real right;
  783. integer nclus, zfrom;
  784. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  785. integer *);
  786. real rqtol;
  787. integer iindc1, iindc2, indin1, indin2;
  788. extern /* Subroutine */ int clar1v_(integer *, integer *, integer *, real
  789. *, real *, real *, real *, real *, real *, real *, complex *,
  790. logical *, integer *, real *, real *, integer *, integer *, real *
  791. , real *, real *, real *);
  792. integer miniwsize;
  793. logical stp2ii;
  794. real lambda;
  795. integer ii;
  796. real gl;
  797. integer im, in;
  798. real gu;
  799. integer ibegin, indeig;
  800. logical needbs;
  801. integer indlld;
  802. real sgndef, mingma;
  803. extern real slamch_(char *);
  804. integer oldien, oldncl, wbegin, negcnt;
  805. real spdiam;
  806. integer oldcls;
  807. real savgap;
  808. integer ndepth;
  809. real ssigma;
  810. extern /* Subroutine */ int claset_(char *, integer *, integer *, complex
  811. *, complex *, complex *, integer *);
  812. logical usedbs;
  813. integer iindwk, offset;
  814. real gaptol;
  815. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  816. *);
  817. integer newcls, oldfst, indwrk, windex, oldlst;
  818. logical usedrq;
  819. integer newfst, newftt, parity, windmn, windpl, isupmn, newlst, zusedl;
  820. real bstres;
  821. integer newsiz, zusedu, zusedw;
  822. real nrminv, rqcorr;
  823. logical tryrqc;
  824. integer isupmx;
  825. extern /* Subroutine */ int slarrb_(integer *, real *, real *, integer *,
  826. integer *, real *, real *, integer *, real *, real *, real *,
  827. real *, integer *, real *, real *, integer *, integer *), slarrf_(
  828. integer *, real *, real *, real *, integer *, integer *, real *,
  829. real *, real *, real *, real *, real *, real *, real *, real *,
  830. real *, real *, integer *);
  831. real gap, eps, tau, tol, tmp;
  832. integer zto;
  833. real ztz;
  834. /* -- LAPACK auxiliary routine (version 3.7.1) -- */
  835. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  836. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  837. /* June 2016 */
  838. /* ===================================================================== */
  839. /* Parameter adjustments */
  840. --d__;
  841. --l;
  842. --isplit;
  843. --w;
  844. --werr;
  845. --wgap;
  846. --iblock;
  847. --indexw;
  848. --gers;
  849. z_dim1 = *ldz;
  850. z_offset = 1 + z_dim1 * 1;
  851. z__ -= z_offset;
  852. --isuppz;
  853. --work;
  854. --iwork;
  855. /* Function Body */
  856. *info = 0;
  857. /* Quick return if possible */
  858. if (*n <= 0 || *m <= 0) {
  859. return 0;
  860. }
  861. /* The first N entries of WORK are reserved for the eigenvalues */
  862. indld = *n + 1;
  863. indlld = (*n << 1) + 1;
  864. indin1 = *n * 3 + 1;
  865. indin2 = (*n << 2) + 1;
  866. indwrk = *n * 5 + 1;
  867. minwsize = *n * 12;
  868. i__1 = minwsize;
  869. for (i__ = 1; i__ <= i__1; ++i__) {
  870. work[i__] = 0.f;
  871. /* L5: */
  872. }
  873. /* IWORK(IINDR+1:IINDR+N) hold the twist indices R for the */
  874. /* factorization used to compute the FP vector */
  875. iindr = 0;
  876. /* IWORK(IINDC1+1:IINC2+N) are used to store the clusters of the current */
  877. /* layer and the one above. */
  878. iindc1 = *n;
  879. iindc2 = *n << 1;
  880. iindwk = *n * 3 + 1;
  881. miniwsize = *n * 7;
  882. i__1 = miniwsize;
  883. for (i__ = 1; i__ <= i__1; ++i__) {
  884. iwork[i__] = 0;
  885. /* L10: */
  886. }
  887. zusedl = 1;
  888. if (*dol > 1) {
  889. /* Set lower bound for use of Z */
  890. zusedl = *dol - 1;
  891. }
  892. zusedu = *m;
  893. if (*dou < *m) {
  894. /* Set lower bound for use of Z */
  895. zusedu = *dou + 1;
  896. }
  897. /* The width of the part of Z that is used */
  898. zusedw = zusedu - zusedl + 1;
  899. claset_("Full", n, &zusedw, &c_b1, &c_b1, &z__[zusedl * z_dim1 + 1], ldz);
  900. eps = slamch_("Precision");
  901. rqtol = eps * 2.f;
  902. /* Set expert flags for standard code. */
  903. tryrqc = TRUE_;
  904. if (*dol == 1 && *dou == *m) {
  905. } else {
  906. /* Only selected eigenpairs are computed. Since the other evalues */
  907. /* are not refined by RQ iteration, bisection has to compute to full */
  908. /* accuracy. */
  909. *rtol1 = eps * 4.f;
  910. *rtol2 = eps * 4.f;
  911. }
  912. /* The entries WBEGIN:WEND in W, WERR, WGAP correspond to the */
  913. /* desired eigenvalues. The support of the nonzero eigenvector */
  914. /* entries is contained in the interval IBEGIN:IEND. */
  915. /* Remark that if k eigenpairs are desired, then the eigenvectors */
  916. /* are stored in k contiguous columns of Z. */
  917. /* DONE is the number of eigenvectors already computed */
  918. done = 0;
  919. ibegin = 1;
  920. wbegin = 1;
  921. i__1 = iblock[*m];
  922. for (jblk = 1; jblk <= i__1; ++jblk) {
  923. iend = isplit[jblk];
  924. sigma = l[iend];
  925. /* Find the eigenvectors of the submatrix indexed IBEGIN */
  926. /* through IEND. */
  927. wend = wbegin - 1;
  928. L15:
  929. if (wend < *m) {
  930. if (iblock[wend + 1] == jblk) {
  931. ++wend;
  932. goto L15;
  933. }
  934. }
  935. if (wend < wbegin) {
  936. ibegin = iend + 1;
  937. goto L170;
  938. } else if (wend < *dol || wbegin > *dou) {
  939. ibegin = iend + 1;
  940. wbegin = wend + 1;
  941. goto L170;
  942. }
  943. /* Find local spectral diameter of the block */
  944. gl = gers[(ibegin << 1) - 1];
  945. gu = gers[ibegin * 2];
  946. i__2 = iend;
  947. for (i__ = ibegin + 1; i__ <= i__2; ++i__) {
  948. /* Computing MIN */
  949. r__1 = gers[(i__ << 1) - 1];
  950. gl = f2cmin(r__1,gl);
  951. /* Computing MAX */
  952. r__1 = gers[i__ * 2];
  953. gu = f2cmax(r__1,gu);
  954. /* L20: */
  955. }
  956. spdiam = gu - gl;
  957. /* OLDIEN is the last index of the previous block */
  958. oldien = ibegin - 1;
  959. /* Calculate the size of the current block */
  960. in = iend - ibegin + 1;
  961. /* The number of eigenvalues in the current block */
  962. im = wend - wbegin + 1;
  963. /* This is for a 1x1 block */
  964. if (ibegin == iend) {
  965. ++done;
  966. i__2 = ibegin + wbegin * z_dim1;
  967. z__[i__2].r = 1.f, z__[i__2].i = 0.f;
  968. isuppz[(wbegin << 1) - 1] = ibegin;
  969. isuppz[wbegin * 2] = ibegin;
  970. w[wbegin] += sigma;
  971. work[wbegin] = w[wbegin];
  972. ibegin = iend + 1;
  973. ++wbegin;
  974. goto L170;
  975. }
  976. /* The desired (shifted) eigenvalues are stored in W(WBEGIN:WEND) */
  977. /* Note that these can be approximations, in this case, the corresp. */
  978. /* entries of WERR give the size of the uncertainty interval. */
  979. /* The eigenvalue approximations will be refined when necessary as */
  980. /* high relative accuracy is required for the computation of the */
  981. /* corresponding eigenvectors. */
  982. scopy_(&im, &w[wbegin], &c__1, &work[wbegin], &c__1);
  983. /* We store in W the eigenvalue approximations w.r.t. the original */
  984. /* matrix T. */
  985. i__2 = im;
  986. for (i__ = 1; i__ <= i__2; ++i__) {
  987. w[wbegin + i__ - 1] += sigma;
  988. /* L30: */
  989. }
  990. /* NDEPTH is the current depth of the representation tree */
  991. ndepth = 0;
  992. /* PARITY is either 1 or 0 */
  993. parity = 1;
  994. /* NCLUS is the number of clusters for the next level of the */
  995. /* representation tree, we start with NCLUS = 1 for the root */
  996. nclus = 1;
  997. iwork[iindc1 + 1] = 1;
  998. iwork[iindc1 + 2] = im;
  999. /* IDONE is the number of eigenvectors already computed in the current */
  1000. /* block */
  1001. idone = 0;
  1002. /* loop while( IDONE.LT.IM ) */
  1003. /* generate the representation tree for the current block and */
  1004. /* compute the eigenvectors */
  1005. L40:
  1006. if (idone < im) {
  1007. /* This is a crude protection against infinitely deep trees */
  1008. if (ndepth > *m) {
  1009. *info = -2;
  1010. return 0;
  1011. }
  1012. /* breadth first processing of the current level of the representation */
  1013. /* tree: OLDNCL = number of clusters on current level */
  1014. oldncl = nclus;
  1015. /* reset NCLUS to count the number of child clusters */
  1016. nclus = 0;
  1017. parity = 1 - parity;
  1018. if (parity == 0) {
  1019. oldcls = iindc1;
  1020. newcls = iindc2;
  1021. } else {
  1022. oldcls = iindc2;
  1023. newcls = iindc1;
  1024. }
  1025. /* Process the clusters on the current level */
  1026. i__2 = oldncl;
  1027. for (i__ = 1; i__ <= i__2; ++i__) {
  1028. j = oldcls + (i__ << 1);
  1029. /* OLDFST, OLDLST = first, last index of current cluster. */
  1030. /* cluster indices start with 1 and are relative */
  1031. /* to WBEGIN when accessing W, WGAP, WERR, Z */
  1032. oldfst = iwork[j - 1];
  1033. oldlst = iwork[j];
  1034. if (ndepth > 0) {
  1035. /* Retrieve relatively robust representation (RRR) of cluster */
  1036. /* that has been computed at the previous level */
  1037. /* The RRR is stored in Z and overwritten once the eigenvectors */
  1038. /* have been computed or when the cluster is refined */
  1039. if (*dol == 1 && *dou == *m) {
  1040. /* Get representation from location of the leftmost evalue */
  1041. /* of the cluster */
  1042. j = wbegin + oldfst - 1;
  1043. } else {
  1044. if (wbegin + oldfst - 1 < *dol) {
  1045. /* Get representation from the left end of Z array */
  1046. j = *dol - 1;
  1047. } else if (wbegin + oldfst - 1 > *dou) {
  1048. /* Get representation from the right end of Z array */
  1049. j = *dou;
  1050. } else {
  1051. j = wbegin + oldfst - 1;
  1052. }
  1053. }
  1054. i__3 = in - 1;
  1055. for (k = 1; k <= i__3; ++k) {
  1056. i__4 = ibegin + k - 1 + j * z_dim1;
  1057. d__[ibegin + k - 1] = z__[i__4].r;
  1058. i__4 = ibegin + k - 1 + (j + 1) * z_dim1;
  1059. l[ibegin + k - 1] = z__[i__4].r;
  1060. /* L45: */
  1061. }
  1062. i__3 = iend + j * z_dim1;
  1063. d__[iend] = z__[i__3].r;
  1064. i__3 = iend + (j + 1) * z_dim1;
  1065. sigma = z__[i__3].r;
  1066. /* Set the corresponding entries in Z to zero */
  1067. claset_("Full", &in, &c__2, &c_b1, &c_b1, &z__[ibegin + j
  1068. * z_dim1], ldz);
  1069. }
  1070. /* Compute DL and DLL of current RRR */
  1071. i__3 = iend - 1;
  1072. for (j = ibegin; j <= i__3; ++j) {
  1073. tmp = d__[j] * l[j];
  1074. work[indld - 1 + j] = tmp;
  1075. work[indlld - 1 + j] = tmp * l[j];
  1076. /* L50: */
  1077. }
  1078. if (ndepth > 0) {
  1079. /* P and Q are index of the first and last eigenvalue to compute */
  1080. /* within the current block */
  1081. p = indexw[wbegin - 1 + oldfst];
  1082. q = indexw[wbegin - 1 + oldlst];
  1083. /* Offset for the arrays WORK, WGAP and WERR, i.e., the P-OFFSET */
  1084. /* through the Q-OFFSET elements of these arrays are to be used. */
  1085. /* OFFSET = P-OLDFST */
  1086. offset = indexw[wbegin] - 1;
  1087. /* perform limited bisection (if necessary) to get approximate */
  1088. /* eigenvalues to the precision needed. */
  1089. slarrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &p,
  1090. &q, rtol1, rtol2, &offset, &work[wbegin], &wgap[
  1091. wbegin], &werr[wbegin], &work[indwrk], &iwork[
  1092. iindwk], pivmin, &spdiam, &in, &iinfo);
  1093. if (iinfo != 0) {
  1094. *info = -1;
  1095. return 0;
  1096. }
  1097. /* We also recompute the extremal gaps. W holds all eigenvalues */
  1098. /* of the unshifted matrix and must be used for computation */
  1099. /* of WGAP, the entries of WORK might stem from RRRs with */
  1100. /* different shifts. The gaps from WBEGIN-1+OLDFST to */
  1101. /* WBEGIN-1+OLDLST are correctly computed in SLARRB. */
  1102. /* However, we only allow the gaps to become greater since */
  1103. /* this is what should happen when we decrease WERR */
  1104. if (oldfst > 1) {
  1105. /* Computing MAX */
  1106. r__1 = wgap[wbegin + oldfst - 2], r__2 = w[wbegin +
  1107. oldfst - 1] - werr[wbegin + oldfst - 1] - w[
  1108. wbegin + oldfst - 2] - werr[wbegin + oldfst -
  1109. 2];
  1110. wgap[wbegin + oldfst - 2] = f2cmax(r__1,r__2);
  1111. }
  1112. if (wbegin + oldlst - 1 < wend) {
  1113. /* Computing MAX */
  1114. r__1 = wgap[wbegin + oldlst - 1], r__2 = w[wbegin +
  1115. oldlst] - werr[wbegin + oldlst] - w[wbegin +
  1116. oldlst - 1] - werr[wbegin + oldlst - 1];
  1117. wgap[wbegin + oldlst - 1] = f2cmax(r__1,r__2);
  1118. }
  1119. /* Each time the eigenvalues in WORK get refined, we store */
  1120. /* the newly found approximation with all shifts applied in W */
  1121. i__3 = oldlst;
  1122. for (j = oldfst; j <= i__3; ++j) {
  1123. w[wbegin + j - 1] = work[wbegin + j - 1] + sigma;
  1124. /* L53: */
  1125. }
  1126. }
  1127. /* Process the current node. */
  1128. newfst = oldfst;
  1129. i__3 = oldlst;
  1130. for (j = oldfst; j <= i__3; ++j) {
  1131. if (j == oldlst) {
  1132. /* we are at the right end of the cluster, this is also the */
  1133. /* boundary of the child cluster */
  1134. newlst = j;
  1135. } else if (wgap[wbegin + j - 1] >= *minrgp * (r__1 = work[
  1136. wbegin + j - 1], abs(r__1))) {
  1137. /* the right relative gap is big enough, the child cluster */
  1138. /* (NEWFST,..,NEWLST) is well separated from the following */
  1139. newlst = j;
  1140. } else {
  1141. /* inside a child cluster, the relative gap is not */
  1142. /* big enough. */
  1143. goto L140;
  1144. }
  1145. /* Compute size of child cluster found */
  1146. newsiz = newlst - newfst + 1;
  1147. /* NEWFTT is the place in Z where the new RRR or the computed */
  1148. /* eigenvector is to be stored */
  1149. if (*dol == 1 && *dou == *m) {
  1150. /* Store representation at location of the leftmost evalue */
  1151. /* of the cluster */
  1152. newftt = wbegin + newfst - 1;
  1153. } else {
  1154. if (wbegin + newfst - 1 < *dol) {
  1155. /* Store representation at the left end of Z array */
  1156. newftt = *dol - 1;
  1157. } else if (wbegin + newfst - 1 > *dou) {
  1158. /* Store representation at the right end of Z array */
  1159. newftt = *dou;
  1160. } else {
  1161. newftt = wbegin + newfst - 1;
  1162. }
  1163. }
  1164. if (newsiz > 1) {
  1165. /* Current child is not a singleton but a cluster. */
  1166. /* Compute and store new representation of child. */
  1167. /* Compute left and right cluster gap. */
  1168. /* LGAP and RGAP are not computed from WORK because */
  1169. /* the eigenvalue approximations may stem from RRRs */
  1170. /* different shifts. However, W hold all eigenvalues */
  1171. /* of the unshifted matrix. Still, the entries in WGAP */
  1172. /* have to be computed from WORK since the entries */
  1173. /* in W might be of the same order so that gaps are not */
  1174. /* exhibited correctly for very close eigenvalues. */
  1175. if (newfst == 1) {
  1176. /* Computing MAX */
  1177. r__1 = 0.f, r__2 = w[wbegin] - werr[wbegin] - *vl;
  1178. lgap = f2cmax(r__1,r__2);
  1179. } else {
  1180. lgap = wgap[wbegin + newfst - 2];
  1181. }
  1182. rgap = wgap[wbegin + newlst - 1];
  1183. /* Compute left- and rightmost eigenvalue of child */
  1184. /* to high precision in order to shift as close */
  1185. /* as possible and obtain as large relative gaps */
  1186. /* as possible */
  1187. for (k = 1; k <= 2; ++k) {
  1188. if (k == 1) {
  1189. p = indexw[wbegin - 1 + newfst];
  1190. } else {
  1191. p = indexw[wbegin - 1 + newlst];
  1192. }
  1193. offset = indexw[wbegin] - 1;
  1194. slarrb_(&in, &d__[ibegin], &work[indlld + ibegin
  1195. - 1], &p, &p, &rqtol, &rqtol, &offset, &
  1196. work[wbegin], &wgap[wbegin], &werr[wbegin]
  1197. , &work[indwrk], &iwork[iindwk], pivmin, &
  1198. spdiam, &in, &iinfo);
  1199. /* L55: */
  1200. }
  1201. if (wbegin + newlst - 1 < *dol || wbegin + newfst - 1
  1202. > *dou) {
  1203. /* if the cluster contains no desired eigenvalues */
  1204. /* skip the computation of that branch of the rep. tree */
  1205. /* We could skip before the refinement of the extremal */
  1206. /* eigenvalues of the child, but then the representation */
  1207. /* tree could be different from the one when nothing is */
  1208. /* skipped. For this reason we skip at this place. */
  1209. idone = idone + newlst - newfst + 1;
  1210. goto L139;
  1211. }
  1212. /* Compute RRR of child cluster. */
  1213. /* Note that the new RRR is stored in Z */
  1214. /* SLARRF needs LWORK = 2*N */
  1215. slarrf_(&in, &d__[ibegin], &l[ibegin], &work[indld +
  1216. ibegin - 1], &newfst, &newlst, &work[wbegin],
  1217. &wgap[wbegin], &werr[wbegin], &spdiam, &lgap,
  1218. &rgap, pivmin, &tau, &work[indin1], &work[
  1219. indin2], &work[indwrk], &iinfo);
  1220. /* In the complex case, SLARRF cannot write */
  1221. /* the new RRR directly into Z and needs an intermediate */
  1222. /* workspace */
  1223. i__4 = in - 1;
  1224. for (k = 1; k <= i__4; ++k) {
  1225. i__5 = ibegin + k - 1 + newftt * z_dim1;
  1226. i__6 = indin1 + k - 1;
  1227. q__1.r = work[i__6], q__1.i = 0.f;
  1228. z__[i__5].r = q__1.r, z__[i__5].i = q__1.i;
  1229. i__5 = ibegin + k - 1 + (newftt + 1) * z_dim1;
  1230. i__6 = indin2 + k - 1;
  1231. q__1.r = work[i__6], q__1.i = 0.f;
  1232. z__[i__5].r = q__1.r, z__[i__5].i = q__1.i;
  1233. /* L56: */
  1234. }
  1235. i__4 = iend + newftt * z_dim1;
  1236. i__5 = indin1 + in - 1;
  1237. q__1.r = work[i__5], q__1.i = 0.f;
  1238. z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
  1239. if (iinfo == 0) {
  1240. /* a new RRR for the cluster was found by SLARRF */
  1241. /* update shift and store it */
  1242. ssigma = sigma + tau;
  1243. i__4 = iend + (newftt + 1) * z_dim1;
  1244. q__1.r = ssigma, q__1.i = 0.f;
  1245. z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
  1246. /* WORK() are the midpoints and WERR() the semi-width */
  1247. /* Note that the entries in W are unchanged. */
  1248. i__4 = newlst;
  1249. for (k = newfst; k <= i__4; ++k) {
  1250. fudge = eps * 3.f * (r__1 = work[wbegin + k -
  1251. 1], abs(r__1));
  1252. work[wbegin + k - 1] -= tau;
  1253. fudge += eps * 4.f * (r__1 = work[wbegin + k
  1254. - 1], abs(r__1));
  1255. /* Fudge errors */
  1256. werr[wbegin + k - 1] += fudge;
  1257. /* Gaps are not fudged. Provided that WERR is small */
  1258. /* when eigenvalues are close, a zero gap indicates */
  1259. /* that a new representation is needed for resolving */
  1260. /* the cluster. A fudge could lead to a wrong decision */
  1261. /* of judging eigenvalues 'separated' which in */
  1262. /* reality are not. This could have a negative impact */
  1263. /* on the orthogonality of the computed eigenvectors. */
  1264. /* L116: */
  1265. }
  1266. ++nclus;
  1267. k = newcls + (nclus << 1);
  1268. iwork[k - 1] = newfst;
  1269. iwork[k] = newlst;
  1270. } else {
  1271. *info = -2;
  1272. return 0;
  1273. }
  1274. } else {
  1275. /* Compute eigenvector of singleton */
  1276. iter = 0;
  1277. tol = log((real) in) * 4.f * eps;
  1278. k = newfst;
  1279. windex = wbegin + k - 1;
  1280. /* Computing MAX */
  1281. i__4 = windex - 1;
  1282. windmn = f2cmax(i__4,1);
  1283. /* Computing MIN */
  1284. i__4 = windex + 1;
  1285. windpl = f2cmin(i__4,*m);
  1286. lambda = work[windex];
  1287. ++done;
  1288. /* Check if eigenvector computation is to be skipped */
  1289. if (windex < *dol || windex > *dou) {
  1290. eskip = TRUE_;
  1291. goto L125;
  1292. } else {
  1293. eskip = FALSE_;
  1294. }
  1295. left = work[windex] - werr[windex];
  1296. right = work[windex] + werr[windex];
  1297. indeig = indexw[windex];
  1298. /* Note that since we compute the eigenpairs for a child, */
  1299. /* all eigenvalue approximations are w.r.t the same shift. */
  1300. /* In this case, the entries in WORK should be used for */
  1301. /* computing the gaps since they exhibit even very small */
  1302. /* differences in the eigenvalues, as opposed to the */
  1303. /* entries in W which might "look" the same. */
  1304. if (k == 1) {
  1305. /* In the case RANGE='I' and with not much initial */
  1306. /* accuracy in LAMBDA and VL, the formula */
  1307. /* LGAP = MAX( ZERO, (SIGMA - VL) + LAMBDA ) */
  1308. /* can lead to an overestimation of the left gap and */
  1309. /* thus to inadequately early RQI 'convergence'. */
  1310. /* Prevent this by forcing a small left gap. */
  1311. /* Computing MAX */
  1312. r__1 = abs(left), r__2 = abs(right);
  1313. lgap = eps * f2cmax(r__1,r__2);
  1314. } else {
  1315. lgap = wgap[windmn];
  1316. }
  1317. if (k == im) {
  1318. /* In the case RANGE='I' and with not much initial */
  1319. /* accuracy in LAMBDA and VU, the formula */
  1320. /* can lead to an overestimation of the right gap and */
  1321. /* thus to inadequately early RQI 'convergence'. */
  1322. /* Prevent this by forcing a small right gap. */
  1323. /* Computing MAX */
  1324. r__1 = abs(left), r__2 = abs(right);
  1325. rgap = eps * f2cmax(r__1,r__2);
  1326. } else {
  1327. rgap = wgap[windex];
  1328. }
  1329. gap = f2cmin(lgap,rgap);
  1330. if (k == 1 || k == im) {
  1331. /* The eigenvector support can become wrong */
  1332. /* because significant entries could be cut off due to a */
  1333. /* large GAPTOL parameter in LAR1V. Prevent this. */
  1334. gaptol = 0.f;
  1335. } else {
  1336. gaptol = gap * eps;
  1337. }
  1338. isupmn = in;
  1339. isupmx = 1;
  1340. /* Update WGAP so that it holds the minimum gap */
  1341. /* to the left or the right. This is crucial in the */
  1342. /* case where bisection is used to ensure that the */
  1343. /* eigenvalue is refined up to the required precision. */
  1344. /* The correct value is restored afterwards. */
  1345. savgap = wgap[windex];
  1346. wgap[windex] = gap;
  1347. /* We want to use the Rayleigh Quotient Correction */
  1348. /* as often as possible since it converges quadratically */
  1349. /* when we are close enough to the desired eigenvalue. */
  1350. /* However, the Rayleigh Quotient can have the wrong sign */
  1351. /* and lead us away from the desired eigenvalue. In this */
  1352. /* case, the best we can do is to use bisection. */
  1353. usedbs = FALSE_;
  1354. usedrq = FALSE_;
  1355. /* Bisection is initially turned off unless it is forced */
  1356. needbs = ! tryrqc;
  1357. L120:
  1358. /* Check if bisection should be used to refine eigenvalue */
  1359. if (needbs) {
  1360. /* Take the bisection as new iterate */
  1361. usedbs = TRUE_;
  1362. itmp1 = iwork[iindr + windex];
  1363. offset = indexw[wbegin] - 1;
  1364. r__1 = eps * 2.f;
  1365. slarrb_(&in, &d__[ibegin], &work[indlld + ibegin
  1366. - 1], &indeig, &indeig, &c_b28, &r__1, &
  1367. offset, &work[wbegin], &wgap[wbegin], &
  1368. werr[wbegin], &work[indwrk], &iwork[
  1369. iindwk], pivmin, &spdiam, &itmp1, &iinfo);
  1370. if (iinfo != 0) {
  1371. *info = -3;
  1372. return 0;
  1373. }
  1374. lambda = work[windex];
  1375. /* Reset twist index from inaccurate LAMBDA to */
  1376. /* force computation of true MINGMA */
  1377. iwork[iindr + windex] = 0;
  1378. }
  1379. /* Given LAMBDA, compute the eigenvector. */
  1380. L__1 = ! usedbs;
  1381. clar1v_(&in, &c__1, &in, &lambda, &d__[ibegin], &l[
  1382. ibegin], &work[indld + ibegin - 1], &work[
  1383. indlld + ibegin - 1], pivmin, &gaptol, &z__[
  1384. ibegin + windex * z_dim1], &L__1, &negcnt, &
  1385. ztz, &mingma, &iwork[iindr + windex], &isuppz[
  1386. (windex << 1) - 1], &nrminv, &resid, &rqcorr,
  1387. &work[indwrk]);
  1388. if (iter == 0) {
  1389. bstres = resid;
  1390. bstw = lambda;
  1391. } else if (resid < bstres) {
  1392. bstres = resid;
  1393. bstw = lambda;
  1394. }
  1395. /* Computing MIN */
  1396. i__4 = isupmn, i__5 = isuppz[(windex << 1) - 1];
  1397. isupmn = f2cmin(i__4,i__5);
  1398. /* Computing MAX */
  1399. i__4 = isupmx, i__5 = isuppz[windex * 2];
  1400. isupmx = f2cmax(i__4,i__5);
  1401. ++iter;
  1402. /* sin alpha <= |resid|/gap */
  1403. /* Note that both the residual and the gap are */
  1404. /* proportional to the matrix, so ||T|| doesn't play */
  1405. /* a role in the quotient */
  1406. /* Convergence test for Rayleigh-Quotient iteration */
  1407. /* (omitted when Bisection has been used) */
  1408. if (resid > tol * gap && abs(rqcorr) > rqtol * abs(
  1409. lambda) && ! usedbs) {
  1410. /* We need to check that the RQCORR update doesn't */
  1411. /* move the eigenvalue away from the desired one and */
  1412. /* towards a neighbor. -> protection with bisection */
  1413. if (indeig <= negcnt) {
  1414. /* The wanted eigenvalue lies to the left */
  1415. sgndef = -1.f;
  1416. } else {
  1417. /* The wanted eigenvalue lies to the right */
  1418. sgndef = 1.f;
  1419. }
  1420. /* We only use the RQCORR if it improves the */
  1421. /* the iterate reasonably. */
  1422. if (rqcorr * sgndef >= 0.f && lambda + rqcorr <=
  1423. right && lambda + rqcorr >= left) {
  1424. usedrq = TRUE_;
  1425. /* Store new midpoint of bisection interval in WORK */
  1426. if (sgndef == 1.f) {
  1427. /* The current LAMBDA is on the left of the true */
  1428. /* eigenvalue */
  1429. left = lambda;
  1430. /* We prefer to assume that the error estimate */
  1431. /* is correct. We could make the interval not */
  1432. /* as a bracket but to be modified if the RQCORR */
  1433. /* chooses to. In this case, the RIGHT side should */
  1434. /* be modified as follows: */
  1435. /* RIGHT = MAX(RIGHT, LAMBDA + RQCORR) */
  1436. } else {
  1437. /* The current LAMBDA is on the right of the true */
  1438. /* eigenvalue */
  1439. right = lambda;
  1440. /* See comment about assuming the error estimate is */
  1441. /* correct above. */
  1442. /* LEFT = MIN(LEFT, LAMBDA + RQCORR) */
  1443. }
  1444. work[windex] = (right + left) * .5f;
  1445. /* Take RQCORR since it has the correct sign and */
  1446. /* improves the iterate reasonably */
  1447. lambda += rqcorr;
  1448. /* Update width of error interval */
  1449. werr[windex] = (right - left) * .5f;
  1450. } else {
  1451. needbs = TRUE_;
  1452. }
  1453. if (right - left < rqtol * abs(lambda)) {
  1454. /* The eigenvalue is computed to bisection accuracy */
  1455. /* compute eigenvector and stop */
  1456. usedbs = TRUE_;
  1457. goto L120;
  1458. } else if (iter < 10) {
  1459. goto L120;
  1460. } else if (iter == 10) {
  1461. needbs = TRUE_;
  1462. goto L120;
  1463. } else {
  1464. *info = 5;
  1465. return 0;
  1466. }
  1467. } else {
  1468. stp2ii = FALSE_;
  1469. if (usedrq && usedbs && bstres <= resid) {
  1470. lambda = bstw;
  1471. stp2ii = TRUE_;
  1472. }
  1473. if (stp2ii) {
  1474. /* improve error angle by second step */
  1475. L__1 = ! usedbs;
  1476. clar1v_(&in, &c__1, &in, &lambda, &d__[ibegin]
  1477. , &l[ibegin], &work[indld + ibegin -
  1478. 1], &work[indlld + ibegin - 1],
  1479. pivmin, &gaptol, &z__[ibegin + windex
  1480. * z_dim1], &L__1, &negcnt, &ztz, &
  1481. mingma, &iwork[iindr + windex], &
  1482. isuppz[(windex << 1) - 1], &nrminv, &
  1483. resid, &rqcorr, &work[indwrk]);
  1484. }
  1485. work[windex] = lambda;
  1486. }
  1487. /* Compute FP-vector support w.r.t. whole matrix */
  1488. isuppz[(windex << 1) - 1] += oldien;
  1489. isuppz[windex * 2] += oldien;
  1490. zfrom = isuppz[(windex << 1) - 1];
  1491. zto = isuppz[windex * 2];
  1492. isupmn += oldien;
  1493. isupmx += oldien;
  1494. /* Ensure vector is ok if support in the RQI has changed */
  1495. if (isupmn < zfrom) {
  1496. i__4 = zfrom - 1;
  1497. for (ii = isupmn; ii <= i__4; ++ii) {
  1498. i__5 = ii + windex * z_dim1;
  1499. z__[i__5].r = 0.f, z__[i__5].i = 0.f;
  1500. /* L122: */
  1501. }
  1502. }
  1503. if (isupmx > zto) {
  1504. i__4 = isupmx;
  1505. for (ii = zto + 1; ii <= i__4; ++ii) {
  1506. i__5 = ii + windex * z_dim1;
  1507. z__[i__5].r = 0.f, z__[i__5].i = 0.f;
  1508. /* L123: */
  1509. }
  1510. }
  1511. i__4 = zto - zfrom + 1;
  1512. csscal_(&i__4, &nrminv, &z__[zfrom + windex * z_dim1],
  1513. &c__1);
  1514. L125:
  1515. /* Update W */
  1516. w[windex] = lambda + sigma;
  1517. /* Recompute the gaps on the left and right */
  1518. /* But only allow them to become larger and not */
  1519. /* smaller (which can only happen through "bad" */
  1520. /* cancellation and doesn't reflect the theory */
  1521. /* where the initial gaps are underestimated due */
  1522. /* to WERR being too crude.) */
  1523. if (! eskip) {
  1524. if (k > 1) {
  1525. /* Computing MAX */
  1526. r__1 = wgap[windmn], r__2 = w[windex] - werr[
  1527. windex] - w[windmn] - werr[windmn];
  1528. wgap[windmn] = f2cmax(r__1,r__2);
  1529. }
  1530. if (windex < wend) {
  1531. /* Computing MAX */
  1532. r__1 = savgap, r__2 = w[windpl] - werr[windpl]
  1533. - w[windex] - werr[windex];
  1534. wgap[windex] = f2cmax(r__1,r__2);
  1535. }
  1536. }
  1537. ++idone;
  1538. }
  1539. /* here ends the code for the current child */
  1540. L139:
  1541. /* Proceed to any remaining child nodes */
  1542. newfst = j + 1;
  1543. L140:
  1544. ;
  1545. }
  1546. /* L150: */
  1547. }
  1548. ++ndepth;
  1549. goto L40;
  1550. }
  1551. ibegin = iend + 1;
  1552. wbegin = wend + 1;
  1553. L170:
  1554. ;
  1555. }
  1556. return 0;
  1557. /* End of CLARRV */
  1558. } /* clarrv_ */