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