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