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.

dgesvj.c 67 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254
  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_b17 = 0.;
  381. static doublereal c_b18 = 1.;
  382. static integer c__1 = 1;
  383. static integer c__0 = 0;
  384. static integer c__2 = 2;
  385. /* > \brief \b DGESVJ */
  386. /* =========== DOCUMENTATION =========== */
  387. /* Online html documentation available at */
  388. /* http://www.netlib.org/lapack/explore-html/ */
  389. /* > \htmlonly */
  390. /* > Download DGESVJ + dependencies */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgesvj.
  392. f"> */
  393. /* > [TGZ]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgesvj.
  395. f"> */
  396. /* > [ZIP]</a> */
  397. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgesvj.
  398. f"> */
  399. /* > [TXT]</a> */
  400. /* > \endhtmlonly */
  401. /* Definition: */
  402. /* =========== */
  403. /* SUBROUTINE DGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V, */
  404. /* LDV, WORK, LWORK, INFO ) */
  405. /* INTEGER INFO, LDA, LDV, LWORK, M, MV, N */
  406. /* CHARACTER*1 JOBA, JOBU, JOBV */
  407. /* DOUBLE PRECISION A( LDA, * ), SVA( N ), V( LDV, * ), */
  408. /* $ WORK( LWORK ) */
  409. /* > \par Purpose: */
  410. /* ============= */
  411. /* > */
  412. /* > \verbatim */
  413. /* > */
  414. /* > DGESVJ computes the singular value decomposition (SVD) of a real */
  415. /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
  416. /* > [++] [xx] [x0] [xx] */
  417. /* > A = U * SIGMA * V^t, [++] = [xx] * [ox] * [xx] */
  418. /* > [++] [xx] */
  419. /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
  420. /* > matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
  421. /* > of SIGMA are the singular values of A. The columns of U and V are the */
  422. /* > left and the right singular vectors of A, respectively. */
  423. /* > DGESVJ can sometimes compute tiny singular values and their singular vectors much */
  424. /* > more accurately than other SVD routines, see below under Further Details. */
  425. /* > \endverbatim */
  426. /* Arguments: */
  427. /* ========== */
  428. /* > \param[in] JOBA */
  429. /* > \verbatim */
  430. /* > JOBA is CHARACTER*1 */
  431. /* > Specifies the structure of A. */
  432. /* > = 'L': The input matrix A is lower triangular; */
  433. /* > = 'U': The input matrix A is upper triangular; */
  434. /* > = 'G': The input matrix A is general M-by-N matrix, M >= N. */
  435. /* > \endverbatim */
  436. /* > */
  437. /* > \param[in] JOBU */
  438. /* > \verbatim */
  439. /* > JOBU is CHARACTER*1 */
  440. /* > Specifies whether to compute the left singular vectors */
  441. /* > (columns of U): */
  442. /* > = 'U': The left singular vectors corresponding to the nonzero */
  443. /* > singular values are computed and returned in the leading */
  444. /* > columns of A. See more details in the description of A. */
  445. /* > The default numerical orthogonality threshold is set to */
  446. /* > approximately TOL=CTOL*EPS, CTOL=DSQRT(M), EPS=DLAMCH('E'). */
  447. /* > = 'C': Analogous to JOBU='U', except that user can control the */
  448. /* > level of numerical orthogonality of the computed left */
  449. /* > singular vectors. TOL can be set to TOL = CTOL*EPS, where */
  450. /* > CTOL is given on input in the array WORK. */
  451. /* > No CTOL smaller than ONE is allowed. CTOL greater */
  452. /* > than 1 / EPS is meaningless. The option 'C' */
  453. /* > can be used if M*EPS is satisfactory orthogonality */
  454. /* > of the computed left singular vectors, so CTOL=M could */
  455. /* > save few sweeps of Jacobi rotations. */
  456. /* > See the descriptions of A and WORK(1). */
  457. /* > = 'N': The matrix U is not computed. However, see the */
  458. /* > description of A. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in] JOBV */
  462. /* > \verbatim */
  463. /* > JOBV is CHARACTER*1 */
  464. /* > Specifies whether to compute the right singular vectors, that */
  465. /* > is, the matrix V: */
  466. /* > = 'V': the matrix V is computed and returned in the array V */
  467. /* > = 'A': the Jacobi rotations are applied to the MV-by-N */
  468. /* > array V. In other words, the right singular vector */
  469. /* > matrix V is not computed explicitly, instead it is */
  470. /* > applied to an MV-by-N matrix initially stored in the */
  471. /* > first MV rows of V. */
  472. /* > = 'N': the matrix V is not computed and the array V is not */
  473. /* > referenced */
  474. /* > \endverbatim */
  475. /* > */
  476. /* > \param[in] M */
  477. /* > \verbatim */
  478. /* > M is INTEGER */
  479. /* > The number of rows of the input matrix A. 1/DLAMCH('E') > M >= 0. */
  480. /* > \endverbatim */
  481. /* > */
  482. /* > \param[in] N */
  483. /* > \verbatim */
  484. /* > N is INTEGER */
  485. /* > The number of columns of the input matrix A. */
  486. /* > M >= N >= 0. */
  487. /* > \endverbatim */
  488. /* > */
  489. /* > \param[in,out] A */
  490. /* > \verbatim */
  491. /* > A is DOUBLE PRECISION array, dimension (LDA,N) */
  492. /* > On entry, the M-by-N matrix A. */
  493. /* > On exit : */
  494. /* > If JOBU = 'U' .OR. JOBU = 'C' : */
  495. /* > If INFO = 0 : */
  496. /* > RANKA orthonormal columns of U are returned in the */
  497. /* > leading RANKA columns of the array A. Here RANKA <= N */
  498. /* > is the number of computed singular values of A that are */
  499. /* > above the underflow threshold DLAMCH('S'). The singular */
  500. /* > vectors corresponding to underflowed or zero singular */
  501. /* > values are not computed. The value of RANKA is returned */
  502. /* > in the array WORK as RANKA=NINT(WORK(2)). Also see the */
  503. /* > descriptions of SVA and WORK. The computed columns of U */
  504. /* > are mutually numerically orthogonal up to approximately */
  505. /* > TOL=DSQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU = 'C'), */
  506. /* > see the description of JOBU. */
  507. /* > If INFO > 0 : */
  508. /* > the procedure DGESVJ did not converge in the given number */
  509. /* > of iterations (sweeps). In that case, the computed */
  510. /* > columns of U may not be orthogonal up to TOL. The output */
  511. /* > U (stored in A), SIGMA (given by the computed singular */
  512. /* > values in SVA(1:N)) and V is still a decomposition of the */
  513. /* > input matrix A in the sense that the residual */
  514. /* > ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small. */
  515. /* > */
  516. /* > If JOBU = 'N' : */
  517. /* > If INFO = 0 : */
  518. /* > Note that the left singular vectors are 'for free' in the */
  519. /* > one-sided Jacobi SVD algorithm. However, if only the */
  520. /* > singular values are needed, the level of numerical */
  521. /* > orthogonality of U is not an issue and iterations are */
  522. /* > stopped when the columns of the iterated matrix are */
  523. /* > numerically orthogonal up to approximately M*EPS. Thus, */
  524. /* > on exit, A contains the columns of U scaled with the */
  525. /* > corresponding singular values. */
  526. /* > If INFO > 0 : */
  527. /* > the procedure DGESVJ did not converge in the given number */
  528. /* > of iterations (sweeps). */
  529. /* > \endverbatim */
  530. /* > */
  531. /* > \param[in] LDA */
  532. /* > \verbatim */
  533. /* > LDA is INTEGER */
  534. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  535. /* > \endverbatim */
  536. /* > */
  537. /* > \param[out] SVA */
  538. /* > \verbatim */
  539. /* > SVA is DOUBLE PRECISION array, dimension (N) */
  540. /* > On exit : */
  541. /* > If INFO = 0 : */
  542. /* > depending on the value SCALE = WORK(1), we have: */
  543. /* > If SCALE = ONE : */
  544. /* > SVA(1:N) contains the computed singular values of A. */
  545. /* > During the computation SVA contains the Euclidean column */
  546. /* > norms of the iterated matrices in the array A. */
  547. /* > If SCALE .NE. ONE : */
  548. /* > The singular values of A are SCALE*SVA(1:N), and this */
  549. /* > factored representation is due to the fact that some of the */
  550. /* > singular values of A might underflow or overflow. */
  551. /* > If INFO > 0 : */
  552. /* > the procedure DGESVJ did not converge in the given number of */
  553. /* > iterations (sweeps) and SCALE*SVA(1:N) may not be accurate. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] MV */
  557. /* > \verbatim */
  558. /* > MV is INTEGER */
  559. /* > If JOBV = 'A', then the product of Jacobi rotations in DGESVJ */
  560. /* > is applied to the first MV rows of V. See the description of JOBV. */
  561. /* > \endverbatim */
  562. /* > */
  563. /* > \param[in,out] V */
  564. /* > \verbatim */
  565. /* > V is DOUBLE PRECISION array, dimension (LDV,N) */
  566. /* > If JOBV = 'V', then V contains on exit the N-by-N matrix of */
  567. /* > the right singular vectors; */
  568. /* > If JOBV = 'A', then V contains the product of the computed right */
  569. /* > singular vector matrix and the initial matrix in */
  570. /* > the array V. */
  571. /* > If JOBV = 'N', then V is not referenced. */
  572. /* > \endverbatim */
  573. /* > */
  574. /* > \param[in] LDV */
  575. /* > \verbatim */
  576. /* > LDV is INTEGER */
  577. /* > The leading dimension of the array V, LDV >= 1. */
  578. /* > If JOBV = 'V', then LDV >= f2cmax(1,N). */
  579. /* > If JOBV = 'A', then LDV >= f2cmax(1,MV) . */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in,out] WORK */
  583. /* > \verbatim */
  584. /* > WORK is DOUBLE PRECISION array, dimension (LWORK) */
  585. /* > On entry : */
  586. /* > If JOBU = 'C' : */
  587. /* > WORK(1) = CTOL, where CTOL defines the threshold for convergence. */
  588. /* > The process stops if all columns of A are mutually */
  589. /* > orthogonal up to CTOL*EPS, EPS=DLAMCH('E'). */
  590. /* > It is required that CTOL >= ONE, i.e. it is not */
  591. /* > allowed to force the routine to obtain orthogonality */
  592. /* > below EPS. */
  593. /* > On exit : */
  594. /* > WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N) */
  595. /* > are the computed singular values of A. */
  596. /* > (See description of SVA().) */
  597. /* > WORK(2) = NINT(WORK(2)) is the number of the computed nonzero */
  598. /* > singular values. */
  599. /* > WORK(3) = NINT(WORK(3)) is the number of the computed singular */
  600. /* > values that are larger than the underflow threshold. */
  601. /* > WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi */
  602. /* > rotations needed for numerical convergence. */
  603. /* > WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep. */
  604. /* > This is useful information in cases when DGESVJ did */
  605. /* > not converge, as it can be used to estimate whether */
  606. /* > the output is still useful and for post festum analysis. */
  607. /* > WORK(6) = the largest absolute value over all sines of the */
  608. /* > Jacobi rotation angles in the last sweep. It can be */
  609. /* > useful for a post festum analysis. */
  610. /* > \endverbatim */
  611. /* > */
  612. /* > \param[in] LWORK */
  613. /* > \verbatim */
  614. /* > LWORK is INTEGER */
  615. /* > length of WORK, WORK >= MAX(6,M+N) */
  616. /* > \endverbatim */
  617. /* > */
  618. /* > \param[out] INFO */
  619. /* > \verbatim */
  620. /* > INFO is INTEGER */
  621. /* > = 0: successful exit. */
  622. /* > < 0: if INFO = -i, then the i-th argument had an illegal value */
  623. /* > > 0: DGESVJ did not converge in the maximal allowed number (30) */
  624. /* > of sweeps. The output may still be useful. See the */
  625. /* > description of WORK. */
  626. /* > \endverbatim */
  627. /* Authors: */
  628. /* ======== */
  629. /* > \author Univ. of Tennessee */
  630. /* > \author Univ. of California Berkeley */
  631. /* > \author Univ. of Colorado Denver */
  632. /* > \author NAG Ltd. */
  633. /* > \date June 2017 */
  634. /* > \ingroup doubleGEcomputational */
  635. /* > \par Further Details: */
  636. /* ===================== */
  637. /* > */
  638. /* > \verbatim */
  639. /* > */
  640. /* > The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane */
  641. /* > rotations. The rotations are implemented as fast scaled rotations of */
  642. /* > Anda and Park [1]. In the case of underflow of the Jacobi angle, a */
  643. /* > modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses */
  644. /* > column interchanges of de Rijk [2]. The relative accuracy of the computed */
  645. /* > singular values and the accuracy of the computed singular vectors (in */
  646. /* > angle metric) is as guaranteed by the theory of Demmel and Veselic [3]. */
  647. /* > The condition number that determines the accuracy in the full rank case */
  648. /* > is essentially min_{D=diag} kappa(A*D), where kappa(.) is the */
  649. /* > spectral condition number. The best performance of this Jacobi SVD */
  650. /* > procedure is achieved if used in an accelerated version of Drmac and */
  651. /* > Veselic [5,6], and it is the kernel routine in the SIGMA library [7]. */
  652. /* > Some tunning parameters (marked with [TP]) are available for the */
  653. /* > implementer. */
  654. /* > The computational range for the nonzero singular values is the machine */
  655. /* > number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even */
  656. /* > denormalized singular values can be computed with the corresponding */
  657. /* > gradual loss of accurate digits. */
  658. /* > \endverbatim */
  659. /* > \par Contributors: */
  660. /* ================== */
  661. /* > */
  662. /* > \verbatim */
  663. /* > */
  664. /* > ============ */
  665. /* > */
  666. /* > Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
  667. /* > \endverbatim */
  668. /* > \par References: */
  669. /* ================ */
  670. /* > */
  671. /* > \verbatim */
  672. /* > */
  673. /* > [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling. */
  674. /* > SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174. */
  675. /* > [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the */
  676. /* > singular value decomposition on a vector computer. */
  677. /* > SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371. */
  678. /* > [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR. */
  679. /* > [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular */
  680. /* > value computation in floating point arithmetic. */
  681. /* > SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222. */
  682. /* > [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. */
  683. /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. */
  684. /* > LAPACK Working note 169. */
  685. /* > [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. */
  686. /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. */
  687. /* > LAPACK Working note 170. */
  688. /* > [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV, */
  689. /* > QSVD, (H,K)-SVD computations. */
  690. /* > Department of Mathematics, University of Zagreb, 2008. */
  691. /* > \endverbatim */
  692. /* > \par Bugs, examples and comments: */
  693. /* ================================= */
  694. /* > */
  695. /* > \verbatim */
  696. /* > =========================== */
  697. /* > Please report all bugs and send interesting test examples and comments to */
  698. /* > drmac@math.hr. Thank you. */
  699. /* > \endverbatim */
  700. /* > */
  701. /* ===================================================================== */
  702. /* Subroutine */ int dgesvj_(char *joba, char *jobu, char *jobv, integer *m,
  703. integer *n, doublereal *a, integer *lda, doublereal *sva, integer *mv,
  704. doublereal *v, integer *ldv, doublereal *work, integer *lwork,
  705. integer *info)
  706. {
  707. /* System generated locals */
  708. integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5;
  709. doublereal d__1, d__2;
  710. /* Local variables */
  711. doublereal aapp, aapq, aaqq;
  712. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  713. integer *);
  714. doublereal ctol;
  715. integer ierr;
  716. doublereal bigtheta;
  717. integer pskipped;
  718. doublereal aapp0;
  719. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  720. doublereal temp1;
  721. integer i__, p, q;
  722. doublereal t;
  723. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  724. integer *);
  725. doublereal large, apoaq, aqoap;
  726. extern logical lsame_(char *, char *);
  727. doublereal theta, small, sfmin;
  728. logical lsvec;
  729. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  730. doublereal *, integer *);
  731. doublereal fastr[5];
  732. extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
  733. doublereal *, integer *);
  734. doublereal epsln;
  735. logical applv, rsvec;
  736. extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
  737. integer *, doublereal *, integer *);
  738. logical uctol;
  739. extern /* Subroutine */ int drotm_(integer *, doublereal *, integer *,
  740. doublereal *, integer *, doublereal *);
  741. logical lower, upper, rotok;
  742. integer n2, n4;
  743. extern /* Subroutine */ int dgsvj0_(char *, integer *, integer *,
  744. doublereal *, integer *, doublereal *, doublereal *, integer *,
  745. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  746. integer *, doublereal *, integer *, integer *), dgsvj1_(
  747. char *, integer *, integer *, integer *, doublereal *, integer *,
  748. doublereal *, doublereal *, integer *, doublereal *, integer *,
  749. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  750. integer *, integer *);
  751. doublereal rootsfmin;
  752. integer n34;
  753. doublereal cs;
  754. extern doublereal dlamch_(char *);
  755. doublereal sn;
  756. extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
  757. doublereal *, doublereal *, integer *, integer *, doublereal *,
  758. integer *, integer *);
  759. extern integer idamax_(integer *, doublereal *, integer *);
  760. extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
  761. doublereal *, doublereal *, doublereal *, integer *),
  762. xerbla_(char *, integer *, ftnlen);
  763. integer ijblsk, swband, blskip;
  764. doublereal mxaapq;
  765. extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *,
  766. doublereal *, doublereal *);
  767. doublereal thsign, mxsinj;
  768. integer ir1, emptsw, notrot, iswrot, jbc;
  769. doublereal big;
  770. integer kbl, lkahead, igl, ibr, jgl, nbl;
  771. doublereal skl;
  772. logical goscale;
  773. doublereal tol;
  774. integer mvl;
  775. logical noscale;
  776. doublereal rootbig, rooteps;
  777. integer rowskip;
  778. doublereal roottol;
  779. /* -- LAPACK computational routine (version 3.7.1) -- */
  780. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  781. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  782. /* June 2017 */
  783. /* ===================================================================== */
  784. /* from BLAS */
  785. /* from LAPACK */
  786. /* from BLAS */
  787. /* from LAPACK */
  788. /* Test the input arguments */
  789. /* Parameter adjustments */
  790. --sva;
  791. a_dim1 = *lda;
  792. a_offset = 1 + a_dim1 * 1;
  793. a -= a_offset;
  794. v_dim1 = *ldv;
  795. v_offset = 1 + v_dim1 * 1;
  796. v -= v_offset;
  797. --work;
  798. /* Function Body */
  799. lsvec = lsame_(jobu, "U");
  800. uctol = lsame_(jobu, "C");
  801. rsvec = lsame_(jobv, "V");
  802. applv = lsame_(jobv, "A");
  803. upper = lsame_(joba, "U");
  804. lower = lsame_(joba, "L");
  805. if (! (upper || lower || lsame_(joba, "G"))) {
  806. *info = -1;
  807. } else if (! (lsvec || uctol || lsame_(jobu, "N")))
  808. {
  809. *info = -2;
  810. } else if (! (rsvec || applv || lsame_(jobv, "N")))
  811. {
  812. *info = -3;
  813. } else if (*m < 0) {
  814. *info = -4;
  815. } else if (*n < 0 || *n > *m) {
  816. *info = -5;
  817. } else if (*lda < *m) {
  818. *info = -7;
  819. } else if (*mv < 0) {
  820. *info = -9;
  821. } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
  822. *info = -11;
  823. } else if (uctol && work[1] <= 1.) {
  824. *info = -12;
  825. } else /* if(complicated condition) */ {
  826. /* Computing MAX */
  827. i__1 = *m + *n;
  828. if (*lwork < f2cmax(i__1,6)) {
  829. *info = -13;
  830. } else {
  831. *info = 0;
  832. }
  833. }
  834. /* #:( */
  835. if (*info != 0) {
  836. i__1 = -(*info);
  837. xerbla_("DGESVJ", &i__1, (ftnlen)6);
  838. return 0;
  839. }
  840. /* #:) Quick return for void matrix */
  841. if (*m == 0 || *n == 0) {
  842. return 0;
  843. }
  844. /* Set numerical parameters */
  845. /* The stopping criterion for Jacobi rotations is */
  846. /* max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS */
  847. /* where EPS is the round-off and CTOL is defined as follows: */
  848. if (uctol) {
  849. /* ... user controlled */
  850. ctol = work[1];
  851. } else {
  852. /* ... default */
  853. if (lsvec || rsvec || applv) {
  854. ctol = sqrt((doublereal) (*m));
  855. } else {
  856. ctol = (doublereal) (*m);
  857. }
  858. }
  859. /* ... and the machine dependent parameters are */
  860. /* [!] (Make sure that DLAMCH() works properly on the target machine.) */
  861. epsln = dlamch_("Epsilon");
  862. rooteps = sqrt(epsln);
  863. sfmin = dlamch_("SafeMinimum");
  864. rootsfmin = sqrt(sfmin);
  865. small = sfmin / epsln;
  866. big = dlamch_("Overflow");
  867. /* BIG = ONE / SFMIN */
  868. rootbig = 1. / rootsfmin;
  869. large = big / sqrt((doublereal) (*m * *n));
  870. bigtheta = 1. / rooteps;
  871. tol = ctol * epsln;
  872. roottol = sqrt(tol);
  873. if ((doublereal) (*m) * epsln >= 1.) {
  874. *info = -4;
  875. i__1 = -(*info);
  876. xerbla_("DGESVJ", &i__1, (ftnlen)6);
  877. return 0;
  878. }
  879. /* Initialize the right singular vector matrix. */
  880. if (rsvec) {
  881. mvl = *n;
  882. dlaset_("A", &mvl, n, &c_b17, &c_b18, &v[v_offset], ldv);
  883. } else if (applv) {
  884. mvl = *mv;
  885. }
  886. rsvec = rsvec || applv;
  887. /* Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N ) */
  888. /* (!) If necessary, scale A to protect the largest singular value */
  889. /* from overflow. It is possible that saving the largest singular */
  890. /* value destroys the information about the small ones. */
  891. /* This initial scaling is almost minimal in the sense that the */
  892. /* goal is to make sure that no column norm overflows, and that */
  893. /* DSQRT(N)*max_i SVA(i) does not overflow. If INFinite entries */
  894. /* in A are detected, the procedure returns with INFO=-6. */
  895. skl = 1. / sqrt((doublereal) (*m) * (doublereal) (*n));
  896. noscale = TRUE_;
  897. goscale = TRUE_;
  898. if (lower) {
  899. /* the input matrix is M-by-N lower triangular (trapezoidal) */
  900. i__1 = *n;
  901. for (p = 1; p <= i__1; ++p) {
  902. aapp = 0.;
  903. aaqq = 1.;
  904. i__2 = *m - p + 1;
  905. dlassq_(&i__2, &a[p + p * a_dim1], &c__1, &aapp, &aaqq);
  906. if (aapp > big) {
  907. *info = -6;
  908. i__2 = -(*info);
  909. xerbla_("DGESVJ", &i__2, (ftnlen)6);
  910. return 0;
  911. }
  912. aaqq = sqrt(aaqq);
  913. if (aapp < big / aaqq && noscale) {
  914. sva[p] = aapp * aaqq;
  915. } else {
  916. noscale = FALSE_;
  917. sva[p] = aapp * (aaqq * skl);
  918. if (goscale) {
  919. goscale = FALSE_;
  920. i__2 = p - 1;
  921. for (q = 1; q <= i__2; ++q) {
  922. sva[q] *= skl;
  923. /* L1873: */
  924. }
  925. }
  926. }
  927. /* L1874: */
  928. }
  929. } else if (upper) {
  930. /* the input matrix is M-by-N upper triangular (trapezoidal) */
  931. i__1 = *n;
  932. for (p = 1; p <= i__1; ++p) {
  933. aapp = 0.;
  934. aaqq = 1.;
  935. dlassq_(&p, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
  936. if (aapp > big) {
  937. *info = -6;
  938. i__2 = -(*info);
  939. xerbla_("DGESVJ", &i__2, (ftnlen)6);
  940. return 0;
  941. }
  942. aaqq = sqrt(aaqq);
  943. if (aapp < big / aaqq && noscale) {
  944. sva[p] = aapp * aaqq;
  945. } else {
  946. noscale = FALSE_;
  947. sva[p] = aapp * (aaqq * skl);
  948. if (goscale) {
  949. goscale = FALSE_;
  950. i__2 = p - 1;
  951. for (q = 1; q <= i__2; ++q) {
  952. sva[q] *= skl;
  953. /* L2873: */
  954. }
  955. }
  956. }
  957. /* L2874: */
  958. }
  959. } else {
  960. /* the input matrix is M-by-N general dense */
  961. i__1 = *n;
  962. for (p = 1; p <= i__1; ++p) {
  963. aapp = 0.;
  964. aaqq = 1.;
  965. dlassq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
  966. if (aapp > big) {
  967. *info = -6;
  968. i__2 = -(*info);
  969. xerbla_("DGESVJ", &i__2, (ftnlen)6);
  970. return 0;
  971. }
  972. aaqq = sqrt(aaqq);
  973. if (aapp < big / aaqq && noscale) {
  974. sva[p] = aapp * aaqq;
  975. } else {
  976. noscale = FALSE_;
  977. sva[p] = aapp * (aaqq * skl);
  978. if (goscale) {
  979. goscale = FALSE_;
  980. i__2 = p - 1;
  981. for (q = 1; q <= i__2; ++q) {
  982. sva[q] *= skl;
  983. /* L3873: */
  984. }
  985. }
  986. }
  987. /* L3874: */
  988. }
  989. }
  990. if (noscale) {
  991. skl = 1.;
  992. }
  993. /* Move the smaller part of the spectrum from the underflow threshold */
  994. /* (!) Start by determining the position of the nonzero entries of the */
  995. /* array SVA() relative to ( SFMIN, BIG ). */
  996. aapp = 0.;
  997. aaqq = big;
  998. i__1 = *n;
  999. for (p = 1; p <= i__1; ++p) {
  1000. if (sva[p] != 0.) {
  1001. /* Computing MIN */
  1002. d__1 = aaqq, d__2 = sva[p];
  1003. aaqq = f2cmin(d__1,d__2);
  1004. }
  1005. /* Computing MAX */
  1006. d__1 = aapp, d__2 = sva[p];
  1007. aapp = f2cmax(d__1,d__2);
  1008. /* L4781: */
  1009. }
  1010. /* #:) Quick return for zero matrix */
  1011. if (aapp == 0.) {
  1012. if (lsvec) {
  1013. dlaset_("G", m, n, &c_b17, &c_b18, &a[a_offset], lda);
  1014. }
  1015. work[1] = 1.;
  1016. work[2] = 0.;
  1017. work[3] = 0.;
  1018. work[4] = 0.;
  1019. work[5] = 0.;
  1020. work[6] = 0.;
  1021. return 0;
  1022. }
  1023. /* #:) Quick return for one-column matrix */
  1024. if (*n == 1) {
  1025. if (lsvec) {
  1026. dlascl_("G", &c__0, &c__0, &sva[1], &skl, m, &c__1, &a[a_dim1 + 1]
  1027. , lda, &ierr);
  1028. }
  1029. work[1] = 1. / skl;
  1030. if (sva[1] >= sfmin) {
  1031. work[2] = 1.;
  1032. } else {
  1033. work[2] = 0.;
  1034. }
  1035. work[3] = 0.;
  1036. work[4] = 0.;
  1037. work[5] = 0.;
  1038. work[6] = 0.;
  1039. return 0;
  1040. }
  1041. /* Protect small singular values from underflow, and try to */
  1042. /* avoid underflows/overflows in computing Jacobi rotations. */
  1043. sn = sqrt(sfmin / epsln);
  1044. temp1 = sqrt(big / (doublereal) (*n));
  1045. if (aapp <= sn || aaqq >= temp1 || sn <= aaqq && aapp <= temp1) {
  1046. /* Computing MIN */
  1047. d__1 = big, d__2 = temp1 / aapp;
  1048. temp1 = f2cmin(d__1,d__2);
  1049. /* AAQQ = AAQQ*TEMP1 */
  1050. /* AAPP = AAPP*TEMP1 */
  1051. } else if (aaqq <= sn && aapp <= temp1) {
  1052. /* Computing MIN */
  1053. d__1 = sn / aaqq, d__2 = big / (aapp * sqrt((doublereal) (*n)));
  1054. temp1 = f2cmin(d__1,d__2);
  1055. /* AAQQ = AAQQ*TEMP1 */
  1056. /* AAPP = AAPP*TEMP1 */
  1057. } else if (aaqq >= sn && aapp >= temp1) {
  1058. /* Computing MAX */
  1059. d__1 = sn / aaqq, d__2 = temp1 / aapp;
  1060. temp1 = f2cmax(d__1,d__2);
  1061. /* AAQQ = AAQQ*TEMP1 */
  1062. /* AAPP = AAPP*TEMP1 */
  1063. } else if (aaqq <= sn && aapp >= temp1) {
  1064. /* Computing MIN */
  1065. d__1 = sn / aaqq, d__2 = big / (sqrt((doublereal) (*n)) * aapp);
  1066. temp1 = f2cmin(d__1,d__2);
  1067. /* AAQQ = AAQQ*TEMP1 */
  1068. /* AAPP = AAPP*TEMP1 */
  1069. } else {
  1070. temp1 = 1.;
  1071. }
  1072. /* Scale, if necessary */
  1073. if (temp1 != 1.) {
  1074. dlascl_("G", &c__0, &c__0, &c_b18, &temp1, n, &c__1, &sva[1], n, &
  1075. ierr);
  1076. }
  1077. skl = temp1 * skl;
  1078. if (skl != 1.) {
  1079. dlascl_(joba, &c__0, &c__0, &c_b18, &skl, m, n, &a[a_offset], lda, &
  1080. ierr);
  1081. skl = 1. / skl;
  1082. }
  1083. /* Row-cyclic Jacobi SVD algorithm with column pivoting */
  1084. emptsw = *n * (*n - 1) / 2;
  1085. notrot = 0;
  1086. fastr[0] = 0.;
  1087. /* A is represented in factored form A = A * diag(WORK), where diag(WORK) */
  1088. /* is initialized to identity. WORK is updated during fast scaled */
  1089. /* rotations. */
  1090. i__1 = *n;
  1091. for (q = 1; q <= i__1; ++q) {
  1092. work[q] = 1.;
  1093. /* L1868: */
  1094. }
  1095. swband = 3;
  1096. /* [TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective */
  1097. /* if DGESVJ is used as a computational routine in the preconditioned */
  1098. /* Jacobi SVD algorithm DGESVJ. For sweeps i=1:SWBAND the procedure */
  1099. /* works on pivots inside a band-like region around the diagonal. */
  1100. /* The boundaries are determined dynamically, based on the number of */
  1101. /* pivots above a threshold. */
  1102. kbl = f2cmin(8,*n);
  1103. /* [TP] KBL is a tuning parameter that defines the tile size in the */
  1104. /* tiling of the p-q loops of pivot pairs. In general, an optimal */
  1105. /* value of KBL depends on the matrix dimensions and on the */
  1106. /* parameters of the computer's memory. */
  1107. nbl = *n / kbl;
  1108. if (nbl * kbl != *n) {
  1109. ++nbl;
  1110. }
  1111. /* Computing 2nd power */
  1112. i__1 = kbl;
  1113. blskip = i__1 * i__1;
  1114. /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
  1115. rowskip = f2cmin(5,kbl);
  1116. /* [TP] ROWSKIP is a tuning parameter. */
  1117. lkahead = 1;
  1118. /* [TP] LKAHEAD is a tuning parameter. */
  1119. /* Quasi block transformations, using the lower (upper) triangular */
  1120. /* structure of the input matrix. The quasi-block-cycling usually */
  1121. /* invokes cubic convergence. Big part of this cycle is done inside */
  1122. /* canonical subspaces of dimensions less than M. */
  1123. /* Computing MAX */
  1124. i__1 = 64, i__2 = kbl << 2;
  1125. if ((lower || upper) && *n > f2cmax(i__1,i__2)) {
  1126. /* [TP] The number of partition levels and the actual partition are */
  1127. /* tuning parameters. */
  1128. n4 = *n / 4;
  1129. n2 = *n / 2;
  1130. n34 = n4 * 3;
  1131. if (applv) {
  1132. q = 0;
  1133. } else {
  1134. q = 1;
  1135. }
  1136. if (lower) {
  1137. /* This works very well on lower triangular matrices, in particular */
  1138. /* in the framework of the preconditioned Jacobi SVD (xGEJSV). */
  1139. /* The idea is simple: */
  1140. /* [+ 0 0 0] Note that Jacobi transformations of [0 0] */
  1141. /* [+ + 0 0] [0 0] */
  1142. /* [+ + x 0] actually work on [x 0] [x 0] */
  1143. /* [+ + x x] [x x]. [x x] */
  1144. i__1 = *m - n34;
  1145. i__2 = *n - n34;
  1146. i__3 = *lwork - *n;
  1147. dgsvj0_(jobv, &i__1, &i__2, &a[n34 + 1 + (n34 + 1) * a_dim1], lda,
  1148. &work[n34 + 1], &sva[n34 + 1], &mvl, &v[n34 * q + 1 + (
  1149. n34 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &
  1150. work[*n + 1], &i__3, &ierr);
  1151. i__1 = *m - n2;
  1152. i__2 = n34 - n2;
  1153. i__3 = *lwork - *n;
  1154. dgsvj0_(jobv, &i__1, &i__2, &a[n2 + 1 + (n2 + 1) * a_dim1], lda, &
  1155. work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1)
  1156. * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &work[*n +
  1157. 1], &i__3, &ierr);
  1158. i__1 = *m - n2;
  1159. i__2 = *n - n2;
  1160. i__3 = *lwork - *n;
  1161. dgsvj1_(jobv, &i__1, &i__2, &n4, &a[n2 + 1 + (n2 + 1) * a_dim1],
  1162. lda, &work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (
  1163. n2 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &
  1164. work[*n + 1], &i__3, &ierr);
  1165. i__1 = *m - n4;
  1166. i__2 = n2 - n4;
  1167. i__3 = *lwork - *n;
  1168. dgsvj0_(jobv, &i__1, &i__2, &a[n4 + 1 + (n4 + 1) * a_dim1], lda, &
  1169. work[n4 + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1)
  1170. * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n +
  1171. 1], &i__3, &ierr);
  1172. i__1 = *lwork - *n;
  1173. dgsvj0_(jobv, m, &n4, &a[a_offset], lda, &work[1], &sva[1], &mvl,
  1174. &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n
  1175. + 1], &i__1, &ierr);
  1176. i__1 = *lwork - *n;
  1177. dgsvj1_(jobv, m, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1], &
  1178. mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
  1179. work[*n + 1], &i__1, &ierr);
  1180. } else if (upper) {
  1181. i__1 = *lwork - *n;
  1182. dgsvj0_(jobv, &n4, &n4, &a[a_offset], lda, &work[1], &sva[1], &
  1183. mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__2, &
  1184. work[*n + 1], &i__1, &ierr);
  1185. i__1 = *lwork - *n;
  1186. dgsvj0_(jobv, &n2, &n4, &a[(n4 + 1) * a_dim1 + 1], lda, &work[n4
  1187. + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1) *
  1188. v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
  1189. &i__1, &ierr);
  1190. i__1 = *lwork - *n;
  1191. dgsvj1_(jobv, &n2, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1],
  1192. &mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
  1193. work[*n + 1], &i__1, &ierr);
  1194. i__1 = n2 + n4;
  1195. i__2 = *lwork - *n;
  1196. dgsvj0_(jobv, &i__1, &n4, &a[(n2 + 1) * a_dim1 + 1], lda, &work[
  1197. n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1) *
  1198. v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
  1199. &i__2, &ierr);
  1200. }
  1201. }
  1202. for (i__ = 1; i__ <= 30; ++i__) {
  1203. mxaapq = 0.;
  1204. mxsinj = 0.;
  1205. iswrot = 0;
  1206. notrot = 0;
  1207. pskipped = 0;
  1208. /* Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs */
  1209. /* 1 <= p < q <= N. This is the first step toward a blocked implementation */
  1210. /* of the rotations. New implementation, based on block transformations, */
  1211. /* is under development. */
  1212. i__1 = nbl;
  1213. for (ibr = 1; ibr <= i__1; ++ibr) {
  1214. igl = (ibr - 1) * kbl + 1;
  1215. /* Computing MIN */
  1216. i__3 = lkahead, i__4 = nbl - ibr;
  1217. i__2 = f2cmin(i__3,i__4);
  1218. for (ir1 = 0; ir1 <= i__2; ++ir1) {
  1219. igl += ir1 * kbl;
  1220. /* Computing MIN */
  1221. i__4 = igl + kbl - 1, i__5 = *n - 1;
  1222. i__3 = f2cmin(i__4,i__5);
  1223. for (p = igl; p <= i__3; ++p) {
  1224. i__4 = *n - p + 1;
  1225. q = idamax_(&i__4, &sva[p], &c__1) + p - 1;
  1226. if (p != q) {
  1227. dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 +
  1228. 1], &c__1);
  1229. if (rsvec) {
  1230. dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1231. v_dim1 + 1], &c__1);
  1232. }
  1233. temp1 = sva[p];
  1234. sva[p] = sva[q];
  1235. sva[q] = temp1;
  1236. temp1 = work[p];
  1237. work[p] = work[q];
  1238. work[q] = temp1;
  1239. }
  1240. if (ir1 == 0) {
  1241. /* Column norms are periodically updated by explicit */
  1242. /* norm computation. */
  1243. /* Caveat: */
  1244. /* Unfortunately, some BLAS implementations compute DNRM2(M,A(1,p),1) */
  1245. /* as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to */
  1246. /* overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and to */
  1247. /* underflow for ||A(:,p)||_2 < DSQRT(underflow_threshold). */
  1248. /* Hence, DNRM2 cannot be trusted, not even in the case when */
  1249. /* the true norm is far from the under(over)flow boundaries. */
  1250. /* If properly implemented DNRM2 is available, the IF-THEN-ELSE */
  1251. /* below should read "AAPP = DNRM2( M, A(1,p), 1 ) * WORK(p)". */
  1252. if (sva[p] < rootbig && sva[p] > rootsfmin) {
  1253. sva[p] = dnrm2_(m, &a[p * a_dim1 + 1], &c__1) *
  1254. work[p];
  1255. } else {
  1256. temp1 = 0.;
  1257. aapp = 1.;
  1258. dlassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
  1259. aapp);
  1260. sva[p] = temp1 * sqrt(aapp) * work[p];
  1261. }
  1262. aapp = sva[p];
  1263. } else {
  1264. aapp = sva[p];
  1265. }
  1266. if (aapp > 0.) {
  1267. pskipped = 0;
  1268. /* Computing MIN */
  1269. i__5 = igl + kbl - 1;
  1270. i__4 = f2cmin(i__5,*n);
  1271. for (q = p + 1; q <= i__4; ++q) {
  1272. aaqq = sva[q];
  1273. if (aaqq > 0.) {
  1274. aapp0 = aapp;
  1275. if (aaqq >= 1.) {
  1276. rotok = small * aapp <= aaqq;
  1277. if (aapp < big / aaqq) {
  1278. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1279. c__1, &a[q * a_dim1 + 1], &
  1280. c__1) * work[p] * work[q] /
  1281. aaqq / aapp;
  1282. } else {
  1283. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1284. work[*n + 1], &c__1);
  1285. dlascl_("G", &c__0, &c__0, &aapp, &
  1286. work[p], m, &c__1, &work[*n +
  1287. 1], lda, &ierr);
  1288. aapq = ddot_(m, &work[*n + 1], &c__1,
  1289. &a[q * a_dim1 + 1], &c__1) *
  1290. work[q] / aaqq;
  1291. }
  1292. } else {
  1293. rotok = aapp <= aaqq / small;
  1294. if (aapp > small / aaqq) {
  1295. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1296. c__1, &a[q * a_dim1 + 1], &
  1297. c__1) * work[p] * work[q] /
  1298. aaqq / aapp;
  1299. } else {
  1300. dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1301. work[*n + 1], &c__1);
  1302. dlascl_("G", &c__0, &c__0, &aaqq, &
  1303. work[q], m, &c__1, &work[*n +
  1304. 1], lda, &ierr);
  1305. aapq = ddot_(m, &work[*n + 1], &c__1,
  1306. &a[p * a_dim1 + 1], &c__1) *
  1307. work[p] / aapp;
  1308. }
  1309. }
  1310. /* Computing MAX */
  1311. d__1 = mxaapq, d__2 = abs(aapq);
  1312. mxaapq = f2cmax(d__1,d__2);
  1313. /* TO rotate or NOT to rotate, THAT is the question ... */
  1314. if (abs(aapq) > tol) {
  1315. /* [RTD] ROTATED = ROTATED + ONE */
  1316. if (ir1 == 0) {
  1317. notrot = 0;
  1318. pskipped = 0;
  1319. ++iswrot;
  1320. }
  1321. if (rotok) {
  1322. aqoap = aaqq / aapp;
  1323. apoaq = aapp / aaqq;
  1324. theta = (d__1 = aqoap - apoaq, abs(
  1325. d__1)) * -.5 / aapq;
  1326. if (abs(theta) > bigtheta) {
  1327. t = .5 / theta;
  1328. fastr[2] = t * work[p] / work[q];
  1329. fastr[3] = -t * work[q] / work[p];
  1330. drotm_(m, &a[p * a_dim1 + 1], &
  1331. c__1, &a[q * a_dim1 + 1],
  1332. &c__1, fastr);
  1333. if (rsvec) {
  1334. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1335. v_dim1 + 1], &c__1, fastr);
  1336. }
  1337. /* Computing MAX */
  1338. d__1 = 0., d__2 = t * apoaq *
  1339. aapq + 1.;
  1340. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1341. d__2)));
  1342. /* Computing MAX */
  1343. d__1 = 0., d__2 = 1. - t * aqoap *
  1344. aapq;
  1345. aapp *= sqrt((f2cmax(d__1,d__2)));
  1346. /* Computing MAX */
  1347. d__1 = mxsinj, d__2 = abs(t);
  1348. mxsinj = f2cmax(d__1,d__2);
  1349. } else {
  1350. thsign = -d_sign(&c_b18, &aapq);
  1351. t = 1. / (theta + thsign * sqrt(
  1352. theta * theta + 1.));
  1353. cs = sqrt(1. / (t * t + 1.));
  1354. sn = t * cs;
  1355. /* Computing MAX */
  1356. d__1 = mxsinj, d__2 = abs(sn);
  1357. mxsinj = f2cmax(d__1,d__2);
  1358. /* Computing MAX */
  1359. d__1 = 0., d__2 = t * apoaq *
  1360. aapq + 1.;
  1361. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1362. d__2)));
  1363. /* Computing MAX */
  1364. d__1 = 0., d__2 = 1. - t * aqoap *
  1365. aapq;
  1366. aapp *= sqrt((f2cmax(d__1,d__2)));
  1367. apoaq = work[p] / work[q];
  1368. aqoap = work[q] / work[p];
  1369. if (work[p] >= 1.) {
  1370. if (work[q] >= 1.) {
  1371. fastr[2] = t * apoaq;
  1372. fastr[3] = -t * aqoap;
  1373. work[p] *= cs;
  1374. work[q] *= cs;
  1375. drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1376. a_dim1 + 1], &c__1, fastr);
  1377. if (rsvec) {
  1378. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1379. q * v_dim1 + 1], &c__1, fastr);
  1380. }
  1381. } else {
  1382. d__1 = -t * aqoap;
  1383. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1384. p * a_dim1 + 1], &c__1);
  1385. d__1 = cs * sn * apoaq;
  1386. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1387. q * a_dim1 + 1], &c__1);
  1388. work[p] *= cs;
  1389. work[q] /= cs;
  1390. if (rsvec) {
  1391. d__1 = -t * aqoap;
  1392. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1393. c__1, &v[p * v_dim1 + 1], &c__1);
  1394. d__1 = cs * sn * apoaq;
  1395. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1396. c__1, &v[q * v_dim1 + 1], &c__1);
  1397. }
  1398. }
  1399. } else {
  1400. if (work[q] >= 1.) {
  1401. d__1 = t * apoaq;
  1402. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1403. q * a_dim1 + 1], &c__1);
  1404. d__1 = -cs * sn * aqoap;
  1405. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1406. p * a_dim1 + 1], &c__1);
  1407. work[p] /= cs;
  1408. work[q] *= cs;
  1409. if (rsvec) {
  1410. d__1 = t * apoaq;
  1411. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1412. c__1, &v[q * v_dim1 + 1], &c__1);
  1413. d__1 = -cs * sn * aqoap;
  1414. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1415. c__1, &v[p * v_dim1 + 1], &c__1);
  1416. }
  1417. } else {
  1418. if (work[p] >= work[q]) {
  1419. d__1 = -t * aqoap;
  1420. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1421. &a[p * a_dim1 + 1], &c__1);
  1422. d__1 = cs * sn * apoaq;
  1423. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1424. &a[q * a_dim1 + 1], &c__1);
  1425. work[p] *= cs;
  1426. work[q] /= cs;
  1427. if (rsvec) {
  1428. d__1 = -t * aqoap;
  1429. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1430. &c__1, &v[p * v_dim1 + 1], &
  1431. c__1);
  1432. d__1 = cs * sn * apoaq;
  1433. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1434. &c__1, &v[q * v_dim1 + 1], &
  1435. c__1);
  1436. }
  1437. } else {
  1438. d__1 = t * apoaq;
  1439. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1440. &a[q * a_dim1 + 1], &c__1);
  1441. d__1 = -cs * sn * aqoap;
  1442. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1443. &a[p * a_dim1 + 1], &c__1);
  1444. work[p] /= cs;
  1445. work[q] *= cs;
  1446. if (rsvec) {
  1447. d__1 = t * apoaq;
  1448. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1449. &c__1, &v[q * v_dim1 + 1], &
  1450. c__1);
  1451. d__1 = -cs * sn * aqoap;
  1452. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1453. &c__1, &v[p * v_dim1 + 1], &
  1454. c__1);
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. } else {
  1461. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1462. work[*n + 1], &c__1);
  1463. dlascl_("G", &c__0, &c__0, &aapp, &
  1464. c_b18, m, &c__1, &work[*n + 1]
  1465. , lda, &ierr);
  1466. dlascl_("G", &c__0, &c__0, &aaqq, &
  1467. c_b18, m, &c__1, &a[q *
  1468. a_dim1 + 1], lda, &ierr);
  1469. temp1 = -aapq * work[p] / work[q];
  1470. daxpy_(m, &temp1, &work[*n + 1], &
  1471. c__1, &a[q * a_dim1 + 1], &
  1472. c__1);
  1473. dlascl_("G", &c__0, &c__0, &c_b18, &
  1474. aaqq, m, &c__1, &a[q * a_dim1
  1475. + 1], lda, &ierr);
  1476. /* Computing MAX */
  1477. d__1 = 0., d__2 = 1. - aapq * aapq;
  1478. sva[q] = aaqq * sqrt((f2cmax(d__1,d__2)))
  1479. ;
  1480. mxsinj = f2cmax(mxsinj,sfmin);
  1481. }
  1482. /* END IF ROTOK THEN ... ELSE */
  1483. /* In the case of cancellation in updating SVA(q), SVA(p) */
  1484. /* recompute SVA(q), SVA(p). */
  1485. /* Computing 2nd power */
  1486. d__1 = sva[q] / aaqq;
  1487. if (d__1 * d__1 <= rooteps) {
  1488. if (aaqq < rootbig && aaqq >
  1489. rootsfmin) {
  1490. sva[q] = dnrm2_(m, &a[q * a_dim1
  1491. + 1], &c__1) * work[q];
  1492. } else {
  1493. t = 0.;
  1494. aaqq = 1.;
  1495. dlassq_(m, &a[q * a_dim1 + 1], &
  1496. c__1, &t, &aaqq);
  1497. sva[q] = t * sqrt(aaqq) * work[q];
  1498. }
  1499. }
  1500. if (aapp / aapp0 <= rooteps) {
  1501. if (aapp < rootbig && aapp >
  1502. rootsfmin) {
  1503. aapp = dnrm2_(m, &a[p * a_dim1 +
  1504. 1], &c__1) * work[p];
  1505. } else {
  1506. t = 0.;
  1507. aapp = 1.;
  1508. dlassq_(m, &a[p * a_dim1 + 1], &
  1509. c__1, &t, &aapp);
  1510. aapp = t * sqrt(aapp) * work[p];
  1511. }
  1512. sva[p] = aapp;
  1513. }
  1514. } else {
  1515. /* A(:,p) and A(:,q) already numerically orthogonal */
  1516. if (ir1 == 0) {
  1517. ++notrot;
  1518. }
  1519. /* [RTD] SKIPPED = SKIPPED + 1 */
  1520. ++pskipped;
  1521. }
  1522. } else {
  1523. /* A(:,q) is zero column */
  1524. if (ir1 == 0) {
  1525. ++notrot;
  1526. }
  1527. ++pskipped;
  1528. }
  1529. if (i__ <= swband && pskipped > rowskip) {
  1530. if (ir1 == 0) {
  1531. aapp = -aapp;
  1532. }
  1533. notrot = 0;
  1534. goto L2103;
  1535. }
  1536. /* L2002: */
  1537. }
  1538. /* END q-LOOP */
  1539. L2103:
  1540. /* bailed out of q-loop */
  1541. sva[p] = aapp;
  1542. } else {
  1543. sva[p] = aapp;
  1544. if (ir1 == 0 && aapp == 0.) {
  1545. /* Computing MIN */
  1546. i__4 = igl + kbl - 1;
  1547. notrot = notrot + f2cmin(i__4,*n) - p;
  1548. }
  1549. }
  1550. /* L2001: */
  1551. }
  1552. /* end of the p-loop */
  1553. /* end of doing the block ( ibr, ibr ) */
  1554. /* L1002: */
  1555. }
  1556. /* end of ir1-loop */
  1557. /* ... go to the off diagonal blocks */
  1558. igl = (ibr - 1) * kbl + 1;
  1559. i__2 = nbl;
  1560. for (jbc = ibr + 1; jbc <= i__2; ++jbc) {
  1561. jgl = (jbc - 1) * kbl + 1;
  1562. /* doing the block at ( ibr, jbc ) */
  1563. ijblsk = 0;
  1564. /* Computing MIN */
  1565. i__4 = igl + kbl - 1;
  1566. i__3 = f2cmin(i__4,*n);
  1567. for (p = igl; p <= i__3; ++p) {
  1568. aapp = sva[p];
  1569. if (aapp > 0.) {
  1570. pskipped = 0;
  1571. /* Computing MIN */
  1572. i__5 = jgl + kbl - 1;
  1573. i__4 = f2cmin(i__5,*n);
  1574. for (q = jgl; q <= i__4; ++q) {
  1575. aaqq = sva[q];
  1576. if (aaqq > 0.) {
  1577. aapp0 = aapp;
  1578. /* Safe Gram matrix computation */
  1579. if (aaqq >= 1.) {
  1580. if (aapp >= aaqq) {
  1581. rotok = small * aapp <= aaqq;
  1582. } else {
  1583. rotok = small * aaqq <= aapp;
  1584. }
  1585. if (aapp < big / aaqq) {
  1586. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1587. c__1, &a[q * a_dim1 + 1], &
  1588. c__1) * work[p] * work[q] /
  1589. aaqq / aapp;
  1590. } else {
  1591. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1592. work[*n + 1], &c__1);
  1593. dlascl_("G", &c__0, &c__0, &aapp, &
  1594. work[p], m, &c__1, &work[*n +
  1595. 1], lda, &ierr);
  1596. aapq = ddot_(m, &work[*n + 1], &c__1,
  1597. &a[q * a_dim1 + 1], &c__1) *
  1598. work[q] / aaqq;
  1599. }
  1600. } else {
  1601. if (aapp >= aaqq) {
  1602. rotok = aapp <= aaqq / small;
  1603. } else {
  1604. rotok = aaqq <= aapp / small;
  1605. }
  1606. if (aapp > small / aaqq) {
  1607. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1608. c__1, &a[q * a_dim1 + 1], &
  1609. c__1) * work[p] * work[q] /
  1610. aaqq / aapp;
  1611. } else {
  1612. dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1613. work[*n + 1], &c__1);
  1614. dlascl_("G", &c__0, &c__0, &aaqq, &
  1615. work[q], m, &c__1, &work[*n +
  1616. 1], lda, &ierr);
  1617. aapq = ddot_(m, &work[*n + 1], &c__1,
  1618. &a[p * a_dim1 + 1], &c__1) *
  1619. work[p] / aapp;
  1620. }
  1621. }
  1622. /* Computing MAX */
  1623. d__1 = mxaapq, d__2 = abs(aapq);
  1624. mxaapq = f2cmax(d__1,d__2);
  1625. /* TO rotate or NOT to rotate, THAT is the question ... */
  1626. if (abs(aapq) > tol) {
  1627. notrot = 0;
  1628. /* [RTD] ROTATED = ROTATED + 1 */
  1629. pskipped = 0;
  1630. ++iswrot;
  1631. if (rotok) {
  1632. aqoap = aaqq / aapp;
  1633. apoaq = aapp / aaqq;
  1634. theta = (d__1 = aqoap - apoaq, abs(
  1635. d__1)) * -.5 / aapq;
  1636. if (aaqq > aapp0) {
  1637. theta = -theta;
  1638. }
  1639. if (abs(theta) > bigtheta) {
  1640. t = .5 / theta;
  1641. fastr[2] = t * work[p] / work[q];
  1642. fastr[3] = -t * work[q] / work[p];
  1643. drotm_(m, &a[p * a_dim1 + 1], &
  1644. c__1, &a[q * a_dim1 + 1],
  1645. &c__1, fastr);
  1646. if (rsvec) {
  1647. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1648. v_dim1 + 1], &c__1, fastr);
  1649. }
  1650. /* Computing MAX */
  1651. d__1 = 0., d__2 = t * apoaq *
  1652. aapq + 1.;
  1653. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1654. d__2)));
  1655. /* Computing MAX */
  1656. d__1 = 0., d__2 = 1. - t * aqoap *
  1657. aapq;
  1658. aapp *= sqrt((f2cmax(d__1,d__2)));
  1659. /* Computing MAX */
  1660. d__1 = mxsinj, d__2 = abs(t);
  1661. mxsinj = f2cmax(d__1,d__2);
  1662. } else {
  1663. thsign = -d_sign(&c_b18, &aapq);
  1664. if (aaqq > aapp0) {
  1665. thsign = -thsign;
  1666. }
  1667. t = 1. / (theta + thsign * sqrt(
  1668. theta * theta + 1.));
  1669. cs = sqrt(1. / (t * t + 1.));
  1670. sn = t * cs;
  1671. /* Computing MAX */
  1672. d__1 = mxsinj, d__2 = abs(sn);
  1673. mxsinj = f2cmax(d__1,d__2);
  1674. /* Computing MAX */
  1675. d__1 = 0., d__2 = t * apoaq *
  1676. aapq + 1.;
  1677. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1678. d__2)));
  1679. /* Computing MAX */
  1680. d__1 = 0., d__2 = 1. - t * aqoap *
  1681. aapq;
  1682. aapp *= sqrt((f2cmax(d__1,d__2)));
  1683. apoaq = work[p] / work[q];
  1684. aqoap = work[q] / work[p];
  1685. if (work[p] >= 1.) {
  1686. if (work[q] >= 1.) {
  1687. fastr[2] = t * apoaq;
  1688. fastr[3] = -t * aqoap;
  1689. work[p] *= cs;
  1690. work[q] *= cs;
  1691. drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1692. a_dim1 + 1], &c__1, fastr);
  1693. if (rsvec) {
  1694. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1695. q * v_dim1 + 1], &c__1, fastr);
  1696. }
  1697. } else {
  1698. d__1 = -t * aqoap;
  1699. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1700. p * a_dim1 + 1], &c__1);
  1701. d__1 = cs * sn * apoaq;
  1702. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1703. q * a_dim1 + 1], &c__1);
  1704. if (rsvec) {
  1705. d__1 = -t * aqoap;
  1706. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1707. c__1, &v[p * v_dim1 + 1], &c__1);
  1708. d__1 = cs * sn * apoaq;
  1709. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1710. c__1, &v[q * v_dim1 + 1], &c__1);
  1711. }
  1712. work[p] *= cs;
  1713. work[q] /= cs;
  1714. }
  1715. } else {
  1716. if (work[q] >= 1.) {
  1717. d__1 = t * apoaq;
  1718. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1719. q * a_dim1 + 1], &c__1);
  1720. d__1 = -cs * sn * aqoap;
  1721. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1722. p * a_dim1 + 1], &c__1);
  1723. if (rsvec) {
  1724. d__1 = t * apoaq;
  1725. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1726. c__1, &v[q * v_dim1 + 1], &c__1);
  1727. d__1 = -cs * sn * aqoap;
  1728. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1729. c__1, &v[p * v_dim1 + 1], &c__1);
  1730. }
  1731. work[p] /= cs;
  1732. work[q] *= cs;
  1733. } else {
  1734. if (work[p] >= work[q]) {
  1735. d__1 = -t * aqoap;
  1736. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1737. &a[p * a_dim1 + 1], &c__1);
  1738. d__1 = cs * sn * apoaq;
  1739. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1740. &a[q * a_dim1 + 1], &c__1);
  1741. work[p] *= cs;
  1742. work[q] /= cs;
  1743. if (rsvec) {
  1744. d__1 = -t * aqoap;
  1745. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1746. &c__1, &v[p * v_dim1 + 1], &
  1747. c__1);
  1748. d__1 = cs * sn * apoaq;
  1749. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1750. &c__1, &v[q * v_dim1 + 1], &
  1751. c__1);
  1752. }
  1753. } else {
  1754. d__1 = t * apoaq;
  1755. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1756. &a[q * a_dim1 + 1], &c__1);
  1757. d__1 = -cs * sn * aqoap;
  1758. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1759. &a[p * a_dim1 + 1], &c__1);
  1760. work[p] /= cs;
  1761. work[q] *= cs;
  1762. if (rsvec) {
  1763. d__1 = t * apoaq;
  1764. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1765. &c__1, &v[q * v_dim1 + 1], &
  1766. c__1);
  1767. d__1 = -cs * sn * aqoap;
  1768. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1769. &c__1, &v[p * v_dim1 + 1], &
  1770. c__1);
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. } else {
  1777. if (aapp > aaqq) {
  1778. dcopy_(m, &a[p * a_dim1 + 1], &
  1779. c__1, &work[*n + 1], &
  1780. c__1);
  1781. dlascl_("G", &c__0, &c__0, &aapp,
  1782. &c_b18, m, &c__1, &work[*
  1783. n + 1], lda, &ierr);
  1784. dlascl_("G", &c__0, &c__0, &aaqq,
  1785. &c_b18, m, &c__1, &a[q *
  1786. a_dim1 + 1], lda, &ierr);
  1787. temp1 = -aapq * work[p] / work[q];
  1788. daxpy_(m, &temp1, &work[*n + 1], &
  1789. c__1, &a[q * a_dim1 + 1],
  1790. &c__1);
  1791. dlascl_("G", &c__0, &c__0, &c_b18,
  1792. &aaqq, m, &c__1, &a[q *
  1793. a_dim1 + 1], lda, &ierr);
  1794. /* Computing MAX */
  1795. d__1 = 0., d__2 = 1. - aapq *
  1796. aapq;
  1797. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1798. d__2)));
  1799. mxsinj = f2cmax(mxsinj,sfmin);
  1800. } else {
  1801. dcopy_(m, &a[q * a_dim1 + 1], &
  1802. c__1, &work[*n + 1], &
  1803. c__1);
  1804. dlascl_("G", &c__0, &c__0, &aaqq,
  1805. &c_b18, m, &c__1, &work[*
  1806. n + 1], lda, &ierr);
  1807. dlascl_("G", &c__0, &c__0, &aapp,
  1808. &c_b18, m, &c__1, &a[p *
  1809. a_dim1 + 1], lda, &ierr);
  1810. temp1 = -aapq * work[q] / work[p];
  1811. daxpy_(m, &temp1, &work[*n + 1], &
  1812. c__1, &a[p * a_dim1 + 1],
  1813. &c__1);
  1814. dlascl_("G", &c__0, &c__0, &c_b18,
  1815. &aapp, m, &c__1, &a[p *
  1816. a_dim1 + 1], lda, &ierr);
  1817. /* Computing MAX */
  1818. d__1 = 0., d__2 = 1. - aapq *
  1819. aapq;
  1820. sva[p] = aapp * sqrt((f2cmax(d__1,
  1821. d__2)));
  1822. mxsinj = f2cmax(mxsinj,sfmin);
  1823. }
  1824. }
  1825. /* END IF ROTOK THEN ... ELSE */
  1826. /* In the case of cancellation in updating SVA(q) */
  1827. /* Computing 2nd power */
  1828. d__1 = sva[q] / aaqq;
  1829. if (d__1 * d__1 <= rooteps) {
  1830. if (aaqq < rootbig && aaqq >
  1831. rootsfmin) {
  1832. sva[q] = dnrm2_(m, &a[q * a_dim1
  1833. + 1], &c__1) * work[q];
  1834. } else {
  1835. t = 0.;
  1836. aaqq = 1.;
  1837. dlassq_(m, &a[q * a_dim1 + 1], &
  1838. c__1, &t, &aaqq);
  1839. sva[q] = t * sqrt(aaqq) * work[q];
  1840. }
  1841. }
  1842. /* Computing 2nd power */
  1843. d__1 = aapp / aapp0;
  1844. if (d__1 * d__1 <= rooteps) {
  1845. if (aapp < rootbig && aapp >
  1846. rootsfmin) {
  1847. aapp = dnrm2_(m, &a[p * a_dim1 +
  1848. 1], &c__1) * work[p];
  1849. } else {
  1850. t = 0.;
  1851. aapp = 1.;
  1852. dlassq_(m, &a[p * a_dim1 + 1], &
  1853. c__1, &t, &aapp);
  1854. aapp = t * sqrt(aapp) * work[p];
  1855. }
  1856. sva[p] = aapp;
  1857. }
  1858. /* end of OK rotation */
  1859. } else {
  1860. ++notrot;
  1861. /* [RTD] SKIPPED = SKIPPED + 1 */
  1862. ++pskipped;
  1863. ++ijblsk;
  1864. }
  1865. } else {
  1866. ++notrot;
  1867. ++pskipped;
  1868. ++ijblsk;
  1869. }
  1870. if (i__ <= swband && ijblsk >= blskip) {
  1871. sva[p] = aapp;
  1872. notrot = 0;
  1873. goto L2011;
  1874. }
  1875. if (i__ <= swband && pskipped > rowskip) {
  1876. aapp = -aapp;
  1877. notrot = 0;
  1878. goto L2203;
  1879. }
  1880. /* L2200: */
  1881. }
  1882. /* end of the q-loop */
  1883. L2203:
  1884. sva[p] = aapp;
  1885. } else {
  1886. if (aapp == 0.) {
  1887. /* Computing MIN */
  1888. i__4 = jgl + kbl - 1;
  1889. notrot = notrot + f2cmin(i__4,*n) - jgl + 1;
  1890. }
  1891. if (aapp < 0.) {
  1892. notrot = 0;
  1893. }
  1894. }
  1895. /* L2100: */
  1896. }
  1897. /* end of the p-loop */
  1898. /* L2010: */
  1899. }
  1900. /* end of the jbc-loop */
  1901. L2011:
  1902. /* 2011 bailed out of the jbc-loop */
  1903. /* Computing MIN */
  1904. i__3 = igl + kbl - 1;
  1905. i__2 = f2cmin(i__3,*n);
  1906. for (p = igl; p <= i__2; ++p) {
  1907. sva[p] = (d__1 = sva[p], abs(d__1));
  1908. /* L2012: */
  1909. }
  1910. /* ** */
  1911. /* L2000: */
  1912. }
  1913. /* 2000 :: end of the ibr-loop */
  1914. if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
  1915. sva[*n] = dnrm2_(m, &a[*n * a_dim1 + 1], &c__1) * work[*n];
  1916. } else {
  1917. t = 0.;
  1918. aapp = 1.;
  1919. dlassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
  1920. sva[*n] = t * sqrt(aapp) * work[*n];
  1921. }
  1922. /* Additional steering devices */
  1923. if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
  1924. swband = i__;
  1925. }
  1926. if (i__ > swband + 1 && mxaapq < sqrt((doublereal) (*n)) * tol && (
  1927. doublereal) (*n) * mxaapq * mxsinj < tol) {
  1928. goto L1994;
  1929. }
  1930. if (notrot >= emptsw) {
  1931. goto L1994;
  1932. }
  1933. /* L1993: */
  1934. }
  1935. /* end i=1:NSWEEP loop */
  1936. /* #:( Reaching this point means that the procedure has not converged. */
  1937. *info = 29;
  1938. goto L1995;
  1939. L1994:
  1940. /* #:) Reaching this point means numerical convergence after the i-th */
  1941. /* sweep. */
  1942. *info = 0;
  1943. /* #:) INFO = 0 confirms successful iterations. */
  1944. L1995:
  1945. /* Sort the singular values and find how many are above */
  1946. /* the underflow threshold. */
  1947. n2 = 0;
  1948. n4 = 0;
  1949. i__1 = *n - 1;
  1950. for (p = 1; p <= i__1; ++p) {
  1951. i__2 = *n - p + 1;
  1952. q = idamax_(&i__2, &sva[p], &c__1) + p - 1;
  1953. if (p != q) {
  1954. temp1 = sva[p];
  1955. sva[p] = sva[q];
  1956. sva[q] = temp1;
  1957. temp1 = work[p];
  1958. work[p] = work[q];
  1959. work[q] = temp1;
  1960. dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
  1961. if (rsvec) {
  1962. dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
  1963. c__1);
  1964. }
  1965. }
  1966. if (sva[p] != 0.) {
  1967. ++n4;
  1968. if (sva[p] * skl > sfmin) {
  1969. ++n2;
  1970. }
  1971. }
  1972. /* L5991: */
  1973. }
  1974. if (sva[*n] != 0.) {
  1975. ++n4;
  1976. if (sva[*n] * skl > sfmin) {
  1977. ++n2;
  1978. }
  1979. }
  1980. /* Normalize the left singular vectors. */
  1981. if (lsvec || uctol) {
  1982. i__1 = n2;
  1983. for (p = 1; p <= i__1; ++p) {
  1984. d__1 = work[p] / sva[p];
  1985. dscal_(m, &d__1, &a[p * a_dim1 + 1], &c__1);
  1986. /* L1998: */
  1987. }
  1988. }
  1989. /* Scale the product of Jacobi rotations (assemble the fast rotations). */
  1990. if (rsvec) {
  1991. if (applv) {
  1992. i__1 = *n;
  1993. for (p = 1; p <= i__1; ++p) {
  1994. dscal_(&mvl, &work[p], &v[p * v_dim1 + 1], &c__1);
  1995. /* L2398: */
  1996. }
  1997. } else {
  1998. i__1 = *n;
  1999. for (p = 1; p <= i__1; ++p) {
  2000. temp1 = 1. / dnrm2_(&mvl, &v[p * v_dim1 + 1], &c__1);
  2001. dscal_(&mvl, &temp1, &v[p * v_dim1 + 1], &c__1);
  2002. /* L2399: */
  2003. }
  2004. }
  2005. }
  2006. /* Undo scaling, if necessary (and possible). */
  2007. if (skl > 1. && sva[1] < big / skl || skl < 1. && sva[f2cmax(n2,1)] > sfmin /
  2008. skl) {
  2009. i__1 = *n;
  2010. for (p = 1; p <= i__1; ++p) {
  2011. sva[p] = skl * sva[p];
  2012. /* L2400: */
  2013. }
  2014. skl = 1.;
  2015. }
  2016. work[1] = skl;
  2017. /* The singular values of A are SKL*SVA(1:N). If SKL.NE.ONE */
  2018. /* then some of the singular values may overflow or underflow and */
  2019. /* the spectrum is given in this factored representation. */
  2020. work[2] = (doublereal) n4;
  2021. /* N4 is the number of computed nonzero singular values of A. */
  2022. work[3] = (doublereal) n2;
  2023. /* N2 is the number of singular values of A greater than SFMIN. */
  2024. /* If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers */
  2025. /* that may carry some information. */
  2026. work[4] = (doublereal) i__;
  2027. /* i is the index of the last sweep before declaring convergence. */
  2028. work[5] = mxaapq;
  2029. /* MXAAPQ is the largest absolute value of scaled pivots in the */
  2030. /* last sweep */
  2031. work[6] = mxsinj;
  2032. /* MXSINJ is the largest absolute value of the sines of Jacobi angles */
  2033. /* in the last sweep */
  2034. return 0;
  2035. } /* dgesvj_ */