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.

sbbcsd.c 54 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  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 doublereal c_b10 = -.125;
  485. static real c_b35 = -1.f;
  486. static integer c__1 = 1;
  487. /* > \brief \b SBBCSD */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download SBBCSD + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sbbcsd.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sbbcsd.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sbbcsd.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE SBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, */
  506. /* THETA, PHI, U1, LDU1, U2, LDU2, V1T, LDV1T, */
  507. /* V2T, LDV2T, B11D, B11E, B12D, B12E, B21D, B21E, */
  508. /* B22D, B22E, WORK, LWORK, INFO ) */
  509. /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
  510. /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LWORK, M, P, Q */
  511. /* REAL B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
  512. /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
  513. /* $ PHI( * ), THETA( * ), WORK( * ) */
  514. /* REAL U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
  515. /* $ V2T( LDV2T, * ) */
  516. /* > \par Purpose: */
  517. /* ============= */
  518. /* > */
  519. /* > \verbatim */
  520. /* > */
  521. /* > SBBCSD computes the CS decomposition of an orthogonal matrix in */
  522. /* > bidiagonal-block form, */
  523. /* > */
  524. /* > */
  525. /* > [ B11 | B12 0 0 ] */
  526. /* > [ 0 | 0 -I 0 ] */
  527. /* > X = [----------------] */
  528. /* > [ B21 | B22 0 0 ] */
  529. /* > [ 0 | 0 0 I ] */
  530. /* > */
  531. /* > [ C | -S 0 0 ] */
  532. /* > [ U1 | ] [ 0 | 0 -I 0 ] [ V1 | ]**T */
  533. /* > = [---------] [---------------] [---------] . */
  534. /* > [ | U2 ] [ S | C 0 0 ] [ | V2 ] */
  535. /* > [ 0 | 0 0 I ] */
  536. /* > */
  537. /* > X is M-by-M, its top-left block is P-by-Q, and Q must be no larger */
  538. /* > than P, M-P, or M-Q. (If Q is not the smallest index, then X must be */
  539. /* > transposed and/or permuted. This can be done in constant time using */
  540. /* > the TRANS and SIGNS options. See SORCSD for details.) */
  541. /* > */
  542. /* > The bidiagonal matrices B11, B12, B21, and B22 are represented */
  543. /* > implicitly by angles THETA(1:Q) and PHI(1:Q-1). */
  544. /* > */
  545. /* > The orthogonal matrices U1, U2, V1T, and V2T are input/output. */
  546. /* > The input matrices are pre- or post-multiplied by the appropriate */
  547. /* > singular vector matrices. */
  548. /* > \endverbatim */
  549. /* Arguments: */
  550. /* ========== */
  551. /* > \param[in] JOBU1 */
  552. /* > \verbatim */
  553. /* > JOBU1 is CHARACTER */
  554. /* > = 'Y': U1 is updated; */
  555. /* > otherwise: U1 is not updated. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in] JOBU2 */
  559. /* > \verbatim */
  560. /* > JOBU2 is CHARACTER */
  561. /* > = 'Y': U2 is updated; */
  562. /* > otherwise: U2 is not updated. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] JOBV1T */
  566. /* > \verbatim */
  567. /* > JOBV1T is CHARACTER */
  568. /* > = 'Y': V1T is updated; */
  569. /* > otherwise: V1T is not updated. */
  570. /* > \endverbatim */
  571. /* > */
  572. /* > \param[in] JOBV2T */
  573. /* > \verbatim */
  574. /* > JOBV2T is CHARACTER */
  575. /* > = 'Y': V2T is updated; */
  576. /* > otherwise: V2T is not updated. */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[in] TRANS */
  580. /* > \verbatim */
  581. /* > TRANS is CHARACTER */
  582. /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
  583. /* > order; */
  584. /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
  585. /* > major order. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] M */
  589. /* > \verbatim */
  590. /* > M is INTEGER */
  591. /* > The number of rows and columns in X, the orthogonal matrix in */
  592. /* > bidiagonal-block form. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in] P */
  596. /* > \verbatim */
  597. /* > P is INTEGER */
  598. /* > The number of rows in the top-left block of X. 0 <= P <= M. */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[in] Q */
  602. /* > \verbatim */
  603. /* > Q is INTEGER */
  604. /* > The number of columns in the top-left block of X. */
  605. /* > 0 <= Q <= MIN(P,M-P,M-Q). */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in,out] THETA */
  609. /* > \verbatim */
  610. /* > THETA is REAL array, dimension (Q) */
  611. /* > On entry, the angles THETA(1),...,THETA(Q) that, along with */
  612. /* > PHI(1), ...,PHI(Q-1), define the matrix in bidiagonal-block */
  613. /* > form. On exit, the angles whose cosines and sines define the */
  614. /* > diagonal blocks in the CS decomposition. */
  615. /* > \endverbatim */
  616. /* > */
  617. /* > \param[in,out] PHI */
  618. /* > \verbatim */
  619. /* > PHI is REAL array, dimension (Q-1) */
  620. /* > The angles PHI(1),...,PHI(Q-1) that, along with THETA(1),..., */
  621. /* > THETA(Q), define the matrix in bidiagonal-block form. */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[in,out] U1 */
  625. /* > \verbatim */
  626. /* > U1 is REAL array, dimension (LDU1,P) */
  627. /* > On entry, a P-by-P matrix. On exit, U1 is postmultiplied */
  628. /* > by the left singular vector matrix common to [ B11 ; 0 ] and */
  629. /* > [ B12 0 0 ; 0 -I 0 0 ]. */
  630. /* > \endverbatim */
  631. /* > */
  632. /* > \param[in] LDU1 */
  633. /* > \verbatim */
  634. /* > LDU1 is INTEGER */
  635. /* > The leading dimension of the array U1, LDU1 >= MAX(1,P). */
  636. /* > \endverbatim */
  637. /* > */
  638. /* > \param[in,out] U2 */
  639. /* > \verbatim */
  640. /* > U2 is REAL array, dimension (LDU2,M-P) */
  641. /* > On entry, an (M-P)-by-(M-P) matrix. On exit, U2 is */
  642. /* > postmultiplied by the left singular vector matrix common to */
  643. /* > [ B21 ; 0 ] and [ B22 0 0 ; 0 0 I ]. */
  644. /* > \endverbatim */
  645. /* > */
  646. /* > \param[in] LDU2 */
  647. /* > \verbatim */
  648. /* > LDU2 is INTEGER */
  649. /* > The leading dimension of the array U2, LDU2 >= MAX(1,M-P). */
  650. /* > \endverbatim */
  651. /* > */
  652. /* > \param[in,out] V1T */
  653. /* > \verbatim */
  654. /* > V1T is REAL array, dimension (LDV1T,Q) */
  655. /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
  656. /* > by the transpose of the right singular vector */
  657. /* > matrix common to [ B11 ; 0 ] and [ B21 ; 0 ]. */
  658. /* > \endverbatim */
  659. /* > */
  660. /* > \param[in] LDV1T */
  661. /* > \verbatim */
  662. /* > LDV1T is INTEGER */
  663. /* > The leading dimension of the array V1T, LDV1T >= MAX(1,Q). */
  664. /* > \endverbatim */
  665. /* > */
  666. /* > \param[in,out] V2T */
  667. /* > \verbatim */
  668. /* > V2T is REAL array, dimension (LDV2T,M-Q) */
  669. /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
  670. /* > premultiplied by the transpose of the right */
  671. /* > singular vector matrix common to [ B12 0 0 ; 0 -I 0 ] and */
  672. /* > [ B22 0 0 ; 0 0 I ]. */
  673. /* > \endverbatim */
  674. /* > */
  675. /* > \param[in] LDV2T */
  676. /* > \verbatim */
  677. /* > LDV2T is INTEGER */
  678. /* > The leading dimension of the array V2T, LDV2T >= MAX(1,M-Q). */
  679. /* > \endverbatim */
  680. /* > */
  681. /* > \param[out] B11D */
  682. /* > \verbatim */
  683. /* > B11D is REAL array, dimension (Q) */
  684. /* > When SBBCSD converges, B11D contains the cosines of THETA(1), */
  685. /* > ..., THETA(Q). If SBBCSD fails to converge, then B11D */
  686. /* > contains the diagonal of the partially reduced top-left */
  687. /* > block. */
  688. /* > \endverbatim */
  689. /* > */
  690. /* > \param[out] B11E */
  691. /* > \verbatim */
  692. /* > B11E is REAL array, dimension (Q-1) */
  693. /* > When SBBCSD converges, B11E contains zeros. If SBBCSD fails */
  694. /* > to converge, then B11E contains the superdiagonal of the */
  695. /* > partially reduced top-left block. */
  696. /* > \endverbatim */
  697. /* > */
  698. /* > \param[out] B12D */
  699. /* > \verbatim */
  700. /* > B12D is REAL array, dimension (Q) */
  701. /* > When SBBCSD converges, B12D contains the negative sines of */
  702. /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
  703. /* > B12D contains the diagonal of the partially reduced top-right */
  704. /* > block. */
  705. /* > \endverbatim */
  706. /* > */
  707. /* > \param[out] B12E */
  708. /* > \verbatim */
  709. /* > B12E is REAL array, dimension (Q-1) */
  710. /* > When SBBCSD converges, B12E contains zeros. If SBBCSD fails */
  711. /* > to converge, then B12E contains the subdiagonal of the */
  712. /* > partially reduced top-right block. */
  713. /* > \endverbatim */
  714. /* > */
  715. /* > \param[out] B21D */
  716. /* > \verbatim */
  717. /* > B21D is REAL array, dimension (Q) */
  718. /* > When SBBCSD converges, B21D contains the negative sines of */
  719. /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
  720. /* > B21D contains the diagonal of the partially reduced bottom-left */
  721. /* > block. */
  722. /* > \endverbatim */
  723. /* > */
  724. /* > \param[out] B21E */
  725. /* > \verbatim */
  726. /* > B21E is REAL array, dimension (Q-1) */
  727. /* > When SBBCSD converges, B21E contains zeros. If SBBCSD fails */
  728. /* > to converge, then B21E contains the subdiagonal of the */
  729. /* > partially reduced bottom-left block. */
  730. /* > \endverbatim */
  731. /* > */
  732. /* > \param[out] B22D */
  733. /* > \verbatim */
  734. /* > B22D is REAL array, dimension (Q) */
  735. /* > When SBBCSD converges, B22D contains the negative sines of */
  736. /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
  737. /* > B22D contains the diagonal of the partially reduced bottom-right */
  738. /* > block. */
  739. /* > \endverbatim */
  740. /* > */
  741. /* > \param[out] B22E */
  742. /* > \verbatim */
  743. /* > B22E is REAL array, dimension (Q-1) */
  744. /* > When SBBCSD converges, B22E contains zeros. If SBBCSD fails */
  745. /* > to converge, then B22E contains the subdiagonal of the */
  746. /* > partially reduced bottom-right block. */
  747. /* > \endverbatim */
  748. /* > */
  749. /* > \param[out] WORK */
  750. /* > \verbatim */
  751. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  752. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  753. /* > \endverbatim */
  754. /* > */
  755. /* > \param[in] LWORK */
  756. /* > \verbatim */
  757. /* > LWORK is INTEGER */
  758. /* > The dimension of the array WORK. LWORK >= MAX(1,8*Q). */
  759. /* > */
  760. /* > If LWORK = -1, then a workspace query is assumed; the */
  761. /* > routine only calculates the optimal size of the WORK array, */
  762. /* > returns this value as the first entry of the work array, and */
  763. /* > no error message related to LWORK is issued by XERBLA. */
  764. /* > \endverbatim */
  765. /* > */
  766. /* > \param[out] INFO */
  767. /* > \verbatim */
  768. /* > INFO is INTEGER */
  769. /* > = 0: successful exit. */
  770. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  771. /* > > 0: if SBBCSD did not converge, INFO specifies the number */
  772. /* > of nonzero entries in PHI, and B11D, B11E, etc., */
  773. /* > contain the partially reduced matrix. */
  774. /* > \endverbatim */
  775. /* > \par Internal Parameters: */
  776. /* ========================= */
  777. /* > */
  778. /* > \verbatim */
  779. /* > TOLMUL REAL, default = MAX(10,MIN(100,EPS**(-1/8))) */
  780. /* > TOLMUL controls the convergence criterion of the QR loop. */
  781. /* > Angles THETA(i), PHI(i) are rounded to 0 or PI/2 when they */
  782. /* > are within TOLMUL*EPS of either bound. */
  783. /* > \endverbatim */
  784. /* > \par References: */
  785. /* ================ */
  786. /* > */
  787. /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
  788. /* > Algorithms, 50(1):33-65, 2009. */
  789. /* Authors: */
  790. /* ======== */
  791. /* > \author Univ. of Tennessee */
  792. /* > \author Univ. of California Berkeley */
  793. /* > \author Univ. of Colorado Denver */
  794. /* > \author NAG Ltd. */
  795. /* > \date June 2016 */
  796. /* > \ingroup realOTHERcomputational */
  797. /* ===================================================================== */
  798. /* Subroutine */ void sbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
  799. jobv2t, char *trans, integer *m, integer *p, integer *q, real *theta,
  800. real *phi, real *u1, integer *ldu1, real *u2, integer *ldu2, real *
  801. v1t, integer *ldv1t, real *v2t, integer *ldv2t, real *b11d, real *
  802. b11e, real *b12d, real *b12e, real *b21d, real *b21e, real *b22d,
  803. real *b22e, real *work, integer *lwork, integer *info)
  804. {
  805. /* System generated locals */
  806. integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
  807. v2t_dim1, v2t_offset, i__1, i__2;
  808. real r__1, r__2, r__3, r__4;
  809. doublereal d__1;
  810. /* Local variables */
  811. integer imin, mini, imax, iter;
  812. real unfl, temp;
  813. logical colmajor;
  814. real thetamin, thetamax;
  815. logical restart11, restart12, restart21, restart22;
  816. integer lworkmin, iu1cs, iu2cs;
  817. extern /* Subroutine */ void slas2_(real *, real *, real *, real *, real *)
  818. ;
  819. integer iu1sn, iu2sn, lworkopt, i__, j;
  820. real r__;
  821. extern logical lsame_(char *, char *);
  822. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  823. integer maxit;
  824. extern /* Subroutine */ void slasr_(char *, char *, char *, integer *,
  825. integer *, real *, real *, real *, integer *);
  826. real dummy;
  827. extern /* Subroutine */ void sswap_(integer *, real *, integer *, real *,
  828. integer *);
  829. real x1, x2, y1, y2;
  830. integer iv1tcs, iv2tcs;
  831. logical wantu1, wantu2;
  832. integer iv1tsn, iv2tsn;
  833. real mu, nu, sigma11, sigma21;
  834. extern real slamch_(char *);
  835. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  836. real thresh, tolmul;
  837. extern /* Subroutine */ void mecago_();
  838. logical lquery;
  839. real b11bulge;
  840. logical wantv1t, wantv2t;
  841. real b12bulge, b21bulge, b22bulge, eps, tol;
  842. extern /* Subroutine */ void slartgp_(real *, real *, real *, real *, real
  843. *), slartgs_(real *, real *, real *, real *, real *);
  844. /* -- LAPACK computational routine (version 3.7.1) -- */
  845. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  846. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  847. /* June 2016 */
  848. /* =================================================================== */
  849. /* Test input arguments */
  850. /* Parameter adjustments */
  851. --theta;
  852. --phi;
  853. u1_dim1 = *ldu1;
  854. u1_offset = 1 + u1_dim1 * 1;
  855. u1 -= u1_offset;
  856. u2_dim1 = *ldu2;
  857. u2_offset = 1 + u2_dim1 * 1;
  858. u2 -= u2_offset;
  859. v1t_dim1 = *ldv1t;
  860. v1t_offset = 1 + v1t_dim1 * 1;
  861. v1t -= v1t_offset;
  862. v2t_dim1 = *ldv2t;
  863. v2t_offset = 1 + v2t_dim1 * 1;
  864. v2t -= v2t_offset;
  865. --b11d;
  866. --b11e;
  867. --b12d;
  868. --b12e;
  869. --b21d;
  870. --b21e;
  871. --b22d;
  872. --b22e;
  873. --work;
  874. /* Function Body */
  875. *info = 0;
  876. lquery = *lwork == -1;
  877. wantu1 = lsame_(jobu1, "Y");
  878. wantu2 = lsame_(jobu2, "Y");
  879. wantv1t = lsame_(jobv1t, "Y");
  880. wantv2t = lsame_(jobv2t, "Y");
  881. colmajor = ! lsame_(trans, "T");
  882. if (*m < 0) {
  883. *info = -6;
  884. } else if (*p < 0 || *p > *m) {
  885. *info = -7;
  886. } else if (*q < 0 || *q > *m) {
  887. *info = -8;
  888. } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
  889. *info = -8;
  890. } else if (wantu1 && *ldu1 < *p) {
  891. *info = -12;
  892. } else if (wantu2 && *ldu2 < *m - *p) {
  893. *info = -14;
  894. } else if (wantv1t && *ldv1t < *q) {
  895. *info = -16;
  896. } else if (wantv2t && *ldv2t < *m - *q) {
  897. *info = -18;
  898. }
  899. /* Quick return if Q = 0 */
  900. if (*info == 0 && *q == 0) {
  901. lworkmin = 1;
  902. work[1] = (real) lworkmin;
  903. return;
  904. }
  905. /* Compute workspace */
  906. if (*info == 0) {
  907. iu1cs = 1;
  908. iu1sn = iu1cs + *q;
  909. iu2cs = iu1sn + *q;
  910. iu2sn = iu2cs + *q;
  911. iv1tcs = iu2sn + *q;
  912. iv1tsn = iv1tcs + *q;
  913. iv2tcs = iv1tsn + *q;
  914. iv2tsn = iv2tcs + *q;
  915. lworkopt = iv2tsn + *q - 1;
  916. lworkmin = lworkopt;
  917. work[1] = (real) lworkopt;
  918. if (*lwork < lworkmin && ! lquery) {
  919. *info = -28;
  920. }
  921. }
  922. if (*info != 0) {
  923. i__1 = -(*info);
  924. xerbla_("SBBCSD", &i__1,(ftnlen)6);
  925. return;
  926. } else if (lquery) {
  927. return;
  928. }
  929. /* Get machine constants */
  930. eps = slamch_("Epsilon");
  931. unfl = slamch_("Safe minimum");
  932. /* Computing MAX */
  933. /* Computing MIN */
  934. d__1 = (doublereal) eps;
  935. r__3 = 100.f, r__4 = pow_dd(&d__1, &c_b10);
  936. r__1 = 10.f, r__2 = f2cmin(r__3,r__4);
  937. tolmul = f2cmax(r__1,r__2);
  938. tol = tolmul * eps;
  939. /* Computing MAX */
  940. r__1 = tol, r__2 = *q * 6 * *q * unfl;
  941. thresh = f2cmax(r__1,r__2);
  942. /* Test for negligible sines or cosines */
  943. i__1 = *q;
  944. for (i__ = 1; i__ <= i__1; ++i__) {
  945. if (theta[i__] < thresh) {
  946. theta[i__] = 0.f;
  947. } else if (theta[i__] > 1.57079632679489662f - thresh) {
  948. theta[i__] = 1.57079632679489662f;
  949. }
  950. }
  951. i__1 = *q - 1;
  952. for (i__ = 1; i__ <= i__1; ++i__) {
  953. if (phi[i__] < thresh) {
  954. phi[i__] = 0.f;
  955. } else if (phi[i__] > 1.57079632679489662f - thresh) {
  956. phi[i__] = 1.57079632679489662f;
  957. }
  958. }
  959. /* Initial deflation */
  960. imax = *q;
  961. while(imax > 1) {
  962. if (phi[imax - 1] != 0.f) {
  963. myexit_();
  964. }
  965. --imax;
  966. }
  967. imin = imax - 1;
  968. if (imin > 1) {
  969. while(phi[imin - 1] != 0.f) {
  970. --imin;
  971. if (imin <= 1) {
  972. myexit_();
  973. }
  974. }
  975. }
  976. /* Initialize iteration counter */
  977. maxit = *q * 6 * *q;
  978. iter = 0;
  979. /* Begin main iteration loop */
  980. while(imax > 1) {
  981. /* Compute the matrix entries */
  982. b11d[imin] = cos(theta[imin]);
  983. b21d[imin] = -sin(theta[imin]);
  984. i__1 = imax - 1;
  985. for (i__ = imin; i__ <= i__1; ++i__) {
  986. b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
  987. b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
  988. b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
  989. b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
  990. b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
  991. b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
  992. b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
  993. b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
  994. }
  995. b12d[imax] = sin(theta[imax]);
  996. b22d[imax] = cos(theta[imax]);
  997. /* Abort if not converging; otherwise, increment ITER */
  998. if (iter > maxit) {
  999. *info = 0;
  1000. i__1 = *q;
  1001. for (i__ = 1; i__ <= i__1; ++i__) {
  1002. if (phi[i__] != 0.f) {
  1003. ++(*info);
  1004. }
  1005. }
  1006. return;
  1007. }
  1008. iter = iter + imax - imin;
  1009. /* Compute shifts */
  1010. thetamax = theta[imin];
  1011. thetamin = theta[imin];
  1012. i__1 = imax;
  1013. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1014. if (theta[i__] > thetamax) {
  1015. thetamax = theta[i__];
  1016. }
  1017. if (theta[i__] < thetamin) {
  1018. thetamin = theta[i__];
  1019. }
  1020. }
  1021. if (thetamax > 1.57079632679489662f - thresh) {
  1022. /* Zero on diagonals of B11 and B22; induce deflation with a */
  1023. /* zero shift */
  1024. mu = 0.f;
  1025. nu = 1.f;
  1026. } else if (thetamin < thresh) {
  1027. /* Zero on diagonals of B12 and B22; induce deflation with a */
  1028. /* zero shift */
  1029. mu = 1.f;
  1030. nu = 0.f;
  1031. } else {
  1032. /* Compute shifts for B11 and B21 and use the lesser */
  1033. slas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
  1034. dummy);
  1035. slas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
  1036. dummy);
  1037. if (sigma11 <= sigma21) {
  1038. mu = sigma11;
  1039. /* Computing 2nd power */
  1040. r__1 = mu;
  1041. nu = sqrt(1.f - r__1 * r__1);
  1042. if (mu < thresh) {
  1043. mu = 0.f;
  1044. nu = 1.f;
  1045. }
  1046. } else {
  1047. nu = sigma21;
  1048. /* Computing 2nd power */
  1049. r__1 = nu;
  1050. mu = sqrt(1.f - r__1 * r__1);
  1051. if (nu < thresh) {
  1052. mu = 1.f;
  1053. nu = 0.f;
  1054. }
  1055. }
  1056. }
  1057. /* Rotate to produce bulges in B11 and B21 */
  1058. if (mu <= nu) {
  1059. slartgs_(&b11d[imin], &b11e[imin], &mu, &work[iv1tcs + imin - 1],
  1060. &work[iv1tsn + imin - 1]);
  1061. } else {
  1062. slartgs_(&b21d[imin], &b21e[imin], &nu, &work[iv1tcs + imin - 1],
  1063. &work[iv1tsn + imin - 1]);
  1064. }
  1065. temp = work[iv1tcs + imin - 1] * b11d[imin] + work[iv1tsn + imin - 1]
  1066. * b11e[imin];
  1067. b11e[imin] = work[iv1tcs + imin - 1] * b11e[imin] - work[iv1tsn +
  1068. imin - 1] * b11d[imin];
  1069. b11d[imin] = temp;
  1070. b11bulge = work[iv1tsn + imin - 1] * b11d[imin + 1];
  1071. b11d[imin + 1] = work[iv1tcs + imin - 1] * b11d[imin + 1];
  1072. temp = work[iv1tcs + imin - 1] * b21d[imin] + work[iv1tsn + imin - 1]
  1073. * b21e[imin];
  1074. b21e[imin] = work[iv1tcs + imin - 1] * b21e[imin] - work[iv1tsn +
  1075. imin - 1] * b21d[imin];
  1076. b21d[imin] = temp;
  1077. b21bulge = work[iv1tsn + imin - 1] * b21d[imin + 1];
  1078. b21d[imin + 1] = work[iv1tcs + imin - 1] * b21d[imin + 1];
  1079. /* Compute THETA(IMIN) */
  1080. /* Computing 2nd power */
  1081. r__1 = b21d[imin];
  1082. /* Computing 2nd power */
  1083. r__2 = b21bulge;
  1084. /* Computing 2nd power */
  1085. r__3 = b11d[imin];
  1086. /* Computing 2nd power */
  1087. r__4 = b11bulge;
  1088. theta[imin] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 * r__3
  1089. + r__4 * r__4));
  1090. /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
  1091. /* Computing 2nd power */
  1092. r__1 = b11d[imin];
  1093. /* Computing 2nd power */
  1094. r__2 = b11bulge;
  1095. /* Computing 2nd power */
  1096. r__3 = thresh;
  1097. if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
  1098. slartgp_(&b11bulge, &b11d[imin], &work[iu1sn + imin - 1], &work[
  1099. iu1cs + imin - 1], &r__);
  1100. } else if (mu <= nu) {
  1101. slartgs_(&b11e[imin], &b11d[imin + 1], &mu, &work[iu1cs + imin -
  1102. 1], &work[iu1sn + imin - 1]);
  1103. } else {
  1104. slartgs_(&b12d[imin], &b12e[imin], &nu, &work[iu1cs + imin - 1], &
  1105. work[iu1sn + imin - 1]);
  1106. }
  1107. /* Computing 2nd power */
  1108. r__1 = b21d[imin];
  1109. /* Computing 2nd power */
  1110. r__2 = b21bulge;
  1111. /* Computing 2nd power */
  1112. r__3 = thresh;
  1113. if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
  1114. slartgp_(&b21bulge, &b21d[imin], &work[iu2sn + imin - 1], &work[
  1115. iu2cs + imin - 1], &r__);
  1116. } else if (nu < mu) {
  1117. slartgs_(&b21e[imin], &b21d[imin + 1], &nu, &work[iu2cs + imin -
  1118. 1], &work[iu2sn + imin - 1]);
  1119. } else {
  1120. slartgs_(&b22d[imin], &b22e[imin], &mu, &work[iu2cs + imin - 1], &
  1121. work[iu2sn + imin - 1]);
  1122. }
  1123. work[iu2cs + imin - 1] = -work[iu2cs + imin - 1];
  1124. work[iu2sn + imin - 1] = -work[iu2sn + imin - 1];
  1125. temp = work[iu1cs + imin - 1] * b11e[imin] + work[iu1sn + imin - 1] *
  1126. b11d[imin + 1];
  1127. b11d[imin + 1] = work[iu1cs + imin - 1] * b11d[imin + 1] - work[iu1sn
  1128. + imin - 1] * b11e[imin];
  1129. b11e[imin] = temp;
  1130. if (imax > imin + 1) {
  1131. b11bulge = work[iu1sn + imin - 1] * b11e[imin + 1];
  1132. b11e[imin + 1] = work[iu1cs + imin - 1] * b11e[imin + 1];
  1133. }
  1134. temp = work[iu1cs + imin - 1] * b12d[imin] + work[iu1sn + imin - 1] *
  1135. b12e[imin];
  1136. b12e[imin] = work[iu1cs + imin - 1] * b12e[imin] - work[iu1sn + imin
  1137. - 1] * b12d[imin];
  1138. b12d[imin] = temp;
  1139. b12bulge = work[iu1sn + imin - 1] * b12d[imin + 1];
  1140. b12d[imin + 1] = work[iu1cs + imin - 1] * b12d[imin + 1];
  1141. temp = work[iu2cs + imin - 1] * b21e[imin] + work[iu2sn + imin - 1] *
  1142. b21d[imin + 1];
  1143. b21d[imin + 1] = work[iu2cs + imin - 1] * b21d[imin + 1] - work[iu2sn
  1144. + imin - 1] * b21e[imin];
  1145. b21e[imin] = temp;
  1146. if (imax > imin + 1) {
  1147. b21bulge = work[iu2sn + imin - 1] * b21e[imin + 1];
  1148. b21e[imin + 1] = work[iu2cs + imin - 1] * b21e[imin + 1];
  1149. }
  1150. temp = work[iu2cs + imin - 1] * b22d[imin] + work[iu2sn + imin - 1] *
  1151. b22e[imin];
  1152. b22e[imin] = work[iu2cs + imin - 1] * b22e[imin] - work[iu2sn + imin
  1153. - 1] * b22d[imin];
  1154. b22d[imin] = temp;
  1155. b22bulge = work[iu2sn + imin - 1] * b22d[imin + 1];
  1156. b22d[imin + 1] = work[iu2cs + imin - 1] * b22d[imin + 1];
  1157. /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
  1158. /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
  1159. /* bottom-right */
  1160. i__1 = imax - 1;
  1161. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1162. /* Compute PHI(I-1) */
  1163. x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
  1164. b21e[i__ - 1];
  1165. x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
  1166. b21bulge;
  1167. y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
  1168. b22d[i__ - 1];
  1169. y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
  1170. b22bulge;
  1171. /* Computing 2nd power */
  1172. r__1 = x1;
  1173. /* Computing 2nd power */
  1174. r__2 = x2;
  1175. /* Computing 2nd power */
  1176. r__3 = y1;
  1177. /* Computing 2nd power */
  1178. r__4 = y2;
  1179. phi[i__ - 1] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
  1180. r__3 + r__4 * r__4));
  1181. /* Determine if there are bulges to chase or if a new direct */
  1182. /* summand has been reached */
  1183. /* Computing 2nd power */
  1184. r__1 = b11e[i__ - 1];
  1185. /* Computing 2nd power */
  1186. r__2 = b11bulge;
  1187. /* Computing 2nd power */
  1188. r__3 = thresh;
  1189. restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1190. /* Computing 2nd power */
  1191. r__1 = b21e[i__ - 1];
  1192. /* Computing 2nd power */
  1193. r__2 = b21bulge;
  1194. /* Computing 2nd power */
  1195. r__3 = thresh;
  1196. restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1197. /* Computing 2nd power */
  1198. r__1 = b12d[i__ - 1];
  1199. /* Computing 2nd power */
  1200. r__2 = b12bulge;
  1201. /* Computing 2nd power */
  1202. r__3 = thresh;
  1203. restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1204. /* Computing 2nd power */
  1205. r__1 = b22d[i__ - 1];
  1206. /* Computing 2nd power */
  1207. r__2 = b22bulge;
  1208. /* Computing 2nd power */
  1209. r__3 = thresh;
  1210. restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1211. /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
  1212. /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
  1213. /* chasing by applying the original shift again. */
  1214. if (! restart11 && ! restart21) {
  1215. slartgp_(&x2, &x1, &work[iv1tsn + i__ - 1], &work[iv1tcs +
  1216. i__ - 1], &r__);
  1217. } else if (! restart11 && restart21) {
  1218. slartgp_(&b11bulge, &b11e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1219. work[iv1tcs + i__ - 1], &r__);
  1220. } else if (restart11 && ! restart21) {
  1221. slartgp_(&b21bulge, &b21e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1222. work[iv1tcs + i__ - 1], &r__);
  1223. } else if (mu <= nu) {
  1224. slartgs_(&b11d[i__], &b11e[i__], &mu, &work[iv1tcs + i__ - 1],
  1225. &work[iv1tsn + i__ - 1]);
  1226. } else {
  1227. slartgs_(&b21d[i__], &b21e[i__], &nu, &work[iv1tcs + i__ - 1],
  1228. &work[iv1tsn + i__ - 1]);
  1229. }
  1230. work[iv1tcs + i__ - 1] = -work[iv1tcs + i__ - 1];
  1231. work[iv1tsn + i__ - 1] = -work[iv1tsn + i__ - 1];
  1232. if (! restart12 && ! restart22) {
  1233. slartgp_(&y2, &y1, &work[iv2tsn + i__ - 2], &work[iv2tcs +
  1234. i__ - 2], &r__);
  1235. } else if (! restart12 && restart22) {
  1236. slartgp_(&b12bulge, &b12d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1237. work[iv2tcs + i__ - 2], &r__);
  1238. } else if (restart12 && ! restart22) {
  1239. slartgp_(&b22bulge, &b22d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1240. work[iv2tcs + i__ - 2], &r__);
  1241. } else if (nu < mu) {
  1242. slartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &work[iv2tcs + i__
  1243. - 2], &work[iv2tsn + i__ - 2]);
  1244. } else {
  1245. slartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &work[iv2tcs + i__
  1246. - 2], &work[iv2tsn + i__ - 2]);
  1247. }
  1248. temp = work[iv1tcs + i__ - 1] * b11d[i__] + work[iv1tsn + i__ - 1]
  1249. * b11e[i__];
  1250. b11e[i__] = work[iv1tcs + i__ - 1] * b11e[i__] - work[iv1tsn +
  1251. i__ - 1] * b11d[i__];
  1252. b11d[i__] = temp;
  1253. b11bulge = work[iv1tsn + i__ - 1] * b11d[i__ + 1];
  1254. b11d[i__ + 1] = work[iv1tcs + i__ - 1] * b11d[i__ + 1];
  1255. temp = work[iv1tcs + i__ - 1] * b21d[i__] + work[iv1tsn + i__ - 1]
  1256. * b21e[i__];
  1257. b21e[i__] = work[iv1tcs + i__ - 1] * b21e[i__] - work[iv1tsn +
  1258. i__ - 1] * b21d[i__];
  1259. b21d[i__] = temp;
  1260. b21bulge = work[iv1tsn + i__ - 1] * b21d[i__ + 1];
  1261. b21d[i__ + 1] = work[iv1tcs + i__ - 1] * b21d[i__ + 1];
  1262. temp = work[iv2tcs + i__ - 2] * b12e[i__ - 1] + work[iv2tsn + i__
  1263. - 2] * b12d[i__];
  1264. b12d[i__] = work[iv2tcs + i__ - 2] * b12d[i__] - work[iv2tsn +
  1265. i__ - 2] * b12e[i__ - 1];
  1266. b12e[i__ - 1] = temp;
  1267. b12bulge = work[iv2tsn + i__ - 2] * b12e[i__];
  1268. b12e[i__] = work[iv2tcs + i__ - 2] * b12e[i__];
  1269. temp = work[iv2tcs + i__ - 2] * b22e[i__ - 1] + work[iv2tsn + i__
  1270. - 2] * b22d[i__];
  1271. b22d[i__] = work[iv2tcs + i__ - 2] * b22d[i__] - work[iv2tsn +
  1272. i__ - 2] * b22e[i__ - 1];
  1273. b22e[i__ - 1] = temp;
  1274. b22bulge = work[iv2tsn + i__ - 2] * b22e[i__];
  1275. b22e[i__] = work[iv2tcs + i__ - 2] * b22e[i__];
  1276. /* Compute THETA(I) */
  1277. x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
  1278. - 1];
  1279. x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
  1280. y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
  1281. - 1];
  1282. y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
  1283. /* Computing 2nd power */
  1284. r__1 = y1;
  1285. /* Computing 2nd power */
  1286. r__2 = y2;
  1287. /* Computing 2nd power */
  1288. r__3 = x1;
  1289. /* Computing 2nd power */
  1290. r__4 = x2;
  1291. theta[i__] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
  1292. r__3 + r__4 * r__4));
  1293. /* Determine if there are bulges to chase or if a new direct */
  1294. /* summand has been reached */
  1295. /* Computing 2nd power */
  1296. r__1 = b11d[i__];
  1297. /* Computing 2nd power */
  1298. r__2 = b11bulge;
  1299. /* Computing 2nd power */
  1300. r__3 = thresh;
  1301. restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1302. /* Computing 2nd power */
  1303. r__1 = b12e[i__ - 1];
  1304. /* Computing 2nd power */
  1305. r__2 = b12bulge;
  1306. /* Computing 2nd power */
  1307. r__3 = thresh;
  1308. restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1309. /* Computing 2nd power */
  1310. r__1 = b21d[i__];
  1311. /* Computing 2nd power */
  1312. r__2 = b21bulge;
  1313. /* Computing 2nd power */
  1314. r__3 = thresh;
  1315. restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1316. /* Computing 2nd power */
  1317. r__1 = b22e[i__ - 1];
  1318. /* Computing 2nd power */
  1319. r__2 = b22bulge;
  1320. /* Computing 2nd power */
  1321. r__3 = thresh;
  1322. restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1323. /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
  1324. /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
  1325. /* chasing by applying the original shift again. */
  1326. if (! restart11 && ! restart12) {
  1327. slartgp_(&x2, &x1, &work[iu1sn + i__ - 1], &work[iu1cs + i__
  1328. - 1], &r__);
  1329. } else if (! restart11 && restart12) {
  1330. slartgp_(&b11bulge, &b11d[i__], &work[iu1sn + i__ - 1], &work[
  1331. iu1cs + i__ - 1], &r__);
  1332. } else if (restart11 && ! restart12) {
  1333. slartgp_(&b12bulge, &b12e[i__ - 1], &work[iu1sn + i__ - 1], &
  1334. work[iu1cs + i__ - 1], &r__);
  1335. } else if (mu <= nu) {
  1336. slartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &work[iu1cs + i__ -
  1337. 1], &work[iu1sn + i__ - 1]);
  1338. } else {
  1339. slartgs_(&b12d[i__], &b12e[i__], &nu, &work[iu1cs + i__ - 1],
  1340. &work[iu1sn + i__ - 1]);
  1341. }
  1342. if (! restart21 && ! restart22) {
  1343. slartgp_(&y2, &y1, &work[iu2sn + i__ - 1], &work[iu2cs + i__
  1344. - 1], &r__);
  1345. } else if (! restart21 && restart22) {
  1346. slartgp_(&b21bulge, &b21d[i__], &work[iu2sn + i__ - 1], &work[
  1347. iu2cs + i__ - 1], &r__);
  1348. } else if (restart21 && ! restart22) {
  1349. slartgp_(&b22bulge, &b22e[i__ - 1], &work[iu2sn + i__ - 1], &
  1350. work[iu2cs + i__ - 1], &r__);
  1351. } else if (nu < mu) {
  1352. slartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &work[iu2cs + i__ -
  1353. 1], &work[iu2sn + i__ - 1]);
  1354. } else {
  1355. slartgs_(&b22d[i__], &b22e[i__], &mu, &work[iu2cs + i__ - 1],
  1356. &work[iu2sn + i__ - 1]);
  1357. }
  1358. work[iu2cs + i__ - 1] = -work[iu2cs + i__ - 1];
  1359. work[iu2sn + i__ - 1] = -work[iu2sn + i__ - 1];
  1360. temp = work[iu1cs + i__ - 1] * b11e[i__] + work[iu1sn + i__ - 1] *
  1361. b11d[i__ + 1];
  1362. b11d[i__ + 1] = work[iu1cs + i__ - 1] * b11d[i__ + 1] - work[
  1363. iu1sn + i__ - 1] * b11e[i__];
  1364. b11e[i__] = temp;
  1365. if (i__ < imax - 1) {
  1366. b11bulge = work[iu1sn + i__ - 1] * b11e[i__ + 1];
  1367. b11e[i__ + 1] = work[iu1cs + i__ - 1] * b11e[i__ + 1];
  1368. }
  1369. temp = work[iu2cs + i__ - 1] * b21e[i__] + work[iu2sn + i__ - 1] *
  1370. b21d[i__ + 1];
  1371. b21d[i__ + 1] = work[iu2cs + i__ - 1] * b21d[i__ + 1] - work[
  1372. iu2sn + i__ - 1] * b21e[i__];
  1373. b21e[i__] = temp;
  1374. if (i__ < imax - 1) {
  1375. b21bulge = work[iu2sn + i__ - 1] * b21e[i__ + 1];
  1376. b21e[i__ + 1] = work[iu2cs + i__ - 1] * b21e[i__ + 1];
  1377. }
  1378. temp = work[iu1cs + i__ - 1] * b12d[i__] + work[iu1sn + i__ - 1] *
  1379. b12e[i__];
  1380. b12e[i__] = work[iu1cs + i__ - 1] * b12e[i__] - work[iu1sn + i__
  1381. - 1] * b12d[i__];
  1382. b12d[i__] = temp;
  1383. b12bulge = work[iu1sn + i__ - 1] * b12d[i__ + 1];
  1384. b12d[i__ + 1] = work[iu1cs + i__ - 1] * b12d[i__ + 1];
  1385. temp = work[iu2cs + i__ - 1] * b22d[i__] + work[iu2sn + i__ - 1] *
  1386. b22e[i__];
  1387. b22e[i__] = work[iu2cs + i__ - 1] * b22e[i__] - work[iu2sn + i__
  1388. - 1] * b22d[i__];
  1389. b22d[i__] = temp;
  1390. b22bulge = work[iu2sn + i__ - 1] * b22d[i__ + 1];
  1391. b22d[i__ + 1] = work[iu2cs + i__ - 1] * b22d[i__ + 1];
  1392. }
  1393. /* Compute PHI(IMAX-1) */
  1394. x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
  1395. b21e[imax - 1];
  1396. y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
  1397. b22d[imax - 1];
  1398. y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
  1399. b22bulge;
  1400. /* Computing 2nd power */
  1401. r__1 = y1;
  1402. /* Computing 2nd power */
  1403. r__2 = y2;
  1404. phi[imax - 1] = atan2((abs(x1)), sqrt(r__1 * r__1 + r__2 * r__2));
  1405. /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
  1406. /* Computing 2nd power */
  1407. r__1 = b12d[imax - 1];
  1408. /* Computing 2nd power */
  1409. r__2 = b12bulge;
  1410. /* Computing 2nd power */
  1411. r__3 = thresh;
  1412. restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1413. /* Computing 2nd power */
  1414. r__1 = b22d[imax - 1];
  1415. /* Computing 2nd power */
  1416. r__2 = b22bulge;
  1417. /* Computing 2nd power */
  1418. r__3 = thresh;
  1419. restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1420. if (! restart12 && ! restart22) {
  1421. slartgp_(&y2, &y1, &work[iv2tsn + imax - 2], &work[iv2tcs + imax
  1422. - 2], &r__);
  1423. } else if (! restart12 && restart22) {
  1424. slartgp_(&b12bulge, &b12d[imax - 1], &work[iv2tsn + imax - 2], &
  1425. work[iv2tcs + imax - 2], &r__);
  1426. } else if (restart12 && ! restart22) {
  1427. slartgp_(&b22bulge, &b22d[imax - 1], &work[iv2tsn + imax - 2], &
  1428. work[iv2tcs + imax - 2], &r__);
  1429. } else if (nu < mu) {
  1430. slartgs_(&b12e[imax - 1], &b12d[imax], &nu, &work[iv2tcs + imax -
  1431. 2], &work[iv2tsn + imax - 2]);
  1432. } else {
  1433. slartgs_(&b22e[imax - 1], &b22d[imax], &mu, &work[iv2tcs + imax -
  1434. 2], &work[iv2tsn + imax - 2]);
  1435. }
  1436. temp = work[iv2tcs + imax - 2] * b12e[imax - 1] + work[iv2tsn + imax
  1437. - 2] * b12d[imax];
  1438. b12d[imax] = work[iv2tcs + imax - 2] * b12d[imax] - work[iv2tsn +
  1439. imax - 2] * b12e[imax - 1];
  1440. b12e[imax - 1] = temp;
  1441. temp = work[iv2tcs + imax - 2] * b22e[imax - 1] + work[iv2tsn + imax
  1442. - 2] * b22d[imax];
  1443. b22d[imax] = work[iv2tcs + imax - 2] * b22d[imax] - work[iv2tsn +
  1444. imax - 2] * b22e[imax - 1];
  1445. b22e[imax - 1] = temp;
  1446. /* Update singular vectors */
  1447. if (wantu1) {
  1448. if (colmajor) {
  1449. i__1 = imax - imin + 1;
  1450. slasr_("R", "V", "F", p, &i__1, &work[iu1cs + imin - 1], &
  1451. work[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1], ldu1);
  1452. } else {
  1453. i__1 = imax - imin + 1;
  1454. slasr_("L", "V", "F", &i__1, p, &work[iu1cs + imin - 1], &
  1455. work[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
  1456. }
  1457. }
  1458. if (wantu2) {
  1459. if (colmajor) {
  1460. i__1 = *m - *p;
  1461. i__2 = imax - imin + 1;
  1462. slasr_("R", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1463. work[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1], ldu2);
  1464. } else {
  1465. i__1 = imax - imin + 1;
  1466. i__2 = *m - *p;
  1467. slasr_("L", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1468. work[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
  1469. }
  1470. }
  1471. if (wantv1t) {
  1472. if (colmajor) {
  1473. i__1 = imax - imin + 1;
  1474. slasr_("L", "V", "F", &i__1, q, &work[iv1tcs + imin - 1], &
  1475. work[iv1tsn + imin - 1], &v1t[imin + v1t_dim1], ldv1t);
  1476. } else {
  1477. i__1 = imax - imin + 1;
  1478. slasr_("R", "V", "F", q, &i__1, &work[iv1tcs + imin - 1], &
  1479. work[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
  1480. ldv1t);
  1481. }
  1482. }
  1483. if (wantv2t) {
  1484. if (colmajor) {
  1485. i__1 = imax - imin + 1;
  1486. i__2 = *m - *q;
  1487. slasr_("L", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1488. &work[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
  1489. ldv2t);
  1490. } else {
  1491. i__1 = *m - *q;
  1492. i__2 = imax - imin + 1;
  1493. slasr_("R", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1494. &work[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
  1495. ldv2t);
  1496. }
  1497. }
  1498. /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
  1499. if (b11e[imax - 1] + b21e[imax - 1] > 0.f) {
  1500. b11d[imax] = -b11d[imax];
  1501. b21d[imax] = -b21d[imax];
  1502. if (wantv1t) {
  1503. if (colmajor) {
  1504. sscal_(q, &c_b35, &v1t[imax + v1t_dim1], ldv1t);
  1505. } else {
  1506. sscal_(q, &c_b35, &v1t[imax * v1t_dim1 + 1], &c__1);
  1507. }
  1508. }
  1509. }
  1510. /* Compute THETA(IMAX) */
  1511. x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
  1512. - 1];
  1513. y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
  1514. - 1];
  1515. theta[imax] = atan2((abs(y1)), (abs(x1)));
  1516. /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
  1517. /* and B22(IMAX,IMAX-1) */
  1518. if (b11d[imax] + b12e[imax - 1] < 0.f) {
  1519. b12d[imax] = -b12d[imax];
  1520. if (wantu1) {
  1521. if (colmajor) {
  1522. sscal_(p, &c_b35, &u1[imax * u1_dim1 + 1], &c__1);
  1523. } else {
  1524. sscal_(p, &c_b35, &u1[imax + u1_dim1], ldu1);
  1525. }
  1526. }
  1527. }
  1528. if (b21d[imax] + b22e[imax - 1] > 0.f) {
  1529. b22d[imax] = -b22d[imax];
  1530. if (wantu2) {
  1531. if (colmajor) {
  1532. i__1 = *m - *p;
  1533. sscal_(&i__1, &c_b35, &u2[imax * u2_dim1 + 1], &c__1);
  1534. } else {
  1535. i__1 = *m - *p;
  1536. sscal_(&i__1, &c_b35, &u2[imax + u2_dim1], ldu2);
  1537. }
  1538. }
  1539. }
  1540. /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
  1541. if (b12d[imax] + b22d[imax] < 0.f) {
  1542. if (wantv2t) {
  1543. if (colmajor) {
  1544. i__1 = *m - *q;
  1545. sscal_(&i__1, &c_b35, &v2t[imax + v2t_dim1], ldv2t);
  1546. } else {
  1547. i__1 = *m - *q;
  1548. sscal_(&i__1, &c_b35, &v2t[imax * v2t_dim1 + 1], &c__1);
  1549. }
  1550. }
  1551. }
  1552. /* Test for negligible sines or cosines */
  1553. i__1 = imax;
  1554. for (i__ = imin; i__ <= i__1; ++i__) {
  1555. if (theta[i__] < thresh) {
  1556. theta[i__] = 0.f;
  1557. } else if (theta[i__] > 1.57079632679489662f - thresh) {
  1558. theta[i__] = 1.57079632679489662f;
  1559. }
  1560. }
  1561. i__1 = imax - 1;
  1562. for (i__ = imin; i__ <= i__1; ++i__) {
  1563. if (phi[i__] < thresh) {
  1564. phi[i__] = 0.f;
  1565. } else if (phi[i__] > 1.57079632679489662f - thresh) {
  1566. phi[i__] = 1.57079632679489662f;
  1567. }
  1568. }
  1569. /* Deflate */
  1570. if (imax > 1) {
  1571. while(phi[imax - 1] == 0.f) {
  1572. --imax;
  1573. if (imax <= 1) {
  1574. myexit_();
  1575. }
  1576. }
  1577. }
  1578. if (imin > imax - 1) {
  1579. imin = imax - 1;
  1580. }
  1581. if (imin > 1) {
  1582. while(phi[imin - 1] != 0.f) {
  1583. --imin;
  1584. if (imin <= 1) {
  1585. myexit_();
  1586. }
  1587. }
  1588. }
  1589. /* Repeat main iteration loop */
  1590. }
  1591. /* Postprocessing: order THETA from least to greatest */
  1592. i__1 = *q;
  1593. for (i__ = 1; i__ <= i__1; ++i__) {
  1594. mini = i__;
  1595. thetamin = theta[i__];
  1596. i__2 = *q;
  1597. for (j = i__ + 1; j <= i__2; ++j) {
  1598. if (theta[j] < thetamin) {
  1599. mini = j;
  1600. thetamin = theta[j];
  1601. }
  1602. }
  1603. if (mini != i__) {
  1604. theta[mini] = theta[i__];
  1605. theta[i__] = thetamin;
  1606. if (colmajor) {
  1607. if (wantu1) {
  1608. sswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
  1609. u1_dim1 + 1], &c__1);
  1610. }
  1611. if (wantu2) {
  1612. i__2 = *m - *p;
  1613. sswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
  1614. u2_dim1 + 1], &c__1);
  1615. }
  1616. if (wantv1t) {
  1617. sswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
  1618. v1t_dim1], ldv1t);
  1619. }
  1620. if (wantv2t) {
  1621. i__2 = *m - *q;
  1622. sswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
  1623. v2t_dim1], ldv2t);
  1624. }
  1625. } else {
  1626. if (wantu1) {
  1627. sswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
  1628. ldu1);
  1629. }
  1630. if (wantu2) {
  1631. i__2 = *m - *p;
  1632. sswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
  1633. u2_dim1], ldu2);
  1634. }
  1635. if (wantv1t) {
  1636. sswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
  1637. v1t_dim1 + 1], &c__1);
  1638. }
  1639. if (wantv2t) {
  1640. i__2 = *m - *q;
  1641. sswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
  1642. v2t_dim1 + 1], &c__1);
  1643. }
  1644. }
  1645. }
  1646. }
  1647. return;
  1648. /* End of SBBCSD */
  1649. } /* sbbcsd_ */