You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cgesvj.c 68 kB

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