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