You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sbbcsd.c 51 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #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++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #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]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static doublereal c_b10 = -.125;
  381. static real c_b35 = -1.f;
  382. static integer c__1 = 1;
  383. /* > \brief \b SBBCSD */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download SBBCSD + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sbbcsd.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sbbcsd.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sbbcsd.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE SBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, */
  402. /* THETA, PHI, U1, LDU1, U2, LDU2, V1T, LDV1T, */
  403. /* V2T, LDV2T, B11D, B11E, B12D, B12E, B21D, B21E, */
  404. /* B22D, B22E, WORK, LWORK, INFO ) */
  405. /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
  406. /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LWORK, M, P, Q */
  407. /* REAL B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
  408. /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
  409. /* $ PHI( * ), THETA( * ), WORK( * ) */
  410. /* REAL U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
  411. /* $ V2T( LDV2T, * ) */
  412. /* > \par Purpose: */
  413. /* ============= */
  414. /* > */
  415. /* > \verbatim */
  416. /* > */
  417. /* > SBBCSD computes the CS decomposition of an orthogonal matrix in */
  418. /* > bidiagonal-block form, */
  419. /* > */
  420. /* > */
  421. /* > [ B11 | B12 0 0 ] */
  422. /* > [ 0 | 0 -I 0 ] */
  423. /* > X = [----------------] */
  424. /* > [ B21 | B22 0 0 ] */
  425. /* > [ 0 | 0 0 I ] */
  426. /* > */
  427. /* > [ C | -S 0 0 ] */
  428. /* > [ U1 | ] [ 0 | 0 -I 0 ] [ V1 | ]**T */
  429. /* > = [---------] [---------------] [---------] . */
  430. /* > [ | U2 ] [ S | C 0 0 ] [ | V2 ] */
  431. /* > [ 0 | 0 0 I ] */
  432. /* > */
  433. /* > X is M-by-M, its top-left block is P-by-Q, and Q must be no larger */
  434. /* > than P, M-P, or M-Q. (If Q is not the smallest index, then X must be */
  435. /* > transposed and/or permuted. This can be done in constant time using */
  436. /* > the TRANS and SIGNS options. See SORCSD for details.) */
  437. /* > */
  438. /* > The bidiagonal matrices B11, B12, B21, and B22 are represented */
  439. /* > implicitly by angles THETA(1:Q) and PHI(1:Q-1). */
  440. /* > */
  441. /* > The orthogonal matrices U1, U2, V1T, and V2T are input/output. */
  442. /* > The input matrices are pre- or post-multiplied by the appropriate */
  443. /* > singular vector matrices. */
  444. /* > \endverbatim */
  445. /* Arguments: */
  446. /* ========== */
  447. /* > \param[in] JOBU1 */
  448. /* > \verbatim */
  449. /* > JOBU1 is CHARACTER */
  450. /* > = 'Y': U1 is updated; */
  451. /* > otherwise: U1 is not updated. */
  452. /* > \endverbatim */
  453. /* > */
  454. /* > \param[in] JOBU2 */
  455. /* > \verbatim */
  456. /* > JOBU2 is CHARACTER */
  457. /* > = 'Y': U2 is updated; */
  458. /* > otherwise: U2 is not updated. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in] JOBV1T */
  462. /* > \verbatim */
  463. /* > JOBV1T is CHARACTER */
  464. /* > = 'Y': V1T is updated; */
  465. /* > otherwise: V1T is not updated. */
  466. /* > \endverbatim */
  467. /* > */
  468. /* > \param[in] JOBV2T */
  469. /* > \verbatim */
  470. /* > JOBV2T is CHARACTER */
  471. /* > = 'Y': V2T is updated; */
  472. /* > otherwise: V2T is not updated. */
  473. /* > \endverbatim */
  474. /* > */
  475. /* > \param[in] TRANS */
  476. /* > \verbatim */
  477. /* > TRANS is CHARACTER */
  478. /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
  479. /* > order; */
  480. /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
  481. /* > major order. */
  482. /* > \endverbatim */
  483. /* > */
  484. /* > \param[in] M */
  485. /* > \verbatim */
  486. /* > M is INTEGER */
  487. /* > The number of rows and columns in X, the orthogonal matrix in */
  488. /* > bidiagonal-block form. */
  489. /* > \endverbatim */
  490. /* > */
  491. /* > \param[in] P */
  492. /* > \verbatim */
  493. /* > P is INTEGER */
  494. /* > The number of rows in the top-left block of X. 0 <= P <= M. */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[in] Q */
  498. /* > \verbatim */
  499. /* > Q is INTEGER */
  500. /* > The number of columns in the top-left block of X. */
  501. /* > 0 <= Q <= MIN(P,M-P,M-Q). */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[in,out] THETA */
  505. /* > \verbatim */
  506. /* > THETA is REAL array, dimension (Q) */
  507. /* > On entry, the angles THETA(1),...,THETA(Q) that, along with */
  508. /* > PHI(1), ...,PHI(Q-1), define the matrix in bidiagonal-block */
  509. /* > form. On exit, the angles whose cosines and sines define the */
  510. /* > diagonal blocks in the CS decomposition. */
  511. /* > \endverbatim */
  512. /* > */
  513. /* > \param[in,out] PHI */
  514. /* > \verbatim */
  515. /* > PHI is REAL array, dimension (Q-1) */
  516. /* > The angles PHI(1),...,PHI(Q-1) that, along with THETA(1),..., */
  517. /* > THETA(Q), define the matrix in bidiagonal-block form. */
  518. /* > \endverbatim */
  519. /* > */
  520. /* > \param[in,out] U1 */
  521. /* > \verbatim */
  522. /* > U1 is REAL array, dimension (LDU1,P) */
  523. /* > On entry, a P-by-P matrix. On exit, U1 is postmultiplied */
  524. /* > by the left singular vector matrix common to [ B11 ; 0 ] and */
  525. /* > [ B12 0 0 ; 0 -I 0 0 ]. */
  526. /* > \endverbatim */
  527. /* > */
  528. /* > \param[in] LDU1 */
  529. /* > \verbatim */
  530. /* > LDU1 is INTEGER */
  531. /* > The leading dimension of the array U1, LDU1 >= MAX(1,P). */
  532. /* > \endverbatim */
  533. /* > */
  534. /* > \param[in,out] U2 */
  535. /* > \verbatim */
  536. /* > U2 is REAL array, dimension (LDU2,M-P) */
  537. /* > On entry, an (M-P)-by-(M-P) matrix. On exit, U2 is */
  538. /* > postmultiplied by the left singular vector matrix common to */
  539. /* > [ B21 ; 0 ] and [ B22 0 0 ; 0 0 I ]. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[in] LDU2 */
  543. /* > \verbatim */
  544. /* > LDU2 is INTEGER */
  545. /* > The leading dimension of the array U2, LDU2 >= MAX(1,M-P). */
  546. /* > \endverbatim */
  547. /* > */
  548. /* > \param[in,out] V1T */
  549. /* > \verbatim */
  550. /* > V1T is REAL array, dimension (LDV1T,Q) */
  551. /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
  552. /* > by the transpose of the right singular vector */
  553. /* > matrix common to [ B11 ; 0 ] and [ B21 ; 0 ]. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] LDV1T */
  557. /* > \verbatim */
  558. /* > LDV1T is INTEGER */
  559. /* > The leading dimension of the array V1T, LDV1T >= MAX(1,Q). */
  560. /* > \endverbatim */
  561. /* > */
  562. /* > \param[in,out] V2T */
  563. /* > \verbatim */
  564. /* > V2T is REAL array, dimension (LDV2T,M-Q) */
  565. /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
  566. /* > premultiplied by the transpose of the right */
  567. /* > singular vector matrix common to [ B12 0 0 ; 0 -I 0 ] and */
  568. /* > [ B22 0 0 ; 0 0 I ]. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] LDV2T */
  572. /* > \verbatim */
  573. /* > LDV2T is INTEGER */
  574. /* > The leading dimension of the array V2T, LDV2T >= MAX(1,M-Q). */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[out] B11D */
  578. /* > \verbatim */
  579. /* > B11D is REAL array, dimension (Q) */
  580. /* > When SBBCSD converges, B11D contains the cosines of THETA(1), */
  581. /* > ..., THETA(Q). If SBBCSD fails to converge, then B11D */
  582. /* > contains the diagonal of the partially reduced top-left */
  583. /* > block. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[out] B11E */
  587. /* > \verbatim */
  588. /* > B11E is REAL array, dimension (Q-1) */
  589. /* > When SBBCSD converges, B11E contains zeros. If SBBCSD fails */
  590. /* > to converge, then B11E contains the superdiagonal of the */
  591. /* > partially reduced top-left block. */
  592. /* > \endverbatim */
  593. /* > */
  594. /* > \param[out] B12D */
  595. /* > \verbatim */
  596. /* > B12D is REAL array, dimension (Q) */
  597. /* > When SBBCSD converges, B12D contains the negative sines of */
  598. /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
  599. /* > B12D contains the diagonal of the partially reduced top-right */
  600. /* > block. */
  601. /* > \endverbatim */
  602. /* > */
  603. /* > \param[out] B12E */
  604. /* > \verbatim */
  605. /* > B12E is REAL array, dimension (Q-1) */
  606. /* > When SBBCSD converges, B12E contains zeros. If SBBCSD fails */
  607. /* > to converge, then B12E contains the subdiagonal of the */
  608. /* > partially reduced top-right block. */
  609. /* > \endverbatim */
  610. /* > */
  611. /* > \param[out] B21D */
  612. /* > \verbatim */
  613. /* > B21D is REAL array, dimension (Q) */
  614. /* > When SBBCSD converges, B21D contains the negative sines of */
  615. /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
  616. /* > B21D contains the diagonal of the partially reduced bottom-left */
  617. /* > block. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[out] B21E */
  621. /* > \verbatim */
  622. /* > B21E is REAL array, dimension (Q-1) */
  623. /* > When SBBCSD converges, B21E contains zeros. If SBBCSD fails */
  624. /* > to converge, then B21E contains the subdiagonal of the */
  625. /* > partially reduced bottom-left block. */
  626. /* > \endverbatim */
  627. /* > */
  628. /* > \param[out] B22D */
  629. /* > \verbatim */
  630. /* > B22D is REAL array, dimension (Q) */
  631. /* > When SBBCSD converges, B22D contains the negative sines of */
  632. /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
  633. /* > B22D contains the diagonal of the partially reduced bottom-right */
  634. /* > block. */
  635. /* > \endverbatim */
  636. /* > */
  637. /* > \param[out] B22E */
  638. /* > \verbatim */
  639. /* > B22E is REAL array, dimension (Q-1) */
  640. /* > When SBBCSD converges, B22E contains zeros. If SBBCSD fails */
  641. /* > to converge, then B22E contains the subdiagonal of the */
  642. /* > partially reduced bottom-right block. */
  643. /* > \endverbatim */
  644. /* > */
  645. /* > \param[out] WORK */
  646. /* > \verbatim */
  647. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  648. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  649. /* > \endverbatim */
  650. /* > */
  651. /* > \param[in] LWORK */
  652. /* > \verbatim */
  653. /* > LWORK is INTEGER */
  654. /* > The dimension of the array WORK. LWORK >= MAX(1,8*Q). */
  655. /* > */
  656. /* > If LWORK = -1, then a workspace query is assumed; the */
  657. /* > routine only calculates the optimal size of the WORK array, */
  658. /* > returns this value as the first entry of the work array, and */
  659. /* > no error message related to LWORK is issued by XERBLA. */
  660. /* > \endverbatim */
  661. /* > */
  662. /* > \param[out] INFO */
  663. /* > \verbatim */
  664. /* > INFO is INTEGER */
  665. /* > = 0: successful exit. */
  666. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  667. /* > > 0: if SBBCSD did not converge, INFO specifies the number */
  668. /* > of nonzero entries in PHI, and B11D, B11E, etc., */
  669. /* > contain the partially reduced matrix. */
  670. /* > \endverbatim */
  671. /* > \par Internal Parameters: */
  672. /* ========================= */
  673. /* > */
  674. /* > \verbatim */
  675. /* > TOLMUL REAL, default = MAX(10,MIN(100,EPS**(-1/8))) */
  676. /* > TOLMUL controls the convergence criterion of the QR loop. */
  677. /* > Angles THETA(i), PHI(i) are rounded to 0 or PI/2 when they */
  678. /* > are within TOLMUL*EPS of either bound. */
  679. /* > \endverbatim */
  680. /* > \par References: */
  681. /* ================ */
  682. /* > */
  683. /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
  684. /* > Algorithms, 50(1):33-65, 2009. */
  685. /* Authors: */
  686. /* ======== */
  687. /* > \author Univ. of Tennessee */
  688. /* > \author Univ. of California Berkeley */
  689. /* > \author Univ. of Colorado Denver */
  690. /* > \author NAG Ltd. */
  691. /* > \date June 2016 */
  692. /* > \ingroup realOTHERcomputational */
  693. /* ===================================================================== */
  694. /* Subroutine */ int sbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
  695. jobv2t, char *trans, integer *m, integer *p, integer *q, real *theta,
  696. real *phi, real *u1, integer *ldu1, real *u2, integer *ldu2, real *
  697. v1t, integer *ldv1t, real *v2t, integer *ldv2t, real *b11d, real *
  698. b11e, real *b12d, real *b12e, real *b21d, real *b21e, real *b22d,
  699. real *b22e, real *work, integer *lwork, integer *info)
  700. {
  701. /* System generated locals */
  702. integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
  703. v2t_dim1, v2t_offset, i__1, i__2;
  704. real r__1, r__2, r__3, r__4;
  705. doublereal d__1;
  706. /* Local variables */
  707. integer imin, mini, imax, iter;
  708. real unfl, temp;
  709. logical colmajor;
  710. real thetamin, thetamax;
  711. logical restart11, restart12, restart21, restart22;
  712. integer lworkmin, iu1cs, iu2cs;
  713. extern /* Subroutine */ int slas2_(real *, real *, real *, real *, real *)
  714. ;
  715. integer iu1sn, iu2sn, lworkopt, i__, j;
  716. real r__;
  717. extern logical lsame_(char *, char *);
  718. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
  719. integer maxit;
  720. extern /* Subroutine */ int slasr_(char *, char *, char *, integer *,
  721. integer *, real *, real *, real *, integer *);
  722. real dummy;
  723. extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *,
  724. integer *);
  725. real x1, x2, y1, y2;
  726. integer iv1tcs, iv2tcs;
  727. logical wantu1, wantu2;
  728. integer iv1tsn, iv2tsn;
  729. real mu, nu, sigma11, sigma21;
  730. extern real slamch_(char *);
  731. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  732. real thresh, tolmul;
  733. extern /* Subroutine */ int mecago_();
  734. logical lquery;
  735. real b11bulge;
  736. logical wantv1t, wantv2t;
  737. real b12bulge, b21bulge, b22bulge, eps, tol;
  738. extern /* Subroutine */ int slartgp_(real *, real *, real *, real *, real
  739. *), slartgs_(real *, real *, real *, real *, real *);
  740. /* -- LAPACK computational routine (version 3.7.1) -- */
  741. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  742. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  743. /* June 2016 */
  744. /* =================================================================== */
  745. /* Test input arguments */
  746. /* Parameter adjustments */
  747. --theta;
  748. --phi;
  749. u1_dim1 = *ldu1;
  750. u1_offset = 1 + u1_dim1 * 1;
  751. u1 -= u1_offset;
  752. u2_dim1 = *ldu2;
  753. u2_offset = 1 + u2_dim1 * 1;
  754. u2 -= u2_offset;
  755. v1t_dim1 = *ldv1t;
  756. v1t_offset = 1 + v1t_dim1 * 1;
  757. v1t -= v1t_offset;
  758. v2t_dim1 = *ldv2t;
  759. v2t_offset = 1 + v2t_dim1 * 1;
  760. v2t -= v2t_offset;
  761. --b11d;
  762. --b11e;
  763. --b12d;
  764. --b12e;
  765. --b21d;
  766. --b21e;
  767. --b22d;
  768. --b22e;
  769. --work;
  770. /* Function Body */
  771. *info = 0;
  772. lquery = *lwork == -1;
  773. wantu1 = lsame_(jobu1, "Y");
  774. wantu2 = lsame_(jobu2, "Y");
  775. wantv1t = lsame_(jobv1t, "Y");
  776. wantv2t = lsame_(jobv2t, "Y");
  777. colmajor = ! lsame_(trans, "T");
  778. if (*m < 0) {
  779. *info = -6;
  780. } else if (*p < 0 || *p > *m) {
  781. *info = -7;
  782. } else if (*q < 0 || *q > *m) {
  783. *info = -8;
  784. } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
  785. *info = -8;
  786. } else if (wantu1 && *ldu1 < *p) {
  787. *info = -12;
  788. } else if (wantu2 && *ldu2 < *m - *p) {
  789. *info = -14;
  790. } else if (wantv1t && *ldv1t < *q) {
  791. *info = -16;
  792. } else if (wantv2t && *ldv2t < *m - *q) {
  793. *info = -18;
  794. }
  795. /* Quick return if Q = 0 */
  796. if (*info == 0 && *q == 0) {
  797. lworkmin = 1;
  798. work[1] = (real) lworkmin;
  799. return 0;
  800. }
  801. /* Compute workspace */
  802. if (*info == 0) {
  803. iu1cs = 1;
  804. iu1sn = iu1cs + *q;
  805. iu2cs = iu1sn + *q;
  806. iu2sn = iu2cs + *q;
  807. iv1tcs = iu2sn + *q;
  808. iv1tsn = iv1tcs + *q;
  809. iv2tcs = iv1tsn + *q;
  810. iv2tsn = iv2tcs + *q;
  811. lworkopt = iv2tsn + *q - 1;
  812. lworkmin = lworkopt;
  813. work[1] = (real) lworkopt;
  814. if (*lwork < lworkmin && ! lquery) {
  815. *info = -28;
  816. }
  817. }
  818. if (*info != 0) {
  819. i__1 = -(*info);
  820. xerbla_("SBBCSD", &i__1,(ftnlen)6);
  821. return 0;
  822. } else if (lquery) {
  823. return 0;
  824. }
  825. /* Get machine constants */
  826. eps = slamch_("Epsilon");
  827. unfl = slamch_("Safe minimum");
  828. /* Computing MAX */
  829. /* Computing MIN */
  830. d__1 = (doublereal) eps;
  831. r__3 = 100.f, r__4 = pow_dd(&d__1, &c_b10);
  832. r__1 = 10.f, r__2 = f2cmin(r__3,r__4);
  833. tolmul = f2cmax(r__1,r__2);
  834. tol = tolmul * eps;
  835. /* Computing MAX */
  836. r__1 = tol, r__2 = *q * 6 * *q * unfl;
  837. thresh = f2cmax(r__1,r__2);
  838. /* Test for negligible sines or cosines */
  839. i__1 = *q;
  840. for (i__ = 1; i__ <= i__1; ++i__) {
  841. if (theta[i__] < thresh) {
  842. theta[i__] = 0.f;
  843. } else if (theta[i__] > 1.57079632679489662f - thresh) {
  844. theta[i__] = 1.57079632679489662f;
  845. }
  846. }
  847. i__1 = *q - 1;
  848. for (i__ = 1; i__ <= i__1; ++i__) {
  849. if (phi[i__] < thresh) {
  850. phi[i__] = 0.f;
  851. } else if (phi[i__] > 1.57079632679489662f - thresh) {
  852. phi[i__] = 1.57079632679489662f;
  853. }
  854. }
  855. /* Initial deflation */
  856. imax = *q;
  857. while(imax > 1) {
  858. if (phi[imax - 1] != 0.f) {
  859. myexit_();
  860. }
  861. --imax;
  862. }
  863. imin = imax - 1;
  864. if (imin > 1) {
  865. while(phi[imin - 1] != 0.f) {
  866. --imin;
  867. if (imin <= 1) {
  868. myexit_();
  869. }
  870. }
  871. }
  872. /* Initialize iteration counter */
  873. maxit = *q * 6 * *q;
  874. iter = 0;
  875. /* Begin main iteration loop */
  876. while(imax > 1) {
  877. /* Compute the matrix entries */
  878. b11d[imin] = cos(theta[imin]);
  879. b21d[imin] = -sin(theta[imin]);
  880. i__1 = imax - 1;
  881. for (i__ = imin; i__ <= i__1; ++i__) {
  882. b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
  883. b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
  884. b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
  885. b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
  886. b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
  887. b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
  888. b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
  889. b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
  890. }
  891. b12d[imax] = sin(theta[imax]);
  892. b22d[imax] = cos(theta[imax]);
  893. /* Abort if not converging; otherwise, increment ITER */
  894. if (iter > maxit) {
  895. *info = 0;
  896. i__1 = *q;
  897. for (i__ = 1; i__ <= i__1; ++i__) {
  898. if (phi[i__] != 0.f) {
  899. ++(*info);
  900. }
  901. }
  902. return 0;
  903. }
  904. iter = iter + imax - imin;
  905. /* Compute shifts */
  906. thetamax = theta[imin];
  907. thetamin = theta[imin];
  908. i__1 = imax;
  909. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  910. if (theta[i__] > thetamax) {
  911. thetamax = theta[i__];
  912. }
  913. if (theta[i__] < thetamin) {
  914. thetamin = theta[i__];
  915. }
  916. }
  917. if (thetamax > 1.57079632679489662f - thresh) {
  918. /* Zero on diagonals of B11 and B22; induce deflation with a */
  919. /* zero shift */
  920. mu = 0.f;
  921. nu = 1.f;
  922. } else if (thetamin < thresh) {
  923. /* Zero on diagonals of B12 and B22; induce deflation with a */
  924. /* zero shift */
  925. mu = 1.f;
  926. nu = 0.f;
  927. } else {
  928. /* Compute shifts for B11 and B21 and use the lesser */
  929. slas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
  930. dummy);
  931. slas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
  932. dummy);
  933. if (sigma11 <= sigma21) {
  934. mu = sigma11;
  935. /* Computing 2nd power */
  936. r__1 = mu;
  937. nu = sqrt(1.f - r__1 * r__1);
  938. if (mu < thresh) {
  939. mu = 0.f;
  940. nu = 1.f;
  941. }
  942. } else {
  943. nu = sigma21;
  944. /* Computing 2nd power */
  945. r__1 = nu;
  946. mu = sqrt(1.f - r__1 * r__1);
  947. if (nu < thresh) {
  948. mu = 1.f;
  949. nu = 0.f;
  950. }
  951. }
  952. }
  953. /* Rotate to produce bulges in B11 and B21 */
  954. if (mu <= nu) {
  955. slartgs_(&b11d[imin], &b11e[imin], &mu, &work[iv1tcs + imin - 1],
  956. &work[iv1tsn + imin - 1]);
  957. } else {
  958. slartgs_(&b21d[imin], &b21e[imin], &nu, &work[iv1tcs + imin - 1],
  959. &work[iv1tsn + imin - 1]);
  960. }
  961. temp = work[iv1tcs + imin - 1] * b11d[imin] + work[iv1tsn + imin - 1]
  962. * b11e[imin];
  963. b11e[imin] = work[iv1tcs + imin - 1] * b11e[imin] - work[iv1tsn +
  964. imin - 1] * b11d[imin];
  965. b11d[imin] = temp;
  966. b11bulge = work[iv1tsn + imin - 1] * b11d[imin + 1];
  967. b11d[imin + 1] = work[iv1tcs + imin - 1] * b11d[imin + 1];
  968. temp = work[iv1tcs + imin - 1] * b21d[imin] + work[iv1tsn + imin - 1]
  969. * b21e[imin];
  970. b21e[imin] = work[iv1tcs + imin - 1] * b21e[imin] - work[iv1tsn +
  971. imin - 1] * b21d[imin];
  972. b21d[imin] = temp;
  973. b21bulge = work[iv1tsn + imin - 1] * b21d[imin + 1];
  974. b21d[imin + 1] = work[iv1tcs + imin - 1] * b21d[imin + 1];
  975. /* Compute THETA(IMIN) */
  976. /* Computing 2nd power */
  977. r__1 = b21d[imin];
  978. /* Computing 2nd power */
  979. r__2 = b21bulge;
  980. /* Computing 2nd power */
  981. r__3 = b11d[imin];
  982. /* Computing 2nd power */
  983. r__4 = b11bulge;
  984. theta[imin] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 * r__3
  985. + r__4 * r__4));
  986. /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
  987. /* Computing 2nd power */
  988. r__1 = b11d[imin];
  989. /* Computing 2nd power */
  990. r__2 = b11bulge;
  991. /* Computing 2nd power */
  992. r__3 = thresh;
  993. if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
  994. slartgp_(&b11bulge, &b11d[imin], &work[iu1sn + imin - 1], &work[
  995. iu1cs + imin - 1], &r__);
  996. } else if (mu <= nu) {
  997. slartgs_(&b11e[imin], &b11d[imin + 1], &mu, &work[iu1cs + imin -
  998. 1], &work[iu1sn + imin - 1]);
  999. } else {
  1000. slartgs_(&b12d[imin], &b12e[imin], &nu, &work[iu1cs + imin - 1], &
  1001. work[iu1sn + imin - 1]);
  1002. }
  1003. /* Computing 2nd power */
  1004. r__1 = b21d[imin];
  1005. /* Computing 2nd power */
  1006. r__2 = b21bulge;
  1007. /* Computing 2nd power */
  1008. r__3 = thresh;
  1009. if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
  1010. slartgp_(&b21bulge, &b21d[imin], &work[iu2sn + imin - 1], &work[
  1011. iu2cs + imin - 1], &r__);
  1012. } else if (nu < mu) {
  1013. slartgs_(&b21e[imin], &b21d[imin + 1], &nu, &work[iu2cs + imin -
  1014. 1], &work[iu2sn + imin - 1]);
  1015. } else {
  1016. slartgs_(&b22d[imin], &b22e[imin], &mu, &work[iu2cs + imin - 1], &
  1017. work[iu2sn + imin - 1]);
  1018. }
  1019. work[iu2cs + imin - 1] = -work[iu2cs + imin - 1];
  1020. work[iu2sn + imin - 1] = -work[iu2sn + imin - 1];
  1021. temp = work[iu1cs + imin - 1] * b11e[imin] + work[iu1sn + imin - 1] *
  1022. b11d[imin + 1];
  1023. b11d[imin + 1] = work[iu1cs + imin - 1] * b11d[imin + 1] - work[iu1sn
  1024. + imin - 1] * b11e[imin];
  1025. b11e[imin] = temp;
  1026. if (imax > imin + 1) {
  1027. b11bulge = work[iu1sn + imin - 1] * b11e[imin + 1];
  1028. b11e[imin + 1] = work[iu1cs + imin - 1] * b11e[imin + 1];
  1029. }
  1030. temp = work[iu1cs + imin - 1] * b12d[imin] + work[iu1sn + imin - 1] *
  1031. b12e[imin];
  1032. b12e[imin] = work[iu1cs + imin - 1] * b12e[imin] - work[iu1sn + imin
  1033. - 1] * b12d[imin];
  1034. b12d[imin] = temp;
  1035. b12bulge = work[iu1sn + imin - 1] * b12d[imin + 1];
  1036. b12d[imin + 1] = work[iu1cs + imin - 1] * b12d[imin + 1];
  1037. temp = work[iu2cs + imin - 1] * b21e[imin] + work[iu2sn + imin - 1] *
  1038. b21d[imin + 1];
  1039. b21d[imin + 1] = work[iu2cs + imin - 1] * b21d[imin + 1] - work[iu2sn
  1040. + imin - 1] * b21e[imin];
  1041. b21e[imin] = temp;
  1042. if (imax > imin + 1) {
  1043. b21bulge = work[iu2sn + imin - 1] * b21e[imin + 1];
  1044. b21e[imin + 1] = work[iu2cs + imin - 1] * b21e[imin + 1];
  1045. }
  1046. temp = work[iu2cs + imin - 1] * b22d[imin] + work[iu2sn + imin - 1] *
  1047. b22e[imin];
  1048. b22e[imin] = work[iu2cs + imin - 1] * b22e[imin] - work[iu2sn + imin
  1049. - 1] * b22d[imin];
  1050. b22d[imin] = temp;
  1051. b22bulge = work[iu2sn + imin - 1] * b22d[imin + 1];
  1052. b22d[imin + 1] = work[iu2cs + imin - 1] * b22d[imin + 1];
  1053. /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
  1054. /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
  1055. /* bottom-right */
  1056. i__1 = imax - 1;
  1057. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1058. /* Compute PHI(I-1) */
  1059. x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
  1060. b21e[i__ - 1];
  1061. x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
  1062. b21bulge;
  1063. y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
  1064. b22d[i__ - 1];
  1065. y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
  1066. b22bulge;
  1067. /* Computing 2nd power */
  1068. r__1 = x1;
  1069. /* Computing 2nd power */
  1070. r__2 = x2;
  1071. /* Computing 2nd power */
  1072. r__3 = y1;
  1073. /* Computing 2nd power */
  1074. r__4 = y2;
  1075. phi[i__ - 1] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
  1076. r__3 + r__4 * r__4));
  1077. /* Determine if there are bulges to chase or if a new direct */
  1078. /* summand has been reached */
  1079. /* Computing 2nd power */
  1080. r__1 = b11e[i__ - 1];
  1081. /* Computing 2nd power */
  1082. r__2 = b11bulge;
  1083. /* Computing 2nd power */
  1084. r__3 = thresh;
  1085. restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1086. /* Computing 2nd power */
  1087. r__1 = b21e[i__ - 1];
  1088. /* Computing 2nd power */
  1089. r__2 = b21bulge;
  1090. /* Computing 2nd power */
  1091. r__3 = thresh;
  1092. restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1093. /* Computing 2nd power */
  1094. r__1 = b12d[i__ - 1];
  1095. /* Computing 2nd power */
  1096. r__2 = b12bulge;
  1097. /* Computing 2nd power */
  1098. r__3 = thresh;
  1099. restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1100. /* Computing 2nd power */
  1101. r__1 = b22d[i__ - 1];
  1102. /* Computing 2nd power */
  1103. r__2 = b22bulge;
  1104. /* Computing 2nd power */
  1105. r__3 = thresh;
  1106. restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1107. /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
  1108. /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
  1109. /* chasing by applying the original shift again. */
  1110. if (! restart11 && ! restart21) {
  1111. slartgp_(&x2, &x1, &work[iv1tsn + i__ - 1], &work[iv1tcs +
  1112. i__ - 1], &r__);
  1113. } else if (! restart11 && restart21) {
  1114. slartgp_(&b11bulge, &b11e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1115. work[iv1tcs + i__ - 1], &r__);
  1116. } else if (restart11 && ! restart21) {
  1117. slartgp_(&b21bulge, &b21e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1118. work[iv1tcs + i__ - 1], &r__);
  1119. } else if (mu <= nu) {
  1120. slartgs_(&b11d[i__], &b11e[i__], &mu, &work[iv1tcs + i__ - 1],
  1121. &work[iv1tsn + i__ - 1]);
  1122. } else {
  1123. slartgs_(&b21d[i__], &b21e[i__], &nu, &work[iv1tcs + i__ - 1],
  1124. &work[iv1tsn + i__ - 1]);
  1125. }
  1126. work[iv1tcs + i__ - 1] = -work[iv1tcs + i__ - 1];
  1127. work[iv1tsn + i__ - 1] = -work[iv1tsn + i__ - 1];
  1128. if (! restart12 && ! restart22) {
  1129. slartgp_(&y2, &y1, &work[iv2tsn + i__ - 2], &work[iv2tcs +
  1130. i__ - 2], &r__);
  1131. } else if (! restart12 && restart22) {
  1132. slartgp_(&b12bulge, &b12d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1133. work[iv2tcs + i__ - 2], &r__);
  1134. } else if (restart12 && ! restart22) {
  1135. slartgp_(&b22bulge, &b22d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1136. work[iv2tcs + i__ - 2], &r__);
  1137. } else if (nu < mu) {
  1138. slartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &work[iv2tcs + i__
  1139. - 2], &work[iv2tsn + i__ - 2]);
  1140. } else {
  1141. slartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &work[iv2tcs + i__
  1142. - 2], &work[iv2tsn + i__ - 2]);
  1143. }
  1144. temp = work[iv1tcs + i__ - 1] * b11d[i__] + work[iv1tsn + i__ - 1]
  1145. * b11e[i__];
  1146. b11e[i__] = work[iv1tcs + i__ - 1] * b11e[i__] - work[iv1tsn +
  1147. i__ - 1] * b11d[i__];
  1148. b11d[i__] = temp;
  1149. b11bulge = work[iv1tsn + i__ - 1] * b11d[i__ + 1];
  1150. b11d[i__ + 1] = work[iv1tcs + i__ - 1] * b11d[i__ + 1];
  1151. temp = work[iv1tcs + i__ - 1] * b21d[i__] + work[iv1tsn + i__ - 1]
  1152. * b21e[i__];
  1153. b21e[i__] = work[iv1tcs + i__ - 1] * b21e[i__] - work[iv1tsn +
  1154. i__ - 1] * b21d[i__];
  1155. b21d[i__] = temp;
  1156. b21bulge = work[iv1tsn + i__ - 1] * b21d[i__ + 1];
  1157. b21d[i__ + 1] = work[iv1tcs + i__ - 1] * b21d[i__ + 1];
  1158. temp = work[iv2tcs + i__ - 2] * b12e[i__ - 1] + work[iv2tsn + i__
  1159. - 2] * b12d[i__];
  1160. b12d[i__] = work[iv2tcs + i__ - 2] * b12d[i__] - work[iv2tsn +
  1161. i__ - 2] * b12e[i__ - 1];
  1162. b12e[i__ - 1] = temp;
  1163. b12bulge = work[iv2tsn + i__ - 2] * b12e[i__];
  1164. b12e[i__] = work[iv2tcs + i__ - 2] * b12e[i__];
  1165. temp = work[iv2tcs + i__ - 2] * b22e[i__ - 1] + work[iv2tsn + i__
  1166. - 2] * b22d[i__];
  1167. b22d[i__] = work[iv2tcs + i__ - 2] * b22d[i__] - work[iv2tsn +
  1168. i__ - 2] * b22e[i__ - 1];
  1169. b22e[i__ - 1] = temp;
  1170. b22bulge = work[iv2tsn + i__ - 2] * b22e[i__];
  1171. b22e[i__] = work[iv2tcs + i__ - 2] * b22e[i__];
  1172. /* Compute THETA(I) */
  1173. x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
  1174. - 1];
  1175. x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
  1176. y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
  1177. - 1];
  1178. y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
  1179. /* Computing 2nd power */
  1180. r__1 = y1;
  1181. /* Computing 2nd power */
  1182. r__2 = y2;
  1183. /* Computing 2nd power */
  1184. r__3 = x1;
  1185. /* Computing 2nd power */
  1186. r__4 = x2;
  1187. theta[i__] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
  1188. r__3 + r__4 * r__4));
  1189. /* Determine if there are bulges to chase or if a new direct */
  1190. /* summand has been reached */
  1191. /* Computing 2nd power */
  1192. r__1 = b11d[i__];
  1193. /* Computing 2nd power */
  1194. r__2 = b11bulge;
  1195. /* Computing 2nd power */
  1196. r__3 = thresh;
  1197. restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1198. /* Computing 2nd power */
  1199. r__1 = b12e[i__ - 1];
  1200. /* Computing 2nd power */
  1201. r__2 = b12bulge;
  1202. /* Computing 2nd power */
  1203. r__3 = thresh;
  1204. restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1205. /* Computing 2nd power */
  1206. r__1 = b21d[i__];
  1207. /* Computing 2nd power */
  1208. r__2 = b21bulge;
  1209. /* Computing 2nd power */
  1210. r__3 = thresh;
  1211. restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1212. /* Computing 2nd power */
  1213. r__1 = b22e[i__ - 1];
  1214. /* Computing 2nd power */
  1215. r__2 = b22bulge;
  1216. /* Computing 2nd power */
  1217. r__3 = thresh;
  1218. restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1219. /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
  1220. /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
  1221. /* chasing by applying the original shift again. */
  1222. if (! restart11 && ! restart12) {
  1223. slartgp_(&x2, &x1, &work[iu1sn + i__ - 1], &work[iu1cs + i__
  1224. - 1], &r__);
  1225. } else if (! restart11 && restart12) {
  1226. slartgp_(&b11bulge, &b11d[i__], &work[iu1sn + i__ - 1], &work[
  1227. iu1cs + i__ - 1], &r__);
  1228. } else if (restart11 && ! restart12) {
  1229. slartgp_(&b12bulge, &b12e[i__ - 1], &work[iu1sn + i__ - 1], &
  1230. work[iu1cs + i__ - 1], &r__);
  1231. } else if (mu <= nu) {
  1232. slartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &work[iu1cs + i__ -
  1233. 1], &work[iu1sn + i__ - 1]);
  1234. } else {
  1235. slartgs_(&b12d[i__], &b12e[i__], &nu, &work[iu1cs + i__ - 1],
  1236. &work[iu1sn + i__ - 1]);
  1237. }
  1238. if (! restart21 && ! restart22) {
  1239. slartgp_(&y2, &y1, &work[iu2sn + i__ - 1], &work[iu2cs + i__
  1240. - 1], &r__);
  1241. } else if (! restart21 && restart22) {
  1242. slartgp_(&b21bulge, &b21d[i__], &work[iu2sn + i__ - 1], &work[
  1243. iu2cs + i__ - 1], &r__);
  1244. } else if (restart21 && ! restart22) {
  1245. slartgp_(&b22bulge, &b22e[i__ - 1], &work[iu2sn + i__ - 1], &
  1246. work[iu2cs + i__ - 1], &r__);
  1247. } else if (nu < mu) {
  1248. slartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &work[iu2cs + i__ -
  1249. 1], &work[iu2sn + i__ - 1]);
  1250. } else {
  1251. slartgs_(&b22d[i__], &b22e[i__], &mu, &work[iu2cs + i__ - 1],
  1252. &work[iu2sn + i__ - 1]);
  1253. }
  1254. work[iu2cs + i__ - 1] = -work[iu2cs + i__ - 1];
  1255. work[iu2sn + i__ - 1] = -work[iu2sn + i__ - 1];
  1256. temp = work[iu1cs + i__ - 1] * b11e[i__] + work[iu1sn + i__ - 1] *
  1257. b11d[i__ + 1];
  1258. b11d[i__ + 1] = work[iu1cs + i__ - 1] * b11d[i__ + 1] - work[
  1259. iu1sn + i__ - 1] * b11e[i__];
  1260. b11e[i__] = temp;
  1261. if (i__ < imax - 1) {
  1262. b11bulge = work[iu1sn + i__ - 1] * b11e[i__ + 1];
  1263. b11e[i__ + 1] = work[iu1cs + i__ - 1] * b11e[i__ + 1];
  1264. }
  1265. temp = work[iu2cs + i__ - 1] * b21e[i__] + work[iu2sn + i__ - 1] *
  1266. b21d[i__ + 1];
  1267. b21d[i__ + 1] = work[iu2cs + i__ - 1] * b21d[i__ + 1] - work[
  1268. iu2sn + i__ - 1] * b21e[i__];
  1269. b21e[i__] = temp;
  1270. if (i__ < imax - 1) {
  1271. b21bulge = work[iu2sn + i__ - 1] * b21e[i__ + 1];
  1272. b21e[i__ + 1] = work[iu2cs + i__ - 1] * b21e[i__ + 1];
  1273. }
  1274. temp = work[iu1cs + i__ - 1] * b12d[i__] + work[iu1sn + i__ - 1] *
  1275. b12e[i__];
  1276. b12e[i__] = work[iu1cs + i__ - 1] * b12e[i__] - work[iu1sn + i__
  1277. - 1] * b12d[i__];
  1278. b12d[i__] = temp;
  1279. b12bulge = work[iu1sn + i__ - 1] * b12d[i__ + 1];
  1280. b12d[i__ + 1] = work[iu1cs + i__ - 1] * b12d[i__ + 1];
  1281. temp = work[iu2cs + i__ - 1] * b22d[i__] + work[iu2sn + i__ - 1] *
  1282. b22e[i__];
  1283. b22e[i__] = work[iu2cs + i__ - 1] * b22e[i__] - work[iu2sn + i__
  1284. - 1] * b22d[i__];
  1285. b22d[i__] = temp;
  1286. b22bulge = work[iu2sn + i__ - 1] * b22d[i__ + 1];
  1287. b22d[i__ + 1] = work[iu2cs + i__ - 1] * b22d[i__ + 1];
  1288. }
  1289. /* Compute PHI(IMAX-1) */
  1290. x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
  1291. b21e[imax - 1];
  1292. y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
  1293. b22d[imax - 1];
  1294. y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
  1295. b22bulge;
  1296. /* Computing 2nd power */
  1297. r__1 = y1;
  1298. /* Computing 2nd power */
  1299. r__2 = y2;
  1300. phi[imax - 1] = atan2((abs(x1)), sqrt(r__1 * r__1 + r__2 * r__2));
  1301. /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
  1302. /* Computing 2nd power */
  1303. r__1 = b12d[imax - 1];
  1304. /* Computing 2nd power */
  1305. r__2 = b12bulge;
  1306. /* Computing 2nd power */
  1307. r__3 = thresh;
  1308. restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1309. /* Computing 2nd power */
  1310. r__1 = b22d[imax - 1];
  1311. /* Computing 2nd power */
  1312. r__2 = b22bulge;
  1313. /* Computing 2nd power */
  1314. r__3 = thresh;
  1315. restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
  1316. if (! restart12 && ! restart22) {
  1317. slartgp_(&y2, &y1, &work[iv2tsn + imax - 2], &work[iv2tcs + imax
  1318. - 2], &r__);
  1319. } else if (! restart12 && restart22) {
  1320. slartgp_(&b12bulge, &b12d[imax - 1], &work[iv2tsn + imax - 2], &
  1321. work[iv2tcs + imax - 2], &r__);
  1322. } else if (restart12 && ! restart22) {
  1323. slartgp_(&b22bulge, &b22d[imax - 1], &work[iv2tsn + imax - 2], &
  1324. work[iv2tcs + imax - 2], &r__);
  1325. } else if (nu < mu) {
  1326. slartgs_(&b12e[imax - 1], &b12d[imax], &nu, &work[iv2tcs + imax -
  1327. 2], &work[iv2tsn + imax - 2]);
  1328. } else {
  1329. slartgs_(&b22e[imax - 1], &b22d[imax], &mu, &work[iv2tcs + imax -
  1330. 2], &work[iv2tsn + imax - 2]);
  1331. }
  1332. temp = work[iv2tcs + imax - 2] * b12e[imax - 1] + work[iv2tsn + imax
  1333. - 2] * b12d[imax];
  1334. b12d[imax] = work[iv2tcs + imax - 2] * b12d[imax] - work[iv2tsn +
  1335. imax - 2] * b12e[imax - 1];
  1336. b12e[imax - 1] = temp;
  1337. temp = work[iv2tcs + imax - 2] * b22e[imax - 1] + work[iv2tsn + imax
  1338. - 2] * b22d[imax];
  1339. b22d[imax] = work[iv2tcs + imax - 2] * b22d[imax] - work[iv2tsn +
  1340. imax - 2] * b22e[imax - 1];
  1341. b22e[imax - 1] = temp;
  1342. /* Update singular vectors */
  1343. if (wantu1) {
  1344. if (colmajor) {
  1345. i__1 = imax - imin + 1;
  1346. slasr_("R", "V", "F", p, &i__1, &work[iu1cs + imin - 1], &
  1347. work[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1], ldu1);
  1348. } else {
  1349. i__1 = imax - imin + 1;
  1350. slasr_("L", "V", "F", &i__1, p, &work[iu1cs + imin - 1], &
  1351. work[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
  1352. }
  1353. }
  1354. if (wantu2) {
  1355. if (colmajor) {
  1356. i__1 = *m - *p;
  1357. i__2 = imax - imin + 1;
  1358. slasr_("R", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1359. work[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1], ldu2);
  1360. } else {
  1361. i__1 = imax - imin + 1;
  1362. i__2 = *m - *p;
  1363. slasr_("L", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1364. work[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
  1365. }
  1366. }
  1367. if (wantv1t) {
  1368. if (colmajor) {
  1369. i__1 = imax - imin + 1;
  1370. slasr_("L", "V", "F", &i__1, q, &work[iv1tcs + imin - 1], &
  1371. work[iv1tsn + imin - 1], &v1t[imin + v1t_dim1], ldv1t);
  1372. } else {
  1373. i__1 = imax - imin + 1;
  1374. slasr_("R", "V", "F", q, &i__1, &work[iv1tcs + imin - 1], &
  1375. work[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
  1376. ldv1t);
  1377. }
  1378. }
  1379. if (wantv2t) {
  1380. if (colmajor) {
  1381. i__1 = imax - imin + 1;
  1382. i__2 = *m - *q;
  1383. slasr_("L", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1384. &work[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
  1385. ldv2t);
  1386. } else {
  1387. i__1 = *m - *q;
  1388. i__2 = imax - imin + 1;
  1389. slasr_("R", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1390. &work[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
  1391. ldv2t);
  1392. }
  1393. }
  1394. /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
  1395. if (b11e[imax - 1] + b21e[imax - 1] > 0.f) {
  1396. b11d[imax] = -b11d[imax];
  1397. b21d[imax] = -b21d[imax];
  1398. if (wantv1t) {
  1399. if (colmajor) {
  1400. sscal_(q, &c_b35, &v1t[imax + v1t_dim1], ldv1t);
  1401. } else {
  1402. sscal_(q, &c_b35, &v1t[imax * v1t_dim1 + 1], &c__1);
  1403. }
  1404. }
  1405. }
  1406. /* Compute THETA(IMAX) */
  1407. x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
  1408. - 1];
  1409. y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
  1410. - 1];
  1411. theta[imax] = atan2((abs(y1)), (abs(x1)));
  1412. /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
  1413. /* and B22(IMAX,IMAX-1) */
  1414. if (b11d[imax] + b12e[imax - 1] < 0.f) {
  1415. b12d[imax] = -b12d[imax];
  1416. if (wantu1) {
  1417. if (colmajor) {
  1418. sscal_(p, &c_b35, &u1[imax * u1_dim1 + 1], &c__1);
  1419. } else {
  1420. sscal_(p, &c_b35, &u1[imax + u1_dim1], ldu1);
  1421. }
  1422. }
  1423. }
  1424. if (b21d[imax] + b22e[imax - 1] > 0.f) {
  1425. b22d[imax] = -b22d[imax];
  1426. if (wantu2) {
  1427. if (colmajor) {
  1428. i__1 = *m - *p;
  1429. sscal_(&i__1, &c_b35, &u2[imax * u2_dim1 + 1], &c__1);
  1430. } else {
  1431. i__1 = *m - *p;
  1432. sscal_(&i__1, &c_b35, &u2[imax + u2_dim1], ldu2);
  1433. }
  1434. }
  1435. }
  1436. /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
  1437. if (b12d[imax] + b22d[imax] < 0.f) {
  1438. if (wantv2t) {
  1439. if (colmajor) {
  1440. i__1 = *m - *q;
  1441. sscal_(&i__1, &c_b35, &v2t[imax + v2t_dim1], ldv2t);
  1442. } else {
  1443. i__1 = *m - *q;
  1444. sscal_(&i__1, &c_b35, &v2t[imax * v2t_dim1 + 1], &c__1);
  1445. }
  1446. }
  1447. }
  1448. /* Test for negligible sines or cosines */
  1449. i__1 = imax;
  1450. for (i__ = imin; i__ <= i__1; ++i__) {
  1451. if (theta[i__] < thresh) {
  1452. theta[i__] = 0.f;
  1453. } else if (theta[i__] > 1.57079632679489662f - thresh) {
  1454. theta[i__] = 1.57079632679489662f;
  1455. }
  1456. }
  1457. i__1 = imax - 1;
  1458. for (i__ = imin; i__ <= i__1; ++i__) {
  1459. if (phi[i__] < thresh) {
  1460. phi[i__] = 0.f;
  1461. } else if (phi[i__] > 1.57079632679489662f - thresh) {
  1462. phi[i__] = 1.57079632679489662f;
  1463. }
  1464. }
  1465. /* Deflate */
  1466. if (imax > 1) {
  1467. while(phi[imax - 1] == 0.f) {
  1468. --imax;
  1469. if (imax <= 1) {
  1470. myexit_();
  1471. }
  1472. }
  1473. }
  1474. if (imin > imax - 1) {
  1475. imin = imax - 1;
  1476. }
  1477. if (imin > 1) {
  1478. while(phi[imin - 1] != 0.f) {
  1479. --imin;
  1480. if (imin <= 1) {
  1481. myexit_();
  1482. }
  1483. }
  1484. }
  1485. /* Repeat main iteration loop */
  1486. }
  1487. /* Postprocessing: order THETA from least to greatest */
  1488. i__1 = *q;
  1489. for (i__ = 1; i__ <= i__1; ++i__) {
  1490. mini = i__;
  1491. thetamin = theta[i__];
  1492. i__2 = *q;
  1493. for (j = i__ + 1; j <= i__2; ++j) {
  1494. if (theta[j] < thetamin) {
  1495. mini = j;
  1496. thetamin = theta[j];
  1497. }
  1498. }
  1499. if (mini != i__) {
  1500. theta[mini] = theta[i__];
  1501. theta[i__] = thetamin;
  1502. if (colmajor) {
  1503. if (wantu1) {
  1504. sswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
  1505. u1_dim1 + 1], &c__1);
  1506. }
  1507. if (wantu2) {
  1508. i__2 = *m - *p;
  1509. sswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
  1510. u2_dim1 + 1], &c__1);
  1511. }
  1512. if (wantv1t) {
  1513. sswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
  1514. v1t_dim1], ldv1t);
  1515. }
  1516. if (wantv2t) {
  1517. i__2 = *m - *q;
  1518. sswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
  1519. v2t_dim1], ldv2t);
  1520. }
  1521. } else {
  1522. if (wantu1) {
  1523. sswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
  1524. ldu1);
  1525. }
  1526. if (wantu2) {
  1527. i__2 = *m - *p;
  1528. sswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
  1529. u2_dim1], ldu2);
  1530. }
  1531. if (wantv1t) {
  1532. sswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
  1533. v1t_dim1 + 1], &c__1);
  1534. }
  1535. if (wantv2t) {
  1536. i__2 = *m - *q;
  1537. sswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
  1538. v2t_dim1 + 1], &c__1);
  1539. }
  1540. }
  1541. }
  1542. }
  1543. return 0;
  1544. /* End of SBBCSD */
  1545. } /* sbbcsd_ */