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.

dbbcsd.c 51 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  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 doublereal c_b35 = -1.;
  382. static integer c__1 = 1;
  383. /* > \brief \b DBBCSD */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download DBBCSD + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbbcsd.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbbcsd.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbbcsd.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE DBBCSD( 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. /* DOUBLE PRECISION B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
  408. /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
  409. /* $ PHI( * ), THETA( * ), WORK( * ) */
  410. /* DOUBLE PRECISION U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
  411. /* $ V2T( LDV2T, * ) */
  412. /* > \par Purpose: */
  413. /* ============= */
  414. /* > */
  415. /* > \verbatim */
  416. /* > */
  417. /* > DBBCSD 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 DORCSD 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION array, dimension (Q) */
  580. /* > When DBBCSD converges, B11D contains the cosines of THETA(1), */
  581. /* > ..., THETA(Q). If DBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  589. /* > When DBBCSD converges, B11E contains zeros. If DBBCSD 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 DOUBLE PRECISION array, dimension (Q) */
  597. /* > When DBBCSD converges, B12D contains the negative sines of */
  598. /* > THETA(1), ..., THETA(Q). If DBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  606. /* > When DBBCSD converges, B12E contains zeros. If DBBCSD 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 DOUBLE PRECISION array, dimension (Q) */
  614. /* > When DBBCSD converges, B21D contains the negative sines of */
  615. /* > THETA(1), ..., THETA(Q). If DBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  623. /* > When DBBCSD converges, B21E contains zeros. If DBBCSD 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 DOUBLE PRECISION array, dimension (Q) */
  631. /* > When DBBCSD converges, B22D contains the negative sines of */
  632. /* > THETA(1), ..., THETA(Q). If DBBCSD 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 DOUBLE PRECISION array, dimension (Q-1) */
  640. /* > When DBBCSD converges, B22E contains zeros. If DBBCSD 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 DOUBLE PRECISION 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 DBBCSD 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 DOUBLE PRECISION, 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 doubleOTHERcomputational */
  693. /* ===================================================================== */
  694. /* Subroutine */ int dbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
  695. jobv2t, char *trans, integer *m, integer *p, integer *q, doublereal *
  696. theta, doublereal *phi, doublereal *u1, integer *ldu1, doublereal *u2,
  697. integer *ldu2, doublereal *v1t, integer *ldv1t, doublereal *v2t,
  698. integer *ldv2t, doublereal *b11d, doublereal *b11e, doublereal *b12d,
  699. doublereal *b12e, doublereal *b21d, doublereal *b21e, doublereal *
  700. b22d, doublereal *b22e, doublereal *work, integer *lwork, integer *
  701. info)
  702. {
  703. /* System generated locals */
  704. integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
  705. v2t_dim1, v2t_offset, i__1, i__2;
  706. doublereal d__1, d__2, d__3, d__4;
  707. /* Local variables */
  708. integer imin, mini, imax, iter;
  709. doublereal unfl, temp;
  710. logical colmajor;
  711. doublereal thetamin, thetamax;
  712. logical restart11, restart12, restart21, restart22;
  713. extern /* Subroutine */ int dlas2_(doublereal *, doublereal *, doublereal
  714. *, doublereal *, doublereal *);
  715. integer lworkmin, iu1cs, iu2cs, iu1sn, iu2sn, lworkopt, i__, j;
  716. doublereal r__;
  717. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  718. integer *);
  719. extern logical lsame_(char *, char *);
  720. extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
  721. integer *, doublereal *, doublereal *, doublereal *, integer *), dswap_(integer *, doublereal *, integer *
  722. , doublereal *, integer *);
  723. integer maxit;
  724. doublereal dummy, x1, x2, y1, y2;
  725. integer iv1tcs, iv2tcs;
  726. logical wantu1, wantu2;
  727. integer iv1tsn, iv2tsn;
  728. extern doublereal dlamch_(char *);
  729. doublereal mu, nu, sigma11, sigma21;
  730. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  731. doublereal thresh, tolmul;
  732. extern /* Subroutine */ int mecago_();
  733. logical lquery;
  734. doublereal b11bulge;
  735. logical wantv1t, wantv2t;
  736. doublereal b12bulge, b21bulge, b22bulge, eps, tol;
  737. extern /* Subroutine */ int dlartgp_(doublereal *, doublereal *,
  738. doublereal *, doublereal *, doublereal *), dlartgs_(doublereal *,
  739. doublereal *, doublereal *, doublereal *, doublereal *);
  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] = (doublereal) 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] = (doublereal) lworkopt;
  814. if (*lwork < lworkmin && ! lquery) {
  815. *info = -28;
  816. }
  817. }
  818. if (*info != 0) {
  819. i__1 = -(*info);
  820. xerbla_("DBBCSD", &i__1, (ftnlen)6);
  821. return 0;
  822. } else if (lquery) {
  823. return 0;
  824. }
  825. /* Get machine constants */
  826. eps = dlamch_("Epsilon");
  827. unfl = dlamch_("Safe minimum");
  828. /* Computing MAX */
  829. /* Computing MIN */
  830. d__3 = 100., d__4 = pow_dd(&eps, &c_b10);
  831. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  832. tolmul = f2cmax(d__1,d__2);
  833. tol = tolmul * eps;
  834. /* Computing MAX */
  835. d__1 = tol, d__2 = *q * 6 * *q * unfl;
  836. thresh = f2cmax(d__1,d__2);
  837. /* Test for negligible sines or cosines */
  838. i__1 = *q;
  839. for (i__ = 1; i__ <= i__1; ++i__) {
  840. if (theta[i__] < thresh) {
  841. theta[i__] = 0.;
  842. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  843. theta[i__] = 1.57079632679489662;
  844. }
  845. }
  846. i__1 = *q - 1;
  847. for (i__ = 1; i__ <= i__1; ++i__) {
  848. if (phi[i__] < thresh) {
  849. phi[i__] = 0.;
  850. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  851. phi[i__] = 1.57079632679489662;
  852. }
  853. }
  854. /* Initial deflation */
  855. imax = *q;
  856. while(imax > 1) {
  857. if (phi[imax - 1] != 0.) {
  858. myexit_();
  859. }
  860. --imax;
  861. }
  862. imin = imax - 1;
  863. if (imin > 1) {
  864. while(phi[imin - 1] != 0.) {
  865. --imin;
  866. if (imin <= 1) {
  867. myexit_();
  868. }
  869. }
  870. }
  871. /* Initialize iteration counter */
  872. maxit = *q * 6 * *q;
  873. iter = 0;
  874. /* Begin main iteration loop */
  875. while(imax > 1) {
  876. /* Compute the matrix entries */
  877. b11d[imin] = cos(theta[imin]);
  878. b21d[imin] = -sin(theta[imin]);
  879. i__1 = imax - 1;
  880. for (i__ = imin; i__ <= i__1; ++i__) {
  881. b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
  882. b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
  883. b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
  884. b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
  885. b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
  886. b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
  887. b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
  888. b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
  889. }
  890. b12d[imax] = sin(theta[imax]);
  891. b22d[imax] = cos(theta[imax]);
  892. /* Abort if not converging; otherwise, increment ITER */
  893. if (iter > maxit) {
  894. *info = 0;
  895. i__1 = *q;
  896. for (i__ = 1; i__ <= i__1; ++i__) {
  897. if (phi[i__] != 0.) {
  898. ++(*info);
  899. }
  900. }
  901. return 0;
  902. }
  903. iter = iter + imax - imin;
  904. /* Compute shifts */
  905. thetamax = theta[imin];
  906. thetamin = theta[imin];
  907. i__1 = imax;
  908. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  909. if (theta[i__] > thetamax) {
  910. thetamax = theta[i__];
  911. }
  912. if (theta[i__] < thetamin) {
  913. thetamin = theta[i__];
  914. }
  915. }
  916. if (thetamax > 1.57079632679489662 - thresh) {
  917. /* Zero on diagonals of B11 and B22; induce deflation with a */
  918. /* zero shift */
  919. mu = 0.;
  920. nu = 1.;
  921. } else if (thetamin < thresh) {
  922. /* Zero on diagonals of B12 and B22; induce deflation with a */
  923. /* zero shift */
  924. mu = 1.;
  925. nu = 0.;
  926. } else {
  927. /* Compute shifts for B11 and B21 and use the lesser */
  928. dlas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
  929. dummy);
  930. dlas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
  931. dummy);
  932. if (sigma11 <= sigma21) {
  933. mu = sigma11;
  934. /* Computing 2nd power */
  935. d__1 = mu;
  936. nu = sqrt(1. - d__1 * d__1);
  937. if (mu < thresh) {
  938. mu = 0.;
  939. nu = 1.;
  940. }
  941. } else {
  942. nu = sigma21;
  943. /* Computing 2nd power */
  944. d__1 = nu;
  945. mu = sqrt(1.f - d__1 * d__1);
  946. if (nu < thresh) {
  947. mu = 1.;
  948. nu = 0.;
  949. }
  950. }
  951. }
  952. /* Rotate to produce bulges in B11 and B21 */
  953. if (mu <= nu) {
  954. dlartgs_(&b11d[imin], &b11e[imin], &mu, &work[iv1tcs + imin - 1],
  955. &work[iv1tsn + imin - 1]);
  956. } else {
  957. dlartgs_(&b21d[imin], &b21e[imin], &nu, &work[iv1tcs + imin - 1],
  958. &work[iv1tsn + imin - 1]);
  959. }
  960. temp = work[iv1tcs + imin - 1] * b11d[imin] + work[iv1tsn + imin - 1]
  961. * b11e[imin];
  962. b11e[imin] = work[iv1tcs + imin - 1] * b11e[imin] - work[iv1tsn +
  963. imin - 1] * b11d[imin];
  964. b11d[imin] = temp;
  965. b11bulge = work[iv1tsn + imin - 1] * b11d[imin + 1];
  966. b11d[imin + 1] = work[iv1tcs + imin - 1] * b11d[imin + 1];
  967. temp = work[iv1tcs + imin - 1] * b21d[imin] + work[iv1tsn + imin - 1]
  968. * b21e[imin];
  969. b21e[imin] = work[iv1tcs + imin - 1] * b21e[imin] - work[iv1tsn +
  970. imin - 1] * b21d[imin];
  971. b21d[imin] = temp;
  972. b21bulge = work[iv1tsn + imin - 1] * b21d[imin + 1];
  973. b21d[imin + 1] = work[iv1tcs + imin - 1] * b21d[imin + 1];
  974. /* Compute THETA(IMIN) */
  975. /* Computing 2nd power */
  976. d__1 = b21d[imin];
  977. /* Computing 2nd power */
  978. d__2 = b21bulge;
  979. /* Computing 2nd power */
  980. d__3 = b11d[imin];
  981. /* Computing 2nd power */
  982. d__4 = b11bulge;
  983. theta[imin] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 * d__3
  984. + d__4 * d__4));
  985. /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
  986. /* Computing 2nd power */
  987. d__1 = b11d[imin];
  988. /* Computing 2nd power */
  989. d__2 = b11bulge;
  990. /* Computing 2nd power */
  991. d__3 = thresh;
  992. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  993. dlartgp_(&b11bulge, &b11d[imin], &work[iu1sn + imin - 1], &work[
  994. iu1cs + imin - 1], &r__);
  995. } else if (mu <= nu) {
  996. dlartgs_(&b11e[imin], &b11d[imin + 1], &mu, &work[iu1cs + imin -
  997. 1], &work[iu1sn + imin - 1]);
  998. } else {
  999. dlartgs_(&b12d[imin], &b12e[imin], &nu, &work[iu1cs + imin - 1], &
  1000. work[iu1sn + imin - 1]);
  1001. }
  1002. /* Computing 2nd power */
  1003. d__1 = b21d[imin];
  1004. /* Computing 2nd power */
  1005. d__2 = b21bulge;
  1006. /* Computing 2nd power */
  1007. d__3 = thresh;
  1008. if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
  1009. dlartgp_(&b21bulge, &b21d[imin], &work[iu2sn + imin - 1], &work[
  1010. iu2cs + imin - 1], &r__);
  1011. } else if (nu < mu) {
  1012. dlartgs_(&b21e[imin], &b21d[imin + 1], &nu, &work[iu2cs + imin -
  1013. 1], &work[iu2sn + imin - 1]);
  1014. } else {
  1015. dlartgs_(&b22d[imin], &b22e[imin], &mu, &work[iu2cs + imin - 1], &
  1016. work[iu2sn + imin - 1]);
  1017. }
  1018. work[iu2cs + imin - 1] = -work[iu2cs + imin - 1];
  1019. work[iu2sn + imin - 1] = -work[iu2sn + imin - 1];
  1020. temp = work[iu1cs + imin - 1] * b11e[imin] + work[iu1sn + imin - 1] *
  1021. b11d[imin + 1];
  1022. b11d[imin + 1] = work[iu1cs + imin - 1] * b11d[imin + 1] - work[iu1sn
  1023. + imin - 1] * b11e[imin];
  1024. b11e[imin] = temp;
  1025. if (imax > imin + 1) {
  1026. b11bulge = work[iu1sn + imin - 1] * b11e[imin + 1];
  1027. b11e[imin + 1] = work[iu1cs + imin - 1] * b11e[imin + 1];
  1028. }
  1029. temp = work[iu1cs + imin - 1] * b12d[imin] + work[iu1sn + imin - 1] *
  1030. b12e[imin];
  1031. b12e[imin] = work[iu1cs + imin - 1] * b12e[imin] - work[iu1sn + imin
  1032. - 1] * b12d[imin];
  1033. b12d[imin] = temp;
  1034. b12bulge = work[iu1sn + imin - 1] * b12d[imin + 1];
  1035. b12d[imin + 1] = work[iu1cs + imin - 1] * b12d[imin + 1];
  1036. temp = work[iu2cs + imin - 1] * b21e[imin] + work[iu2sn + imin - 1] *
  1037. b21d[imin + 1];
  1038. b21d[imin + 1] = work[iu2cs + imin - 1] * b21d[imin + 1] - work[iu2sn
  1039. + imin - 1] * b21e[imin];
  1040. b21e[imin] = temp;
  1041. if (imax > imin + 1) {
  1042. b21bulge = work[iu2sn + imin - 1] * b21e[imin + 1];
  1043. b21e[imin + 1] = work[iu2cs + imin - 1] * b21e[imin + 1];
  1044. }
  1045. temp = work[iu2cs + imin - 1] * b22d[imin] + work[iu2sn + imin - 1] *
  1046. b22e[imin];
  1047. b22e[imin] = work[iu2cs + imin - 1] * b22e[imin] - work[iu2sn + imin
  1048. - 1] * b22d[imin];
  1049. b22d[imin] = temp;
  1050. b22bulge = work[iu2sn + imin - 1] * b22d[imin + 1];
  1051. b22d[imin + 1] = work[iu2cs + imin - 1] * b22d[imin + 1];
  1052. /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
  1053. /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
  1054. /* bottom-right */
  1055. i__1 = imax - 1;
  1056. for (i__ = imin + 1; i__ <= i__1; ++i__) {
  1057. /* Compute PHI(I-1) */
  1058. x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
  1059. b21e[i__ - 1];
  1060. x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
  1061. b21bulge;
  1062. y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
  1063. b22d[i__ - 1];
  1064. y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
  1065. b22bulge;
  1066. /* Computing 2nd power */
  1067. d__1 = x1;
  1068. /* Computing 2nd power */
  1069. d__2 = x2;
  1070. /* Computing 2nd power */
  1071. d__3 = y1;
  1072. /* Computing 2nd power */
  1073. d__4 = y2;
  1074. phi[i__ - 1] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1075. d__3 + d__4 * d__4));
  1076. /* Determine if there are bulges to chase or if a new direct */
  1077. /* summand has been reached */
  1078. /* Computing 2nd power */
  1079. d__1 = b11e[i__ - 1];
  1080. /* Computing 2nd power */
  1081. d__2 = b11bulge;
  1082. /* Computing 2nd power */
  1083. d__3 = thresh;
  1084. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1085. /* Computing 2nd power */
  1086. d__1 = b21e[i__ - 1];
  1087. /* Computing 2nd power */
  1088. d__2 = b21bulge;
  1089. /* Computing 2nd power */
  1090. d__3 = thresh;
  1091. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1092. /* Computing 2nd power */
  1093. d__1 = b12d[i__ - 1];
  1094. /* Computing 2nd power */
  1095. d__2 = b12bulge;
  1096. /* Computing 2nd power */
  1097. d__3 = thresh;
  1098. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1099. /* Computing 2nd power */
  1100. d__1 = b22d[i__ - 1];
  1101. /* Computing 2nd power */
  1102. d__2 = b22bulge;
  1103. /* Computing 2nd power */
  1104. d__3 = thresh;
  1105. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1106. /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
  1107. /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
  1108. /* chasing by applying the original shift again. */
  1109. if (! restart11 && ! restart21) {
  1110. dlartgp_(&x2, &x1, &work[iv1tsn + i__ - 1], &work[iv1tcs +
  1111. i__ - 1], &r__);
  1112. } else if (! restart11 && restart21) {
  1113. dlartgp_(&b11bulge, &b11e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1114. work[iv1tcs + i__ - 1], &r__);
  1115. } else if (restart11 && ! restart21) {
  1116. dlartgp_(&b21bulge, &b21e[i__ - 1], &work[iv1tsn + i__ - 1], &
  1117. work[iv1tcs + i__ - 1], &r__);
  1118. } else if (mu <= nu) {
  1119. dlartgs_(&b11d[i__], &b11e[i__], &mu, &work[iv1tcs + i__ - 1],
  1120. &work[iv1tsn + i__ - 1]);
  1121. } else {
  1122. dlartgs_(&b21d[i__], &b21e[i__], &nu, &work[iv1tcs + i__ - 1],
  1123. &work[iv1tsn + i__ - 1]);
  1124. }
  1125. work[iv1tcs + i__ - 1] = -work[iv1tcs + i__ - 1];
  1126. work[iv1tsn + i__ - 1] = -work[iv1tsn + i__ - 1];
  1127. if (! restart12 && ! restart22) {
  1128. dlartgp_(&y2, &y1, &work[iv2tsn + i__ - 2], &work[iv2tcs +
  1129. i__ - 2], &r__);
  1130. } else if (! restart12 && restart22) {
  1131. dlartgp_(&b12bulge, &b12d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1132. work[iv2tcs + i__ - 2], &r__);
  1133. } else if (restart12 && ! restart22) {
  1134. dlartgp_(&b22bulge, &b22d[i__ - 1], &work[iv2tsn + i__ - 2], &
  1135. work[iv2tcs + i__ - 2], &r__);
  1136. } else if (nu < mu) {
  1137. dlartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &work[iv2tcs + i__
  1138. - 2], &work[iv2tsn + i__ - 2]);
  1139. } else {
  1140. dlartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &work[iv2tcs + i__
  1141. - 2], &work[iv2tsn + i__ - 2]);
  1142. }
  1143. temp = work[iv1tcs + i__ - 1] * b11d[i__] + work[iv1tsn + i__ - 1]
  1144. * b11e[i__];
  1145. b11e[i__] = work[iv1tcs + i__ - 1] * b11e[i__] - work[iv1tsn +
  1146. i__ - 1] * b11d[i__];
  1147. b11d[i__] = temp;
  1148. b11bulge = work[iv1tsn + i__ - 1] * b11d[i__ + 1];
  1149. b11d[i__ + 1] = work[iv1tcs + i__ - 1] * b11d[i__ + 1];
  1150. temp = work[iv1tcs + i__ - 1] * b21d[i__] + work[iv1tsn + i__ - 1]
  1151. * b21e[i__];
  1152. b21e[i__] = work[iv1tcs + i__ - 1] * b21e[i__] - work[iv1tsn +
  1153. i__ - 1] * b21d[i__];
  1154. b21d[i__] = temp;
  1155. b21bulge = work[iv1tsn + i__ - 1] * b21d[i__ + 1];
  1156. b21d[i__ + 1] = work[iv1tcs + i__ - 1] * b21d[i__ + 1];
  1157. temp = work[iv2tcs + i__ - 2] * b12e[i__ - 1] + work[iv2tsn + i__
  1158. - 2] * b12d[i__];
  1159. b12d[i__] = work[iv2tcs + i__ - 2] * b12d[i__] - work[iv2tsn +
  1160. i__ - 2] * b12e[i__ - 1];
  1161. b12e[i__ - 1] = temp;
  1162. b12bulge = work[iv2tsn + i__ - 2] * b12e[i__];
  1163. b12e[i__] = work[iv2tcs + i__ - 2] * b12e[i__];
  1164. temp = work[iv2tcs + i__ - 2] * b22e[i__ - 1] + work[iv2tsn + i__
  1165. - 2] * b22d[i__];
  1166. b22d[i__] = work[iv2tcs + i__ - 2] * b22d[i__] - work[iv2tsn +
  1167. i__ - 2] * b22e[i__ - 1];
  1168. b22e[i__ - 1] = temp;
  1169. b22bulge = work[iv2tsn + i__ - 2] * b22e[i__];
  1170. b22e[i__] = work[iv2tcs + i__ - 2] * b22e[i__];
  1171. /* Compute THETA(I) */
  1172. x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
  1173. - 1];
  1174. x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
  1175. y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
  1176. - 1];
  1177. y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
  1178. /* Computing 2nd power */
  1179. d__1 = y1;
  1180. /* Computing 2nd power */
  1181. d__2 = y2;
  1182. /* Computing 2nd power */
  1183. d__3 = x1;
  1184. /* Computing 2nd power */
  1185. d__4 = x2;
  1186. theta[i__] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
  1187. d__3 + d__4 * d__4));
  1188. /* Determine if there are bulges to chase or if a new direct */
  1189. /* summand has been reached */
  1190. /* Computing 2nd power */
  1191. d__1 = b11d[i__];
  1192. /* Computing 2nd power */
  1193. d__2 = b11bulge;
  1194. /* Computing 2nd power */
  1195. d__3 = thresh;
  1196. restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1197. /* Computing 2nd power */
  1198. d__1 = b12e[i__ - 1];
  1199. /* Computing 2nd power */
  1200. d__2 = b12bulge;
  1201. /* Computing 2nd power */
  1202. d__3 = thresh;
  1203. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1204. /* Computing 2nd power */
  1205. d__1 = b21d[i__];
  1206. /* Computing 2nd power */
  1207. d__2 = b21bulge;
  1208. /* Computing 2nd power */
  1209. d__3 = thresh;
  1210. restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1211. /* Computing 2nd power */
  1212. d__1 = b22e[i__ - 1];
  1213. /* Computing 2nd power */
  1214. d__2 = b22bulge;
  1215. /* Computing 2nd power */
  1216. d__3 = thresh;
  1217. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1218. /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
  1219. /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
  1220. /* chasing by applying the original shift again. */
  1221. if (! restart11 && ! restart12) {
  1222. dlartgp_(&x2, &x1, &work[iu1sn + i__ - 1], &work[iu1cs + i__
  1223. - 1], &r__);
  1224. } else if (! restart11 && restart12) {
  1225. dlartgp_(&b11bulge, &b11d[i__], &work[iu1sn + i__ - 1], &work[
  1226. iu1cs + i__ - 1], &r__);
  1227. } else if (restart11 && ! restart12) {
  1228. dlartgp_(&b12bulge, &b12e[i__ - 1], &work[iu1sn + i__ - 1], &
  1229. work[iu1cs + i__ - 1], &r__);
  1230. } else if (mu <= nu) {
  1231. dlartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &work[iu1cs + i__ -
  1232. 1], &work[iu1sn + i__ - 1]);
  1233. } else {
  1234. dlartgs_(&b12d[i__], &b12e[i__], &nu, &work[iu1cs + i__ - 1],
  1235. &work[iu1sn + i__ - 1]);
  1236. }
  1237. if (! restart21 && ! restart22) {
  1238. dlartgp_(&y2, &y1, &work[iu2sn + i__ - 1], &work[iu2cs + i__
  1239. - 1], &r__);
  1240. } else if (! restart21 && restart22) {
  1241. dlartgp_(&b21bulge, &b21d[i__], &work[iu2sn + i__ - 1], &work[
  1242. iu2cs + i__ - 1], &r__);
  1243. } else if (restart21 && ! restart22) {
  1244. dlartgp_(&b22bulge, &b22e[i__ - 1], &work[iu2sn + i__ - 1], &
  1245. work[iu2cs + i__ - 1], &r__);
  1246. } else if (nu < mu) {
  1247. dlartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &work[iu2cs + i__ -
  1248. 1], &work[iu2sn + i__ - 1]);
  1249. } else {
  1250. dlartgs_(&b22d[i__], &b22e[i__], &mu, &work[iu2cs + i__ - 1],
  1251. &work[iu2sn + i__ - 1]);
  1252. }
  1253. work[iu2cs + i__ - 1] = -work[iu2cs + i__ - 1];
  1254. work[iu2sn + i__ - 1] = -work[iu2sn + i__ - 1];
  1255. temp = work[iu1cs + i__ - 1] * b11e[i__] + work[iu1sn + i__ - 1] *
  1256. b11d[i__ + 1];
  1257. b11d[i__ + 1] = work[iu1cs + i__ - 1] * b11d[i__ + 1] - work[
  1258. iu1sn + i__ - 1] * b11e[i__];
  1259. b11e[i__] = temp;
  1260. if (i__ < imax - 1) {
  1261. b11bulge = work[iu1sn + i__ - 1] * b11e[i__ + 1];
  1262. b11e[i__ + 1] = work[iu1cs + i__ - 1] * b11e[i__ + 1];
  1263. }
  1264. temp = work[iu2cs + i__ - 1] * b21e[i__] + work[iu2sn + i__ - 1] *
  1265. b21d[i__ + 1];
  1266. b21d[i__ + 1] = work[iu2cs + i__ - 1] * b21d[i__ + 1] - work[
  1267. iu2sn + i__ - 1] * b21e[i__];
  1268. b21e[i__] = temp;
  1269. if (i__ < imax - 1) {
  1270. b21bulge = work[iu2sn + i__ - 1] * b21e[i__ + 1];
  1271. b21e[i__ + 1] = work[iu2cs + i__ - 1] * b21e[i__ + 1];
  1272. }
  1273. temp = work[iu1cs + i__ - 1] * b12d[i__] + work[iu1sn + i__ - 1] *
  1274. b12e[i__];
  1275. b12e[i__] = work[iu1cs + i__ - 1] * b12e[i__] - work[iu1sn + i__
  1276. - 1] * b12d[i__];
  1277. b12d[i__] = temp;
  1278. b12bulge = work[iu1sn + i__ - 1] * b12d[i__ + 1];
  1279. b12d[i__ + 1] = work[iu1cs + i__ - 1] * b12d[i__ + 1];
  1280. temp = work[iu2cs + i__ - 1] * b22d[i__] + work[iu2sn + i__ - 1] *
  1281. b22e[i__];
  1282. b22e[i__] = work[iu2cs + i__ - 1] * b22e[i__] - work[iu2sn + i__
  1283. - 1] * b22d[i__];
  1284. b22d[i__] = temp;
  1285. b22bulge = work[iu2sn + i__ - 1] * b22d[i__ + 1];
  1286. b22d[i__ + 1] = work[iu2cs + i__ - 1] * b22d[i__ + 1];
  1287. }
  1288. /* Compute PHI(IMAX-1) */
  1289. x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
  1290. b21e[imax - 1];
  1291. y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
  1292. b22d[imax - 1];
  1293. y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
  1294. b22bulge;
  1295. /* Computing 2nd power */
  1296. d__1 = y1;
  1297. /* Computing 2nd power */
  1298. d__2 = y2;
  1299. phi[imax - 1] = atan2((abs(x1)), sqrt(d__1 * d__1 + d__2 * d__2));
  1300. /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
  1301. /* Computing 2nd power */
  1302. d__1 = b12d[imax - 1];
  1303. /* Computing 2nd power */
  1304. d__2 = b12bulge;
  1305. /* Computing 2nd power */
  1306. d__3 = thresh;
  1307. restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1308. /* Computing 2nd power */
  1309. d__1 = b22d[imax - 1];
  1310. /* Computing 2nd power */
  1311. d__2 = b22bulge;
  1312. /* Computing 2nd power */
  1313. d__3 = thresh;
  1314. restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
  1315. if (! restart12 && ! restart22) {
  1316. dlartgp_(&y2, &y1, &work[iv2tsn + imax - 2], &work[iv2tcs + imax
  1317. - 2], &r__);
  1318. } else if (! restart12 && restart22) {
  1319. dlartgp_(&b12bulge, &b12d[imax - 1], &work[iv2tsn + imax - 2], &
  1320. work[iv2tcs + imax - 2], &r__);
  1321. } else if (restart12 && ! restart22) {
  1322. dlartgp_(&b22bulge, &b22d[imax - 1], &work[iv2tsn + imax - 2], &
  1323. work[iv2tcs + imax - 2], &r__);
  1324. } else if (nu < mu) {
  1325. dlartgs_(&b12e[imax - 1], &b12d[imax], &nu, &work[iv2tcs + imax -
  1326. 2], &work[iv2tsn + imax - 2]);
  1327. } else {
  1328. dlartgs_(&b22e[imax - 1], &b22d[imax], &mu, &work[iv2tcs + imax -
  1329. 2], &work[iv2tsn + imax - 2]);
  1330. }
  1331. temp = work[iv2tcs + imax - 2] * b12e[imax - 1] + work[iv2tsn + imax
  1332. - 2] * b12d[imax];
  1333. b12d[imax] = work[iv2tcs + imax - 2] * b12d[imax] - work[iv2tsn +
  1334. imax - 2] * b12e[imax - 1];
  1335. b12e[imax - 1] = temp;
  1336. temp = work[iv2tcs + imax - 2] * b22e[imax - 1] + work[iv2tsn + imax
  1337. - 2] * b22d[imax];
  1338. b22d[imax] = work[iv2tcs + imax - 2] * b22d[imax] - work[iv2tsn +
  1339. imax - 2] * b22e[imax - 1];
  1340. b22e[imax - 1] = temp;
  1341. /* Update singular vectors */
  1342. if (wantu1) {
  1343. if (colmajor) {
  1344. i__1 = imax - imin + 1;
  1345. dlasr_("R", "V", "F", p, &i__1, &work[iu1cs + imin - 1], &
  1346. work[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1], ldu1);
  1347. } else {
  1348. i__1 = imax - imin + 1;
  1349. dlasr_("L", "V", "F", &i__1, p, &work[iu1cs + imin - 1], &
  1350. work[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
  1351. }
  1352. }
  1353. if (wantu2) {
  1354. if (colmajor) {
  1355. i__1 = *m - *p;
  1356. i__2 = imax - imin + 1;
  1357. dlasr_("R", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1358. work[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1], ldu2);
  1359. } else {
  1360. i__1 = imax - imin + 1;
  1361. i__2 = *m - *p;
  1362. dlasr_("L", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
  1363. work[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
  1364. }
  1365. }
  1366. if (wantv1t) {
  1367. if (colmajor) {
  1368. i__1 = imax - imin + 1;
  1369. dlasr_("L", "V", "F", &i__1, q, &work[iv1tcs + imin - 1], &
  1370. work[iv1tsn + imin - 1], &v1t[imin + v1t_dim1], ldv1t);
  1371. } else {
  1372. i__1 = imax - imin + 1;
  1373. dlasr_("R", "V", "F", q, &i__1, &work[iv1tcs + imin - 1], &
  1374. work[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
  1375. ldv1t);
  1376. }
  1377. }
  1378. if (wantv2t) {
  1379. if (colmajor) {
  1380. i__1 = imax - imin + 1;
  1381. i__2 = *m - *q;
  1382. dlasr_("L", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1383. &work[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
  1384. ldv2t);
  1385. } else {
  1386. i__1 = *m - *q;
  1387. i__2 = imax - imin + 1;
  1388. dlasr_("R", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
  1389. &work[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
  1390. ldv2t);
  1391. }
  1392. }
  1393. /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
  1394. if (b11e[imax - 1] + b21e[imax - 1] > 0.) {
  1395. b11d[imax] = -b11d[imax];
  1396. b21d[imax] = -b21d[imax];
  1397. if (wantv1t) {
  1398. if (colmajor) {
  1399. dscal_(q, &c_b35, &v1t[imax + v1t_dim1], ldv1t);
  1400. } else {
  1401. dscal_(q, &c_b35, &v1t[imax * v1t_dim1 + 1], &c__1);
  1402. }
  1403. }
  1404. }
  1405. /* Compute THETA(IMAX) */
  1406. x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
  1407. - 1];
  1408. y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
  1409. - 1];
  1410. theta[imax] = atan2((abs(y1)), (abs(x1)));
  1411. /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
  1412. /* and B22(IMAX,IMAX-1) */
  1413. if (b11d[imax] + b12e[imax - 1] < 0.) {
  1414. b12d[imax] = -b12d[imax];
  1415. if (wantu1) {
  1416. if (colmajor) {
  1417. dscal_(p, &c_b35, &u1[imax * u1_dim1 + 1], &c__1);
  1418. } else {
  1419. dscal_(p, &c_b35, &u1[imax + u1_dim1], ldu1);
  1420. }
  1421. }
  1422. }
  1423. if (b21d[imax] + b22e[imax - 1] > 0.) {
  1424. b22d[imax] = -b22d[imax];
  1425. if (wantu2) {
  1426. if (colmajor) {
  1427. i__1 = *m - *p;
  1428. dscal_(&i__1, &c_b35, &u2[imax * u2_dim1 + 1], &c__1);
  1429. } else {
  1430. i__1 = *m - *p;
  1431. dscal_(&i__1, &c_b35, &u2[imax + u2_dim1], ldu2);
  1432. }
  1433. }
  1434. }
  1435. /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
  1436. if (b12d[imax] + b22d[imax] < 0.) {
  1437. if (wantv2t) {
  1438. if (colmajor) {
  1439. i__1 = *m - *q;
  1440. dscal_(&i__1, &c_b35, &v2t[imax + v2t_dim1], ldv2t);
  1441. } else {
  1442. i__1 = *m - *q;
  1443. dscal_(&i__1, &c_b35, &v2t[imax * v2t_dim1 + 1], &c__1);
  1444. }
  1445. }
  1446. }
  1447. /* Test for negligible sines or cosines */
  1448. i__1 = imax;
  1449. for (i__ = imin; i__ <= i__1; ++i__) {
  1450. if (theta[i__] < thresh) {
  1451. theta[i__] = 0.;
  1452. } else if (theta[i__] > 1.57079632679489662 - thresh) {
  1453. theta[i__] = 1.57079632679489662;
  1454. }
  1455. }
  1456. i__1 = imax - 1;
  1457. for (i__ = imin; i__ <= i__1; ++i__) {
  1458. if (phi[i__] < thresh) {
  1459. phi[i__] = 0.;
  1460. } else if (phi[i__] > 1.57079632679489662 - thresh) {
  1461. phi[i__] = 1.57079632679489662;
  1462. }
  1463. }
  1464. /* Deflate */
  1465. if (imax > 1) {
  1466. while(phi[imax - 1] == 0.) {
  1467. --imax;
  1468. if (imax <= 1) {
  1469. myexit_();
  1470. }
  1471. }
  1472. }
  1473. if (imin > imax - 1) {
  1474. imin = imax - 1;
  1475. }
  1476. if (imin > 1) {
  1477. while(phi[imin - 1] != 0.) {
  1478. --imin;
  1479. if (imin <= 1) {
  1480. myexit_();
  1481. }
  1482. }
  1483. }
  1484. /* Repeat main iteration loop */
  1485. }
  1486. /* Postprocessing: order THETA from least to greatest */
  1487. i__1 = *q;
  1488. for (i__ = 1; i__ <= i__1; ++i__) {
  1489. mini = i__;
  1490. thetamin = theta[i__];
  1491. i__2 = *q;
  1492. for (j = i__ + 1; j <= i__2; ++j) {
  1493. if (theta[j] < thetamin) {
  1494. mini = j;
  1495. thetamin = theta[j];
  1496. }
  1497. }
  1498. if (mini != i__) {
  1499. theta[mini] = theta[i__];
  1500. theta[i__] = thetamin;
  1501. if (colmajor) {
  1502. if (wantu1) {
  1503. dswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
  1504. u1_dim1 + 1], &c__1);
  1505. }
  1506. if (wantu2) {
  1507. i__2 = *m - *p;
  1508. dswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
  1509. u2_dim1 + 1], &c__1);
  1510. }
  1511. if (wantv1t) {
  1512. dswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
  1513. v1t_dim1], ldv1t);
  1514. }
  1515. if (wantv2t) {
  1516. i__2 = *m - *q;
  1517. dswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
  1518. v2t_dim1], ldv2t);
  1519. }
  1520. } else {
  1521. if (wantu1) {
  1522. dswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
  1523. ldu1);
  1524. }
  1525. if (wantu2) {
  1526. i__2 = *m - *p;
  1527. dswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
  1528. u2_dim1], ldu2);
  1529. }
  1530. if (wantv1t) {
  1531. dswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
  1532. v1t_dim1 + 1], &c__1);
  1533. }
  1534. if (wantv2t) {
  1535. i__2 = *m - *q;
  1536. dswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
  1537. v2t_dim1 + 1], &c__1);
  1538. }
  1539. }
  1540. }
  1541. }
  1542. return 0;
  1543. /* End of DBBCSD */
  1544. } /* dbbcsd_ */