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