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