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.

sbdsvdx.c 43 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  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 real c_b10 = 1.f;
  485. static doublereal c_b14 = -.125;
  486. static integer c__1 = 1;
  487. static real c_b19 = 0.f;
  488. static integer c__2 = 2;
  489. /* > \brief \b SBDSVDX */
  490. /* =========== DOCUMENTATION =========== */
  491. /* Online html documentation available at */
  492. /* http://www.netlib.org/lapack/explore-html/ */
  493. /* > \htmlonly */
  494. /* > Download SBDSVDX + dependencies */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sbdsvdx
  496. .f"> */
  497. /* > [TGZ]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sbdsvdx
  499. .f"> */
  500. /* > [ZIP]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sbdsvdx
  502. .f"> */
  503. /* > [TXT]</a> */
  504. /* > \endhtmlonly */
  505. /* Definition: */
  506. /* =========== */
  507. /* SUBROUTINE SBDSVDX( UPLO, JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
  508. /* $ NS, S, Z, LDZ, WORK, IWORK, INFO ) */
  509. /* CHARACTER JOBZ, RANGE, UPLO */
  510. /* INTEGER IL, INFO, IU, LDZ, N, NS */
  511. /* REAL VL, VU */
  512. /* INTEGER IWORK( * ) */
  513. /* REAL D( * ), E( * ), S( * ), WORK( * ), */
  514. /* Z( LDZ, * ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > SBDSVDX computes the singular value decomposition (SVD) of a real */
  521. /* > N-by-N (upper or lower) bidiagonal matrix B, B = U * S * VT, */
  522. /* > where S is a diagonal matrix with non-negative diagonal elements */
  523. /* > (the singular values of B), and U and VT are orthogonal matrices */
  524. /* > of left and right singular vectors, respectively. */
  525. /* > */
  526. /* > Given an upper bidiagonal B with diagonal D = [ d_1 d_2 ... d_N ] */
  527. /* > and superdiagonal E = [ e_1 e_2 ... e_N-1 ], SBDSVDX computes the */
  528. /* > singular value decompositon of B through the eigenvalues and */
  529. /* > eigenvectors of the N*2-by-N*2 tridiagonal matrix */
  530. /* > */
  531. /* > | 0 d_1 | */
  532. /* > | d_1 0 e_1 | */
  533. /* > TGK = | e_1 0 d_2 | */
  534. /* > | d_2 . . | */
  535. /* > | . . . | */
  536. /* > */
  537. /* > If (s,u,v) is a singular triplet of B with ||u|| = ||v|| = 1, then */
  538. /* > (+/-s,q), ||q|| = 1, are eigenpairs of TGK, with q = P * ( u' +/-v' ) / */
  539. /* > sqrt(2) = ( v_1 u_1 v_2 u_2 ... v_n u_n ) / sqrt(2), and */
  540. /* > P = [ e_{n+1} e_{1} e_{n+2} e_{2} ... ]. */
  541. /* > */
  542. /* > Given a TGK matrix, one can either a) compute -s,-v and change signs */
  543. /* > so that the singular values (and corresponding vectors) are already in */
  544. /* > descending order (as in SGESVD/SGESDD) or b) compute s,v and reorder */
  545. /* > the values (and corresponding vectors). SBDSVDX implements a) by */
  546. /* > calling SSTEVX (bisection plus inverse iteration, to be replaced */
  547. /* > with a version of the Multiple Relative Robust Representation */
  548. /* > algorithm. (See P. Willems and B. Lang, A framework for the MR^3 */
  549. /* > algorithm: theory and implementation, SIAM J. Sci. Comput., */
  550. /* > 35:740-766, 2013.) */
  551. /* > \endverbatim */
  552. /* Arguments: */
  553. /* ========== */
  554. /* > \param[in] UPLO */
  555. /* > \verbatim */
  556. /* > UPLO is CHARACTER*1 */
  557. /* > = 'U': B is upper bidiagonal; */
  558. /* > = 'L': B is lower bidiagonal. */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[in] JOBZ */
  562. /* > \verbatim */
  563. /* > JOBZ is CHARACTER*1 */
  564. /* > = 'N': Compute singular values only; */
  565. /* > = 'V': Compute singular values and singular vectors. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[in] RANGE */
  569. /* > \verbatim */
  570. /* > RANGE is CHARACTER*1 */
  571. /* > = 'A': all singular values will be found. */
  572. /* > = 'V': all singular values in the half-open interval [VL,VU) */
  573. /* > will be found. */
  574. /* > = 'I': the IL-th through IU-th singular values will be found. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in] N */
  578. /* > \verbatim */
  579. /* > N is INTEGER */
  580. /* > The order of the bidiagonal matrix. N >= 0. */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[in] D */
  584. /* > \verbatim */
  585. /* > D is REAL array, dimension (N) */
  586. /* > The n diagonal elements of the bidiagonal matrix B. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] E */
  590. /* > \verbatim */
  591. /* > E is REAL array, dimension (f2cmax(1,N-1)) */
  592. /* > The (n-1) superdiagonal elements of the bidiagonal matrix */
  593. /* > B in elements 1 to N-1. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in] VL */
  597. /* > \verbatim */
  598. /* > VL is REAL */
  599. /* > If RANGE='V', the lower bound of the interval to */
  600. /* > be searched for singular values. VU > VL. */
  601. /* > Not referenced if RANGE = 'A' or 'I'. */
  602. /* > \endverbatim */
  603. /* > */
  604. /* > \param[in] VU */
  605. /* > \verbatim */
  606. /* > VU is REAL */
  607. /* > If RANGE='V', the upper bound of the interval to */
  608. /* > be searched for singular values. VU > VL. */
  609. /* > Not referenced if RANGE = 'A' or 'I'. */
  610. /* > \endverbatim */
  611. /* > */
  612. /* > \param[in] IL */
  613. /* > \verbatim */
  614. /* > IL is INTEGER */
  615. /* > If RANGE='I', the index of the */
  616. /* > smallest singular value to be returned. */
  617. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  618. /* > Not referenced if RANGE = 'A' or 'V'. */
  619. /* > \endverbatim */
  620. /* > */
  621. /* > \param[in] IU */
  622. /* > \verbatim */
  623. /* > IU is INTEGER */
  624. /* > If RANGE='I', the index of the */
  625. /* > largest singular value to be returned. */
  626. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  627. /* > Not referenced if RANGE = 'A' or 'V'. */
  628. /* > \endverbatim */
  629. /* > */
  630. /* > \param[out] NS */
  631. /* > \verbatim */
  632. /* > NS is INTEGER */
  633. /* > The total number of singular values found. 0 <= NS <= N. */
  634. /* > If RANGE = 'A', NS = N, and if RANGE = 'I', NS = IU-IL+1. */
  635. /* > \endverbatim */
  636. /* > */
  637. /* > \param[out] S */
  638. /* > \verbatim */
  639. /* > S is REAL array, dimension (N) */
  640. /* > The first NS elements contain the selected singular values in */
  641. /* > ascending order. */
  642. /* > \endverbatim */
  643. /* > */
  644. /* > \param[out] Z */
  645. /* > \verbatim */
  646. /* > Z is REAL array, dimension (2*N,K) */
  647. /* > If JOBZ = 'V', then if INFO = 0 the first NS columns of Z */
  648. /* > contain the singular vectors of the matrix B corresponding to */
  649. /* > the selected singular values, with U in rows 1 to N and V */
  650. /* > in rows N+1 to N*2, i.e. */
  651. /* > Z = [ U ] */
  652. /* > [ V ] */
  653. /* > If JOBZ = 'N', then Z is not referenced. */
  654. /* > Note: The user must ensure that at least K = NS+1 columns are */
  655. /* > supplied in the array Z; if RANGE = 'V', the exact value of */
  656. /* > NS is not known in advance and an upper bound must be used. */
  657. /* > \endverbatim */
  658. /* > */
  659. /* > \param[in] LDZ */
  660. /* > \verbatim */
  661. /* > LDZ is INTEGER */
  662. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  663. /* > JOBZ = 'V', LDZ >= f2cmax(2,N*2). */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[out] WORK */
  667. /* > \verbatim */
  668. /* > WORK is REAL array, dimension (14*N) */
  669. /* > \endverbatim */
  670. /* > */
  671. /* > \param[out] IWORK */
  672. /* > \verbatim */
  673. /* > IWORK is INTEGER array, dimension (12*N) */
  674. /* > If JOBZ = 'V', then if INFO = 0, the first NS elements of */
  675. /* > IWORK are zero. If INFO > 0, then IWORK contains the indices */
  676. /* > of the eigenvectors that failed to converge in DSTEVX. */
  677. /* > \endverbatim */
  678. /* > */
  679. /* > \param[out] INFO */
  680. /* > \verbatim */
  681. /* > INFO is INTEGER */
  682. /* > = 0: successful exit */
  683. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  684. /* > > 0: if INFO = i, then i eigenvectors failed to converge */
  685. /* > in SSTEVX. The indices of the eigenvectors */
  686. /* > (as returned by SSTEVX) are stored in the */
  687. /* > array IWORK. */
  688. /* > if INFO = N*2 + 1, an internal error occurred. */
  689. /* > \endverbatim */
  690. /* Authors: */
  691. /* ======== */
  692. /* > \author Univ. of Tennessee */
  693. /* > \author Univ. of California Berkeley */
  694. /* > \author Univ. of Colorado Denver */
  695. /* > \author NAG Ltd. */
  696. /* > \date June 2016 */
  697. /* > \ingroup realOTHEReigen */
  698. /* ===================================================================== */
  699. /* Subroutine */ void sbdsvdx_(char *uplo, char *jobz, char *range, integer *n,
  700. real *d__, real *e, real *vl, real *vu, integer *il, integer *iu,
  701. integer *ns, real *s, real *z__, integer *ldz, real *work, integer *
  702. iwork, integer *info)
  703. {
  704. /* System generated locals */
  705. integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
  706. real r__1, r__2, r__3, r__4;
  707. doublereal d__1;
  708. /* Local variables */
  709. real emin;
  710. integer ntgk;
  711. real smin, smax;
  712. extern real sdot_(integer *, real *, integer *, real *, integer *);
  713. real nrmu, nrmv;
  714. logical sveq0;
  715. extern real snrm2_(integer *, real *, integer *);
  716. integer i__, idbeg, j, k;
  717. real sqrt2;
  718. integer idend, isbeg;
  719. extern logical lsame_(char *, char *);
  720. integer idtgk, ietgk;
  721. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  722. integer iltgk, itemp, icolz;
  723. logical allsv;
  724. integer idptr;
  725. logical indsv;
  726. integer ieptr, iutgk;
  727. real vltgk;
  728. logical lower;
  729. real zjtji;
  730. logical split, valsv;
  731. integer isplt;
  732. real ortol, vutgk;
  733. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  734. integer *), sswap_(integer *, real *, integer *, real *, integer *
  735. );
  736. logical wantz;
  737. char rngvx[1];
  738. integer irowu, irowv;
  739. extern /* Subroutine */ void saxpy_(integer *, real *, real *, integer *,
  740. real *, integer *);
  741. integer irowz, iifail;
  742. real mu;
  743. extern real slamch_(char *);
  744. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  745. extern integer isamax_(integer *, real *, integer *);
  746. real abstol;
  747. extern /* Subroutine */ void slaset_(char *, integer *, integer *, real *,
  748. real *, real *, integer *);
  749. real thresh;
  750. integer iiwork;
  751. extern /* Subroutine */ void mecago_(), sstevx_(char *, char *,
  752. integer *, real *, real *, real *, real *, integer *, integer *,
  753. real *, integer *, real *, real *, integer *, real *, integer *,
  754. integer *, integer *);
  755. real eps;
  756. integer nsl;
  757. real tol, ulp;
  758. integer nru, nrv;
  759. /* -- LAPACK driver routine (version 3.8.0) -- */
  760. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  761. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  762. /* November 2017 */
  763. /* ===================================================================== */
  764. /* Test the input parameters. */
  765. /* Parameter adjustments */
  766. --d__;
  767. --e;
  768. --s;
  769. z_dim1 = *ldz;
  770. z_offset = 1 + z_dim1 * 1;
  771. z__ -= z_offset;
  772. --work;
  773. --iwork;
  774. /* Function Body */
  775. allsv = lsame_(range, "A");
  776. valsv = lsame_(range, "V");
  777. indsv = lsame_(range, "I");
  778. wantz = lsame_(jobz, "V");
  779. lower = lsame_(uplo, "L");
  780. *info = 0;
  781. if (! lsame_(uplo, "U") && ! lower) {
  782. *info = -1;
  783. } else if (! (wantz || lsame_(jobz, "N"))) {
  784. *info = -2;
  785. } else if (! (allsv || valsv || indsv)) {
  786. *info = -3;
  787. } else if (*n < 0) {
  788. *info = -4;
  789. } else if (*n > 0) {
  790. if (valsv) {
  791. if (*vl < 0.f) {
  792. *info = -7;
  793. } else if (*vu <= *vl) {
  794. *info = -8;
  795. }
  796. } else if (indsv) {
  797. if (*il < 1 || *il > f2cmax(1,*n)) {
  798. *info = -9;
  799. } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
  800. *info = -10;
  801. }
  802. }
  803. }
  804. if (*info == 0) {
  805. if (*ldz < 1 || wantz && *ldz < *n << 1) {
  806. *info = -14;
  807. }
  808. }
  809. if (*info != 0) {
  810. i__1 = -(*info);
  811. xerbla_("SBDSVDX", &i__1, (ftnlen)7);
  812. return;
  813. }
  814. /* Quick return if possible (N.LE.1) */
  815. *ns = 0;
  816. if (*n == 0) {
  817. return;
  818. }
  819. if (*n == 1) {
  820. if (allsv || indsv) {
  821. *ns = 1;
  822. s[1] = abs(d__[1]);
  823. } else {
  824. if (*vl < abs(d__[1]) && *vu >= abs(d__[1])) {
  825. *ns = 1;
  826. s[1] = abs(d__[1]);
  827. }
  828. }
  829. if (wantz) {
  830. z__[z_dim1 + 1] = r_sign(&c_b10, &d__[1]);
  831. z__[z_dim1 + 2] = 1.f;
  832. }
  833. return;
  834. }
  835. abstol = slamch_("Safe Minimum") * 2;
  836. ulp = slamch_("Precision");
  837. eps = slamch_("Epsilon");
  838. sqrt2 = sqrt(2.f);
  839. ortol = sqrt(ulp);
  840. /* Criterion for splitting is taken from SBDSQR when singular */
  841. /* values are computed to relative accuracy TOL. (See J. Demmel and */
  842. /* W. Kahan, Accurate singular values of bidiagonal matrices, SIAM */
  843. /* J. Sci. and Stat. Comput., 11:873–912, 1990.) */
  844. /* Computing MAX */
  845. /* Computing MIN */
  846. d__1 = (doublereal) eps;
  847. r__3 = 100.f, r__4 = pow_dd(&d__1, &c_b14);
  848. r__1 = 10.f, r__2 = f2cmin(r__3,r__4);
  849. tol = f2cmax(r__1,r__2) * eps;
  850. /* Compute approximate maximum, minimum singular values. */
  851. i__ = isamax_(n, &d__[1], &c__1);
  852. smax = (r__1 = d__[i__], abs(r__1));
  853. i__1 = *n - 1;
  854. i__ = isamax_(&i__1, &e[1], &c__1);
  855. /* Computing MAX */
  856. r__2 = smax, r__3 = (r__1 = e[i__], abs(r__1));
  857. smax = f2cmax(r__2,r__3);
  858. /* Compute threshold for neglecting D's and E's. */
  859. smin = abs(d__[1]);
  860. if (smin != 0.f) {
  861. mu = smin;
  862. i__1 = *n;
  863. for (i__ = 2; i__ <= i__1; ++i__) {
  864. mu = (r__2 = d__[i__], abs(r__2)) * (mu / (mu + (r__1 = e[i__ - 1]
  865. , abs(r__1))));
  866. smin = f2cmin(smin,mu);
  867. if (smin == 0.f) {
  868. myexit_();
  869. }
  870. }
  871. }
  872. smin /= sqrt((real) (*n));
  873. thresh = tol * smin;
  874. /* Check for zeros in D and E (splits), i.e. submatrices. */
  875. i__1 = *n - 1;
  876. for (i__ = 1; i__ <= i__1; ++i__) {
  877. if ((r__1 = d__[i__], abs(r__1)) <= thresh) {
  878. d__[i__] = 0.f;
  879. }
  880. if ((r__1 = e[i__], abs(r__1)) <= thresh) {
  881. e[i__] = 0.f;
  882. }
  883. }
  884. if ((r__1 = d__[*n], abs(r__1)) <= thresh) {
  885. d__[*n] = 0.f;
  886. }
  887. /* Pointers for arrays used by SSTEVX. */
  888. idtgk = 1;
  889. ietgk = idtgk + (*n << 1);
  890. itemp = ietgk + (*n << 1);
  891. iifail = 1;
  892. iiwork = iifail + (*n << 1);
  893. /* Set RNGVX, which corresponds to RANGE for SSTEVX in TGK mode. */
  894. /* VL,VU or IL,IU are redefined to conform to implementation a) */
  895. /* described in the leading comments. */
  896. iltgk = 0;
  897. iutgk = 0;
  898. vltgk = 0.f;
  899. vutgk = 0.f;
  900. if (allsv) {
  901. /* All singular values will be found. We aim at -s (see */
  902. /* leading comments) with RNGVX = 'I'. IL and IU are set */
  903. /* later (as ILTGK and IUTGK) according to the dimension */
  904. /* of the active submatrix. */
  905. *(unsigned char *)rngvx = 'I';
  906. if (wantz) {
  907. i__1 = *n << 1;
  908. i__2 = *n + 1;
  909. slaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  910. }
  911. } else if (valsv) {
  912. /* Find singular values in a half-open interval. We aim */
  913. /* at -s (see leading comments) and we swap VL and VU */
  914. /* (as VUTGK and VLTGK), changing their signs. */
  915. *(unsigned char *)rngvx = 'V';
  916. vltgk = -(*vu);
  917. vutgk = -(*vl);
  918. i__1 = idtgk + (*n << 1) - 1;
  919. for (i__ = idtgk; i__ <= i__1; ++i__) {
  920. work[i__] = 0.f;
  921. }
  922. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  923. scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  924. i__1 = *n - 1;
  925. scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  926. i__1 = *n << 1;
  927. sstevx_("N", "V", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vutgk, &
  928. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  929. itemp], &iwork[iiwork], &iwork[iifail], info);
  930. if (*ns == 0) {
  931. return;
  932. } else {
  933. if (wantz) {
  934. i__1 = *n << 1;
  935. slaset_("F", &i__1, ns, &c_b19, &c_b19, &z__[z_offset], ldz);
  936. }
  937. }
  938. } else if (indsv) {
  939. /* Find the IL-th through the IU-th singular values. We aim */
  940. /* at -s (see leading comments) and indices are mapped into */
  941. /* values, therefore mimicking SSTEBZ, where */
  942. /* GL = GL - FUDGE*TNORM*ULP*N - FUDGE*TWO*PIVMIN */
  943. /* GU = GU + FUDGE*TNORM*ULP*N + FUDGE*PIVMIN */
  944. iltgk = *il;
  945. iutgk = *iu;
  946. *(unsigned char *)rngvx = 'V';
  947. i__1 = idtgk + (*n << 1) - 1;
  948. for (i__ = idtgk; i__ <= i__1; ++i__) {
  949. work[i__] = 0.f;
  950. }
  951. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  952. scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  953. i__1 = *n - 1;
  954. scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  955. i__1 = *n << 1;
  956. sstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vltgk, &
  957. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  958. itemp], &iwork[iiwork], &iwork[iifail], info);
  959. vltgk = s[1] - smax * 2.f * ulp * *n;
  960. i__1 = idtgk + (*n << 1) - 1;
  961. for (i__ = idtgk; i__ <= i__1; ++i__) {
  962. work[i__] = 0.f;
  963. }
  964. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  965. scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  966. i__1 = *n - 1;
  967. scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  968. i__1 = *n << 1;
  969. sstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vutgk, &vutgk, &
  970. iutgk, &iutgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  971. itemp], &iwork[iiwork], &iwork[iifail], info);
  972. vutgk = s[1] + smax * 2.f * ulp * *n;
  973. vutgk = f2cmin(vutgk,0.f);
  974. /* If VLTGK=VUTGK, SSTEVX returns an error message, */
  975. /* so if needed we change VUTGK slightly. */
  976. if (vltgk == vutgk) {
  977. vltgk -= tol;
  978. }
  979. if (wantz) {
  980. i__1 = *n << 1;
  981. i__2 = *iu - *il + 1;
  982. slaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  983. }
  984. }
  985. /* Initialize variables and pointers for S, Z, and WORK. */
  986. /* NRU, NRV: number of rows in U and V for the active submatrix */
  987. /* IDBEG, ISBEG: offsets for the entries of D and S */
  988. /* IROWZ, ICOLZ: offsets for the rows and columns of Z */
  989. /* IROWU, IROWV: offsets for the rows of U and V */
  990. *ns = 0;
  991. nru = 0;
  992. nrv = 0;
  993. idbeg = 1;
  994. isbeg = 1;
  995. irowz = 1;
  996. icolz = 1;
  997. irowu = 2;
  998. irowv = 1;
  999. split = FALSE_;
  1000. sveq0 = FALSE_;
  1001. /* Form the tridiagonal TGK matrix. */
  1002. i__1 = *n;
  1003. for (i__ = 1; i__ <= i__1; ++i__) {
  1004. s[i__] = 0.f;
  1005. }
  1006. /* S( 1:N ) = ZERO */
  1007. work[ietgk + (*n << 1) - 1] = 0.f;
  1008. i__1 = idtgk + (*n << 1) - 1;
  1009. for (i__ = idtgk; i__ <= i__1; ++i__) {
  1010. work[i__] = 0.f;
  1011. }
  1012. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  1013. scopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  1014. i__1 = *n - 1;
  1015. scopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  1016. /* Check for splits in two levels, outer level */
  1017. /* in E and inner level in D. */
  1018. i__1 = *n << 1;
  1019. for (ieptr = 2; ieptr <= i__1; ieptr += 2) {
  1020. if (work[ietgk + ieptr - 1] == 0.f) {
  1021. /* Split in E (this piece of B is square) or bottom */
  1022. /* of the (input bidiagonal) matrix. */
  1023. isplt = idbeg;
  1024. idend = ieptr - 1;
  1025. i__2 = idend;
  1026. for (idptr = idbeg; idptr <= i__2; idptr += 2) {
  1027. if (work[ietgk + idptr - 1] == 0.f) {
  1028. /* Split in D (rectangular submatrix). Set the number */
  1029. /* of rows in U and V (NRU and NRV) accordingly. */
  1030. if (idptr == idbeg) {
  1031. /* D=0 at the top. */
  1032. sveq0 = TRUE_;
  1033. if (idbeg == idend) {
  1034. nru = 1;
  1035. nrv = 1;
  1036. }
  1037. } else if (idptr == idend) {
  1038. /* D=0 at the bottom. */
  1039. sveq0 = TRUE_;
  1040. nru = (idend - isplt) / 2 + 1;
  1041. nrv = nru;
  1042. if (isplt != idbeg) {
  1043. ++nru;
  1044. }
  1045. } else {
  1046. if (isplt == idbeg) {
  1047. /* Split: top rectangular submatrix. */
  1048. nru = (idptr - idbeg) / 2;
  1049. nrv = nru + 1;
  1050. } else {
  1051. /* Split: middle square submatrix. */
  1052. nru = (idptr - isplt) / 2 + 1;
  1053. nrv = nru;
  1054. }
  1055. }
  1056. } else if (idptr == idend) {
  1057. /* Last entry of D in the active submatrix. */
  1058. if (isplt == idbeg) {
  1059. /* No split (trivial case). */
  1060. nru = (idend - idbeg) / 2 + 1;
  1061. nrv = nru;
  1062. } else {
  1063. /* Split: bottom rectangular submatrix. */
  1064. nrv = (idend - isplt) / 2 + 1;
  1065. nru = nrv + 1;
  1066. }
  1067. }
  1068. ntgk = nru + nrv;
  1069. if (ntgk > 0) {
  1070. /* Compute eigenvalues/vectors of the active */
  1071. /* submatrix according to RANGE: */
  1072. /* if RANGE='A' (ALLSV) then RNGVX = 'I' */
  1073. /* if RANGE='V' (VALSV) then RNGVX = 'V' */
  1074. /* if RANGE='I' (INDSV) then RNGVX = 'V' */
  1075. iltgk = 1;
  1076. iutgk = ntgk / 2;
  1077. if (allsv || vutgk == 0.f) {
  1078. if (sveq0 || smin < eps || ntgk % 2 > 0) {
  1079. /* Special case: eigenvalue equal to zero or very */
  1080. /* small, additional eigenvector is needed. */
  1081. ++iutgk;
  1082. }
  1083. }
  1084. /* Workspace needed by SSTEVX: */
  1085. /* WORK( ITEMP: ): 2*5*NTGK */
  1086. /* IWORK( 1: ): 2*6*NTGK */
  1087. sstevx_(jobz, rngvx, &ntgk, &work[idtgk + isplt - 1], &
  1088. work[ietgk + isplt - 1], &vltgk, &vutgk, &iltgk, &
  1089. iutgk, &abstol, &nsl, &s[isbeg], &z__[irowz +
  1090. icolz * z_dim1], ldz, &work[itemp], &iwork[iiwork]
  1091. , &iwork[iifail], info);
  1092. if (*info != 0) {
  1093. /* Exit with the error code from SSTEVX. */
  1094. return;
  1095. }
  1096. emin = (r__1 = s[isbeg], abs(r__1));
  1097. i__3 = isbeg + nsl - 1;
  1098. for (i__ = isbeg; i__ <= i__3; ++i__) {
  1099. if ((r__1 = s[i__], abs(r__1)) > emin) {
  1100. emin = s[i__];
  1101. }
  1102. }
  1103. /* EMIN = ABS( MAXVAL( S( ISBEG:ISBEG+NSL-1 ) ) ) */
  1104. if (nsl > 0 && wantz) {
  1105. /* Normalize u=Z([2,4,...],:) and v=Z([1,3,...],:), */
  1106. /* changing the sign of v as discussed in the leading */
  1107. /* comments. The norms of u and v may be (slightly) */
  1108. /* different from 1/sqrt(2) if the corresponding */
  1109. /* eigenvalues are very small or too close. We check */
  1110. /* those norms and, if needed, reorthogonalize the */
  1111. /* vectors. */
  1112. if (nsl > 1 && vutgk == 0.f && ntgk % 2 == 0 && emin
  1113. == 0.f && ! split) {
  1114. /* D=0 at the top or bottom of the active submatrix: */
  1115. /* one eigenvalue is equal to zero; concatenate the */
  1116. /* eigenvectors corresponding to the two smallest */
  1117. /* eigenvalues. */
  1118. i__3 = irowz + ntgk - 1;
  1119. for (i__ = irowz; i__ <= i__3; ++i__) {
  1120. z__[i__ + (icolz + nsl - 2) * z_dim1] += z__[
  1121. i__ + (icolz + nsl - 1) * z_dim1];
  1122. z__[i__ + (icolz + nsl - 1) * z_dim1] = 0.f;
  1123. }
  1124. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) = */
  1125. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) + */
  1126. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) */
  1127. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) = */
  1128. /* $ ZERO */
  1129. /* IF( IUTGK*2.GT.NTGK ) THEN */
  1130. /* Eigenvalue equal to zero or very small. */
  1131. /* NSL = NSL - 1 */
  1132. /* END IF */
  1133. }
  1134. /* Computing MIN */
  1135. i__4 = nsl - 1, i__5 = nru - 1;
  1136. i__3 = f2cmin(i__4,i__5);
  1137. for (i__ = 0; i__ <= i__3; ++i__) {
  1138. nrmu = snrm2_(&nru, &z__[irowu + (icolz + i__) *
  1139. z_dim1], &c__2);
  1140. if (nrmu == 0.f) {
  1141. *info = (*n << 1) + 1;
  1142. return;
  1143. }
  1144. r__1 = 1.f / nrmu;
  1145. sscal_(&nru, &r__1, &z__[irowu + (icolz + i__) *
  1146. z_dim1], &c__2);
  1147. if (nrmu != 1.f && (r__1 = nrmu - ortol, abs(r__1)
  1148. ) * sqrt2 > 1.f) {
  1149. i__4 = i__ - 1;
  1150. for (j = 0; j <= i__4; ++j) {
  1151. zjtji = -sdot_(&nru, &z__[irowu + (icolz
  1152. + j) * z_dim1], &c__2, &z__[irowu
  1153. + (icolz + i__) * z_dim1], &c__2);
  1154. saxpy_(&nru, &zjtji, &z__[irowu + (icolz
  1155. + j) * z_dim1], &c__2, &z__[irowu
  1156. + (icolz + i__) * z_dim1], &c__2);
  1157. }
  1158. nrmu = snrm2_(&nru, &z__[irowu + (icolz + i__)
  1159. * z_dim1], &c__2);
  1160. r__1 = 1.f / nrmu;
  1161. sscal_(&nru, &r__1, &z__[irowu + (icolz + i__)
  1162. * z_dim1], &c__2);
  1163. }
  1164. }
  1165. /* Computing MIN */
  1166. i__4 = nsl - 1, i__5 = nrv - 1;
  1167. i__3 = f2cmin(i__4,i__5);
  1168. for (i__ = 0; i__ <= i__3; ++i__) {
  1169. nrmv = snrm2_(&nrv, &z__[irowv + (icolz + i__) *
  1170. z_dim1], &c__2);
  1171. if (nrmv == 0.f) {
  1172. *info = (*n << 1) + 1;
  1173. return;
  1174. }
  1175. r__1 = -1.f / nrmv;
  1176. sscal_(&nrv, &r__1, &z__[irowv + (icolz + i__) *
  1177. z_dim1], &c__2);
  1178. if (nrmv != 1.f && (r__1 = nrmv - ortol, abs(r__1)
  1179. ) * sqrt2 > 1.f) {
  1180. i__4 = i__ - 1;
  1181. for (j = 0; j <= i__4; ++j) {
  1182. zjtji = -sdot_(&nrv, &z__[irowv + (icolz
  1183. + j) * z_dim1], &c__2, &z__[irowv
  1184. + (icolz + i__) * z_dim1], &c__2);
  1185. saxpy_(&nru, &zjtji, &z__[irowv + (icolz
  1186. + j) * z_dim1], &c__2, &z__[irowv
  1187. + (icolz + i__) * z_dim1], &c__2);
  1188. }
  1189. nrmv = snrm2_(&nrv, &z__[irowv + (icolz + i__)
  1190. * z_dim1], &c__2);
  1191. r__1 = 1.f / nrmv;
  1192. sscal_(&nrv, &r__1, &z__[irowv + (icolz + i__)
  1193. * z_dim1], &c__2);
  1194. }
  1195. }
  1196. if (vutgk == 0.f && idptr < idend && ntgk % 2 > 0) {
  1197. /* D=0 in the middle of the active submatrix (one */
  1198. /* eigenvalue is equal to zero): save the corresponding */
  1199. /* eigenvector for later use (when bottom of the */
  1200. /* active submatrix is reached). */
  1201. split = TRUE_;
  1202. i__3 = irowz + ntgk - 1;
  1203. for (i__ = irowz; i__ <= i__3; ++i__) {
  1204. z__[i__ + (*n + 1) * z_dim1] = z__[i__ + (*ns
  1205. + nsl) * z_dim1];
  1206. z__[i__ + (*ns + nsl) * z_dim1] = 0.f;
  1207. }
  1208. /* Z( IROWZ:IROWZ+NTGK-1,N+1 ) = */
  1209. /* $ Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) */
  1210. /* Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) = */
  1211. /* $ ZERO */
  1212. }
  1213. }
  1214. /* ** WANTZ **! */
  1215. nsl = f2cmin(nsl,nru);
  1216. sveq0 = FALSE_;
  1217. /* Absolute values of the eigenvalues of TGK. */
  1218. i__3 = nsl - 1;
  1219. for (i__ = 0; i__ <= i__3; ++i__) {
  1220. s[isbeg + i__] = (r__1 = s[isbeg + i__], abs(r__1));
  1221. }
  1222. /* Update pointers for TGK, S and Z. */
  1223. isbeg += nsl;
  1224. irowz += ntgk;
  1225. icolz += nsl;
  1226. irowu = irowz;
  1227. irowv = irowz + 1;
  1228. isplt = idptr + 1;
  1229. *ns += nsl;
  1230. nru = 0;
  1231. nrv = 0;
  1232. }
  1233. /* ** NTGK.GT.0 **! */
  1234. if (irowz < *n << 1 && wantz) {
  1235. i__3 = irowz - 1;
  1236. for (i__ = 1; i__ <= i__3; ++i__) {
  1237. z__[i__ + icolz * z_dim1] = 0.f;
  1238. }
  1239. /* Z( 1:IROWZ-1, ICOLZ ) = ZERO */
  1240. }
  1241. }
  1242. /* ** IDPTR loop **! */
  1243. if (split && wantz) {
  1244. /* Bring back eigenvector corresponding */
  1245. /* to eigenvalue equal to zero. */
  1246. i__2 = idend - ntgk + 1;
  1247. for (i__ = idbeg; i__ <= i__2; ++i__) {
  1248. z__[i__ + (isbeg - 1) * z_dim1] += z__[i__ + (*n + 1) *
  1249. z_dim1];
  1250. z__[i__ + (*n + 1) * z_dim1] = 0.f;
  1251. }
  1252. /* Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) = */
  1253. /* $ Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) + */
  1254. /* $ Z( IDBEG:IDEND-NTGK+1,N+1 ) */
  1255. /* Z( IDBEG:IDEND-NTGK+1,N+1 ) = 0 */
  1256. }
  1257. --irowv;
  1258. ++irowu;
  1259. idbeg = ieptr + 1;
  1260. sveq0 = FALSE_;
  1261. split = FALSE_;
  1262. }
  1263. /* ** Check for split in E **! */
  1264. }
  1265. /* Sort the singular values into decreasing order (insertion sort on */
  1266. /* singular values, but only one transposition per singular vector) */
  1267. /* ** IEPTR loop **! */
  1268. i__1 = *ns - 1;
  1269. for (i__ = 1; i__ <= i__1; ++i__) {
  1270. k = 1;
  1271. smin = s[1];
  1272. i__2 = *ns + 1 - i__;
  1273. for (j = 2; j <= i__2; ++j) {
  1274. if (s[j] <= smin) {
  1275. k = j;
  1276. smin = s[j];
  1277. }
  1278. }
  1279. if (k != *ns + 1 - i__) {
  1280. s[k] = s[*ns + 1 - i__];
  1281. s[*ns + 1 - i__] = smin;
  1282. if (wantz) {
  1283. i__2 = *n << 1;
  1284. sswap_(&i__2, &z__[k * z_dim1 + 1], &c__1, &z__[(*ns + 1 -
  1285. i__) * z_dim1 + 1], &c__1);
  1286. }
  1287. }
  1288. }
  1289. /* If RANGE=I, check for singular values/vectors to be discarded. */
  1290. if (indsv) {
  1291. k = *iu - *il + 1;
  1292. if (k < *ns) {
  1293. i__1 = *ns;
  1294. for (i__ = k + 1; i__ <= i__1; ++i__) {
  1295. s[i__] = 0.f;
  1296. }
  1297. /* S( K+1:NS ) = ZERO */
  1298. if (wantz) {
  1299. i__1 = *n << 1;
  1300. for (i__ = 1; i__ <= i__1; ++i__) {
  1301. i__2 = *ns;
  1302. for (j = k + 1; j <= i__2; ++j) {
  1303. z__[i__ + j * z_dim1] = 0.f;
  1304. }
  1305. }
  1306. /* Z( 1:N*2,K+1:NS ) = ZERO */
  1307. }
  1308. *ns = k;
  1309. }
  1310. }
  1311. /* Reorder Z: U = Z( 1:N,1:NS ), V = Z( N+1:N*2,1:NS ). */
  1312. /* If B is a lower diagonal, swap U and V. */
  1313. if (wantz) {
  1314. i__1 = *ns;
  1315. for (i__ = 1; i__ <= i__1; ++i__) {
  1316. i__2 = *n << 1;
  1317. scopy_(&i__2, &z__[i__ * z_dim1 + 1], &c__1, &work[1], &c__1);
  1318. if (lower) {
  1319. scopy_(n, &work[2], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1320. ;
  1321. scopy_(n, &work[1], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1322. } else {
  1323. scopy_(n, &work[2], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1324. scopy_(n, &work[1], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1325. ;
  1326. }
  1327. }
  1328. }
  1329. return;
  1330. /* End of SBDSVDX */
  1331. } /* sbdsvdx_ */