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