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 70 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static doublereal c_b17 = 0.;
  485. static doublereal c_b18 = 1.;
  486. static integer c__1 = 1;
  487. static integer c__0 = 0;
  488. static integer c__2 = 2;
  489. /* > \brief \b DGESVJ */
  490. /* =========== DOCUMENTATION =========== */
  491. /* Online html documentation available at */
  492. /* http://www.netlib.org/lapack/explore-html/ */
  493. /* > \htmlonly */
  494. /* > Download DGESVJ + dependencies */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgesvj.
  496. f"> */
  497. /* > [TGZ]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgesvj.
  499. f"> */
  500. /* > [ZIP]</a> */
  501. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgesvj.
  502. f"> */
  503. /* > [TXT]</a> */
  504. /* > \endhtmlonly */
  505. /* Definition: */
  506. /* =========== */
  507. /* SUBROUTINE DGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V, */
  508. /* LDV, WORK, LWORK, INFO ) */
  509. /* INTEGER INFO, LDA, LDV, LWORK, M, MV, N */
  510. /* CHARACTER*1 JOBA, JOBU, JOBV */
  511. /* DOUBLE PRECISION A( LDA, * ), SVA( N ), V( LDV, * ), */
  512. /* $ WORK( LWORK ) */
  513. /* > \par Purpose: */
  514. /* ============= */
  515. /* > */
  516. /* > \verbatim */
  517. /* > */
  518. /* > DGESVJ computes the singular value decomposition (SVD) of a real */
  519. /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
  520. /* > [++] [xx] [x0] [xx] */
  521. /* > A = U * SIGMA * V^t, [++] = [xx] * [ox] * [xx] */
  522. /* > [++] [xx] */
  523. /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
  524. /* > matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
  525. /* > of SIGMA are the singular values of A. The columns of U and V are the */
  526. /* > left and the right singular vectors of A, respectively. */
  527. /* > DGESVJ can sometimes compute tiny singular values and their singular vectors much */
  528. /* > more accurately than other SVD routines, see below under Further Details. */
  529. /* > \endverbatim */
  530. /* Arguments: */
  531. /* ========== */
  532. /* > \param[in] JOBA */
  533. /* > \verbatim */
  534. /* > JOBA is CHARACTER*1 */
  535. /* > Specifies the structure of A. */
  536. /* > = 'L': The input matrix A is lower triangular; */
  537. /* > = 'U': The input matrix A is upper triangular; */
  538. /* > = 'G': The input matrix A is general M-by-N matrix, M >= N. */
  539. /* > \endverbatim */
  540. /* > */
  541. /* > \param[in] JOBU */
  542. /* > \verbatim */
  543. /* > JOBU is CHARACTER*1 */
  544. /* > Specifies whether to compute the left singular vectors */
  545. /* > (columns of U): */
  546. /* > = 'U': The left singular vectors corresponding to the nonzero */
  547. /* > singular values are computed and returned in the leading */
  548. /* > columns of A. See more details in the description of A. */
  549. /* > The default numerical orthogonality threshold is set to */
  550. /* > approximately TOL=CTOL*EPS, CTOL=DSQRT(M), EPS=DLAMCH('E'). */
  551. /* > = 'C': Analogous to JOBU='U', except that user can control the */
  552. /* > level of numerical orthogonality of the computed left */
  553. /* > singular vectors. TOL can be set to TOL = CTOL*EPS, where */
  554. /* > CTOL is given on input in the array WORK. */
  555. /* > No CTOL smaller than ONE is allowed. CTOL greater */
  556. /* > than 1 / EPS is meaningless. The option 'C' */
  557. /* > can be used if M*EPS is satisfactory orthogonality */
  558. /* > of the computed left singular vectors, so CTOL=M could */
  559. /* > save few sweeps of Jacobi rotations. */
  560. /* > See the descriptions of A and WORK(1). */
  561. /* > = 'N': The matrix U is not computed. However, see the */
  562. /* > description of A. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] JOBV */
  566. /* > \verbatim */
  567. /* > JOBV is CHARACTER*1 */
  568. /* > Specifies whether to compute the right singular vectors, that */
  569. /* > is, the matrix V: */
  570. /* > = 'V': the matrix V is computed and returned in the array V */
  571. /* > = 'A': the Jacobi rotations are applied to the MV-by-N */
  572. /* > array V. In other words, the right singular vector */
  573. /* > matrix V is not computed explicitly, instead it is */
  574. /* > applied to an MV-by-N matrix initially stored in the */
  575. /* > first MV rows of V. */
  576. /* > = 'N': the matrix V is not computed and the array V is not */
  577. /* > referenced */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in] M */
  581. /* > \verbatim */
  582. /* > M is INTEGER */
  583. /* > The number of rows of the input matrix A. 1/DLAMCH('E') > M >= 0. */
  584. /* > \endverbatim */
  585. /* > */
  586. /* > \param[in] N */
  587. /* > \verbatim */
  588. /* > N is INTEGER */
  589. /* > The number of columns of the input matrix A. */
  590. /* > M >= N >= 0. */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[in,out] A */
  594. /* > \verbatim */
  595. /* > A is DOUBLE PRECISION array, dimension (LDA,N) */
  596. /* > On entry, the M-by-N matrix A. */
  597. /* > On exit : */
  598. /* > If JOBU = 'U' .OR. JOBU = 'C' : */
  599. /* > If INFO = 0 : */
  600. /* > RANKA orthonormal columns of U are returned in the */
  601. /* > leading RANKA columns of the array A. Here RANKA <= N */
  602. /* > is the number of computed singular values of A that are */
  603. /* > above the underflow threshold DLAMCH('S'). The singular */
  604. /* > vectors corresponding to underflowed or zero singular */
  605. /* > values are not computed. The value of RANKA is returned */
  606. /* > in the array WORK as RANKA=NINT(WORK(2)). Also see the */
  607. /* > descriptions of SVA and WORK. The computed columns of U */
  608. /* > are mutually numerically orthogonal up to approximately */
  609. /* > TOL=DSQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU = 'C'), */
  610. /* > see the description of JOBU. */
  611. /* > If INFO > 0 : */
  612. /* > the procedure DGESVJ did not converge in the given number */
  613. /* > of iterations (sweeps). In that case, the computed */
  614. /* > columns of U may not be orthogonal up to TOL. The output */
  615. /* > U (stored in A), SIGMA (given by the computed singular */
  616. /* > values in SVA(1:N)) and V is still a decomposition of the */
  617. /* > input matrix A in the sense that the residual */
  618. /* > ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small. */
  619. /* > */
  620. /* > If JOBU = 'N' : */
  621. /* > If INFO = 0 : */
  622. /* > Note that the left singular vectors are 'for free' in the */
  623. /* > one-sided Jacobi SVD algorithm. However, if only the */
  624. /* > singular values are needed, the level of numerical */
  625. /* > orthogonality of U is not an issue and iterations are */
  626. /* > stopped when the columns of the iterated matrix are */
  627. /* > numerically orthogonal up to approximately M*EPS. Thus, */
  628. /* > on exit, A contains the columns of U scaled with the */
  629. /* > corresponding singular values. */
  630. /* > If INFO > 0 : */
  631. /* > the procedure DGESVJ did not converge in the given number */
  632. /* > of iterations (sweeps). */
  633. /* > \endverbatim */
  634. /* > */
  635. /* > \param[in] LDA */
  636. /* > \verbatim */
  637. /* > LDA is INTEGER */
  638. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  639. /* > \endverbatim */
  640. /* > */
  641. /* > \param[out] SVA */
  642. /* > \verbatim */
  643. /* > SVA is DOUBLE PRECISION array, dimension (N) */
  644. /* > On exit : */
  645. /* > If INFO = 0 : */
  646. /* > depending on the value SCALE = WORK(1), we have: */
  647. /* > If SCALE = ONE : */
  648. /* > SVA(1:N) contains the computed singular values of A. */
  649. /* > During the computation SVA contains the Euclidean column */
  650. /* > norms of the iterated matrices in the array A. */
  651. /* > If SCALE .NE. ONE : */
  652. /* > The singular values of A are SCALE*SVA(1:N), and this */
  653. /* > factored representation is due to the fact that some of the */
  654. /* > singular values of A might underflow or overflow. */
  655. /* > If INFO > 0 : */
  656. /* > the procedure DGESVJ did not converge in the given number of */
  657. /* > iterations (sweeps) and SCALE*SVA(1:N) may not be accurate. */
  658. /* > \endverbatim */
  659. /* > */
  660. /* > \param[in] MV */
  661. /* > \verbatim */
  662. /* > MV is INTEGER */
  663. /* > If JOBV = 'A', then the product of Jacobi rotations in DGESVJ */
  664. /* > is applied to the first MV rows of V. See the description of JOBV. */
  665. /* > \endverbatim */
  666. /* > */
  667. /* > \param[in,out] V */
  668. /* > \verbatim */
  669. /* > V is DOUBLE PRECISION array, dimension (LDV,N) */
  670. /* > If JOBV = 'V', then V contains on exit the N-by-N matrix of */
  671. /* > the right singular vectors; */
  672. /* > If JOBV = 'A', then V contains the product of the computed right */
  673. /* > singular vector matrix and the initial matrix in */
  674. /* > the array V. */
  675. /* > If JOBV = 'N', then V is not referenced. */
  676. /* > \endverbatim */
  677. /* > */
  678. /* > \param[in] LDV */
  679. /* > \verbatim */
  680. /* > LDV is INTEGER */
  681. /* > The leading dimension of the array V, LDV >= 1. */
  682. /* > If JOBV = 'V', then LDV >= f2cmax(1,N). */
  683. /* > If JOBV = 'A', then LDV >= f2cmax(1,MV) . */
  684. /* > \endverbatim */
  685. /* > */
  686. /* > \param[in,out] WORK */
  687. /* > \verbatim */
  688. /* > WORK is DOUBLE PRECISION array, dimension (LWORK) */
  689. /* > On entry : */
  690. /* > If JOBU = 'C' : */
  691. /* > WORK(1) = CTOL, where CTOL defines the threshold for convergence. */
  692. /* > The process stops if all columns of A are mutually */
  693. /* > orthogonal up to CTOL*EPS, EPS=DLAMCH('E'). */
  694. /* > It is required that CTOL >= ONE, i.e. it is not */
  695. /* > allowed to force the routine to obtain orthogonality */
  696. /* > below EPS. */
  697. /* > On exit : */
  698. /* > WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N) */
  699. /* > are the computed singular values of A. */
  700. /* > (See description of SVA().) */
  701. /* > WORK(2) = NINT(WORK(2)) is the number of the computed nonzero */
  702. /* > singular values. */
  703. /* > WORK(3) = NINT(WORK(3)) is the number of the computed singular */
  704. /* > values that are larger than the underflow threshold. */
  705. /* > WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi */
  706. /* > rotations needed for numerical convergence. */
  707. /* > WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep. */
  708. /* > This is useful information in cases when DGESVJ did */
  709. /* > not converge, as it can be used to estimate whether */
  710. /* > the output is still useful and for post festum analysis. */
  711. /* > WORK(6) = the largest absolute value over all sines of the */
  712. /* > Jacobi rotation angles in the last sweep. It can be */
  713. /* > useful for a post festum analysis. */
  714. /* > \endverbatim */
  715. /* > */
  716. /* > \param[in] LWORK */
  717. /* > \verbatim */
  718. /* > LWORK is INTEGER */
  719. /* > length of WORK, WORK >= MAX(6,M+N) */
  720. /* > \endverbatim */
  721. /* > */
  722. /* > \param[out] INFO */
  723. /* > \verbatim */
  724. /* > INFO is INTEGER */
  725. /* > = 0: successful exit. */
  726. /* > < 0: if INFO = -i, then the i-th argument had an illegal value */
  727. /* > > 0: DGESVJ did not converge in the maximal allowed number (30) */
  728. /* > of sweeps. The output may still be useful. See the */
  729. /* > description of WORK. */
  730. /* > \endverbatim */
  731. /* Authors: */
  732. /* ======== */
  733. /* > \author Univ. of Tennessee */
  734. /* > \author Univ. of California Berkeley */
  735. /* > \author Univ. of Colorado Denver */
  736. /* > \author NAG Ltd. */
  737. /* > \date June 2017 */
  738. /* > \ingroup doubleGEcomputational */
  739. /* > \par Further Details: */
  740. /* ===================== */
  741. /* > */
  742. /* > \verbatim */
  743. /* > */
  744. /* > The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane */
  745. /* > rotations. The rotations are implemented as fast scaled rotations of */
  746. /* > Anda and Park [1]. In the case of underflow of the Jacobi angle, a */
  747. /* > modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses */
  748. /* > column interchanges of de Rijk [2]. The relative accuracy of the computed */
  749. /* > singular values and the accuracy of the computed singular vectors (in */
  750. /* > angle metric) is as guaranteed by the theory of Demmel and Veselic [3]. */
  751. /* > The condition number that determines the accuracy in the full rank case */
  752. /* > is essentially min_{D=diag} kappa(A*D), where kappa(.) is the */
  753. /* > spectral condition number. The best performance of this Jacobi SVD */
  754. /* > procedure is achieved if used in an accelerated version of Drmac and */
  755. /* > Veselic [5,6], and it is the kernel routine in the SIGMA library [7]. */
  756. /* > Some tunning parameters (marked with [TP]) are available for the */
  757. /* > implementer. */
  758. /* > The computational range for the nonzero singular values is the machine */
  759. /* > number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even */
  760. /* > denormalized singular values can be computed with the corresponding */
  761. /* > gradual loss of accurate digits. */
  762. /* > \endverbatim */
  763. /* > \par Contributors: */
  764. /* ================== */
  765. /* > */
  766. /* > \verbatim */
  767. /* > */
  768. /* > ============ */
  769. /* > */
  770. /* > Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
  771. /* > \endverbatim */
  772. /* > \par References: */
  773. /* ================ */
  774. /* > */
  775. /* > \verbatim */
  776. /* > */
  777. /* > [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling. */
  778. /* > SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174. */
  779. /* > [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the */
  780. /* > singular value decomposition on a vector computer. */
  781. /* > SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371. */
  782. /* > [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR. */
  783. /* > [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular */
  784. /* > value computation in floating point arithmetic. */
  785. /* > SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222. */
  786. /* > [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. */
  787. /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. */
  788. /* > LAPACK Working note 169. */
  789. /* > [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. */
  790. /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. */
  791. /* > LAPACK Working note 170. */
  792. /* > [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV, */
  793. /* > QSVD, (H,K)-SVD computations. */
  794. /* > Department of Mathematics, University of Zagreb, 2008. */
  795. /* > \endverbatim */
  796. /* > \par Bugs, examples and comments: */
  797. /* ================================= */
  798. /* > */
  799. /* > \verbatim */
  800. /* > =========================== */
  801. /* > Please report all bugs and send interesting test examples and comments to */
  802. /* > drmac@math.hr. Thank you. */
  803. /* > \endverbatim */
  804. /* > */
  805. /* ===================================================================== */
  806. /* Subroutine */ void dgesvj_(char *joba, char *jobu, char *jobv, integer *m,
  807. integer *n, doublereal *a, integer *lda, doublereal *sva, integer *mv,
  808. doublereal *v, integer *ldv, doublereal *work, integer *lwork,
  809. integer *info)
  810. {
  811. /* System generated locals */
  812. integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5;
  813. doublereal d__1, d__2;
  814. /* Local variables */
  815. doublereal aapp, aapq, aaqq;
  816. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  817. integer *);
  818. doublereal ctol;
  819. integer ierr;
  820. doublereal bigtheta;
  821. integer pskipped;
  822. doublereal aapp0;
  823. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  824. doublereal temp1;
  825. integer i__, p, q;
  826. doublereal t;
  827. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  828. integer *);
  829. doublereal large, apoaq, aqoap;
  830. extern logical lsame_(char *, char *);
  831. doublereal theta, small, sfmin;
  832. logical lsvec;
  833. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  834. doublereal *, integer *);
  835. doublereal fastr[5];
  836. extern /* Subroutine */ void dswap_(integer *, doublereal *, integer *,
  837. doublereal *, integer *);
  838. doublereal epsln;
  839. logical applv, rsvec;
  840. extern /* Subroutine */ void daxpy_(integer *, doublereal *, doublereal *,
  841. integer *, doublereal *, integer *);
  842. logical uctol;
  843. extern /* Subroutine */ void drotm_(integer *, doublereal *, integer *,
  844. doublereal *, integer *, doublereal *);
  845. logical lower, upper, rotok;
  846. integer n2, n4;
  847. extern /* Subroutine */ void dgsvj0_(char *, integer *, integer *,
  848. doublereal *, integer *, doublereal *, doublereal *, integer *,
  849. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  850. integer *, doublereal *, integer *, integer *), dgsvj1_(
  851. char *, integer *, integer *, integer *, doublereal *, integer *,
  852. doublereal *, doublereal *, integer *, doublereal *, integer *,
  853. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  854. integer *, integer *);
  855. doublereal rootsfmin;
  856. integer n34;
  857. doublereal cs;
  858. extern doublereal dlamch_(char *);
  859. doublereal sn;
  860. extern /* Subroutine */ void dlascl_(char *, integer *, integer *,
  861. doublereal *, doublereal *, integer *, integer *, doublereal *,
  862. integer *, integer *);
  863. extern integer idamax_(integer *, doublereal *, integer *);
  864. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  865. doublereal *, doublereal *, doublereal *, integer *);
  866. extern int xerbla_(char *, integer *, ftnlen);
  867. integer ijblsk, swband, blskip;
  868. doublereal mxaapq;
  869. extern /* Subroutine */ void dlassq_(integer *, doublereal *, integer *,
  870. doublereal *, doublereal *);
  871. doublereal thsign, mxsinj;
  872. integer ir1, emptsw, notrot, iswrot, jbc;
  873. doublereal big;
  874. integer kbl, lkahead, igl, ibr, jgl, nbl;
  875. doublereal skl;
  876. logical goscale;
  877. doublereal tol;
  878. integer mvl;
  879. logical noscale;
  880. doublereal rootbig, rooteps;
  881. integer rowskip;
  882. doublereal roottol;
  883. /* -- LAPACK computational routine (version 3.7.1) -- */
  884. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  885. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  886. /* June 2017 */
  887. /* ===================================================================== */
  888. /* from BLAS */
  889. /* from LAPACK */
  890. /* from BLAS */
  891. /* from LAPACK */
  892. /* Test the input arguments */
  893. /* Parameter adjustments */
  894. --sva;
  895. a_dim1 = *lda;
  896. a_offset = 1 + a_dim1 * 1;
  897. a -= a_offset;
  898. v_dim1 = *ldv;
  899. v_offset = 1 + v_dim1 * 1;
  900. v -= v_offset;
  901. --work;
  902. /* Function Body */
  903. lsvec = lsame_(jobu, "U");
  904. uctol = lsame_(jobu, "C");
  905. rsvec = lsame_(jobv, "V");
  906. applv = lsame_(jobv, "A");
  907. upper = lsame_(joba, "U");
  908. lower = lsame_(joba, "L");
  909. if (! (upper || lower || lsame_(joba, "G"))) {
  910. *info = -1;
  911. } else if (! (lsvec || uctol || lsame_(jobu, "N")))
  912. {
  913. *info = -2;
  914. } else if (! (rsvec || applv || lsame_(jobv, "N")))
  915. {
  916. *info = -3;
  917. } else if (*m < 0) {
  918. *info = -4;
  919. } else if (*n < 0 || *n > *m) {
  920. *info = -5;
  921. } else if (*lda < *m) {
  922. *info = -7;
  923. } else if (*mv < 0) {
  924. *info = -9;
  925. } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
  926. *info = -11;
  927. } else if (uctol && work[1] <= 1.) {
  928. *info = -12;
  929. } else /* if(complicated condition) */ {
  930. /* Computing MAX */
  931. i__1 = *m + *n;
  932. if (*lwork < f2cmax(i__1,6)) {
  933. *info = -13;
  934. } else {
  935. *info = 0;
  936. }
  937. }
  938. /* #:( */
  939. if (*info != 0) {
  940. i__1 = -(*info);
  941. xerbla_("DGESVJ", &i__1, (ftnlen)6);
  942. return;
  943. }
  944. /* #:) Quick return for void matrix */
  945. if (*m == 0 || *n == 0) {
  946. return;
  947. }
  948. /* Set numerical parameters */
  949. /* The stopping criterion for Jacobi rotations is */
  950. /* max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS */
  951. /* where EPS is the round-off and CTOL is defined as follows: */
  952. if (uctol) {
  953. /* ... user controlled */
  954. ctol = work[1];
  955. } else {
  956. /* ... default */
  957. if (lsvec || rsvec || applv) {
  958. ctol = sqrt((doublereal) (*m));
  959. } else {
  960. ctol = (doublereal) (*m);
  961. }
  962. }
  963. /* ... and the machine dependent parameters are */
  964. /* [!] (Make sure that DLAMCH() works properly on the target machine.) */
  965. epsln = dlamch_("Epsilon");
  966. rooteps = sqrt(epsln);
  967. sfmin = dlamch_("SafeMinimum");
  968. rootsfmin = sqrt(sfmin);
  969. small = sfmin / epsln;
  970. big = dlamch_("Overflow");
  971. /* BIG = ONE / SFMIN */
  972. rootbig = 1. / rootsfmin;
  973. large = big / sqrt((doublereal) (*m * *n));
  974. bigtheta = 1. / rooteps;
  975. tol = ctol * epsln;
  976. roottol = sqrt(tol);
  977. if ((doublereal) (*m) * epsln >= 1.) {
  978. *info = -4;
  979. i__1 = -(*info);
  980. xerbla_("DGESVJ", &i__1, (ftnlen)6);
  981. return;
  982. }
  983. /* Initialize the right singular vector matrix. */
  984. if (rsvec) {
  985. mvl = *n;
  986. dlaset_("A", &mvl, n, &c_b17, &c_b18, &v[v_offset], ldv);
  987. } else if (applv) {
  988. mvl = *mv;
  989. }
  990. rsvec = rsvec || applv;
  991. /* Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N ) */
  992. /* (!) If necessary, scale A to protect the largest singular value */
  993. /* from overflow. It is possible that saving the largest singular */
  994. /* value destroys the information about the small ones. */
  995. /* This initial scaling is almost minimal in the sense that the */
  996. /* goal is to make sure that no column norm overflows, and that */
  997. /* DSQRT(N)*max_i SVA(i) does not overflow. If INFinite entries */
  998. /* in A are detected, the procedure returns with INFO=-6. */
  999. skl = 1. / sqrt((doublereal) (*m) * (doublereal) (*n));
  1000. noscale = TRUE_;
  1001. goscale = TRUE_;
  1002. if (lower) {
  1003. /* the input matrix is M-by-N lower triangular (trapezoidal) */
  1004. i__1 = *n;
  1005. for (p = 1; p <= i__1; ++p) {
  1006. aapp = 0.;
  1007. aaqq = 1.;
  1008. i__2 = *m - p + 1;
  1009. dlassq_(&i__2, &a[p + p * a_dim1], &c__1, &aapp, &aaqq);
  1010. if (aapp > big) {
  1011. *info = -6;
  1012. i__2 = -(*info);
  1013. xerbla_("DGESVJ", &i__2, (ftnlen)6);
  1014. return;
  1015. }
  1016. aaqq = sqrt(aaqq);
  1017. if (aapp < big / aaqq && noscale) {
  1018. sva[p] = aapp * aaqq;
  1019. } else {
  1020. noscale = FALSE_;
  1021. sva[p] = aapp * (aaqq * skl);
  1022. if (goscale) {
  1023. goscale = FALSE_;
  1024. i__2 = p - 1;
  1025. for (q = 1; q <= i__2; ++q) {
  1026. sva[q] *= skl;
  1027. /* L1873: */
  1028. }
  1029. }
  1030. }
  1031. /* L1874: */
  1032. }
  1033. } else if (upper) {
  1034. /* the input matrix is M-by-N upper triangular (trapezoidal) */
  1035. i__1 = *n;
  1036. for (p = 1; p <= i__1; ++p) {
  1037. aapp = 0.;
  1038. aaqq = 1.;
  1039. dlassq_(&p, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
  1040. if (aapp > big) {
  1041. *info = -6;
  1042. i__2 = -(*info);
  1043. xerbla_("DGESVJ", &i__2, (ftnlen)6);
  1044. return;
  1045. }
  1046. aaqq = sqrt(aaqq);
  1047. if (aapp < big / aaqq && noscale) {
  1048. sva[p] = aapp * aaqq;
  1049. } else {
  1050. noscale = FALSE_;
  1051. sva[p] = aapp * (aaqq * skl);
  1052. if (goscale) {
  1053. goscale = FALSE_;
  1054. i__2 = p - 1;
  1055. for (q = 1; q <= i__2; ++q) {
  1056. sva[q] *= skl;
  1057. /* L2873: */
  1058. }
  1059. }
  1060. }
  1061. /* L2874: */
  1062. }
  1063. } else {
  1064. /* the input matrix is M-by-N general dense */
  1065. i__1 = *n;
  1066. for (p = 1; p <= i__1; ++p) {
  1067. aapp = 0.;
  1068. aaqq = 1.;
  1069. dlassq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
  1070. if (aapp > big) {
  1071. *info = -6;
  1072. i__2 = -(*info);
  1073. xerbla_("DGESVJ", &i__2, (ftnlen)6);
  1074. return;
  1075. }
  1076. aaqq = sqrt(aaqq);
  1077. if (aapp < big / aaqq && noscale) {
  1078. sva[p] = aapp * aaqq;
  1079. } else {
  1080. noscale = FALSE_;
  1081. sva[p] = aapp * (aaqq * skl);
  1082. if (goscale) {
  1083. goscale = FALSE_;
  1084. i__2 = p - 1;
  1085. for (q = 1; q <= i__2; ++q) {
  1086. sva[q] *= skl;
  1087. /* L3873: */
  1088. }
  1089. }
  1090. }
  1091. /* L3874: */
  1092. }
  1093. }
  1094. if (noscale) {
  1095. skl = 1.;
  1096. }
  1097. /* Move the smaller part of the spectrum from the underflow threshold */
  1098. /* (!) Start by determining the position of the nonzero entries of the */
  1099. /* array SVA() relative to ( SFMIN, BIG ). */
  1100. aapp = 0.;
  1101. aaqq = big;
  1102. i__1 = *n;
  1103. for (p = 1; p <= i__1; ++p) {
  1104. if (sva[p] != 0.) {
  1105. /* Computing MIN */
  1106. d__1 = aaqq, d__2 = sva[p];
  1107. aaqq = f2cmin(d__1,d__2);
  1108. }
  1109. /* Computing MAX */
  1110. d__1 = aapp, d__2 = sva[p];
  1111. aapp = f2cmax(d__1,d__2);
  1112. /* L4781: */
  1113. }
  1114. /* #:) Quick return for zero matrix */
  1115. if (aapp == 0.) {
  1116. if (lsvec) {
  1117. dlaset_("G", m, n, &c_b17, &c_b18, &a[a_offset], lda);
  1118. }
  1119. work[1] = 1.;
  1120. work[2] = 0.;
  1121. work[3] = 0.;
  1122. work[4] = 0.;
  1123. work[5] = 0.;
  1124. work[6] = 0.;
  1125. return;
  1126. }
  1127. /* #:) Quick return for one-column matrix */
  1128. if (*n == 1) {
  1129. if (lsvec) {
  1130. dlascl_("G", &c__0, &c__0, &sva[1], &skl, m, &c__1, &a[a_dim1 + 1]
  1131. , lda, &ierr);
  1132. }
  1133. work[1] = 1. / skl;
  1134. if (sva[1] >= sfmin) {
  1135. work[2] = 1.;
  1136. } else {
  1137. work[2] = 0.;
  1138. }
  1139. work[3] = 0.;
  1140. work[4] = 0.;
  1141. work[5] = 0.;
  1142. work[6] = 0.;
  1143. return;
  1144. }
  1145. /* Protect small singular values from underflow, and try to */
  1146. /* avoid underflows/overflows in computing Jacobi rotations. */
  1147. sn = sqrt(sfmin / epsln);
  1148. temp1 = sqrt(big / (doublereal) (*n));
  1149. if (aapp <= sn || aaqq >= temp1 || sn <= aaqq && aapp <= temp1) {
  1150. /* Computing MIN */
  1151. d__1 = big, d__2 = temp1 / aapp;
  1152. temp1 = f2cmin(d__1,d__2);
  1153. /* AAQQ = AAQQ*TEMP1 */
  1154. /* AAPP = AAPP*TEMP1 */
  1155. } else if (aaqq <= sn && aapp <= temp1) {
  1156. /* Computing MIN */
  1157. d__1 = sn / aaqq, d__2 = big / (aapp * sqrt((doublereal) (*n)));
  1158. temp1 = f2cmin(d__1,d__2);
  1159. /* AAQQ = AAQQ*TEMP1 */
  1160. /* AAPP = AAPP*TEMP1 */
  1161. } else if (aaqq >= sn && aapp >= temp1) {
  1162. /* Computing MAX */
  1163. d__1 = sn / aaqq, d__2 = temp1 / aapp;
  1164. temp1 = f2cmax(d__1,d__2);
  1165. /* AAQQ = AAQQ*TEMP1 */
  1166. /* AAPP = AAPP*TEMP1 */
  1167. } else if (aaqq <= sn && aapp >= temp1) {
  1168. /* Computing MIN */
  1169. d__1 = sn / aaqq, d__2 = big / (sqrt((doublereal) (*n)) * aapp);
  1170. temp1 = f2cmin(d__1,d__2);
  1171. /* AAQQ = AAQQ*TEMP1 */
  1172. /* AAPP = AAPP*TEMP1 */
  1173. } else {
  1174. temp1 = 1.;
  1175. }
  1176. /* Scale, if necessary */
  1177. if (temp1 != 1.) {
  1178. dlascl_("G", &c__0, &c__0, &c_b18, &temp1, n, &c__1, &sva[1], n, &
  1179. ierr);
  1180. }
  1181. skl = temp1 * skl;
  1182. if (skl != 1.) {
  1183. dlascl_(joba, &c__0, &c__0, &c_b18, &skl, m, n, &a[a_offset], lda, &
  1184. ierr);
  1185. skl = 1. / skl;
  1186. }
  1187. /* Row-cyclic Jacobi SVD algorithm with column pivoting */
  1188. emptsw = *n * (*n - 1) / 2;
  1189. notrot = 0;
  1190. fastr[0] = 0.;
  1191. /* A is represented in factored form A = A * diag(WORK), where diag(WORK) */
  1192. /* is initialized to identity. WORK is updated during fast scaled */
  1193. /* rotations. */
  1194. i__1 = *n;
  1195. for (q = 1; q <= i__1; ++q) {
  1196. work[q] = 1.;
  1197. /* L1868: */
  1198. }
  1199. swband = 3;
  1200. /* [TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective */
  1201. /* if DGESVJ is used as a computational routine in the preconditioned */
  1202. /* Jacobi SVD algorithm DGESVJ. For sweeps i=1:SWBAND the procedure */
  1203. /* works on pivots inside a band-like region around the diagonal. */
  1204. /* The boundaries are determined dynamically, based on the number of */
  1205. /* pivots above a threshold. */
  1206. kbl = f2cmin(8,*n);
  1207. /* [TP] KBL is a tuning parameter that defines the tile size in the */
  1208. /* tiling of the p-q loops of pivot pairs. In general, an optimal */
  1209. /* value of KBL depends on the matrix dimensions and on the */
  1210. /* parameters of the computer's memory. */
  1211. nbl = *n / kbl;
  1212. if (nbl * kbl != *n) {
  1213. ++nbl;
  1214. }
  1215. /* Computing 2nd power */
  1216. i__1 = kbl;
  1217. blskip = i__1 * i__1;
  1218. /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
  1219. rowskip = f2cmin(5,kbl);
  1220. /* [TP] ROWSKIP is a tuning parameter. */
  1221. lkahead = 1;
  1222. /* [TP] LKAHEAD is a tuning parameter. */
  1223. /* Quasi block transformations, using the lower (upper) triangular */
  1224. /* structure of the input matrix. The quasi-block-cycling usually */
  1225. /* invokes cubic convergence. Big part of this cycle is done inside */
  1226. /* canonical subspaces of dimensions less than M. */
  1227. /* Computing MAX */
  1228. i__1 = 64, i__2 = kbl << 2;
  1229. if ((lower || upper) && *n > f2cmax(i__1,i__2)) {
  1230. /* [TP] The number of partition levels and the actual partition are */
  1231. /* tuning parameters. */
  1232. n4 = *n / 4;
  1233. n2 = *n / 2;
  1234. n34 = n4 * 3;
  1235. if (applv) {
  1236. q = 0;
  1237. } else {
  1238. q = 1;
  1239. }
  1240. if (lower) {
  1241. /* This works very well on lower triangular matrices, in particular */
  1242. /* in the framework of the preconditioned Jacobi SVD (xGEJSV). */
  1243. /* The idea is simple: */
  1244. /* [+ 0 0 0] Note that Jacobi transformations of [0 0] */
  1245. /* [+ + 0 0] [0 0] */
  1246. /* [+ + x 0] actually work on [x 0] [x 0] */
  1247. /* [+ + x x] [x x]. [x x] */
  1248. i__1 = *m - n34;
  1249. i__2 = *n - n34;
  1250. i__3 = *lwork - *n;
  1251. dgsvj0_(jobv, &i__1, &i__2, &a[n34 + 1 + (n34 + 1) * a_dim1], lda,
  1252. &work[n34 + 1], &sva[n34 + 1], &mvl, &v[n34 * q + 1 + (
  1253. n34 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &
  1254. work[*n + 1], &i__3, &ierr);
  1255. i__1 = *m - n2;
  1256. i__2 = n34 - n2;
  1257. i__3 = *lwork - *n;
  1258. dgsvj0_(jobv, &i__1, &i__2, &a[n2 + 1 + (n2 + 1) * a_dim1], lda, &
  1259. work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1)
  1260. * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &work[*n +
  1261. 1], &i__3, &ierr);
  1262. i__1 = *m - n2;
  1263. i__2 = *n - n2;
  1264. i__3 = *lwork - *n;
  1265. dgsvj1_(jobv, &i__1, &i__2, &n4, &a[n2 + 1 + (n2 + 1) * a_dim1],
  1266. lda, &work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (
  1267. n2 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &
  1268. work[*n + 1], &i__3, &ierr);
  1269. i__1 = *m - n4;
  1270. i__2 = n2 - n4;
  1271. i__3 = *lwork - *n;
  1272. dgsvj0_(jobv, &i__1, &i__2, &a[n4 + 1 + (n4 + 1) * a_dim1], lda, &
  1273. work[n4 + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1)
  1274. * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n +
  1275. 1], &i__3, &ierr);
  1276. i__1 = *lwork - *n;
  1277. dgsvj0_(jobv, m, &n4, &a[a_offset], lda, &work[1], &sva[1], &mvl,
  1278. &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n
  1279. + 1], &i__1, &ierr);
  1280. i__1 = *lwork - *n;
  1281. dgsvj1_(jobv, m, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1], &
  1282. mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
  1283. work[*n + 1], &i__1, &ierr);
  1284. } else if (upper) {
  1285. i__1 = *lwork - *n;
  1286. dgsvj0_(jobv, &n4, &n4, &a[a_offset], lda, &work[1], &sva[1], &
  1287. mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__2, &
  1288. work[*n + 1], &i__1, &ierr);
  1289. i__1 = *lwork - *n;
  1290. dgsvj0_(jobv, &n2, &n4, &a[(n4 + 1) * a_dim1 + 1], lda, &work[n4
  1291. + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1) *
  1292. v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
  1293. &i__1, &ierr);
  1294. i__1 = *lwork - *n;
  1295. dgsvj1_(jobv, &n2, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1],
  1296. &mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
  1297. work[*n + 1], &i__1, &ierr);
  1298. i__1 = n2 + n4;
  1299. i__2 = *lwork - *n;
  1300. dgsvj0_(jobv, &i__1, &n4, &a[(n2 + 1) * a_dim1 + 1], lda, &work[
  1301. n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1) *
  1302. v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
  1303. &i__2, &ierr);
  1304. }
  1305. }
  1306. for (i__ = 1; i__ <= 30; ++i__) {
  1307. mxaapq = 0.;
  1308. mxsinj = 0.;
  1309. iswrot = 0;
  1310. notrot = 0;
  1311. pskipped = 0;
  1312. /* Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs */
  1313. /* 1 <= p < q <= N. This is the first step toward a blocked implementation */
  1314. /* of the rotations. New implementation, based on block transformations, */
  1315. /* is under development. */
  1316. i__1 = nbl;
  1317. for (ibr = 1; ibr <= i__1; ++ibr) {
  1318. igl = (ibr - 1) * kbl + 1;
  1319. /* Computing MIN */
  1320. i__3 = lkahead, i__4 = nbl - ibr;
  1321. i__2 = f2cmin(i__3,i__4);
  1322. for (ir1 = 0; ir1 <= i__2; ++ir1) {
  1323. igl += ir1 * kbl;
  1324. /* Computing MIN */
  1325. i__4 = igl + kbl - 1, i__5 = *n - 1;
  1326. i__3 = f2cmin(i__4,i__5);
  1327. for (p = igl; p <= i__3; ++p) {
  1328. i__4 = *n - p + 1;
  1329. q = idamax_(&i__4, &sva[p], &c__1) + p - 1;
  1330. if (p != q) {
  1331. dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 +
  1332. 1], &c__1);
  1333. if (rsvec) {
  1334. dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1335. v_dim1 + 1], &c__1);
  1336. }
  1337. temp1 = sva[p];
  1338. sva[p] = sva[q];
  1339. sva[q] = temp1;
  1340. temp1 = work[p];
  1341. work[p] = work[q];
  1342. work[q] = temp1;
  1343. }
  1344. if (ir1 == 0) {
  1345. /* Column norms are periodically updated by explicit */
  1346. /* norm computation. */
  1347. /* Caveat: */
  1348. /* Unfortunately, some BLAS implementations compute DNRM2(M,A(1,p),1) */
  1349. /* as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to */
  1350. /* overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and to */
  1351. /* underflow for ||A(:,p)||_2 < DSQRT(underflow_threshold). */
  1352. /* Hence, DNRM2 cannot be trusted, not even in the case when */
  1353. /* the true norm is far from the under(over)flow boundaries. */
  1354. /* If properly implemented DNRM2 is available, the IF-THEN-ELSE */
  1355. /* below should read "AAPP = DNRM2( M, A(1,p), 1 ) * WORK(p)". */
  1356. if (sva[p] < rootbig && sva[p] > rootsfmin) {
  1357. sva[p] = dnrm2_(m, &a[p * a_dim1 + 1], &c__1) *
  1358. work[p];
  1359. } else {
  1360. temp1 = 0.;
  1361. aapp = 1.;
  1362. dlassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
  1363. aapp);
  1364. sva[p] = temp1 * sqrt(aapp) * work[p];
  1365. }
  1366. aapp = sva[p];
  1367. } else {
  1368. aapp = sva[p];
  1369. }
  1370. if (aapp > 0.) {
  1371. pskipped = 0;
  1372. /* Computing MIN */
  1373. i__5 = igl + kbl - 1;
  1374. i__4 = f2cmin(i__5,*n);
  1375. for (q = p + 1; q <= i__4; ++q) {
  1376. aaqq = sva[q];
  1377. if (aaqq > 0.) {
  1378. aapp0 = aapp;
  1379. if (aaqq >= 1.) {
  1380. rotok = small * aapp <= aaqq;
  1381. if (aapp < big / aaqq) {
  1382. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1383. c__1, &a[q * a_dim1 + 1], &
  1384. c__1) * work[p] * work[q] /
  1385. aaqq / aapp;
  1386. } else {
  1387. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1388. work[*n + 1], &c__1);
  1389. dlascl_("G", &c__0, &c__0, &aapp, &
  1390. work[p], m, &c__1, &work[*n +
  1391. 1], lda, &ierr);
  1392. aapq = ddot_(m, &work[*n + 1], &c__1,
  1393. &a[q * a_dim1 + 1], &c__1) *
  1394. work[q] / aaqq;
  1395. }
  1396. } else {
  1397. rotok = aapp <= aaqq / small;
  1398. if (aapp > small / aaqq) {
  1399. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1400. c__1, &a[q * a_dim1 + 1], &
  1401. c__1) * work[p] * work[q] /
  1402. aaqq / aapp;
  1403. } else {
  1404. dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1405. work[*n + 1], &c__1);
  1406. dlascl_("G", &c__0, &c__0, &aaqq, &
  1407. work[q], m, &c__1, &work[*n +
  1408. 1], lda, &ierr);
  1409. aapq = ddot_(m, &work[*n + 1], &c__1,
  1410. &a[p * a_dim1 + 1], &c__1) *
  1411. work[p] / aapp;
  1412. }
  1413. }
  1414. /* Computing MAX */
  1415. d__1 = mxaapq, d__2 = abs(aapq);
  1416. mxaapq = f2cmax(d__1,d__2);
  1417. /* TO rotate or NOT to rotate, THAT is the question ... */
  1418. if (abs(aapq) > tol) {
  1419. /* [RTD] ROTATED = ROTATED + ONE */
  1420. if (ir1 == 0) {
  1421. notrot = 0;
  1422. pskipped = 0;
  1423. ++iswrot;
  1424. }
  1425. if (rotok) {
  1426. aqoap = aaqq / aapp;
  1427. apoaq = aapp / aaqq;
  1428. theta = (d__1 = aqoap - apoaq, abs(
  1429. d__1)) * -.5 / aapq;
  1430. if (abs(theta) > bigtheta) {
  1431. t = .5 / theta;
  1432. fastr[2] = t * work[p] / work[q];
  1433. fastr[3] = -t * work[q] / work[p];
  1434. drotm_(m, &a[p * a_dim1 + 1], &
  1435. c__1, &a[q * a_dim1 + 1],
  1436. &c__1, fastr);
  1437. if (rsvec) {
  1438. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1439. v_dim1 + 1], &c__1, fastr);
  1440. }
  1441. /* Computing MAX */
  1442. d__1 = 0., d__2 = t * apoaq *
  1443. aapq + 1.;
  1444. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1445. d__2)));
  1446. /* Computing MAX */
  1447. d__1 = 0., d__2 = 1. - t * aqoap *
  1448. aapq;
  1449. aapp *= sqrt((f2cmax(d__1,d__2)));
  1450. /* Computing MAX */
  1451. d__1 = mxsinj, d__2 = abs(t);
  1452. mxsinj = f2cmax(d__1,d__2);
  1453. } else {
  1454. thsign = -d_sign(&c_b18, &aapq);
  1455. t = 1. / (theta + thsign * sqrt(
  1456. theta * theta + 1.));
  1457. cs = sqrt(1. / (t * t + 1.));
  1458. sn = t * cs;
  1459. /* Computing MAX */
  1460. d__1 = mxsinj, d__2 = abs(sn);
  1461. mxsinj = f2cmax(d__1,d__2);
  1462. /* Computing MAX */
  1463. d__1 = 0., d__2 = t * apoaq *
  1464. aapq + 1.;
  1465. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1466. d__2)));
  1467. /* Computing MAX */
  1468. d__1 = 0., d__2 = 1. - t * aqoap *
  1469. aapq;
  1470. aapp *= sqrt((f2cmax(d__1,d__2)));
  1471. apoaq = work[p] / work[q];
  1472. aqoap = work[q] / work[p];
  1473. if (work[p] >= 1.) {
  1474. if (work[q] >= 1.) {
  1475. fastr[2] = t * apoaq;
  1476. fastr[3] = -t * aqoap;
  1477. work[p] *= cs;
  1478. work[q] *= cs;
  1479. drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1480. a_dim1 + 1], &c__1, fastr);
  1481. if (rsvec) {
  1482. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1483. q * v_dim1 + 1], &c__1, fastr);
  1484. }
  1485. } else {
  1486. d__1 = -t * aqoap;
  1487. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1488. p * a_dim1 + 1], &c__1);
  1489. d__1 = cs * sn * apoaq;
  1490. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1491. q * a_dim1 + 1], &c__1);
  1492. work[p] *= cs;
  1493. work[q] /= cs;
  1494. if (rsvec) {
  1495. d__1 = -t * aqoap;
  1496. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1497. c__1, &v[p * v_dim1 + 1], &c__1);
  1498. d__1 = cs * sn * apoaq;
  1499. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1500. c__1, &v[q * v_dim1 + 1], &c__1);
  1501. }
  1502. }
  1503. } else {
  1504. if (work[q] >= 1.) {
  1505. d__1 = t * apoaq;
  1506. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1507. q * a_dim1 + 1], &c__1);
  1508. d__1 = -cs * sn * aqoap;
  1509. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1510. p * a_dim1 + 1], &c__1);
  1511. work[p] /= cs;
  1512. work[q] *= cs;
  1513. if (rsvec) {
  1514. d__1 = t * apoaq;
  1515. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1516. c__1, &v[q * v_dim1 + 1], &c__1);
  1517. d__1 = -cs * sn * aqoap;
  1518. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1519. c__1, &v[p * v_dim1 + 1], &c__1);
  1520. }
  1521. } else {
  1522. if (work[p] >= work[q]) {
  1523. d__1 = -t * aqoap;
  1524. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1525. &a[p * a_dim1 + 1], &c__1);
  1526. d__1 = cs * sn * apoaq;
  1527. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1528. &a[q * a_dim1 + 1], &c__1);
  1529. work[p] *= cs;
  1530. work[q] /= cs;
  1531. if (rsvec) {
  1532. d__1 = -t * aqoap;
  1533. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1534. &c__1, &v[p * v_dim1 + 1], &
  1535. c__1);
  1536. d__1 = cs * sn * apoaq;
  1537. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1538. &c__1, &v[q * v_dim1 + 1], &
  1539. c__1);
  1540. }
  1541. } else {
  1542. d__1 = t * apoaq;
  1543. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1544. &a[q * a_dim1 + 1], &c__1);
  1545. d__1 = -cs * sn * aqoap;
  1546. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1547. &a[p * a_dim1 + 1], &c__1);
  1548. work[p] /= cs;
  1549. work[q] *= cs;
  1550. if (rsvec) {
  1551. d__1 = t * apoaq;
  1552. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1553. &c__1, &v[q * v_dim1 + 1], &
  1554. c__1);
  1555. d__1 = -cs * sn * aqoap;
  1556. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1557. &c__1, &v[p * v_dim1 + 1], &
  1558. c__1);
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. } else {
  1565. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1566. work[*n + 1], &c__1);
  1567. dlascl_("G", &c__0, &c__0, &aapp, &
  1568. c_b18, m, &c__1, &work[*n + 1]
  1569. , lda, &ierr);
  1570. dlascl_("G", &c__0, &c__0, &aaqq, &
  1571. c_b18, m, &c__1, &a[q *
  1572. a_dim1 + 1], lda, &ierr);
  1573. temp1 = -aapq * work[p] / work[q];
  1574. daxpy_(m, &temp1, &work[*n + 1], &
  1575. c__1, &a[q * a_dim1 + 1], &
  1576. c__1);
  1577. dlascl_("G", &c__0, &c__0, &c_b18, &
  1578. aaqq, m, &c__1, &a[q * a_dim1
  1579. + 1], lda, &ierr);
  1580. /* Computing MAX */
  1581. d__1 = 0., d__2 = 1. - aapq * aapq;
  1582. sva[q] = aaqq * sqrt((f2cmax(d__1,d__2)))
  1583. ;
  1584. mxsinj = f2cmax(mxsinj,sfmin);
  1585. }
  1586. /* END IF ROTOK THEN ... ELSE */
  1587. /* In the case of cancellation in updating SVA(q), SVA(p) */
  1588. /* recompute SVA(q), SVA(p). */
  1589. /* Computing 2nd power */
  1590. d__1 = sva[q] / aaqq;
  1591. if (d__1 * d__1 <= rooteps) {
  1592. if (aaqq < rootbig && aaqq >
  1593. rootsfmin) {
  1594. sva[q] = dnrm2_(m, &a[q * a_dim1
  1595. + 1], &c__1) * work[q];
  1596. } else {
  1597. t = 0.;
  1598. aaqq = 1.;
  1599. dlassq_(m, &a[q * a_dim1 + 1], &
  1600. c__1, &t, &aaqq);
  1601. sva[q] = t * sqrt(aaqq) * work[q];
  1602. }
  1603. }
  1604. if (aapp / aapp0 <= rooteps) {
  1605. if (aapp < rootbig && aapp >
  1606. rootsfmin) {
  1607. aapp = dnrm2_(m, &a[p * a_dim1 +
  1608. 1], &c__1) * work[p];
  1609. } else {
  1610. t = 0.;
  1611. aapp = 1.;
  1612. dlassq_(m, &a[p * a_dim1 + 1], &
  1613. c__1, &t, &aapp);
  1614. aapp = t * sqrt(aapp) * work[p];
  1615. }
  1616. sva[p] = aapp;
  1617. }
  1618. } else {
  1619. /* A(:,p) and A(:,q) already numerically orthogonal */
  1620. if (ir1 == 0) {
  1621. ++notrot;
  1622. }
  1623. /* [RTD] SKIPPED = SKIPPED + 1 */
  1624. ++pskipped;
  1625. }
  1626. } else {
  1627. /* A(:,q) is zero column */
  1628. if (ir1 == 0) {
  1629. ++notrot;
  1630. }
  1631. ++pskipped;
  1632. }
  1633. if (i__ <= swband && pskipped > rowskip) {
  1634. if (ir1 == 0) {
  1635. aapp = -aapp;
  1636. }
  1637. notrot = 0;
  1638. goto L2103;
  1639. }
  1640. /* L2002: */
  1641. }
  1642. /* END q-LOOP */
  1643. L2103:
  1644. /* bailed out of q-loop */
  1645. sva[p] = aapp;
  1646. } else {
  1647. sva[p] = aapp;
  1648. if (ir1 == 0 && aapp == 0.) {
  1649. /* Computing MIN */
  1650. i__4 = igl + kbl - 1;
  1651. notrot = notrot + f2cmin(i__4,*n) - p;
  1652. }
  1653. }
  1654. /* L2001: */
  1655. }
  1656. /* end of the p-loop */
  1657. /* end of doing the block ( ibr, ibr ) */
  1658. /* L1002: */
  1659. }
  1660. /* end of ir1-loop */
  1661. /* ... go to the off diagonal blocks */
  1662. igl = (ibr - 1) * kbl + 1;
  1663. i__2 = nbl;
  1664. for (jbc = ibr + 1; jbc <= i__2; ++jbc) {
  1665. jgl = (jbc - 1) * kbl + 1;
  1666. /* doing the block at ( ibr, jbc ) */
  1667. ijblsk = 0;
  1668. /* Computing MIN */
  1669. i__4 = igl + kbl - 1;
  1670. i__3 = f2cmin(i__4,*n);
  1671. for (p = igl; p <= i__3; ++p) {
  1672. aapp = sva[p];
  1673. if (aapp > 0.) {
  1674. pskipped = 0;
  1675. /* Computing MIN */
  1676. i__5 = jgl + kbl - 1;
  1677. i__4 = f2cmin(i__5,*n);
  1678. for (q = jgl; q <= i__4; ++q) {
  1679. aaqq = sva[q];
  1680. if (aaqq > 0.) {
  1681. aapp0 = aapp;
  1682. /* Safe Gram matrix computation */
  1683. if (aaqq >= 1.) {
  1684. if (aapp >= aaqq) {
  1685. rotok = small * aapp <= aaqq;
  1686. } else {
  1687. rotok = small * aaqq <= aapp;
  1688. }
  1689. if (aapp < big / aaqq) {
  1690. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1691. c__1, &a[q * a_dim1 + 1], &
  1692. c__1) * work[p] * work[q] /
  1693. aaqq / aapp;
  1694. } else {
  1695. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1696. work[*n + 1], &c__1);
  1697. dlascl_("G", &c__0, &c__0, &aapp, &
  1698. work[p], m, &c__1, &work[*n +
  1699. 1], lda, &ierr);
  1700. aapq = ddot_(m, &work[*n + 1], &c__1,
  1701. &a[q * a_dim1 + 1], &c__1) *
  1702. work[q] / aaqq;
  1703. }
  1704. } else {
  1705. if (aapp >= aaqq) {
  1706. rotok = aapp <= aaqq / small;
  1707. } else {
  1708. rotok = aaqq <= aapp / small;
  1709. }
  1710. if (aapp > small / aaqq) {
  1711. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1712. c__1, &a[q * a_dim1 + 1], &
  1713. c__1) * work[p] * work[q] /
  1714. aaqq / aapp;
  1715. } else {
  1716. dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1717. work[*n + 1], &c__1);
  1718. dlascl_("G", &c__0, &c__0, &aaqq, &
  1719. work[q], m, &c__1, &work[*n +
  1720. 1], lda, &ierr);
  1721. aapq = ddot_(m, &work[*n + 1], &c__1,
  1722. &a[p * a_dim1 + 1], &c__1) *
  1723. work[p] / aapp;
  1724. }
  1725. }
  1726. /* Computing MAX */
  1727. d__1 = mxaapq, d__2 = abs(aapq);
  1728. mxaapq = f2cmax(d__1,d__2);
  1729. /* TO rotate or NOT to rotate, THAT is the question ... */
  1730. if (abs(aapq) > tol) {
  1731. notrot = 0;
  1732. /* [RTD] ROTATED = ROTATED + 1 */
  1733. pskipped = 0;
  1734. ++iswrot;
  1735. if (rotok) {
  1736. aqoap = aaqq / aapp;
  1737. apoaq = aapp / aaqq;
  1738. theta = (d__1 = aqoap - apoaq, abs(
  1739. d__1)) * -.5 / aapq;
  1740. if (aaqq > aapp0) {
  1741. theta = -theta;
  1742. }
  1743. if (abs(theta) > bigtheta) {
  1744. t = .5 / theta;
  1745. fastr[2] = t * work[p] / work[q];
  1746. fastr[3] = -t * work[q] / work[p];
  1747. drotm_(m, &a[p * a_dim1 + 1], &
  1748. c__1, &a[q * a_dim1 + 1],
  1749. &c__1, fastr);
  1750. if (rsvec) {
  1751. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1752. v_dim1 + 1], &c__1, fastr);
  1753. }
  1754. /* Computing MAX */
  1755. d__1 = 0., d__2 = t * apoaq *
  1756. aapq + 1.;
  1757. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1758. d__2)));
  1759. /* Computing MAX */
  1760. d__1 = 0., d__2 = 1. - t * aqoap *
  1761. aapq;
  1762. aapp *= sqrt((f2cmax(d__1,d__2)));
  1763. /* Computing MAX */
  1764. d__1 = mxsinj, d__2 = abs(t);
  1765. mxsinj = f2cmax(d__1,d__2);
  1766. } else {
  1767. thsign = -d_sign(&c_b18, &aapq);
  1768. if (aaqq > aapp0) {
  1769. thsign = -thsign;
  1770. }
  1771. t = 1. / (theta + thsign * sqrt(
  1772. theta * theta + 1.));
  1773. cs = sqrt(1. / (t * t + 1.));
  1774. sn = t * cs;
  1775. /* Computing MAX */
  1776. d__1 = mxsinj, d__2 = abs(sn);
  1777. mxsinj = f2cmax(d__1,d__2);
  1778. /* Computing MAX */
  1779. d__1 = 0., d__2 = t * apoaq *
  1780. aapq + 1.;
  1781. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1782. d__2)));
  1783. /* Computing MAX */
  1784. d__1 = 0., d__2 = 1. - t * aqoap *
  1785. aapq;
  1786. aapp *= sqrt((f2cmax(d__1,d__2)));
  1787. apoaq = work[p] / work[q];
  1788. aqoap = work[q] / work[p];
  1789. if (work[p] >= 1.) {
  1790. if (work[q] >= 1.) {
  1791. fastr[2] = t * apoaq;
  1792. fastr[3] = -t * aqoap;
  1793. work[p] *= cs;
  1794. work[q] *= cs;
  1795. drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1796. a_dim1 + 1], &c__1, fastr);
  1797. if (rsvec) {
  1798. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1799. q * v_dim1 + 1], &c__1, fastr);
  1800. }
  1801. } else {
  1802. d__1 = -t * aqoap;
  1803. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1804. p * a_dim1 + 1], &c__1);
  1805. d__1 = cs * sn * apoaq;
  1806. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1807. q * a_dim1 + 1], &c__1);
  1808. if (rsvec) {
  1809. d__1 = -t * aqoap;
  1810. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1811. c__1, &v[p * v_dim1 + 1], &c__1);
  1812. d__1 = cs * sn * apoaq;
  1813. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1814. c__1, &v[q * v_dim1 + 1], &c__1);
  1815. }
  1816. work[p] *= cs;
  1817. work[q] /= cs;
  1818. }
  1819. } else {
  1820. if (work[q] >= 1.) {
  1821. d__1 = t * apoaq;
  1822. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1823. q * a_dim1 + 1], &c__1);
  1824. d__1 = -cs * sn * aqoap;
  1825. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1826. p * a_dim1 + 1], &c__1);
  1827. if (rsvec) {
  1828. d__1 = t * apoaq;
  1829. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1830. c__1, &v[q * v_dim1 + 1], &c__1);
  1831. d__1 = -cs * sn * aqoap;
  1832. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1833. c__1, &v[p * v_dim1 + 1], &c__1);
  1834. }
  1835. work[p] /= cs;
  1836. work[q] *= cs;
  1837. } else {
  1838. if (work[p] >= work[q]) {
  1839. d__1 = -t * aqoap;
  1840. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1841. &a[p * a_dim1 + 1], &c__1);
  1842. d__1 = cs * sn * apoaq;
  1843. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1844. &a[q * a_dim1 + 1], &c__1);
  1845. work[p] *= cs;
  1846. work[q] /= cs;
  1847. if (rsvec) {
  1848. d__1 = -t * aqoap;
  1849. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1850. &c__1, &v[p * v_dim1 + 1], &
  1851. c__1);
  1852. d__1 = cs * sn * apoaq;
  1853. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1854. &c__1, &v[q * v_dim1 + 1], &
  1855. c__1);
  1856. }
  1857. } else {
  1858. d__1 = t * apoaq;
  1859. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1860. &a[q * a_dim1 + 1], &c__1);
  1861. d__1 = -cs * sn * aqoap;
  1862. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1863. &a[p * a_dim1 + 1], &c__1);
  1864. work[p] /= cs;
  1865. work[q] *= cs;
  1866. if (rsvec) {
  1867. d__1 = t * apoaq;
  1868. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1869. &c__1, &v[q * v_dim1 + 1], &
  1870. c__1);
  1871. d__1 = -cs * sn * aqoap;
  1872. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1873. &c__1, &v[p * v_dim1 + 1], &
  1874. c__1);
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. } else {
  1881. if (aapp > aaqq) {
  1882. dcopy_(m, &a[p * a_dim1 + 1], &
  1883. c__1, &work[*n + 1], &
  1884. c__1);
  1885. dlascl_("G", &c__0, &c__0, &aapp,
  1886. &c_b18, m, &c__1, &work[*
  1887. n + 1], lda, &ierr);
  1888. dlascl_("G", &c__0, &c__0, &aaqq,
  1889. &c_b18, m, &c__1, &a[q *
  1890. a_dim1 + 1], lda, &ierr);
  1891. temp1 = -aapq * work[p] / work[q];
  1892. daxpy_(m, &temp1, &work[*n + 1], &
  1893. c__1, &a[q * a_dim1 + 1],
  1894. &c__1);
  1895. dlascl_("G", &c__0, &c__0, &c_b18,
  1896. &aaqq, m, &c__1, &a[q *
  1897. a_dim1 + 1], lda, &ierr);
  1898. /* Computing MAX */
  1899. d__1 = 0., d__2 = 1. - aapq *
  1900. aapq;
  1901. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1902. d__2)));
  1903. mxsinj = f2cmax(mxsinj,sfmin);
  1904. } else {
  1905. dcopy_(m, &a[q * a_dim1 + 1], &
  1906. c__1, &work[*n + 1], &
  1907. c__1);
  1908. dlascl_("G", &c__0, &c__0, &aaqq,
  1909. &c_b18, m, &c__1, &work[*
  1910. n + 1], lda, &ierr);
  1911. dlascl_("G", &c__0, &c__0, &aapp,
  1912. &c_b18, m, &c__1, &a[p *
  1913. a_dim1 + 1], lda, &ierr);
  1914. temp1 = -aapq * work[q] / work[p];
  1915. daxpy_(m, &temp1, &work[*n + 1], &
  1916. c__1, &a[p * a_dim1 + 1],
  1917. &c__1);
  1918. dlascl_("G", &c__0, &c__0, &c_b18,
  1919. &aapp, m, &c__1, &a[p *
  1920. a_dim1 + 1], lda, &ierr);
  1921. /* Computing MAX */
  1922. d__1 = 0., d__2 = 1. - aapq *
  1923. aapq;
  1924. sva[p] = aapp * sqrt((f2cmax(d__1,
  1925. d__2)));
  1926. mxsinj = f2cmax(mxsinj,sfmin);
  1927. }
  1928. }
  1929. /* END IF ROTOK THEN ... ELSE */
  1930. /* In the case of cancellation in updating SVA(q) */
  1931. /* Computing 2nd power */
  1932. d__1 = sva[q] / aaqq;
  1933. if (d__1 * d__1 <= rooteps) {
  1934. if (aaqq < rootbig && aaqq >
  1935. rootsfmin) {
  1936. sva[q] = dnrm2_(m, &a[q * a_dim1
  1937. + 1], &c__1) * work[q];
  1938. } else {
  1939. t = 0.;
  1940. aaqq = 1.;
  1941. dlassq_(m, &a[q * a_dim1 + 1], &
  1942. c__1, &t, &aaqq);
  1943. sva[q] = t * sqrt(aaqq) * work[q];
  1944. }
  1945. }
  1946. /* Computing 2nd power */
  1947. d__1 = aapp / aapp0;
  1948. if (d__1 * d__1 <= rooteps) {
  1949. if (aapp < rootbig && aapp >
  1950. rootsfmin) {
  1951. aapp = dnrm2_(m, &a[p * a_dim1 +
  1952. 1], &c__1) * work[p];
  1953. } else {
  1954. t = 0.;
  1955. aapp = 1.;
  1956. dlassq_(m, &a[p * a_dim1 + 1], &
  1957. c__1, &t, &aapp);
  1958. aapp = t * sqrt(aapp) * work[p];
  1959. }
  1960. sva[p] = aapp;
  1961. }
  1962. /* end of OK rotation */
  1963. } else {
  1964. ++notrot;
  1965. /* [RTD] SKIPPED = SKIPPED + 1 */
  1966. ++pskipped;
  1967. ++ijblsk;
  1968. }
  1969. } else {
  1970. ++notrot;
  1971. ++pskipped;
  1972. ++ijblsk;
  1973. }
  1974. if (i__ <= swband && ijblsk >= blskip) {
  1975. sva[p] = aapp;
  1976. notrot = 0;
  1977. goto L2011;
  1978. }
  1979. if (i__ <= swband && pskipped > rowskip) {
  1980. aapp = -aapp;
  1981. notrot = 0;
  1982. goto L2203;
  1983. }
  1984. /* L2200: */
  1985. }
  1986. /* end of the q-loop */
  1987. L2203:
  1988. sva[p] = aapp;
  1989. } else {
  1990. if (aapp == 0.) {
  1991. /* Computing MIN */
  1992. i__4 = jgl + kbl - 1;
  1993. notrot = notrot + f2cmin(i__4,*n) - jgl + 1;
  1994. }
  1995. if (aapp < 0.) {
  1996. notrot = 0;
  1997. }
  1998. }
  1999. /* L2100: */
  2000. }
  2001. /* end of the p-loop */
  2002. /* L2010: */
  2003. }
  2004. /* end of the jbc-loop */
  2005. L2011:
  2006. /* 2011 bailed out of the jbc-loop */
  2007. /* Computing MIN */
  2008. i__3 = igl + kbl - 1;
  2009. i__2 = f2cmin(i__3,*n);
  2010. for (p = igl; p <= i__2; ++p) {
  2011. sva[p] = (d__1 = sva[p], abs(d__1));
  2012. /* L2012: */
  2013. }
  2014. /* ** */
  2015. /* L2000: */
  2016. }
  2017. /* 2000 :: end of the ibr-loop */
  2018. if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
  2019. sva[*n] = dnrm2_(m, &a[*n * a_dim1 + 1], &c__1) * work[*n];
  2020. } else {
  2021. t = 0.;
  2022. aapp = 1.;
  2023. dlassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
  2024. sva[*n] = t * sqrt(aapp) * work[*n];
  2025. }
  2026. /* Additional steering devices */
  2027. if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
  2028. swband = i__;
  2029. }
  2030. if (i__ > swband + 1 && mxaapq < sqrt((doublereal) (*n)) * tol && (
  2031. doublereal) (*n) * mxaapq * mxsinj < tol) {
  2032. goto L1994;
  2033. }
  2034. if (notrot >= emptsw) {
  2035. goto L1994;
  2036. }
  2037. /* L1993: */
  2038. }
  2039. /* end i=1:NSWEEP loop */
  2040. /* #:( Reaching this point means that the procedure has not converged. */
  2041. *info = 29;
  2042. goto L1995;
  2043. L1994:
  2044. /* #:) Reaching this point means numerical convergence after the i-th */
  2045. /* sweep. */
  2046. *info = 0;
  2047. /* #:) INFO = 0 confirms successful iterations. */
  2048. L1995:
  2049. /* Sort the singular values and find how many are above */
  2050. /* the underflow threshold. */
  2051. n2 = 0;
  2052. n4 = 0;
  2053. i__1 = *n - 1;
  2054. for (p = 1; p <= i__1; ++p) {
  2055. i__2 = *n - p + 1;
  2056. q = idamax_(&i__2, &sva[p], &c__1) + p - 1;
  2057. if (p != q) {
  2058. temp1 = sva[p];
  2059. sva[p] = sva[q];
  2060. sva[q] = temp1;
  2061. temp1 = work[p];
  2062. work[p] = work[q];
  2063. work[q] = temp1;
  2064. dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
  2065. if (rsvec) {
  2066. dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
  2067. c__1);
  2068. }
  2069. }
  2070. if (sva[p] != 0.) {
  2071. ++n4;
  2072. if (sva[p] * skl > sfmin) {
  2073. ++n2;
  2074. }
  2075. }
  2076. /* L5991: */
  2077. }
  2078. if (sva[*n] != 0.) {
  2079. ++n4;
  2080. if (sva[*n] * skl > sfmin) {
  2081. ++n2;
  2082. }
  2083. }
  2084. /* Normalize the left singular vectors. */
  2085. if (lsvec || uctol) {
  2086. i__1 = n2;
  2087. for (p = 1; p <= i__1; ++p) {
  2088. d__1 = work[p] / sva[p];
  2089. dscal_(m, &d__1, &a[p * a_dim1 + 1], &c__1);
  2090. /* L1998: */
  2091. }
  2092. }
  2093. /* Scale the product of Jacobi rotations (assemble the fast rotations). */
  2094. if (rsvec) {
  2095. if (applv) {
  2096. i__1 = *n;
  2097. for (p = 1; p <= i__1; ++p) {
  2098. dscal_(&mvl, &work[p], &v[p * v_dim1 + 1], &c__1);
  2099. /* L2398: */
  2100. }
  2101. } else {
  2102. i__1 = *n;
  2103. for (p = 1; p <= i__1; ++p) {
  2104. temp1 = 1. / dnrm2_(&mvl, &v[p * v_dim1 + 1], &c__1);
  2105. dscal_(&mvl, &temp1, &v[p * v_dim1 + 1], &c__1);
  2106. /* L2399: */
  2107. }
  2108. }
  2109. }
  2110. /* Undo scaling, if necessary (and possible). */
  2111. if (skl > 1. && sva[1] < big / skl || skl < 1. && sva[f2cmax(n2,1)] > sfmin /
  2112. skl) {
  2113. i__1 = *n;
  2114. for (p = 1; p <= i__1; ++p) {
  2115. sva[p] = skl * sva[p];
  2116. /* L2400: */
  2117. }
  2118. skl = 1.;
  2119. }
  2120. work[1] = skl;
  2121. /* The singular values of A are SKL*SVA(1:N). If SKL.NE.ONE */
  2122. /* then some of the singular values may overflow or underflow and */
  2123. /* the spectrum is given in this factored representation. */
  2124. work[2] = (doublereal) n4;
  2125. /* N4 is the number of computed nonzero singular values of A. */
  2126. work[3] = (doublereal) n2;
  2127. /* N2 is the number of singular values of A greater than SFMIN. */
  2128. /* If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers */
  2129. /* that may carry some information. */
  2130. work[4] = (doublereal) i__;
  2131. /* i is the index of the last sweep before declaring convergence. */
  2132. work[5] = mxaapq;
  2133. /* MXAAPQ is the largest absolute value of scaled pivots in the */
  2134. /* last sweep */
  2135. work[6] = mxsinj;
  2136. /* MXSINJ is the largest absolute value of the sines of Jacobi angles */
  2137. /* in the last sweep */
  2138. return;
  2139. } /* dgesvj_ */