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.

sgesvj.c 70 kB

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