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.

zgesvj.c 68 kB

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