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.

cgesvj.c 68 kB

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