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.

dgsvj0.c 48 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__1 = 1;
  485. static integer c__0 = 0;
  486. static doublereal c_b42 = 1.;
  487. /* > \brief \b DGSVJ0 pre-processor for the routine dgesvj. */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download DGSVJ0 + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgsvj0.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgsvj0.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgsvj0.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE DGSVJ0( JOBV, M, N, A, LDA, D, SVA, MV, V, LDV, EPS, */
  506. /* SFMIN, TOL, NSWEEP, WORK, LWORK, INFO ) */
  507. /* INTEGER INFO, LDA, LDV, LWORK, M, MV, N, NSWEEP */
  508. /* DOUBLE PRECISION EPS, SFMIN, TOL */
  509. /* CHARACTER*1 JOBV */
  510. /* DOUBLE PRECISION A( LDA, * ), SVA( N ), D( N ), V( LDV, * ), */
  511. /* $ WORK( LWORK ) */
  512. /* > \par Purpose: */
  513. /* ============= */
  514. /* > */
  515. /* > \verbatim */
  516. /* > */
  517. /* > DGSVJ0 is called from DGESVJ as a pre-processor and that is its main */
  518. /* > purpose. It applies Jacobi rotations in the same way as DGESVJ does, but */
  519. /* > it does not check convergence (stopping criterion). Few tuning */
  520. /* > parameters (marked by [TP]) are available for the implementer. */
  521. /* > \endverbatim */
  522. /* Arguments: */
  523. /* ========== */
  524. /* > \param[in] JOBV */
  525. /* > \verbatim */
  526. /* > JOBV is CHARACTER*1 */
  527. /* > Specifies whether the output from this procedure is used */
  528. /* > to compute the matrix V: */
  529. /* > = 'V': the product of the Jacobi rotations is accumulated */
  530. /* > by postmulyiplying the N-by-N array V. */
  531. /* > (See the description of V.) */
  532. /* > = 'A': the product of the Jacobi rotations is accumulated */
  533. /* > by postmulyiplying the MV-by-N array V. */
  534. /* > (See the descriptions of MV and V.) */
  535. /* > = 'N': the Jacobi rotations are not accumulated. */
  536. /* > \endverbatim */
  537. /* > */
  538. /* > \param[in] M */
  539. /* > \verbatim */
  540. /* > M is INTEGER */
  541. /* > The number of rows of the input matrix A. M >= 0. */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] N */
  545. /* > \verbatim */
  546. /* > N is INTEGER */
  547. /* > The number of columns of the input matrix A. */
  548. /* > M >= N >= 0. */
  549. /* > \endverbatim */
  550. /* > */
  551. /* > \param[in,out] A */
  552. /* > \verbatim */
  553. /* > A is DOUBLE PRECISION array, dimension (LDA,N) */
  554. /* > On entry, M-by-N matrix A, such that A*diag(D) represents */
  555. /* > the input matrix. */
  556. /* > On exit, */
  557. /* > A_onexit * D_onexit represents the input matrix A*diag(D) */
  558. /* > post-multiplied by a sequence of Jacobi rotations, where the */
  559. /* > rotation threshold and the total number of sweeps are given in */
  560. /* > TOL and NSWEEP, respectively. */
  561. /* > (See the descriptions of D, TOL and NSWEEP.) */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[in] LDA */
  565. /* > \verbatim */
  566. /* > LDA is INTEGER */
  567. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in,out] D */
  571. /* > \verbatim */
  572. /* > D is DOUBLE PRECISION array, dimension (N) */
  573. /* > The array D accumulates the scaling factors from the fast scaled */
  574. /* > Jacobi rotations. */
  575. /* > On entry, A*diag(D) represents the input matrix. */
  576. /* > On exit, A_onexit*diag(D_onexit) represents the input matrix */
  577. /* > post-multiplied by a sequence of Jacobi rotations, where the */
  578. /* > rotation threshold and the total number of sweeps are given in */
  579. /* > TOL and NSWEEP, respectively. */
  580. /* > (See the descriptions of A, TOL and NSWEEP.) */
  581. /* > \endverbatim */
  582. /* > */
  583. /* > \param[in,out] SVA */
  584. /* > \verbatim */
  585. /* > SVA is DOUBLE PRECISION array, dimension (N) */
  586. /* > On entry, SVA contains the Euclidean norms of the columns of */
  587. /* > the matrix A*diag(D). */
  588. /* > On exit, SVA contains the Euclidean norms of the columns of */
  589. /* > the matrix onexit*diag(D_onexit). */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[in] MV */
  593. /* > \verbatim */
  594. /* > MV is INTEGER */
  595. /* > If JOBV = 'A', then MV rows of V are post-multipled by a */
  596. /* > sequence of Jacobi rotations. */
  597. /* > If JOBV = 'N', then MV is not referenced. */
  598. /* > \endverbatim */
  599. /* > */
  600. /* > \param[in,out] V */
  601. /* > \verbatim */
  602. /* > V is DOUBLE PRECISION array, dimension (LDV,N) */
  603. /* > If JOBV = 'V' then N rows of V are post-multipled by a */
  604. /* > sequence of Jacobi rotations. */
  605. /* > If JOBV = 'A' then MV rows of V are post-multipled by a */
  606. /* > sequence of Jacobi rotations. */
  607. /* > If JOBV = 'N', then V is not referenced. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[in] LDV */
  611. /* > \verbatim */
  612. /* > LDV is INTEGER */
  613. /* > The leading dimension of the array V, LDV >= 1. */
  614. /* > If JOBV = 'V', LDV >= N. */
  615. /* > If JOBV = 'A', LDV >= MV. */
  616. /* > \endverbatim */
  617. /* > */
  618. /* > \param[in] EPS */
  619. /* > \verbatim */
  620. /* > EPS is DOUBLE PRECISION */
  621. /* > EPS = DLAMCH('Epsilon') */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[in] SFMIN */
  625. /* > \verbatim */
  626. /* > SFMIN is DOUBLE PRECISION */
  627. /* > SFMIN = DLAMCH('Safe Minimum') */
  628. /* > \endverbatim */
  629. /* > */
  630. /* > \param[in] TOL */
  631. /* > \verbatim */
  632. /* > TOL is DOUBLE PRECISION */
  633. /* > TOL is the threshold for Jacobi rotations. For a pair */
  634. /* > A(:,p), A(:,q) of pivot columns, the Jacobi rotation is */
  635. /* > applied only if DABS(COS(angle(A(:,p),A(:,q)))) > TOL. */
  636. /* > \endverbatim */
  637. /* > */
  638. /* > \param[in] NSWEEP */
  639. /* > \verbatim */
  640. /* > NSWEEP is INTEGER */
  641. /* > NSWEEP is the number of sweeps of Jacobi rotations to be */
  642. /* > performed. */
  643. /* > \endverbatim */
  644. /* > */
  645. /* > \param[out] WORK */
  646. /* > \verbatim */
  647. /* > WORK is DOUBLE PRECISION array, dimension (LWORK) */
  648. /* > \endverbatim */
  649. /* > */
  650. /* > \param[in] LWORK */
  651. /* > \verbatim */
  652. /* > LWORK is INTEGER */
  653. /* > LWORK is the dimension of WORK. LWORK >= M. */
  654. /* > \endverbatim */
  655. /* > */
  656. /* > \param[out] INFO */
  657. /* > \verbatim */
  658. /* > INFO is INTEGER */
  659. /* > = 0: successful exit. */
  660. /* > < 0: if INFO = -i, then the i-th argument had an illegal value */
  661. /* > \endverbatim */
  662. /* Authors: */
  663. /* ======== */
  664. /* > \author Univ. of Tennessee */
  665. /* > \author Univ. of California Berkeley */
  666. /* > \author Univ. of Colorado Denver */
  667. /* > \author NAG Ltd. */
  668. /* > \date November 2017 */
  669. /* > \ingroup doubleOTHERcomputational */
  670. /* > \par Further Details: */
  671. /* ===================== */
  672. /* > */
  673. /* > DGSVJ0 is used just to enable DGESVJ to call a simplified version of */
  674. /* > itself to work on a submatrix of the original matrix. */
  675. /* > */
  676. /* > \par Contributors: */
  677. /* ================== */
  678. /* > */
  679. /* > Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
  680. /* > */
  681. /* > \par Bugs, Examples and Comments: */
  682. /* ================================= */
  683. /* > */
  684. /* > Please report all bugs and send interesting test examples and comments to */
  685. /* > drmac@math.hr. Thank you. */
  686. /* ===================================================================== */
  687. /* Subroutine */ void dgsvj0_(char *jobv, integer *m, integer *n, doublereal *
  688. a, integer *lda, doublereal *d__, doublereal *sva, integer *mv,
  689. doublereal *v, integer *ldv, doublereal *eps, doublereal *sfmin,
  690. doublereal *tol, integer *nsweep, doublereal *work, integer *lwork,
  691. integer *info)
  692. {
  693. /* System generated locals */
  694. integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5,
  695. i__6;
  696. doublereal d__1, d__2;
  697. /* Local variables */
  698. doublereal aapp, aapq, aaqq;
  699. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  700. integer *);
  701. integer ierr;
  702. doublereal bigtheta;
  703. integer pskipped;
  704. doublereal aapp0;
  705. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  706. doublereal temp1;
  707. integer i__, p, q;
  708. doublereal t, apoaq, aqoap;
  709. extern logical lsame_(char *, char *);
  710. doublereal theta, small;
  711. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  712. doublereal *, integer *);
  713. doublereal fastr[5];
  714. extern /* Subroutine */ void dswap_(integer *, doublereal *, integer *,
  715. doublereal *, integer *);
  716. logical applv, rsvec;
  717. extern /* Subroutine */ void daxpy_(integer *, doublereal *, doublereal *,
  718. integer *, doublereal *, integer *), drotm_(integer *, doublereal
  719. *, integer *, doublereal *, integer *, doublereal *);
  720. logical rotok;
  721. doublereal rootsfmin, cs, sn;
  722. extern /* Subroutine */ void dlascl_(char *, integer *, integer *,
  723. doublereal *, doublereal *, integer *, integer *, doublereal *,
  724. integer *, integer *);
  725. extern integer idamax_(integer *, doublereal *, integer *);
  726. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  727. integer ijblsk, swband, blskip;
  728. doublereal mxaapq;
  729. extern /* Subroutine */ void dlassq_(integer *, doublereal *, integer *,
  730. doublereal *, doublereal *);
  731. doublereal thsign, mxsinj;
  732. integer ir1, emptsw, notrot, iswrot, jbc;
  733. doublereal big;
  734. integer kbl, lkahead, igl, ibr, jgl, nbl, mvl;
  735. doublereal rootbig, rooteps;
  736. integer rowskip;
  737. doublereal roottol;
  738. /* -- LAPACK computational routine (version 3.8.0) -- */
  739. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  740. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  741. /* November 2017 */
  742. /* ===================================================================== */
  743. /* Test the input parameters. */
  744. /* Parameter adjustments */
  745. --sva;
  746. --d__;
  747. a_dim1 = *lda;
  748. a_offset = 1 + a_dim1 * 1;
  749. a -= a_offset;
  750. v_dim1 = *ldv;
  751. v_offset = 1 + v_dim1 * 1;
  752. v -= v_offset;
  753. --work;
  754. /* Function Body */
  755. applv = lsame_(jobv, "A");
  756. rsvec = lsame_(jobv, "V");
  757. if (! (rsvec || applv || lsame_(jobv, "N"))) {
  758. *info = -1;
  759. } else if (*m < 0) {
  760. *info = -2;
  761. } else if (*n < 0 || *n > *m) {
  762. *info = -3;
  763. } else if (*lda < *m) {
  764. *info = -5;
  765. } else if ((rsvec || applv) && *mv < 0) {
  766. *info = -8;
  767. } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
  768. *info = -10;
  769. } else if (*tol <= *eps) {
  770. *info = -13;
  771. } else if (*nsweep < 0) {
  772. *info = -14;
  773. } else if (*lwork < *m) {
  774. *info = -16;
  775. } else {
  776. *info = 0;
  777. }
  778. /* #:( */
  779. if (*info != 0) {
  780. i__1 = -(*info);
  781. xerbla_("DGSVJ0", &i__1, (ftnlen)6);
  782. return;
  783. }
  784. if (rsvec) {
  785. mvl = *n;
  786. } else if (applv) {
  787. mvl = *mv;
  788. }
  789. rsvec = rsvec || applv;
  790. rooteps = sqrt(*eps);
  791. rootsfmin = sqrt(*sfmin);
  792. small = *sfmin / *eps;
  793. big = 1. / *sfmin;
  794. rootbig = 1. / rootsfmin;
  795. bigtheta = 1. / rooteps;
  796. roottol = sqrt(*tol);
  797. /* -#- Row-cyclic Jacobi SVD algorithm with column pivoting -#- */
  798. emptsw = *n * (*n - 1) / 2;
  799. notrot = 0;
  800. fastr[0] = 0.;
  801. /* -#- Row-cyclic pivot strategy with de Rijk's pivoting -#- */
  802. swband = 0;
  803. /* [TP] SWBAND is a tuning parameter. It is meaningful and effective */
  804. /* if SGESVJ is used as a computational routine in the preconditioned */
  805. /* Jacobi SVD algorithm SGESVJ. For sweeps i=1:SWBAND the procedure */
  806. /* ...... */
  807. kbl = f2cmin(8,*n);
  808. /* [TP] KBL is a tuning parameter that defines the tile size in the */
  809. /* tiling of the p-q loops of pivot pairs. In general, an optimal */
  810. /* value of KBL depends on the matrix dimensions and on the */
  811. /* parameters of the computer's memory. */
  812. nbl = *n / kbl;
  813. if (nbl * kbl != *n) {
  814. ++nbl;
  815. }
  816. /* Computing 2nd power */
  817. i__1 = kbl;
  818. blskip = i__1 * i__1 + 1;
  819. /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
  820. rowskip = f2cmin(5,kbl);
  821. /* [TP] ROWSKIP is a tuning parameter. */
  822. lkahead = 1;
  823. /* [TP] LKAHEAD is a tuning parameter. */
  824. swband = 0;
  825. pskipped = 0;
  826. i__1 = *nsweep;
  827. for (i__ = 1; i__ <= i__1; ++i__) {
  828. mxaapq = 0.;
  829. mxsinj = 0.;
  830. iswrot = 0;
  831. notrot = 0;
  832. pskipped = 0;
  833. i__2 = nbl;
  834. for (ibr = 1; ibr <= i__2; ++ibr) {
  835. igl = (ibr - 1) * kbl + 1;
  836. /* Computing MIN */
  837. i__4 = lkahead, i__5 = nbl - ibr;
  838. i__3 = f2cmin(i__4,i__5);
  839. for (ir1 = 0; ir1 <= i__3; ++ir1) {
  840. igl += ir1 * kbl;
  841. /* Computing MIN */
  842. i__5 = igl + kbl - 1, i__6 = *n - 1;
  843. i__4 = f2cmin(i__5,i__6);
  844. for (p = igl; p <= i__4; ++p) {
  845. i__5 = *n - p + 1;
  846. q = idamax_(&i__5, &sva[p], &c__1) + p - 1;
  847. if (p != q) {
  848. dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 +
  849. 1], &c__1);
  850. if (rsvec) {
  851. dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  852. v_dim1 + 1], &c__1);
  853. }
  854. temp1 = sva[p];
  855. sva[p] = sva[q];
  856. sva[q] = temp1;
  857. temp1 = d__[p];
  858. d__[p] = d__[q];
  859. d__[q] = temp1;
  860. }
  861. if (ir1 == 0) {
  862. /* Column norms are periodically updated by explicit */
  863. /* norm computation. */
  864. /* Caveat: */
  865. /* Some BLAS implementations compute DNRM2(M,A(1,p),1) */
  866. /* as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may result in */
  867. /* overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and */
  868. /* undeflow for ||A(:,p)||_2 < DSQRT(underflow_threshold). */
  869. /* Hence, DNRM2 cannot be trusted, not even in the case when */
  870. /* the true norm is far from the under(over)flow boundaries. */
  871. /* If properly implemented DNRM2 is available, the IF-THEN-ELSE */
  872. /* below should read "AAPP = DNRM2( M, A(1,p), 1 ) * D(p)". */
  873. if (sva[p] < rootbig && sva[p] > rootsfmin) {
  874. sva[p] = dnrm2_(m, &a[p * a_dim1 + 1], &c__1) *
  875. d__[p];
  876. } else {
  877. temp1 = 0.;
  878. aapp = 1.;
  879. dlassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
  880. aapp);
  881. sva[p] = temp1 * sqrt(aapp) * d__[p];
  882. }
  883. aapp = sva[p];
  884. } else {
  885. aapp = sva[p];
  886. }
  887. if (aapp > 0.) {
  888. pskipped = 0;
  889. /* Computing MIN */
  890. i__6 = igl + kbl - 1;
  891. i__5 = f2cmin(i__6,*n);
  892. for (q = p + 1; q <= i__5; ++q) {
  893. aaqq = sva[q];
  894. if (aaqq > 0.) {
  895. aapp0 = aapp;
  896. if (aaqq >= 1.) {
  897. rotok = small * aapp <= aaqq;
  898. if (aapp < big / aaqq) {
  899. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  900. c__1, &a[q * a_dim1 + 1], &
  901. c__1) * d__[p] * d__[q] /
  902. aaqq / aapp;
  903. } else {
  904. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  905. work[1], &c__1);
  906. dlascl_("G", &c__0, &c__0, &aapp, &
  907. d__[p], m, &c__1, &work[1],
  908. lda, &ierr);
  909. aapq = ddot_(m, &work[1], &c__1, &a[q
  910. * a_dim1 + 1], &c__1) * d__[q]
  911. / aaqq;
  912. }
  913. } else {
  914. rotok = aapp <= aaqq / small;
  915. if (aapp > small / aaqq) {
  916. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  917. c__1, &a[q * a_dim1 + 1], &
  918. c__1) * d__[p] * d__[q] /
  919. aaqq / aapp;
  920. } else {
  921. dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
  922. work[1], &c__1);
  923. dlascl_("G", &c__0, &c__0, &aaqq, &
  924. d__[q], m, &c__1, &work[1],
  925. lda, &ierr);
  926. aapq = ddot_(m, &work[1], &c__1, &a[p
  927. * a_dim1 + 1], &c__1) * d__[p]
  928. / aapp;
  929. }
  930. }
  931. /* Computing MAX */
  932. d__1 = mxaapq, d__2 = abs(aapq);
  933. mxaapq = f2cmax(d__1,d__2);
  934. /* TO rotate or NOT to rotate, THAT is the question ... */
  935. if (abs(aapq) > *tol) {
  936. /* ROTATED = ROTATED + ONE */
  937. if (ir1 == 0) {
  938. notrot = 0;
  939. pskipped = 0;
  940. ++iswrot;
  941. }
  942. if (rotok) {
  943. aqoap = aaqq / aapp;
  944. apoaq = aapp / aaqq;
  945. theta = (d__1 = aqoap - apoaq, abs(
  946. d__1)) * -.5 / aapq;
  947. if (abs(theta) > bigtheta) {
  948. t = .5 / theta;
  949. fastr[2] = t * d__[p] / d__[q];
  950. fastr[3] = -t * d__[q] / d__[p];
  951. drotm_(m, &a[p * a_dim1 + 1], &
  952. c__1, &a[q * a_dim1 + 1],
  953. &c__1, fastr);
  954. if (rsvec) {
  955. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  956. v_dim1 + 1], &c__1, fastr);
  957. }
  958. /* Computing MAX */
  959. d__1 = 0., d__2 = t * apoaq *
  960. aapq + 1.;
  961. sva[q] = aaqq * sqrt((f2cmax(d__1,
  962. d__2)));
  963. /* Computing MAX */
  964. d__1 = 0., d__2 = 1. - t * aqoap *
  965. aapq;
  966. aapp *= sqrt((f2cmax(d__1,d__2)));
  967. /* Computing MAX */
  968. d__1 = mxsinj, d__2 = abs(t);
  969. mxsinj = f2cmax(d__1,d__2);
  970. } else {
  971. thsign = -d_sign(&c_b42, &aapq);
  972. t = 1. / (theta + thsign * sqrt(
  973. theta * theta + 1.));
  974. cs = sqrt(1. / (t * t + 1.));
  975. sn = t * cs;
  976. /* Computing MAX */
  977. d__1 = mxsinj, d__2 = abs(sn);
  978. mxsinj = f2cmax(d__1,d__2);
  979. /* Computing MAX */
  980. d__1 = 0., d__2 = t * apoaq *
  981. aapq + 1.;
  982. sva[q] = aaqq * sqrt((f2cmax(d__1,
  983. d__2)));
  984. /* Computing MAX */
  985. d__1 = 0., d__2 = 1. - t * aqoap *
  986. aapq;
  987. aapp *= sqrt((f2cmax(d__1,d__2)));
  988. apoaq = d__[p] / d__[q];
  989. aqoap = d__[q] / d__[p];
  990. if (d__[p] >= 1.) {
  991. if (d__[q] >= 1.) {
  992. fastr[2] = t * apoaq;
  993. fastr[3] = -t * aqoap;
  994. d__[p] *= cs;
  995. d__[q] *= cs;
  996. drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  997. a_dim1 + 1], &c__1, fastr);
  998. if (rsvec) {
  999. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1000. q * v_dim1 + 1], &c__1, fastr);
  1001. }
  1002. } else {
  1003. d__1 = -t * aqoap;
  1004. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1005. p * a_dim1 + 1], &c__1);
  1006. d__1 = cs * sn * apoaq;
  1007. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1008. q * a_dim1 + 1], &c__1);
  1009. d__[p] *= cs;
  1010. d__[q] /= cs;
  1011. if (rsvec) {
  1012. d__1 = -t * aqoap;
  1013. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1014. c__1, &v[p * v_dim1 + 1], &c__1);
  1015. d__1 = cs * sn * apoaq;
  1016. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1017. c__1, &v[q * v_dim1 + 1], &c__1);
  1018. }
  1019. }
  1020. } else {
  1021. if (d__[q] >= 1.) {
  1022. d__1 = t * apoaq;
  1023. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1024. q * a_dim1 + 1], &c__1);
  1025. d__1 = -cs * sn * aqoap;
  1026. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1027. p * a_dim1 + 1], &c__1);
  1028. d__[p] /= cs;
  1029. d__[q] *= cs;
  1030. if (rsvec) {
  1031. d__1 = t * apoaq;
  1032. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1033. c__1, &v[q * v_dim1 + 1], &c__1);
  1034. d__1 = -cs * sn * aqoap;
  1035. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1036. c__1, &v[p * v_dim1 + 1], &c__1);
  1037. }
  1038. } else {
  1039. if (d__[p] >= d__[q]) {
  1040. d__1 = -t * aqoap;
  1041. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1042. &a[p * a_dim1 + 1], &c__1);
  1043. d__1 = cs * sn * apoaq;
  1044. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1045. &a[q * a_dim1 + 1], &c__1);
  1046. d__[p] *= cs;
  1047. d__[q] /= cs;
  1048. if (rsvec) {
  1049. d__1 = -t * aqoap;
  1050. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1051. &c__1, &v[p * v_dim1 + 1], &
  1052. c__1);
  1053. d__1 = cs * sn * apoaq;
  1054. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1055. &c__1, &v[q * v_dim1 + 1], &
  1056. c__1);
  1057. }
  1058. } else {
  1059. d__1 = t * apoaq;
  1060. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1061. &a[q * a_dim1 + 1], &c__1);
  1062. d__1 = -cs * sn * aqoap;
  1063. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1064. &a[p * a_dim1 + 1], &c__1);
  1065. d__[p] /= cs;
  1066. d__[q] *= cs;
  1067. if (rsvec) {
  1068. d__1 = t * apoaq;
  1069. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1070. &c__1, &v[q * v_dim1 + 1], &
  1071. c__1);
  1072. d__1 = -cs * sn * aqoap;
  1073. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1074. &c__1, &v[p * v_dim1 + 1], &
  1075. c__1);
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. } else {
  1082. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1083. work[1], &c__1);
  1084. dlascl_("G", &c__0, &c__0, &aapp, &
  1085. c_b42, m, &c__1, &work[1],
  1086. lda, &ierr);
  1087. dlascl_("G", &c__0, &c__0, &aaqq, &
  1088. c_b42, m, &c__1, &a[q *
  1089. a_dim1 + 1], lda, &ierr);
  1090. temp1 = -aapq * d__[p] / d__[q];
  1091. daxpy_(m, &temp1, &work[1], &c__1, &a[
  1092. q * a_dim1 + 1], &c__1);
  1093. dlascl_("G", &c__0, &c__0, &c_b42, &
  1094. aaqq, m, &c__1, &a[q * a_dim1
  1095. + 1], lda, &ierr);
  1096. /* Computing MAX */
  1097. d__1 = 0., d__2 = 1. - aapq * aapq;
  1098. sva[q] = aaqq * sqrt((f2cmax(d__1,d__2)))
  1099. ;
  1100. mxsinj = f2cmax(mxsinj,*sfmin);
  1101. }
  1102. /* END IF ROTOK THEN ... ELSE */
  1103. /* In the case of cancellation in updating SVA(q), SVA(p) */
  1104. /* recompute SVA(q), SVA(p). */
  1105. /* Computing 2nd power */
  1106. d__1 = sva[q] / aaqq;
  1107. if (d__1 * d__1 <= rooteps) {
  1108. if (aaqq < rootbig && aaqq >
  1109. rootsfmin) {
  1110. sva[q] = dnrm2_(m, &a[q * a_dim1
  1111. + 1], &c__1) * d__[q];
  1112. } else {
  1113. t = 0.;
  1114. aaqq = 1.;
  1115. dlassq_(m, &a[q * a_dim1 + 1], &
  1116. c__1, &t, &aaqq);
  1117. sva[q] = t * sqrt(aaqq) * d__[q];
  1118. }
  1119. }
  1120. if (aapp / aapp0 <= rooteps) {
  1121. if (aapp < rootbig && aapp >
  1122. rootsfmin) {
  1123. aapp = dnrm2_(m, &a[p * a_dim1 +
  1124. 1], &c__1) * d__[p];
  1125. } else {
  1126. t = 0.;
  1127. aapp = 1.;
  1128. dlassq_(m, &a[p * a_dim1 + 1], &
  1129. c__1, &t, &aapp);
  1130. aapp = t * sqrt(aapp) * d__[p];
  1131. }
  1132. sva[p] = aapp;
  1133. }
  1134. } else {
  1135. /* A(:,p) and A(:,q) already numerically orthogonal */
  1136. if (ir1 == 0) {
  1137. ++notrot;
  1138. }
  1139. ++pskipped;
  1140. }
  1141. } else {
  1142. /* A(:,q) is zero column */
  1143. if (ir1 == 0) {
  1144. ++notrot;
  1145. }
  1146. ++pskipped;
  1147. }
  1148. if (i__ <= swband && pskipped > rowskip) {
  1149. if (ir1 == 0) {
  1150. aapp = -aapp;
  1151. }
  1152. notrot = 0;
  1153. goto L2103;
  1154. }
  1155. /* L2002: */
  1156. }
  1157. /* END q-LOOP */
  1158. L2103:
  1159. /* bailed out of q-loop */
  1160. sva[p] = aapp;
  1161. } else {
  1162. sva[p] = aapp;
  1163. if (ir1 == 0 && aapp == 0.) {
  1164. /* Computing MIN */
  1165. i__5 = igl + kbl - 1;
  1166. notrot = notrot + f2cmin(i__5,*n) - p;
  1167. }
  1168. }
  1169. /* L2001: */
  1170. }
  1171. /* end of the p-loop */
  1172. /* end of doing the block ( ibr, ibr ) */
  1173. /* L1002: */
  1174. }
  1175. /* end of ir1-loop */
  1176. /* ........................................................ */
  1177. /* ... go to the off diagonal blocks */
  1178. igl = (ibr - 1) * kbl + 1;
  1179. i__3 = nbl;
  1180. for (jbc = ibr + 1; jbc <= i__3; ++jbc) {
  1181. jgl = (jbc - 1) * kbl + 1;
  1182. /* doing the block at ( ibr, jbc ) */
  1183. ijblsk = 0;
  1184. /* Computing MIN */
  1185. i__5 = igl + kbl - 1;
  1186. i__4 = f2cmin(i__5,*n);
  1187. for (p = igl; p <= i__4; ++p) {
  1188. aapp = sva[p];
  1189. if (aapp > 0.) {
  1190. pskipped = 0;
  1191. /* Computing MIN */
  1192. i__6 = jgl + kbl - 1;
  1193. i__5 = f2cmin(i__6,*n);
  1194. for (q = jgl; q <= i__5; ++q) {
  1195. aaqq = sva[q];
  1196. if (aaqq > 0.) {
  1197. aapp0 = aapp;
  1198. /* -#- M x 2 Jacobi SVD -#- */
  1199. /* -#- Safe Gram matrix computation -#- */
  1200. if (aaqq >= 1.) {
  1201. if (aapp >= aaqq) {
  1202. rotok = small * aapp <= aaqq;
  1203. } else {
  1204. rotok = small * aaqq <= aapp;
  1205. }
  1206. if (aapp < big / aaqq) {
  1207. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1208. c__1, &a[q * a_dim1 + 1], &
  1209. c__1) * d__[p] * d__[q] /
  1210. aaqq / aapp;
  1211. } else {
  1212. dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1213. work[1], &c__1);
  1214. dlascl_("G", &c__0, &c__0, &aapp, &
  1215. d__[p], m, &c__1, &work[1],
  1216. lda, &ierr);
  1217. aapq = ddot_(m, &work[1], &c__1, &a[q
  1218. * a_dim1 + 1], &c__1) * d__[q]
  1219. / aaqq;
  1220. }
  1221. } else {
  1222. if (aapp >= aaqq) {
  1223. rotok = aapp <= aaqq / small;
  1224. } else {
  1225. rotok = aaqq <= aapp / small;
  1226. }
  1227. if (aapp > small / aaqq) {
  1228. aapq = ddot_(m, &a[p * a_dim1 + 1], &
  1229. c__1, &a[q * a_dim1 + 1], &
  1230. c__1) * d__[p] * d__[q] /
  1231. aaqq / aapp;
  1232. } else {
  1233. dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1234. work[1], &c__1);
  1235. dlascl_("G", &c__0, &c__0, &aaqq, &
  1236. d__[q], m, &c__1, &work[1],
  1237. lda, &ierr);
  1238. aapq = ddot_(m, &work[1], &c__1, &a[p
  1239. * a_dim1 + 1], &c__1) * d__[p]
  1240. / aapp;
  1241. }
  1242. }
  1243. /* Computing MAX */
  1244. d__1 = mxaapq, d__2 = abs(aapq);
  1245. mxaapq = f2cmax(d__1,d__2);
  1246. /* TO rotate or NOT to rotate, THAT is the question ... */
  1247. if (abs(aapq) > *tol) {
  1248. notrot = 0;
  1249. /* ROTATED = ROTATED + 1 */
  1250. pskipped = 0;
  1251. ++iswrot;
  1252. if (rotok) {
  1253. aqoap = aaqq / aapp;
  1254. apoaq = aapp / aaqq;
  1255. theta = (d__1 = aqoap - apoaq, abs(
  1256. d__1)) * -.5 / aapq;
  1257. if (aaqq > aapp0) {
  1258. theta = -theta;
  1259. }
  1260. if (abs(theta) > bigtheta) {
  1261. t = .5 / theta;
  1262. fastr[2] = t * d__[p] / d__[q];
  1263. fastr[3] = -t * d__[q] / d__[p];
  1264. drotm_(m, &a[p * a_dim1 + 1], &
  1265. c__1, &a[q * a_dim1 + 1],
  1266. &c__1, fastr);
  1267. if (rsvec) {
  1268. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1269. v_dim1 + 1], &c__1, fastr);
  1270. }
  1271. /* Computing MAX */
  1272. d__1 = 0., d__2 = t * apoaq *
  1273. aapq + 1.;
  1274. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1275. d__2)));
  1276. /* Computing MAX */
  1277. d__1 = 0., d__2 = 1. - t * aqoap *
  1278. aapq;
  1279. aapp *= sqrt((f2cmax(d__1,d__2)));
  1280. /* Computing MAX */
  1281. d__1 = mxsinj, d__2 = abs(t);
  1282. mxsinj = f2cmax(d__1,d__2);
  1283. } else {
  1284. thsign = -d_sign(&c_b42, &aapq);
  1285. if (aaqq > aapp0) {
  1286. thsign = -thsign;
  1287. }
  1288. t = 1. / (theta + thsign * sqrt(
  1289. theta * theta + 1.));
  1290. cs = sqrt(1. / (t * t + 1.));
  1291. sn = t * cs;
  1292. /* Computing MAX */
  1293. d__1 = mxsinj, d__2 = abs(sn);
  1294. mxsinj = f2cmax(d__1,d__2);
  1295. /* Computing MAX */
  1296. d__1 = 0., d__2 = t * apoaq *
  1297. aapq + 1.;
  1298. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1299. d__2)));
  1300. /* Computing MAX */
  1301. d__1 = 0., d__2 = 1. - t * aqoap *
  1302. aapq;
  1303. aapp *= sqrt((f2cmax(d__1,d__2)));
  1304. apoaq = d__[p] / d__[q];
  1305. aqoap = d__[q] / d__[p];
  1306. if (d__[p] >= 1.) {
  1307. if (d__[q] >= 1.) {
  1308. fastr[2] = t * apoaq;
  1309. fastr[3] = -t * aqoap;
  1310. d__[p] *= cs;
  1311. d__[q] *= cs;
  1312. drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1313. a_dim1 + 1], &c__1, fastr);
  1314. if (rsvec) {
  1315. drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1316. q * v_dim1 + 1], &c__1, fastr);
  1317. }
  1318. } else {
  1319. d__1 = -t * aqoap;
  1320. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1321. p * a_dim1 + 1], &c__1);
  1322. d__1 = cs * sn * apoaq;
  1323. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1324. q * a_dim1 + 1], &c__1);
  1325. if (rsvec) {
  1326. d__1 = -t * aqoap;
  1327. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1328. c__1, &v[p * v_dim1 + 1], &c__1);
  1329. d__1 = cs * sn * apoaq;
  1330. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1331. c__1, &v[q * v_dim1 + 1], &c__1);
  1332. }
  1333. d__[p] *= cs;
  1334. d__[q] /= cs;
  1335. }
  1336. } else {
  1337. if (d__[q] >= 1.) {
  1338. d__1 = t * apoaq;
  1339. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
  1340. q * a_dim1 + 1], &c__1);
  1341. d__1 = -cs * sn * aqoap;
  1342. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
  1343. p * a_dim1 + 1], &c__1);
  1344. if (rsvec) {
  1345. d__1 = t * apoaq;
  1346. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
  1347. c__1, &v[q * v_dim1 + 1], &c__1);
  1348. d__1 = -cs * sn * aqoap;
  1349. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
  1350. c__1, &v[p * v_dim1 + 1], &c__1);
  1351. }
  1352. d__[p] /= cs;
  1353. d__[q] *= cs;
  1354. } else {
  1355. if (d__[p] >= d__[q]) {
  1356. d__1 = -t * aqoap;
  1357. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1358. &a[p * a_dim1 + 1], &c__1);
  1359. d__1 = cs * sn * apoaq;
  1360. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1361. &a[q * a_dim1 + 1], &c__1);
  1362. d__[p] *= cs;
  1363. d__[q] /= cs;
  1364. if (rsvec) {
  1365. d__1 = -t * aqoap;
  1366. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1367. &c__1, &v[p * v_dim1 + 1], &
  1368. c__1);
  1369. d__1 = cs * sn * apoaq;
  1370. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1371. &c__1, &v[q * v_dim1 + 1], &
  1372. c__1);
  1373. }
  1374. } else {
  1375. d__1 = t * apoaq;
  1376. daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
  1377. &a[q * a_dim1 + 1], &c__1);
  1378. d__1 = -cs * sn * aqoap;
  1379. daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
  1380. &a[p * a_dim1 + 1], &c__1);
  1381. d__[p] /= cs;
  1382. d__[q] *= cs;
  1383. if (rsvec) {
  1384. d__1 = t * apoaq;
  1385. daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
  1386. &c__1, &v[q * v_dim1 + 1], &
  1387. c__1);
  1388. d__1 = -cs * sn * aqoap;
  1389. daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
  1390. &c__1, &v[p * v_dim1 + 1], &
  1391. c__1);
  1392. }
  1393. }
  1394. }
  1395. }
  1396. }
  1397. } else {
  1398. if (aapp > aaqq) {
  1399. dcopy_(m, &a[p * a_dim1 + 1], &
  1400. c__1, &work[1], &c__1);
  1401. dlascl_("G", &c__0, &c__0, &aapp,
  1402. &c_b42, m, &c__1, &work[1]
  1403. , lda, &ierr);
  1404. dlascl_("G", &c__0, &c__0, &aaqq,
  1405. &c_b42, m, &c__1, &a[q *
  1406. a_dim1 + 1], lda, &ierr);
  1407. temp1 = -aapq * d__[p] / d__[q];
  1408. daxpy_(m, &temp1, &work[1], &c__1,
  1409. &a[q * a_dim1 + 1], &
  1410. c__1);
  1411. dlascl_("G", &c__0, &c__0, &c_b42,
  1412. &aaqq, m, &c__1, &a[q *
  1413. a_dim1 + 1], lda, &ierr);
  1414. /* Computing MAX */
  1415. d__1 = 0., d__2 = 1. - aapq *
  1416. aapq;
  1417. sva[q] = aaqq * sqrt((f2cmax(d__1,
  1418. d__2)));
  1419. mxsinj = f2cmax(mxsinj,*sfmin);
  1420. } else {
  1421. dcopy_(m, &a[q * a_dim1 + 1], &
  1422. c__1, &work[1], &c__1);
  1423. dlascl_("G", &c__0, &c__0, &aaqq,
  1424. &c_b42, m, &c__1, &work[1]
  1425. , lda, &ierr);
  1426. dlascl_("G", &c__0, &c__0, &aapp,
  1427. &c_b42, m, &c__1, &a[p *
  1428. a_dim1 + 1], lda, &ierr);
  1429. temp1 = -aapq * d__[q] / d__[p];
  1430. daxpy_(m, &temp1, &work[1], &c__1,
  1431. &a[p * a_dim1 + 1], &
  1432. c__1);
  1433. dlascl_("G", &c__0, &c__0, &c_b42,
  1434. &aapp, m, &c__1, &a[p *
  1435. a_dim1 + 1], lda, &ierr);
  1436. /* Computing MAX */
  1437. d__1 = 0., d__2 = 1. - aapq *
  1438. aapq;
  1439. sva[p] = aapp * sqrt((f2cmax(d__1,
  1440. d__2)));
  1441. mxsinj = f2cmax(mxsinj,*sfmin);
  1442. }
  1443. }
  1444. /* END IF ROTOK THEN ... ELSE */
  1445. /* In the case of cancellation in updating SVA(q) */
  1446. /* Computing 2nd power */
  1447. d__1 = sva[q] / aaqq;
  1448. if (d__1 * d__1 <= rooteps) {
  1449. if (aaqq < rootbig && aaqq >
  1450. rootsfmin) {
  1451. sva[q] = dnrm2_(m, &a[q * a_dim1
  1452. + 1], &c__1) * d__[q];
  1453. } else {
  1454. t = 0.;
  1455. aaqq = 1.;
  1456. dlassq_(m, &a[q * a_dim1 + 1], &
  1457. c__1, &t, &aaqq);
  1458. sva[q] = t * sqrt(aaqq) * d__[q];
  1459. }
  1460. }
  1461. /* Computing 2nd power */
  1462. d__1 = aapp / aapp0;
  1463. if (d__1 * d__1 <= rooteps) {
  1464. if (aapp < rootbig && aapp >
  1465. rootsfmin) {
  1466. aapp = dnrm2_(m, &a[p * a_dim1 +
  1467. 1], &c__1) * d__[p];
  1468. } else {
  1469. t = 0.;
  1470. aapp = 1.;
  1471. dlassq_(m, &a[p * a_dim1 + 1], &
  1472. c__1, &t, &aapp);
  1473. aapp = t * sqrt(aapp) * d__[p];
  1474. }
  1475. sva[p] = aapp;
  1476. }
  1477. /* end of OK rotation */
  1478. } else {
  1479. ++notrot;
  1480. ++pskipped;
  1481. ++ijblsk;
  1482. }
  1483. } else {
  1484. ++notrot;
  1485. ++pskipped;
  1486. ++ijblsk;
  1487. }
  1488. if (i__ <= swband && ijblsk >= blskip) {
  1489. sva[p] = aapp;
  1490. notrot = 0;
  1491. goto L2011;
  1492. }
  1493. if (i__ <= swband && pskipped > rowskip) {
  1494. aapp = -aapp;
  1495. notrot = 0;
  1496. goto L2203;
  1497. }
  1498. /* L2200: */
  1499. }
  1500. /* end of the q-loop */
  1501. L2203:
  1502. sva[p] = aapp;
  1503. } else {
  1504. if (aapp == 0.) {
  1505. /* Computing MIN */
  1506. i__5 = jgl + kbl - 1;
  1507. notrot = notrot + f2cmin(i__5,*n) - jgl + 1;
  1508. }
  1509. if (aapp < 0.) {
  1510. notrot = 0;
  1511. }
  1512. }
  1513. /* L2100: */
  1514. }
  1515. /* end of the p-loop */
  1516. /* L2010: */
  1517. }
  1518. /* end of the jbc-loop */
  1519. L2011:
  1520. /* 2011 bailed out of the jbc-loop */
  1521. /* Computing MIN */
  1522. i__4 = igl + kbl - 1;
  1523. i__3 = f2cmin(i__4,*n);
  1524. for (p = igl; p <= i__3; ++p) {
  1525. sva[p] = (d__1 = sva[p], abs(d__1));
  1526. /* L2012: */
  1527. }
  1528. /* L2000: */
  1529. }
  1530. /* 2000 :: end of the ibr-loop */
  1531. if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
  1532. sva[*n] = dnrm2_(m, &a[*n * a_dim1 + 1], &c__1) * d__[*n];
  1533. } else {
  1534. t = 0.;
  1535. aapp = 1.;
  1536. dlassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
  1537. sva[*n] = t * sqrt(aapp) * d__[*n];
  1538. }
  1539. /* Additional steering devices */
  1540. if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
  1541. swband = i__;
  1542. }
  1543. if (i__ > swband + 1 && mxaapq < (doublereal) (*n) * *tol && (
  1544. doublereal) (*n) * mxaapq * mxsinj < *tol) {
  1545. goto L1994;
  1546. }
  1547. if (notrot >= emptsw) {
  1548. goto L1994;
  1549. }
  1550. /* L1993: */
  1551. }
  1552. /* end i=1:NSWEEP loop */
  1553. /* #:) Reaching this point means that the procedure has completed the given */
  1554. /* number of iterations. */
  1555. *info = *nsweep - 1;
  1556. goto L1995;
  1557. L1994:
  1558. /* #:) Reaching this point means that during the i-th sweep all pivots were */
  1559. /* below the given tolerance, causing early exit. */
  1560. *info = 0;
  1561. /* #:) INFO = 0 confirms successful iterations. */
  1562. L1995:
  1563. /* Sort the vector D. */
  1564. i__1 = *n - 1;
  1565. for (p = 1; p <= i__1; ++p) {
  1566. i__2 = *n - p + 1;
  1567. q = idamax_(&i__2, &sva[p], &c__1) + p - 1;
  1568. if (p != q) {
  1569. temp1 = sva[p];
  1570. sva[p] = sva[q];
  1571. sva[q] = temp1;
  1572. temp1 = d__[p];
  1573. d__[p] = d__[q];
  1574. d__[q] = temp1;
  1575. dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
  1576. if (rsvec) {
  1577. dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
  1578. c__1);
  1579. }
  1580. }
  1581. /* L5991: */
  1582. }
  1583. return;
  1584. } /* dgsvj0_ */