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.

zbbcsd.c 55 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  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 doublecomplex c_b1 = {-1.,0.};
  485. static doublereal c_b11 = -.125;
  486. static integer c__1 = 1;
  487. /* > \brief \b ZBBCSD */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download ZBBCSD + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zbbcsd.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zbbcsd.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zbbcsd.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE ZBBCSD( 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, RWORK, LRWORK, INFO ) */
  509. /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
  510. /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LRWORK, M, P, Q */
  511. /* DOUBLE PRECISION B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
  512. /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
  513. /* $ PHI( * ), THETA( * ), RWORK( * ) */
  514. /* COMPLEX*16 U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
  515. /* $ V2T( LDV2T, * ) */
  516. /* > \par Purpose: */
  517. /* ============= */
  518. /* > */
  519. /* > \verbatim */
  520. /* > */
  521. /* > ZBBCSD computes the CS decomposition of a unitary 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 | ]**H */
  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 ZUNCSD 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 unitary 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 unitary 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 COMPLEX*16 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 COMPLEX*16 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 COMPLEX*16 array, dimension (LDV1T,Q) */
  655. /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
  656. /* > by the conjugate 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 COMPLEX*16 array, dimension (LDV2T,M-Q) */
  669. /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
  670. /* > premultiplied by the conjugate 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 DOUBLE PRECISION array, dimension (Q) */
  684. /* > When ZBBCSD converges, B11D contains the cosines of THETA(1), */
  685. /* > ..., THETA(Q). If ZBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  693. /* > When ZBBCSD converges, B11E contains zeros. If ZBBCSD 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 DOUBLE PRECISION array, dimension (Q) */
  701. /* > When ZBBCSD converges, B12D contains the negative sines of */
  702. /* > THETA(1), ..., THETA(Q). If ZBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  710. /* > When ZBBCSD converges, B12E contains zeros. If ZBBCSD 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 DOUBLE PRECISION array, dimension (Q) */
  718. /* > When ZBBCSD converges, B21D contains the negative sines of */
  719. /* > THETA(1), ..., THETA(Q). If ZBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  727. /* > When ZBBCSD converges, B21E contains zeros. If ZBBCSD 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 DOUBLE PRECISION array, dimension (Q) */
  735. /* > When ZBBCSD converges, B22D contains the negative sines of */
  736. /* > THETA(1), ..., THETA(Q). If ZBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  744. /* > When ZBBCSD converges, B22E contains zeros. If ZBBCSD fails */
  745. /* > to converge, then B22E contains the subdiagonal of the */
  746. /* > partially reduced bottom-right block. */
  747. /* > \endverbatim */
  748. /* > */
  749. /* > \param[out] RWORK */
  750. /* > \verbatim */
  751. /* > RWORK is DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */
  752. /* > On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
  753. /* > \endverbatim */
  754. /* > */
  755. /* > \param[in] LRWORK */
  756. /* > \verbatim */
  757. /* > LRWORK is INTEGER */
  758. /* > The dimension of the array RWORK. LRWORK >= MAX(1,8*Q). */
  759. /* > */
  760. /* > If LRWORK = -1, then a workspace query is assumed; the */
  761. /* > routine only calculates the optimal size of the RWORK array, */
  762. /* > returns this value as the first entry of the work array, and */
  763. /* > no error message related to LRWORK 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 ZBBCSD 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 DOUBLE PRECISION, 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 complex16OTHERcomputational */
  797. /* ===================================================================== */
  798. /* Subroutine */ void zbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
  799. jobv2t, char *trans, integer *m, integer *p, integer *q, doublereal *
  800. theta, doublereal *phi, doublecomplex *u1, integer *ldu1,
  801. doublecomplex *u2, integer *ldu2, doublecomplex *v1t, integer *ldv1t,
  802. doublecomplex *v2t, integer *ldv2t, doublereal *b11d, doublereal *
  803. b11e, doublereal *b12d, doublereal *b12e, doublereal *b21d,
  804. doublereal *b21e, doublereal *b22d, doublereal *b22e, doublereal *
  805. rwork, integer *lrwork, 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. doublereal d__1, d__2, d__3, d__4;
  811. /* Local variables */
  812. integer imin, mini, imax, iter;
  813. doublereal unfl, temp;
  814. logical colmajor;
  815. doublereal thetamin, thetamax;
  816. logical restart11, restart12, restart21, restart22;
  817. extern /* Subroutine */ void dlas2_(doublereal *, doublereal *, doublereal
  818. *, doublereal *, doublereal *);
  819. integer iu1cs, iu2cs, iu1sn, iu2sn, i__, j;
  820. doublereal r__;
  821. extern logical lsame_(char *, char *);
  822. extern /* Subroutine */ void zscal_(integer *, doublecomplex *,
  823. doublecomplex *, integer *);
  824. integer maxit;
  825. doublereal dummy;
  826. extern /* Subroutine */ void zlasr_(char *, char *, char *, integer *,
  827. integer *, doublereal *, doublereal *, doublecomplex *, integer *), zswap_(integer *, doublecomplex *,
  828. integer *, doublecomplex *, integer *);
  829. doublereal x1, x2, y1, y2;
  830. integer lrworkmin, iv1tcs, iv2tcs;
  831. logical wantu1, wantu2;
  832. integer lrworkopt, iv1tsn, iv2tsn;
  833. extern doublereal dlamch_(char *);
  834. doublereal mu, nu, sigma11, sigma21;
  835. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  836. doublereal thresh, tolmul;
  837. extern /* Subroutine */ void mecago_();
  838. logical lquery;
  839. doublereal b11bulge;
  840. logical wantv1t, wantv2t;
  841. doublereal b12bulge, b21bulge, b22bulge, eps, tol;
  842. extern /* Subroutine */ void dlartgp_(doublereal *, doublereal *,
  843. doublereal *, doublereal *, doublereal *), dlartgs_(doublereal *,
  844. doublereal *, doublereal *, doublereal *, doublereal *);
  845. /* -- LAPACK computational routine (version 3.7.1) -- */
  846. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  847. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  848. /* June 2016 */
  849. /* =================================================================== */
  850. /* Test input arguments */
  851. /* Parameter adjustments */
  852. --theta;
  853. --phi;
  854. u1_dim1 = *ldu1;
  855. u1_offset = 1 + u1_dim1 * 1;
  856. u1 -= u1_offset;
  857. u2_dim1 = *ldu2;
  858. u2_offset = 1 + u2_dim1 * 1;
  859. u2 -= u2_offset;
  860. v1t_dim1 = *ldv1t;
  861. v1t_offset = 1 + v1t_dim1 * 1;
  862. v1t -= v1t_offset;
  863. v2t_dim1 = *ldv2t;
  864. v2t_offset = 1 + v2t_dim1 * 1;
  865. v2t -= v2t_offset;
  866. --b11d;
  867. --b11e;
  868. --b12d;
  869. --b12e;
  870. --b21d;
  871. --b21e;
  872. --b22d;
  873. --b22e;
  874. --rwork;
  875. /* Function Body */
  876. *info = 0;
  877. lquery = *lrwork == -1;
  878. wantu1 = lsame_(jobu1, "Y");
  879. wantu2 = lsame_(jobu2, "Y");
  880. wantv1t = lsame_(jobv1t, "Y");
  881. wantv2t = lsame_(jobv2t, "Y");
  882. colmajor = ! lsame_(trans, "T");
  883. if (*m < 0) {
  884. *info = -6;
  885. } else if (*p < 0 || *p > *m) {
  886. *info = -7;
  887. } else if (*q < 0 || *q > *m) {
  888. *info = -8;
  889. } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
  890. *info = -8;
  891. } else if (wantu1 && *ldu1 < *p) {
  892. *info = -12;
  893. } else if (wantu2 && *ldu2 < *m - *p) {
  894. *info = -14;
  895. } else if (wantv1t && *ldv1t < *q) {
  896. *info = -16;
  897. } else if (wantv2t && *ldv2t < *m - *q) {
  898. *info = -18;
  899. }
  900. /* Quick return if Q = 0 */
  901. if (*info == 0 && *q == 0) {
  902. lrworkmin = 1;
  903. rwork[1] = (doublereal) lrworkmin;
  904. return;
  905. }
  906. /* Compute workspace */
  907. if (*info == 0) {
  908. iu1cs = 1;
  909. iu1sn = iu1cs + *q;
  910. iu2cs = iu1sn + *q;
  911. iu2sn = iu2cs + *q;
  912. iv1tcs = iu2sn + *q;
  913. iv1tsn = iv1tcs + *q;
  914. iv2tcs = iv1tsn + *q;
  915. iv2tsn = iv2tcs + *q;
  916. lrworkopt = iv2tsn + *q - 1;
  917. lrworkmin = lrworkopt;
  918. rwork[1] = (doublereal) lrworkopt;
  919. if (*lrwork < lrworkmin && ! lquery) {
  920. *info = -28;
  921. }
  922. }
  923. if (*info != 0) {
  924. i__1 = -(*info);
  925. xerbla_("ZBBCSD", &i__1, (ftnlen)6);
  926. return;
  927. } else if (lquery) {
  928. return;
  929. }
  930. /* Get machine constants */
  931. eps = dlamch_("Epsilon");
  932. unfl = dlamch_("Safe minimum");
  933. /* Computing MAX */
  934. /* Computing MIN */
  935. d__3 = 100., d__4 = pow_dd(&eps, &c_b11);
  936. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  937. tolmul = f2cmax(d__1,d__2);
  938. tol = tolmul * eps;
  939. /* Computing MAX */
  940. d__1 = tol, d__2 = *q * 6 * *q * unfl;
  941. thresh = f2cmax(d__1,d__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.;
  947. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  948. theta[i__] = 1.57079632679489662;
  949. }
  950. }
  951. i__1 = *q - 1;
  952. for (i__ = 1; i__ <= i__1; ++i__) {
  953. if (phi[i__] < thresh) {
  954. phi[i__] = 0.;
  955. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  956. phi[i__] = 1.57079632679489662;
  957. }
  958. }
  959. /* Initial deflation */
  960. imax = *q;
  961. while(imax > 1) {
  962. if (phi[imax - 1] != 0.) {
  963. myexit_();
  964. }
  965. --imax;
  966. }
  967. imin = imax - 1;
  968. if (imin > 1) {
  969. while(phi[imin - 1] != 0.) {
  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.) {
  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.57079632679489662 - thresh) {
  1022. /* Zero on diagonals of B11 and B22; induce deflation with a */
  1023. /* zero shift */
  1024. mu = 0.;
  1025. nu = 1.;
  1026. } else if (thetamin < thresh) {
  1027. /* Zero on diagonals of B12 and B22; induce deflation with a */
  1028. /* zero shift */
  1029. mu = 1.;
  1030. nu = 0.;
  1031. } else {
  1032. /* Compute shifts for B11 and B21 and use the lesser */
  1033. dlas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
  1034. dummy);
  1035. dlas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
  1036. dummy);
  1037. if (sigma11 <= sigma21) {
  1038. mu = sigma11;
  1039. /* Computing 2nd power */
  1040. d__1 = mu;
  1041. nu = sqrt(1. - d__1 * d__1);
  1042. if (mu < thresh) {
  1043. mu = 0.;
  1044. nu = 1.;
  1045. }
  1046. } else {
  1047. nu = sigma21;
  1048. /* Computing 2nd power */
  1049. d__1 = nu;
  1050. mu = sqrt(1.f - d__1 * d__1);
  1051. if (nu < thresh) {
  1052. mu = 1.;
  1053. nu = 0.;
  1054. }
  1055. }
  1056. }
  1057. /* Rotate to produce bulges in B11 and B21 */
  1058. if (mu <= nu) {
  1059. dlartgs_(&b11d[imin], &b11e[imin], &mu, &rwork[iv1tcs + imin - 1],
  1060. &rwork[iv1tsn + imin - 1]);
  1061. } else {
  1062. dlartgs_(&b21d[imin], &b21e[imin], &nu, &rwork[iv1tcs + imin - 1],
  1063. &rwork[iv1tsn + imin - 1]);
  1064. }
  1065. temp = rwork[iv1tcs + imin - 1] * b11d[imin] + rwork[iv1tsn + imin -
  1066. 1] * b11e[imin];
  1067. b11e[imin] = rwork[iv1tcs + imin - 1] * b11e[imin] - rwork[iv1tsn +
  1068. imin - 1] * b11d[imin];
  1069. b11d[imin] = temp;
  1070. b11bulge = rwork[iv1tsn + imin - 1] * b11d[imin + 1];
  1071. b11d[imin + 1] = rwork[iv1tcs + imin - 1] * b11d[imin + 1];
  1072. temp = rwork[iv1tcs + imin - 1] * b21d[imin] + rwork[iv1tsn + imin -
  1073. 1] * b21e[imin];
  1074. b21e[imin] = rwork[iv1tcs + imin - 1] * b21e[imin] - rwork[iv1tsn +
  1075. imin - 1] * b21d[imin];
  1076. b21d[imin] = temp;
  1077. b21bulge = rwork[iv1tsn + imin - 1] * b21d[imin + 1];
  1078. b21d[imin + 1] = rwork[iv1tcs + imin - 1] * b21d[imin + 1];
  1079. /* Compute THETA(IMIN) */
  1080. /* Computing 2nd power */
  1081. d__1 = b21d[imin];
  1082. /* Computing 2nd power */
  1083. d__2 = b21bulge;
  1084. /* Computing 2nd power */
  1085. d__3 = b11d[imin];
  1086. /* Computing 2nd power */
  1087. d__4 = b11bulge;
  1088. theta[imin] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 * d__3
  1089. + d__4 * d__4));
  1090. /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
  1091. /* Computing 2nd power */
  1092. d__1 = b11d[imin];
  1093. /* Computing 2nd power */
  1094. d__2 = b11bulge;
  1095. /* Computing 2nd power */
  1096. d__3 = thresh;
  1097. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  1098. dlartgp_(&b11bulge, &b11d[imin], &rwork[iu1sn + imin - 1], &rwork[
  1099. iu1cs + imin - 1], &r__);
  1100. } else if (mu <= nu) {
  1101. dlartgs_(&b11e[imin], &b11d[imin + 1], &mu, &rwork[iu1cs + imin -
  1102. 1], &rwork[iu1sn + imin - 1]);
  1103. } else {
  1104. dlartgs_(&b12d[imin], &b12e[imin], &nu, &rwork[iu1cs + imin - 1],
  1105. &rwork[iu1sn + imin - 1]);
  1106. }
  1107. /* Computing 2nd power */
  1108. d__1 = b21d[imin];
  1109. /* Computing 2nd power */
  1110. d__2 = b21bulge;
  1111. /* Computing 2nd power */
  1112. d__3 = thresh;
  1113. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  1114. dlartgp_(&b21bulge, &b21d[imin], &rwork[iu2sn + imin - 1], &rwork[
  1115. iu2cs + imin - 1], &r__);
  1116. } else if (nu < mu) {
  1117. dlartgs_(&b21e[imin], &b21d[imin + 1], &nu, &rwork[iu2cs + imin -
  1118. 1], &rwork[iu2sn + imin - 1]);
  1119. } else {
  1120. dlartgs_(&b22d[imin], &b22e[imin], &mu, &rwork[iu2cs + imin - 1],
  1121. &rwork[iu2sn + imin - 1]);
  1122. }
  1123. rwork[iu2cs + imin - 1] = -rwork[iu2cs + imin - 1];
  1124. rwork[iu2sn + imin - 1] = -rwork[iu2sn + imin - 1];
  1125. temp = rwork[iu1cs + imin - 1] * b11e[imin] + rwork[iu1sn + imin - 1]
  1126. * b11d[imin + 1];
  1127. b11d[imin + 1] = rwork[iu1cs + imin - 1] * b11d[imin + 1] - rwork[
  1128. iu1sn + imin - 1] * b11e[imin];
  1129. b11e[imin] = temp;
  1130. if (imax > imin + 1) {
  1131. b11bulge = rwork[iu1sn + imin - 1] * b11e[imin + 1];
  1132. b11e[imin + 1] = rwork[iu1cs + imin - 1] * b11e[imin + 1];
  1133. }
  1134. temp = rwork[iu1cs + imin - 1] * b12d[imin] + rwork[iu1sn + imin - 1]
  1135. * b12e[imin];
  1136. b12e[imin] = rwork[iu1cs + imin - 1] * b12e[imin] - rwork[iu1sn +
  1137. imin - 1] * b12d[imin];
  1138. b12d[imin] = temp;
  1139. b12bulge = rwork[iu1sn + imin - 1] * b12d[imin + 1];
  1140. b12d[imin + 1] = rwork[iu1cs + imin - 1] * b12d[imin + 1];
  1141. temp = rwork[iu2cs + imin - 1] * b21e[imin] + rwork[iu2sn + imin - 1]
  1142. * b21d[imin + 1];
  1143. b21d[imin + 1] = rwork[iu2cs + imin - 1] * b21d[imin + 1] - rwork[
  1144. iu2sn + imin - 1] * b21e[imin];
  1145. b21e[imin] = temp;
  1146. if (imax > imin + 1) {
  1147. b21bulge = rwork[iu2sn + imin - 1] * b21e[imin + 1];
  1148. b21e[imin + 1] = rwork[iu2cs + imin - 1] * b21e[imin + 1];
  1149. }
  1150. temp = rwork[iu2cs + imin - 1] * b22d[imin] + rwork[iu2sn + imin - 1]
  1151. * b22e[imin];
  1152. b22e[imin] = rwork[iu2cs + imin - 1] * b22e[imin] - rwork[iu2sn +
  1153. imin - 1] * b22d[imin];
  1154. b22d[imin] = temp;
  1155. b22bulge = rwork[iu2sn + imin - 1] * b22d[imin + 1];
  1156. b22d[imin + 1] = rwork[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. d__1 = x1;
  1173. /* Computing 2nd power */
  1174. d__2 = x2;
  1175. /* Computing 2nd power */
  1176. d__3 = y1;
  1177. /* Computing 2nd power */
  1178. d__4 = y2;
  1179. phi[i__ - 1] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1180. d__3 + d__4 * d__4));
  1181. /* Determine if there are bulges to chase or if a new direct */
  1182. /* summand has been reached */
  1183. /* Computing 2nd power */
  1184. d__1 = b11e[i__ - 1];
  1185. /* Computing 2nd power */
  1186. d__2 = b11bulge;
  1187. /* Computing 2nd power */
  1188. d__3 = thresh;
  1189. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1190. /* Computing 2nd power */
  1191. d__1 = b21e[i__ - 1];
  1192. /* Computing 2nd power */
  1193. d__2 = b21bulge;
  1194. /* Computing 2nd power */
  1195. d__3 = thresh;
  1196. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1197. /* Computing 2nd power */
  1198. d__1 = b12d[i__ - 1];
  1199. /* Computing 2nd power */
  1200. d__2 = b12bulge;
  1201. /* Computing 2nd power */
  1202. d__3 = thresh;
  1203. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1204. /* Computing 2nd power */
  1205. d__1 = b22d[i__ - 1];
  1206. /* Computing 2nd power */
  1207. d__2 = b22bulge;
  1208. /* Computing 2nd power */
  1209. d__3 = thresh;
  1210. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__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. dlartgp_(&x2, &x1, &rwork[iv1tsn + i__ - 1], &rwork[iv1tcs +
  1216. i__ - 1], &r__);
  1217. } else if (! restart11 && restart21) {
  1218. dlartgp_(&b11bulge, &b11e[i__ - 1], &rwork[iv1tsn + i__ - 1],
  1219. &rwork[iv1tcs + i__ - 1], &r__);
  1220. } else if (restart11 && ! restart21) {
  1221. dlartgp_(&b21bulge, &b21e[i__ - 1], &rwork[iv1tsn + i__ - 1],
  1222. &rwork[iv1tcs + i__ - 1], &r__);
  1223. } else if (mu <= nu) {
  1224. dlartgs_(&b11d[i__], &b11e[i__], &mu, &rwork[iv1tcs + i__ - 1]
  1225. , &rwork[iv1tsn + i__ - 1]);
  1226. } else {
  1227. dlartgs_(&b21d[i__], &b21e[i__], &nu, &rwork[iv1tcs + i__ - 1]
  1228. , &rwork[iv1tsn + i__ - 1]);
  1229. }
  1230. rwork[iv1tcs + i__ - 1] = -rwork[iv1tcs + i__ - 1];
  1231. rwork[iv1tsn + i__ - 1] = -rwork[iv1tsn + i__ - 1];
  1232. if (! restart12 && ! restart22) {
  1233. dlartgp_(&y2, &y1, &rwork[iv2tsn + i__ - 2], &rwork[iv2tcs +
  1234. i__ - 2], &r__);
  1235. } else if (! restart12 && restart22) {
  1236. dlartgp_(&b12bulge, &b12d[i__ - 1], &rwork[iv2tsn + i__ - 2],
  1237. &rwork[iv2tcs + i__ - 2], &r__);
  1238. } else if (restart12 && ! restart22) {
  1239. dlartgp_(&b22bulge, &b22d[i__ - 1], &rwork[iv2tsn + i__ - 2],
  1240. &rwork[iv2tcs + i__ - 2], &r__);
  1241. } else if (nu < mu) {
  1242. dlartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &rwork[iv2tcs + i__
  1243. - 2], &rwork[iv2tsn + i__ - 2]);
  1244. } else {
  1245. dlartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &rwork[iv2tcs + i__
  1246. - 2], &rwork[iv2tsn + i__ - 2]);
  1247. }
  1248. temp = rwork[iv1tcs + i__ - 1] * b11d[i__] + rwork[iv1tsn + i__ -
  1249. 1] * b11e[i__];
  1250. b11e[i__] = rwork[iv1tcs + i__ - 1] * b11e[i__] - rwork[iv1tsn +
  1251. i__ - 1] * b11d[i__];
  1252. b11d[i__] = temp;
  1253. b11bulge = rwork[iv1tsn + i__ - 1] * b11d[i__ + 1];
  1254. b11d[i__ + 1] = rwork[iv1tcs + i__ - 1] * b11d[i__ + 1];
  1255. temp = rwork[iv1tcs + i__ - 1] * b21d[i__] + rwork[iv1tsn + i__ -
  1256. 1] * b21e[i__];
  1257. b21e[i__] = rwork[iv1tcs + i__ - 1] * b21e[i__] - rwork[iv1tsn +
  1258. i__ - 1] * b21d[i__];
  1259. b21d[i__] = temp;
  1260. b21bulge = rwork[iv1tsn + i__ - 1] * b21d[i__ + 1];
  1261. b21d[i__ + 1] = rwork[iv1tcs + i__ - 1] * b21d[i__ + 1];
  1262. temp = rwork[iv2tcs + i__ - 2] * b12e[i__ - 1] + rwork[iv2tsn +
  1263. i__ - 2] * b12d[i__];
  1264. b12d[i__] = rwork[iv2tcs + i__ - 2] * b12d[i__] - rwork[iv2tsn +
  1265. i__ - 2] * b12e[i__ - 1];
  1266. b12e[i__ - 1] = temp;
  1267. b12bulge = rwork[iv2tsn + i__ - 2] * b12e[i__];
  1268. b12e[i__] = rwork[iv2tcs + i__ - 2] * b12e[i__];
  1269. temp = rwork[iv2tcs + i__ - 2] * b22e[i__ - 1] + rwork[iv2tsn +
  1270. i__ - 2] * b22d[i__];
  1271. b22d[i__] = rwork[iv2tcs + i__ - 2] * b22d[i__] - rwork[iv2tsn +
  1272. i__ - 2] * b22e[i__ - 1];
  1273. b22e[i__ - 1] = temp;
  1274. b22bulge = rwork[iv2tsn + i__ - 2] * b22e[i__];
  1275. b22e[i__] = rwork[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. d__1 = y1;
  1285. /* Computing 2nd power */
  1286. d__2 = y2;
  1287. /* Computing 2nd power */
  1288. d__3 = x1;
  1289. /* Computing 2nd power */
  1290. d__4 = x2;
  1291. theta[i__] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1292. d__3 + d__4 * d__4));
  1293. /* Determine if there are bulges to chase or if a new direct */
  1294. /* summand has been reached */
  1295. /* Computing 2nd power */
  1296. d__1 = b11d[i__];
  1297. /* Computing 2nd power */
  1298. d__2 = b11bulge;
  1299. /* Computing 2nd power */
  1300. d__3 = thresh;
  1301. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1302. /* Computing 2nd power */
  1303. d__1 = b12e[i__ - 1];
  1304. /* Computing 2nd power */
  1305. d__2 = b12bulge;
  1306. /* Computing 2nd power */
  1307. d__3 = thresh;
  1308. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1309. /* Computing 2nd power */
  1310. d__1 = b21d[i__];
  1311. /* Computing 2nd power */
  1312. d__2 = b21bulge;
  1313. /* Computing 2nd power */
  1314. d__3 = thresh;
  1315. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1316. /* Computing 2nd power */
  1317. d__1 = b22e[i__ - 1];
  1318. /* Computing 2nd power */
  1319. d__2 = b22bulge;
  1320. /* Computing 2nd power */
  1321. d__3 = thresh;
  1322. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__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. dlartgp_(&x2, &x1, &rwork[iu1sn + i__ - 1], &rwork[iu1cs +
  1328. i__ - 1], &r__);
  1329. } else if (! restart11 && restart12) {
  1330. dlartgp_(&b11bulge, &b11d[i__], &rwork[iu1sn + i__ - 1], &
  1331. rwork[iu1cs + i__ - 1], &r__);
  1332. } else if (restart11 && ! restart12) {
  1333. dlartgp_(&b12bulge, &b12e[i__ - 1], &rwork[iu1sn + i__ - 1], &
  1334. rwork[iu1cs + i__ - 1], &r__);
  1335. } else if (mu <= nu) {
  1336. dlartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &rwork[iu1cs + i__
  1337. - 1], &rwork[iu1sn + i__ - 1]);
  1338. } else {
  1339. dlartgs_(&b12d[i__], &b12e[i__], &nu, &rwork[iu1cs + i__ - 1],
  1340. &rwork[iu1sn + i__ - 1]);
  1341. }
  1342. if (! restart21 && ! restart22) {
  1343. dlartgp_(&y2, &y1, &rwork[iu2sn + i__ - 1], &rwork[iu2cs +
  1344. i__ - 1], &r__);
  1345. } else if (! restart21 && restart22) {
  1346. dlartgp_(&b21bulge, &b21d[i__], &rwork[iu2sn + i__ - 1], &
  1347. rwork[iu2cs + i__ - 1], &r__);
  1348. } else if (restart21 && ! restart22) {
  1349. dlartgp_(&b22bulge, &b22e[i__ - 1], &rwork[iu2sn + i__ - 1], &
  1350. rwork[iu2cs + i__ - 1], &r__);
  1351. } else if (nu < mu) {
  1352. dlartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &rwork[iu2cs + i__
  1353. - 1], &rwork[iu2sn + i__ - 1]);
  1354. } else {
  1355. dlartgs_(&b22d[i__], &b22e[i__], &mu, &rwork[iu2cs + i__ - 1],
  1356. &rwork[iu2sn + i__ - 1]);
  1357. }
  1358. rwork[iu2cs + i__ - 1] = -rwork[iu2cs + i__ - 1];
  1359. rwork[iu2sn + i__ - 1] = -rwork[iu2sn + i__ - 1];
  1360. temp = rwork[iu1cs + i__ - 1] * b11e[i__] + rwork[iu1sn + i__ - 1]
  1361. * b11d[i__ + 1];
  1362. b11d[i__ + 1] = rwork[iu1cs + i__ - 1] * b11d[i__ + 1] - rwork[
  1363. iu1sn + i__ - 1] * b11e[i__];
  1364. b11e[i__] = temp;
  1365. if (i__ < imax - 1) {
  1366. b11bulge = rwork[iu1sn + i__ - 1] * b11e[i__ + 1];
  1367. b11e[i__ + 1] = rwork[iu1cs + i__ - 1] * b11e[i__ + 1];
  1368. }
  1369. temp = rwork[iu2cs + i__ - 1] * b21e[i__] + rwork[iu2sn + i__ - 1]
  1370. * b21d[i__ + 1];
  1371. b21d[i__ + 1] = rwork[iu2cs + i__ - 1] * b21d[i__ + 1] - rwork[
  1372. iu2sn + i__ - 1] * b21e[i__];
  1373. b21e[i__] = temp;
  1374. if (i__ < imax - 1) {
  1375. b21bulge = rwork[iu2sn + i__ - 1] * b21e[i__ + 1];
  1376. b21e[i__ + 1] = rwork[iu2cs + i__ - 1] * b21e[i__ + 1];
  1377. }
  1378. temp = rwork[iu1cs + i__ - 1] * b12d[i__] + rwork[iu1sn + i__ - 1]
  1379. * b12e[i__];
  1380. b12e[i__] = rwork[iu1cs + i__ - 1] * b12e[i__] - rwork[iu1sn +
  1381. i__ - 1] * b12d[i__];
  1382. b12d[i__] = temp;
  1383. b12bulge = rwork[iu1sn + i__ - 1] * b12d[i__ + 1];
  1384. b12d[i__ + 1] = rwork[iu1cs + i__ - 1] * b12d[i__ + 1];
  1385. temp = rwork[iu2cs + i__ - 1] * b22d[i__] + rwork[iu2sn + i__ - 1]
  1386. * b22e[i__];
  1387. b22e[i__] = rwork[iu2cs + i__ - 1] * b22e[i__] - rwork[iu2sn +
  1388. i__ - 1] * b22d[i__];
  1389. b22d[i__] = temp;
  1390. b22bulge = rwork[iu2sn + i__ - 1] * b22d[i__ + 1];
  1391. b22d[i__ + 1] = rwork[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. d__1 = y1;
  1402. /* Computing 2nd power */
  1403. d__2 = y2;
  1404. phi[imax - 1] = atan2((abs(x1)), sqrt(d__1 * d__1 + d__2 * d__2));
  1405. /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
  1406. /* Computing 2nd power */
  1407. d__1 = b12d[imax - 1];
  1408. /* Computing 2nd power */
  1409. d__2 = b12bulge;
  1410. /* Computing 2nd power */
  1411. d__3 = thresh;
  1412. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1413. /* Computing 2nd power */
  1414. d__1 = b22d[imax - 1];
  1415. /* Computing 2nd power */
  1416. d__2 = b22bulge;
  1417. /* Computing 2nd power */
  1418. d__3 = thresh;
  1419. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1420. if (! restart12 && ! restart22) {
  1421. dlartgp_(&y2, &y1, &rwork[iv2tsn + imax - 2], &rwork[iv2tcs +
  1422. imax - 2], &r__);
  1423. } else if (! restart12 && restart22) {
  1424. dlartgp_(&b12bulge, &b12d[imax - 1], &rwork[iv2tsn + imax - 2], &
  1425. rwork[iv2tcs + imax - 2], &r__);
  1426. } else if (restart12 && ! restart22) {
  1427. dlartgp_(&b22bulge, &b22d[imax - 1], &rwork[iv2tsn + imax - 2], &
  1428. rwork[iv2tcs + imax - 2], &r__);
  1429. } else if (nu < mu) {
  1430. dlartgs_(&b12e[imax - 1], &b12d[imax], &nu, &rwork[iv2tcs + imax
  1431. - 2], &rwork[iv2tsn + imax - 2]);
  1432. } else {
  1433. dlartgs_(&b22e[imax - 1], &b22d[imax], &mu, &rwork[iv2tcs + imax
  1434. - 2], &rwork[iv2tsn + imax - 2]);
  1435. }
  1436. temp = rwork[iv2tcs + imax - 2] * b12e[imax - 1] + rwork[iv2tsn +
  1437. imax - 2] * b12d[imax];
  1438. b12d[imax] = rwork[iv2tcs + imax - 2] * b12d[imax] - rwork[iv2tsn +
  1439. imax - 2] * b12e[imax - 1];
  1440. b12e[imax - 1] = temp;
  1441. temp = rwork[iv2tcs + imax - 2] * b22e[imax - 1] + rwork[iv2tsn +
  1442. imax - 2] * b22d[imax];
  1443. b22d[imax] = rwork[iv2tcs + imax - 2] * b22d[imax] - rwork[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. zlasr_("R", "V", "F", p, &i__1, &rwork[iu1cs + imin - 1], &
  1451. rwork[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1],
  1452. ldu1);
  1453. } else {
  1454. i__1 = imax - imin + 1;
  1455. zlasr_("L", "V", "F", &i__1, p, &rwork[iu1cs + imin - 1], &
  1456. rwork[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
  1457. }
  1458. }
  1459. if (wantu2) {
  1460. if (colmajor) {
  1461. i__1 = *m - *p;
  1462. i__2 = imax - imin + 1;
  1463. zlasr_("R", "V", "F", &i__1, &i__2, &rwork[iu2cs + imin - 1],
  1464. &rwork[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1],
  1465. ldu2);
  1466. } else {
  1467. i__1 = imax - imin + 1;
  1468. i__2 = *m - *p;
  1469. zlasr_("L", "V", "F", &i__1, &i__2, &rwork[iu2cs + imin - 1],
  1470. &rwork[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
  1471. }
  1472. }
  1473. if (wantv1t) {
  1474. if (colmajor) {
  1475. i__1 = imax - imin + 1;
  1476. zlasr_("L", "V", "F", &i__1, q, &rwork[iv1tcs + imin - 1], &
  1477. rwork[iv1tsn + imin - 1], &v1t[imin + v1t_dim1],
  1478. ldv1t);
  1479. } else {
  1480. i__1 = imax - imin + 1;
  1481. zlasr_("R", "V", "F", q, &i__1, &rwork[iv1tcs + imin - 1], &
  1482. rwork[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
  1483. ldv1t);
  1484. }
  1485. }
  1486. if (wantv2t) {
  1487. if (colmajor) {
  1488. i__1 = imax - imin + 1;
  1489. i__2 = *m - *q;
  1490. zlasr_("L", "V", "F", &i__1, &i__2, &rwork[iv2tcs + imin - 1],
  1491. &rwork[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
  1492. ldv2t);
  1493. } else {
  1494. i__1 = *m - *q;
  1495. i__2 = imax - imin + 1;
  1496. zlasr_("R", "V", "F", &i__1, &i__2, &rwork[iv2tcs + imin - 1],
  1497. &rwork[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
  1498. ldv2t);
  1499. }
  1500. }
  1501. /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
  1502. if (b11e[imax - 1] + b21e[imax - 1] > 0.) {
  1503. b11d[imax] = -b11d[imax];
  1504. b21d[imax] = -b21d[imax];
  1505. if (wantv1t) {
  1506. if (colmajor) {
  1507. zscal_(q, &c_b1, &v1t[imax + v1t_dim1], ldv1t);
  1508. } else {
  1509. zscal_(q, &c_b1, &v1t[imax * v1t_dim1 + 1], &c__1);
  1510. }
  1511. }
  1512. }
  1513. /* Compute THETA(IMAX) */
  1514. x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
  1515. - 1];
  1516. y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
  1517. - 1];
  1518. theta[imax] = atan2((abs(y1)), (abs(x1)));
  1519. /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
  1520. /* and B22(IMAX,IMAX-1) */
  1521. if (b11d[imax] + b12e[imax - 1] < 0.) {
  1522. b12d[imax] = -b12d[imax];
  1523. if (wantu1) {
  1524. if (colmajor) {
  1525. zscal_(p, &c_b1, &u1[imax * u1_dim1 + 1], &c__1);
  1526. } else {
  1527. zscal_(p, &c_b1, &u1[imax + u1_dim1], ldu1);
  1528. }
  1529. }
  1530. }
  1531. if (b21d[imax] + b22e[imax - 1] > 0.) {
  1532. b22d[imax] = -b22d[imax];
  1533. if (wantu2) {
  1534. if (colmajor) {
  1535. i__1 = *m - *p;
  1536. zscal_(&i__1, &c_b1, &u2[imax * u2_dim1 + 1], &c__1);
  1537. } else {
  1538. i__1 = *m - *p;
  1539. zscal_(&i__1, &c_b1, &u2[imax + u2_dim1], ldu2);
  1540. }
  1541. }
  1542. }
  1543. /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
  1544. if (b12d[imax] + b22d[imax] < 0.) {
  1545. if (wantv2t) {
  1546. if (colmajor) {
  1547. i__1 = *m - *q;
  1548. zscal_(&i__1, &c_b1, &v2t[imax + v2t_dim1], ldv2t);
  1549. } else {
  1550. i__1 = *m - *q;
  1551. zscal_(&i__1, &c_b1, &v2t[imax * v2t_dim1 + 1], &c__1);
  1552. }
  1553. }
  1554. }
  1555. /* Test for negligible sines or cosines */
  1556. i__1 = imax;
  1557. for (i__ = imin; i__ <= i__1; ++i__) {
  1558. if (theta[i__] < thresh) {
  1559. theta[i__] = 0.;
  1560. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  1561. theta[i__] = 1.57079632679489662;
  1562. }
  1563. }
  1564. i__1 = imax - 1;
  1565. for (i__ = imin; i__ <= i__1; ++i__) {
  1566. if (phi[i__] < thresh) {
  1567. phi[i__] = 0.;
  1568. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  1569. phi[i__] = 1.57079632679489662;
  1570. }
  1571. }
  1572. /* Deflate */
  1573. if (imax > 1) {
  1574. while(phi[imax - 1] == 0.) {
  1575. --imax;
  1576. if (imax <= 1) {
  1577. myexit_();
  1578. }
  1579. }
  1580. }
  1581. if (imin > imax - 1) {
  1582. imin = imax - 1;
  1583. }
  1584. if (imin > 1) {
  1585. while(phi[imin - 1] != 0.) {
  1586. --imin;
  1587. if (imin <= 1) {
  1588. myexit_();
  1589. }
  1590. }
  1591. }
  1592. /* Repeat main iteration loop */
  1593. }
  1594. /* Postprocessing: order THETA from least to greatest */
  1595. i__1 = *q;
  1596. for (i__ = 1; i__ <= i__1; ++i__) {
  1597. mini = i__;
  1598. thetamin = theta[i__];
  1599. i__2 = *q;
  1600. for (j = i__ + 1; j <= i__2; ++j) {
  1601. if (theta[j] < thetamin) {
  1602. mini = j;
  1603. thetamin = theta[j];
  1604. }
  1605. }
  1606. if (mini != i__) {
  1607. theta[mini] = theta[i__];
  1608. theta[i__] = thetamin;
  1609. if (colmajor) {
  1610. if (wantu1) {
  1611. zswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
  1612. u1_dim1 + 1], &c__1);
  1613. }
  1614. if (wantu2) {
  1615. i__2 = *m - *p;
  1616. zswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
  1617. u2_dim1 + 1], &c__1);
  1618. }
  1619. if (wantv1t) {
  1620. zswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
  1621. v1t_dim1], ldv1t);
  1622. }
  1623. if (wantv2t) {
  1624. i__2 = *m - *q;
  1625. zswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
  1626. v2t_dim1], ldv2t);
  1627. }
  1628. } else {
  1629. if (wantu1) {
  1630. zswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
  1631. ldu1);
  1632. }
  1633. if (wantu2) {
  1634. i__2 = *m - *p;
  1635. zswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
  1636. u2_dim1], ldu2);
  1637. }
  1638. if (wantv1t) {
  1639. zswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
  1640. v1t_dim1 + 1], &c__1);
  1641. }
  1642. if (wantv2t) {
  1643. i__2 = *m - *q;
  1644. zswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
  1645. v2t_dim1 + 1], &c__1);
  1646. }
  1647. }
  1648. }
  1649. }
  1650. return;
  1651. /* End of ZBBCSD */
  1652. } /* zbbcsd_ */