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.

sgsvj0.c 48 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  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 real c_b42 = 1.f;
  487. /* > \brief \b SGSVJ0 pre-processor for the routine sgesvj. */
  488. /* =========== DOCUMENTATION =========== */
  489. /* Online html documentation available at */
  490. /* http://www.netlib.org/lapack/explore-html/ */
  491. /* > \htmlonly */
  492. /* > Download SGSVJ0 + dependencies */
  493. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgsvj0.
  494. f"> */
  495. /* > [TGZ]</a> */
  496. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgsvj0.
  497. f"> */
  498. /* > [ZIP]</a> */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgsvj0.
  500. f"> */
  501. /* > [TXT]</a> */
  502. /* > \endhtmlonly */
  503. /* Definition: */
  504. /* =========== */
  505. /* SUBROUTINE SGSVJ0( 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. /* REAL EPS, SFMIN, TOL */
  509. /* CHARACTER*1 JOBV */
  510. /* REAL A( LDA, * ), SVA( N ), D( N ), V( LDV, * ), */
  511. /* $ WORK( LWORK ) */
  512. /* > \par Purpose: */
  513. /* ============= */
  514. /* > */
  515. /* > \verbatim */
  516. /* > */
  517. /* > SGSVJ0 is called from SGESVJ as a pre-processor and that is its main */
  518. /* > purpose. It applies Jacobi rotations in the same way as SGESVJ 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 REAL 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 REAL 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 REAL 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 REAL 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 REAL */
  621. /* > EPS = SLAMCH('Epsilon') */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[in] SFMIN */
  625. /* > \verbatim */
  626. /* > SFMIN is REAL */
  627. /* > SFMIN = SLAMCH('Safe Minimum') */
  628. /* > \endverbatim */
  629. /* > */
  630. /* > \param[in] TOL */
  631. /* > \verbatim */
  632. /* > TOL is REAL */
  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 ABS(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 REAL 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 realOTHERcomputational */
  670. /* > \par Further Details: */
  671. /* ===================== */
  672. /* > */
  673. /* > SGSVJ0 is used just to enable SGESVJ 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 sgsvj0_(char *jobv, integer *m, integer *n, real *a,
  688. integer *lda, real *d__, real *sva, integer *mv, real *v, integer *
  689. ldv, real *eps, real *sfmin, real *tol, integer *nsweep, real *work,
  690. integer *lwork, integer *info)
  691. {
  692. /* System generated locals */
  693. integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5,
  694. i__6;
  695. real r__1, r__2;
  696. /* Local variables */
  697. real aapp, aapq, aaqq;
  698. integer ierr;
  699. real bigtheta;
  700. extern real sdot_(integer *, real *, integer *, real *, integer *);
  701. integer pskipped;
  702. real aapp0, temp1;
  703. extern real snrm2_(integer *, real *, integer *);
  704. integer i__, p, q;
  705. real t, apoaq, aqoap;
  706. extern logical lsame_(char *, char *);
  707. real theta, small, fastr[5];
  708. logical applv, rsvec;
  709. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  710. integer *);
  711. logical rotok;
  712. extern /* Subroutine */ void sswap_(integer *, real *, integer *, real *,
  713. integer *), saxpy_(integer *, real *, real *, integer *, real *,
  714. integer *), srotm_(integer *, real *, integer *, real *, integer *
  715. , real *);
  716. real rootsfmin, cs, sn;
  717. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  718. integer ijblsk, swband;
  719. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  720. real *, integer *, integer *, real *, integer *, integer *);
  721. extern integer isamax_(integer *, real *, integer *);
  722. integer blskip;
  723. real mxaapq, thsign;
  724. extern /* Subroutine */ void slassq_(integer *, real *, integer *, real *,
  725. real *);
  726. real mxsinj;
  727. integer ir1, emptsw, notrot, iswrot, jbc;
  728. real big;
  729. integer kbl, lkahead, igl, ibr, jgl, nbl, mvl;
  730. real rootbig, rooteps;
  731. integer rowskip;
  732. real roottol;
  733. /* -- LAPACK computational routine (version 3.8.0) -- */
  734. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  735. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  736. /* November 2017 */
  737. /* ===================================================================== */
  738. /* Test the input parameters. */
  739. /* Parameter adjustments */
  740. --sva;
  741. --d__;
  742. a_dim1 = *lda;
  743. a_offset = 1 + a_dim1 * 1;
  744. a -= a_offset;
  745. v_dim1 = *ldv;
  746. v_offset = 1 + v_dim1 * 1;
  747. v -= v_offset;
  748. --work;
  749. /* Function Body */
  750. applv = lsame_(jobv, "A");
  751. rsvec = lsame_(jobv, "V");
  752. if (! (rsvec || applv || lsame_(jobv, "N"))) {
  753. *info = -1;
  754. } else if (*m < 0) {
  755. *info = -2;
  756. } else if (*n < 0 || *n > *m) {
  757. *info = -3;
  758. } else if (*lda < *m) {
  759. *info = -5;
  760. } else if ((rsvec || applv) && *mv < 0) {
  761. *info = -8;
  762. } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
  763. *info = -10;
  764. } else if (*tol <= *eps) {
  765. *info = -13;
  766. } else if (*nsweep < 0) {
  767. *info = -14;
  768. } else if (*lwork < *m) {
  769. *info = -16;
  770. } else {
  771. *info = 0;
  772. }
  773. /* #:( */
  774. if (*info != 0) {
  775. i__1 = -(*info);
  776. xerbla_("SGSVJ0", &i__1, (ftnlen)6);
  777. return;
  778. }
  779. if (rsvec) {
  780. mvl = *n;
  781. } else if (applv) {
  782. mvl = *mv;
  783. }
  784. rsvec = rsvec || applv;
  785. rooteps = sqrt(*eps);
  786. rootsfmin = sqrt(*sfmin);
  787. small = *sfmin / *eps;
  788. big = 1.f / *sfmin;
  789. rootbig = 1.f / rootsfmin;
  790. bigtheta = 1.f / rooteps;
  791. roottol = sqrt(*tol);
  792. emptsw = *n * (*n - 1) / 2;
  793. notrot = 0;
  794. fastr[0] = 0.f;
  795. swband = 0;
  796. /* [TP] SWBAND is a tuning parameter. It is meaningful and effective */
  797. /* if SGESVJ is used as a computational routine in the preconditioned */
  798. /* Jacobi SVD algorithm SGESVJ. For sweeps i=1:SWBAND the procedure */
  799. /* ...... */
  800. kbl = f2cmin(8,*n);
  801. /* [TP] KBL is a tuning parameter that defines the tile size in the */
  802. /* tiling of the p-q loops of pivot pairs. In general, an optimal */
  803. /* value of KBL depends on the matrix dimensions and on the */
  804. /* parameters of the computer's memory. */
  805. nbl = *n / kbl;
  806. if (nbl * kbl != *n) {
  807. ++nbl;
  808. }
  809. /* Computing 2nd power */
  810. i__1 = kbl;
  811. blskip = i__1 * i__1 + 1;
  812. /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
  813. rowskip = f2cmin(5,kbl);
  814. /* [TP] ROWSKIP is a tuning parameter. */
  815. lkahead = 1;
  816. /* [TP] LKAHEAD is a tuning parameter. */
  817. swband = 0;
  818. pskipped = 0;
  819. i__1 = *nsweep;
  820. for (i__ = 1; i__ <= i__1; ++i__) {
  821. mxaapq = 0.f;
  822. mxsinj = 0.f;
  823. iswrot = 0;
  824. notrot = 0;
  825. pskipped = 0;
  826. i__2 = nbl;
  827. for (ibr = 1; ibr <= i__2; ++ibr) {
  828. igl = (ibr - 1) * kbl + 1;
  829. /* Computing MIN */
  830. i__4 = lkahead, i__5 = nbl - ibr;
  831. i__3 = f2cmin(i__4,i__5);
  832. for (ir1 = 0; ir1 <= i__3; ++ir1) {
  833. igl += ir1 * kbl;
  834. /* Computing MIN */
  835. i__5 = igl + kbl - 1, i__6 = *n - 1;
  836. i__4 = f2cmin(i__5,i__6);
  837. for (p = igl; p <= i__4; ++p) {
  838. i__5 = *n - p + 1;
  839. q = isamax_(&i__5, &sva[p], &c__1) + p - 1;
  840. if (p != q) {
  841. sswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 +
  842. 1], &c__1);
  843. if (rsvec) {
  844. sswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  845. v_dim1 + 1], &c__1);
  846. }
  847. temp1 = sva[p];
  848. sva[p] = sva[q];
  849. sva[q] = temp1;
  850. temp1 = d__[p];
  851. d__[p] = d__[q];
  852. d__[q] = temp1;
  853. }
  854. if (ir1 == 0) {
  855. /* Column norms are periodically updated by explicit */
  856. /* norm computation. */
  857. /* Caveat: */
  858. /* Some BLAS implementations compute SNRM2(M,A(1,p),1) */
  859. /* as SQRT(SDOT(M,A(1,p),1,A(1,p),1)), which may result in */
  860. /* overflow for ||A(:,p)||_2 > SQRT(overflow_threshold), and */
  861. /* undeflow for ||A(:,p)||_2 < SQRT(underflow_threshold). */
  862. /* Hence, SNRM2 cannot be trusted, not even in the case when */
  863. /* the true norm is far from the under(over)flow boundaries. */
  864. /* If properly implemented SNRM2 is available, the IF-THEN-ELSE */
  865. /* below should read "AAPP = SNRM2( M, A(1,p), 1 ) * D(p)". */
  866. if (sva[p] < rootbig && sva[p] > rootsfmin) {
  867. sva[p] = snrm2_(m, &a[p * a_dim1 + 1], &c__1) *
  868. d__[p];
  869. } else {
  870. temp1 = 0.f;
  871. aapp = 1.f;
  872. slassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
  873. aapp);
  874. sva[p] = temp1 * sqrt(aapp) * d__[p];
  875. }
  876. aapp = sva[p];
  877. } else {
  878. aapp = sva[p];
  879. }
  880. if (aapp > 0.f) {
  881. pskipped = 0;
  882. /* Computing MIN */
  883. i__6 = igl + kbl - 1;
  884. i__5 = f2cmin(i__6,*n);
  885. for (q = p + 1; q <= i__5; ++q) {
  886. aaqq = sva[q];
  887. if (aaqq > 0.f) {
  888. aapp0 = aapp;
  889. if (aaqq >= 1.f) {
  890. rotok = small * aapp <= aaqq;
  891. if (aapp < big / aaqq) {
  892. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  893. c__1, &a[q * a_dim1 + 1], &
  894. c__1) * d__[p] * d__[q] /
  895. aaqq / aapp;
  896. } else {
  897. scopy_(m, &a[p * a_dim1 + 1], &c__1, &
  898. work[1], &c__1);
  899. slascl_("G", &c__0, &c__0, &aapp, &
  900. d__[p], m, &c__1, &work[1],
  901. lda, &ierr);
  902. aapq = sdot_(m, &work[1], &c__1, &a[q
  903. * a_dim1 + 1], &c__1) * d__[q]
  904. / aaqq;
  905. }
  906. } else {
  907. rotok = aapp <= aaqq / small;
  908. if (aapp > small / aaqq) {
  909. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  910. c__1, &a[q * a_dim1 + 1], &
  911. c__1) * d__[p] * d__[q] /
  912. aaqq / aapp;
  913. } else {
  914. scopy_(m, &a[q * a_dim1 + 1], &c__1, &
  915. work[1], &c__1);
  916. slascl_("G", &c__0, &c__0, &aaqq, &
  917. d__[q], m, &c__1, &work[1],
  918. lda, &ierr);
  919. aapq = sdot_(m, &work[1], &c__1, &a[p
  920. * a_dim1 + 1], &c__1) * d__[p]
  921. / aapp;
  922. }
  923. }
  924. /* Computing MAX */
  925. r__1 = mxaapq, r__2 = abs(aapq);
  926. mxaapq = f2cmax(r__1,r__2);
  927. /* TO rotate or NOT to rotate, THAT is the question ... */
  928. if (abs(aapq) > *tol) {
  929. /* ROTATED = ROTATED + ONE */
  930. if (ir1 == 0) {
  931. notrot = 0;
  932. pskipped = 0;
  933. ++iswrot;
  934. }
  935. if (rotok) {
  936. aqoap = aaqq / aapp;
  937. apoaq = aapp / aaqq;
  938. theta = (r__1 = aqoap - apoaq, abs(
  939. r__1)) * -.5f / aapq;
  940. if (abs(theta) > bigtheta) {
  941. t = .5f / theta;
  942. fastr[2] = t * d__[p] / d__[q];
  943. fastr[3] = -t * d__[q] / d__[p];
  944. srotm_(m, &a[p * a_dim1 + 1], &
  945. c__1, &a[q * a_dim1 + 1],
  946. &c__1, fastr);
  947. if (rsvec) {
  948. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  949. v_dim1 + 1], &c__1, fastr);
  950. }
  951. /* Computing MAX */
  952. r__1 = 0.f, r__2 = t * apoaq *
  953. aapq + 1.f;
  954. sva[q] = aaqq * sqrt((f2cmax(r__1,
  955. r__2)));
  956. /* Computing MAX */
  957. r__1 = 0.f, r__2 = 1.f - t *
  958. aqoap * aapq;
  959. aapp *= sqrt((f2cmax(r__1,r__2)));
  960. /* Computing MAX */
  961. r__1 = mxsinj, r__2 = abs(t);
  962. mxsinj = f2cmax(r__1,r__2);
  963. } else {
  964. thsign = -r_sign(&c_b42, &aapq);
  965. t = 1.f / (theta + thsign * sqrt(
  966. theta * theta + 1.f));
  967. cs = sqrt(1.f / (t * t + 1.f));
  968. sn = t * cs;
  969. /* Computing MAX */
  970. r__1 = mxsinj, r__2 = abs(sn);
  971. mxsinj = f2cmax(r__1,r__2);
  972. /* Computing MAX */
  973. r__1 = 0.f, r__2 = t * apoaq *
  974. aapq + 1.f;
  975. sva[q] = aaqq * sqrt((f2cmax(r__1,
  976. r__2)));
  977. /* Computing MAX */
  978. r__1 = 0.f, r__2 = 1.f - t *
  979. aqoap * aapq;
  980. aapp *= sqrt((f2cmax(r__1,r__2)));
  981. apoaq = d__[p] / d__[q];
  982. aqoap = d__[q] / d__[p];
  983. if (d__[p] >= 1.f) {
  984. if (d__[q] >= 1.f) {
  985. fastr[2] = t * apoaq;
  986. fastr[3] = -t * aqoap;
  987. d__[p] *= cs;
  988. d__[q] *= cs;
  989. srotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  990. a_dim1 + 1], &c__1, fastr);
  991. if (rsvec) {
  992. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  993. q * v_dim1 + 1], &c__1, fastr);
  994. }
  995. } else {
  996. r__1 = -t * aqoap;
  997. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  998. p * a_dim1 + 1], &c__1);
  999. r__1 = cs * sn * apoaq;
  1000. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1001. q * a_dim1 + 1], &c__1);
  1002. d__[p] *= cs;
  1003. d__[q] /= cs;
  1004. if (rsvec) {
  1005. r__1 = -t * aqoap;
  1006. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1007. c__1, &v[p * v_dim1 + 1], &c__1);
  1008. r__1 = cs * sn * apoaq;
  1009. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1010. c__1, &v[q * v_dim1 + 1], &c__1);
  1011. }
  1012. }
  1013. } else {
  1014. if (d__[q] >= 1.f) {
  1015. r__1 = t * apoaq;
  1016. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1017. q * a_dim1 + 1], &c__1);
  1018. r__1 = -cs * sn * aqoap;
  1019. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  1020. p * a_dim1 + 1], &c__1);
  1021. d__[p] /= cs;
  1022. d__[q] *= cs;
  1023. if (rsvec) {
  1024. r__1 = t * apoaq;
  1025. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1026. c__1, &v[q * v_dim1 + 1], &c__1);
  1027. r__1 = -cs * sn * aqoap;
  1028. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1029. c__1, &v[p * v_dim1 + 1], &c__1);
  1030. }
  1031. } else {
  1032. if (d__[p] >= d__[q]) {
  1033. r__1 = -t * aqoap;
  1034. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1035. &a[p * a_dim1 + 1], &c__1);
  1036. r__1 = cs * sn * apoaq;
  1037. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1038. &a[q * a_dim1 + 1], &c__1);
  1039. d__[p] *= cs;
  1040. d__[q] /= cs;
  1041. if (rsvec) {
  1042. r__1 = -t * aqoap;
  1043. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1044. &c__1, &v[p * v_dim1 + 1], &
  1045. c__1);
  1046. r__1 = cs * sn * apoaq;
  1047. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1048. &c__1, &v[q * v_dim1 + 1], &
  1049. c__1);
  1050. }
  1051. } else {
  1052. r__1 = t * apoaq;
  1053. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1054. &a[q * a_dim1 + 1], &c__1);
  1055. r__1 = -cs * sn * aqoap;
  1056. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1057. &a[p * a_dim1 + 1], &c__1);
  1058. d__[p] /= cs;
  1059. d__[q] *= cs;
  1060. if (rsvec) {
  1061. r__1 = t * apoaq;
  1062. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1063. &c__1, &v[q * v_dim1 + 1], &
  1064. c__1);
  1065. r__1 = -cs * sn * aqoap;
  1066. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1067. &c__1, &v[p * v_dim1 + 1], &
  1068. c__1);
  1069. }
  1070. }
  1071. }
  1072. }
  1073. }
  1074. } else {
  1075. scopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1076. work[1], &c__1);
  1077. slascl_("G", &c__0, &c__0, &aapp, &
  1078. c_b42, m, &c__1, &work[1],
  1079. lda, &ierr);
  1080. slascl_("G", &c__0, &c__0, &aaqq, &
  1081. c_b42, m, &c__1, &a[q *
  1082. a_dim1 + 1], lda, &ierr);
  1083. temp1 = -aapq * d__[p] / d__[q];
  1084. saxpy_(m, &temp1, &work[1], &c__1, &a[
  1085. q * a_dim1 + 1], &c__1);
  1086. slascl_("G", &c__0, &c__0, &c_b42, &
  1087. aaqq, m, &c__1, &a[q * a_dim1
  1088. + 1], lda, &ierr);
  1089. /* Computing MAX */
  1090. r__1 = 0.f, r__2 = 1.f - aapq * aapq;
  1091. sva[q] = aaqq * sqrt((f2cmax(r__1,r__2)))
  1092. ;
  1093. mxsinj = f2cmax(mxsinj,*sfmin);
  1094. }
  1095. /* END IF ROTOK THEN ... ELSE */
  1096. /* In the case of cancellation in updating SVA(q), SVA(p) */
  1097. /* recompute SVA(q), SVA(p). */
  1098. /* Computing 2nd power */
  1099. r__1 = sva[q] / aaqq;
  1100. if (r__1 * r__1 <= rooteps) {
  1101. if (aaqq < rootbig && aaqq >
  1102. rootsfmin) {
  1103. sva[q] = snrm2_(m, &a[q * a_dim1
  1104. + 1], &c__1) * d__[q];
  1105. } else {
  1106. t = 0.f;
  1107. aaqq = 1.f;
  1108. slassq_(m, &a[q * a_dim1 + 1], &
  1109. c__1, &t, &aaqq);
  1110. sva[q] = t * sqrt(aaqq) * d__[q];
  1111. }
  1112. }
  1113. if (aapp / aapp0 <= rooteps) {
  1114. if (aapp < rootbig && aapp >
  1115. rootsfmin) {
  1116. aapp = snrm2_(m, &a[p * a_dim1 +
  1117. 1], &c__1) * d__[p];
  1118. } else {
  1119. t = 0.f;
  1120. aapp = 1.f;
  1121. slassq_(m, &a[p * a_dim1 + 1], &
  1122. c__1, &t, &aapp);
  1123. aapp = t * sqrt(aapp) * d__[p];
  1124. }
  1125. sva[p] = aapp;
  1126. }
  1127. } else {
  1128. /* A(:,p) and A(:,q) already numerically orthogonal */
  1129. if (ir1 == 0) {
  1130. ++notrot;
  1131. }
  1132. ++pskipped;
  1133. }
  1134. } else {
  1135. /* A(:,q) is zero column */
  1136. if (ir1 == 0) {
  1137. ++notrot;
  1138. }
  1139. ++pskipped;
  1140. }
  1141. if (i__ <= swband && pskipped > rowskip) {
  1142. if (ir1 == 0) {
  1143. aapp = -aapp;
  1144. }
  1145. notrot = 0;
  1146. goto L2103;
  1147. }
  1148. /* L2002: */
  1149. }
  1150. /* END q-LOOP */
  1151. L2103:
  1152. /* bailed out of q-loop */
  1153. sva[p] = aapp;
  1154. } else {
  1155. sva[p] = aapp;
  1156. if (ir1 == 0 && aapp == 0.f) {
  1157. /* Computing MIN */
  1158. i__5 = igl + kbl - 1;
  1159. notrot = notrot + f2cmin(i__5,*n) - p;
  1160. }
  1161. }
  1162. /* L2001: */
  1163. }
  1164. /* end of the p-loop */
  1165. /* end of doing the block ( ibr, ibr ) */
  1166. /* L1002: */
  1167. }
  1168. /* end of ir1-loop */
  1169. /* ........................................................ */
  1170. /* ... go to the off diagonal blocks */
  1171. igl = (ibr - 1) * kbl + 1;
  1172. i__3 = nbl;
  1173. for (jbc = ibr + 1; jbc <= i__3; ++jbc) {
  1174. jgl = (jbc - 1) * kbl + 1;
  1175. /* doing the block at ( ibr, jbc ) */
  1176. ijblsk = 0;
  1177. /* Computing MIN */
  1178. i__5 = igl + kbl - 1;
  1179. i__4 = f2cmin(i__5,*n);
  1180. for (p = igl; p <= i__4; ++p) {
  1181. aapp = sva[p];
  1182. if (aapp > 0.f) {
  1183. pskipped = 0;
  1184. /* Computing MIN */
  1185. i__6 = jgl + kbl - 1;
  1186. i__5 = f2cmin(i__6,*n);
  1187. for (q = jgl; q <= i__5; ++q) {
  1188. aaqq = sva[q];
  1189. if (aaqq > 0.f) {
  1190. aapp0 = aapp;
  1191. if (aaqq >= 1.f) {
  1192. if (aapp >= aaqq) {
  1193. rotok = small * aapp <= aaqq;
  1194. } else {
  1195. rotok = small * aaqq <= aapp;
  1196. }
  1197. if (aapp < big / aaqq) {
  1198. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  1199. c__1, &a[q * a_dim1 + 1], &
  1200. c__1) * d__[p] * d__[q] /
  1201. aaqq / aapp;
  1202. } else {
  1203. scopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1204. work[1], &c__1);
  1205. slascl_("G", &c__0, &c__0, &aapp, &
  1206. d__[p], m, &c__1, &work[1],
  1207. lda, &ierr);
  1208. aapq = sdot_(m, &work[1], &c__1, &a[q
  1209. * a_dim1 + 1], &c__1) * d__[q]
  1210. / aaqq;
  1211. }
  1212. } else {
  1213. if (aapp >= aaqq) {
  1214. rotok = aapp <= aaqq / small;
  1215. } else {
  1216. rotok = aaqq <= aapp / small;
  1217. }
  1218. if (aapp > small / aaqq) {
  1219. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  1220. c__1, &a[q * a_dim1 + 1], &
  1221. c__1) * d__[p] * d__[q] /
  1222. aaqq / aapp;
  1223. } else {
  1224. scopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1225. work[1], &c__1);
  1226. slascl_("G", &c__0, &c__0, &aaqq, &
  1227. d__[q], m, &c__1, &work[1],
  1228. lda, &ierr);
  1229. aapq = sdot_(m, &work[1], &c__1, &a[p
  1230. * a_dim1 + 1], &c__1) * d__[p]
  1231. / aapp;
  1232. }
  1233. }
  1234. /* Computing MAX */
  1235. r__1 = mxaapq, r__2 = abs(aapq);
  1236. mxaapq = f2cmax(r__1,r__2);
  1237. /* TO rotate or NOT to rotate, THAT is the question ... */
  1238. if (abs(aapq) > *tol) {
  1239. notrot = 0;
  1240. /* ROTATED = ROTATED + 1 */
  1241. pskipped = 0;
  1242. ++iswrot;
  1243. if (rotok) {
  1244. aqoap = aaqq / aapp;
  1245. apoaq = aapp / aaqq;
  1246. theta = (r__1 = aqoap - apoaq, abs(
  1247. r__1)) * -.5f / aapq;
  1248. if (aaqq > aapp0) {
  1249. theta = -theta;
  1250. }
  1251. if (abs(theta) > bigtheta) {
  1252. t = .5f / theta;
  1253. fastr[2] = t * d__[p] / d__[q];
  1254. fastr[3] = -t * d__[q] / d__[p];
  1255. srotm_(m, &a[p * a_dim1 + 1], &
  1256. c__1, &a[q * a_dim1 + 1],
  1257. &c__1, fastr);
  1258. if (rsvec) {
  1259. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1260. v_dim1 + 1], &c__1, fastr);
  1261. }
  1262. /* Computing MAX */
  1263. r__1 = 0.f, r__2 = t * apoaq *
  1264. aapq + 1.f;
  1265. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1266. r__2)));
  1267. /* Computing MAX */
  1268. r__1 = 0.f, r__2 = 1.f - t *
  1269. aqoap * aapq;
  1270. aapp *= sqrt((f2cmax(r__1,r__2)));
  1271. /* Computing MAX */
  1272. r__1 = mxsinj, r__2 = abs(t);
  1273. mxsinj = f2cmax(r__1,r__2);
  1274. } else {
  1275. thsign = -r_sign(&c_b42, &aapq);
  1276. if (aaqq > aapp0) {
  1277. thsign = -thsign;
  1278. }
  1279. t = 1.f / (theta + thsign * sqrt(
  1280. theta * theta + 1.f));
  1281. cs = sqrt(1.f / (t * t + 1.f));
  1282. sn = t * cs;
  1283. /* Computing MAX */
  1284. r__1 = mxsinj, r__2 = abs(sn);
  1285. mxsinj = f2cmax(r__1,r__2);
  1286. /* Computing MAX */
  1287. r__1 = 0.f, r__2 = t * apoaq *
  1288. aapq + 1.f;
  1289. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1290. r__2)));
  1291. /* Computing MAX */
  1292. r__1 = 0.f, r__2 = 1.f - t *
  1293. aqoap * aapq;
  1294. aapp *= sqrt((f2cmax(r__1,r__2)));
  1295. apoaq = d__[p] / d__[q];
  1296. aqoap = d__[q] / d__[p];
  1297. if (d__[p] >= 1.f) {
  1298. if (d__[q] >= 1.f) {
  1299. fastr[2] = t * apoaq;
  1300. fastr[3] = -t * aqoap;
  1301. d__[p] *= cs;
  1302. d__[q] *= cs;
  1303. srotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1304. a_dim1 + 1], &c__1, fastr);
  1305. if (rsvec) {
  1306. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1307. q * v_dim1 + 1], &c__1, fastr);
  1308. }
  1309. } else {
  1310. r__1 = -t * aqoap;
  1311. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  1312. p * a_dim1 + 1], &c__1);
  1313. r__1 = cs * sn * apoaq;
  1314. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1315. q * a_dim1 + 1], &c__1);
  1316. if (rsvec) {
  1317. r__1 = -t * aqoap;
  1318. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1319. c__1, &v[p * v_dim1 + 1], &c__1);
  1320. r__1 = cs * sn * apoaq;
  1321. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1322. c__1, &v[q * v_dim1 + 1], &c__1);
  1323. }
  1324. d__[p] *= cs;
  1325. d__[q] /= cs;
  1326. }
  1327. } else {
  1328. if (d__[q] >= 1.f) {
  1329. r__1 = t * apoaq;
  1330. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1331. q * a_dim1 + 1], &c__1);
  1332. r__1 = -cs * sn * aqoap;
  1333. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  1334. p * a_dim1 + 1], &c__1);
  1335. if (rsvec) {
  1336. r__1 = t * apoaq;
  1337. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1338. c__1, &v[q * v_dim1 + 1], &c__1);
  1339. r__1 = -cs * sn * aqoap;
  1340. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1341. c__1, &v[p * v_dim1 + 1], &c__1);
  1342. }
  1343. d__[p] /= cs;
  1344. d__[q] *= cs;
  1345. } else {
  1346. if (d__[p] >= d__[q]) {
  1347. r__1 = -t * aqoap;
  1348. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1349. &a[p * a_dim1 + 1], &c__1);
  1350. r__1 = cs * sn * apoaq;
  1351. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1352. &a[q * a_dim1 + 1], &c__1);
  1353. d__[p] *= cs;
  1354. d__[q] /= cs;
  1355. if (rsvec) {
  1356. r__1 = -t * aqoap;
  1357. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1358. &c__1, &v[p * v_dim1 + 1], &
  1359. c__1);
  1360. r__1 = cs * sn * apoaq;
  1361. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1362. &c__1, &v[q * v_dim1 + 1], &
  1363. c__1);
  1364. }
  1365. } else {
  1366. r__1 = t * apoaq;
  1367. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1368. &a[q * a_dim1 + 1], &c__1);
  1369. r__1 = -cs * sn * aqoap;
  1370. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1371. &a[p * a_dim1 + 1], &c__1);
  1372. d__[p] /= cs;
  1373. d__[q] *= cs;
  1374. if (rsvec) {
  1375. r__1 = t * apoaq;
  1376. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1377. &c__1, &v[q * v_dim1 + 1], &
  1378. c__1);
  1379. r__1 = -cs * sn * aqoap;
  1380. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1381. &c__1, &v[p * v_dim1 + 1], &
  1382. c__1);
  1383. }
  1384. }
  1385. }
  1386. }
  1387. }
  1388. } else {
  1389. if (aapp > aaqq) {
  1390. scopy_(m, &a[p * a_dim1 + 1], &
  1391. c__1, &work[1], &c__1);
  1392. slascl_("G", &c__0, &c__0, &aapp,
  1393. &c_b42, m, &c__1, &work[1]
  1394. , lda, &ierr);
  1395. slascl_("G", &c__0, &c__0, &aaqq,
  1396. &c_b42, m, &c__1, &a[q *
  1397. a_dim1 + 1], lda, &ierr);
  1398. temp1 = -aapq * d__[p] / d__[q];
  1399. saxpy_(m, &temp1, &work[1], &c__1,
  1400. &a[q * a_dim1 + 1], &
  1401. c__1);
  1402. slascl_("G", &c__0, &c__0, &c_b42,
  1403. &aaqq, m, &c__1, &a[q *
  1404. a_dim1 + 1], lda, &ierr);
  1405. /* Computing MAX */
  1406. r__1 = 0.f, r__2 = 1.f - aapq *
  1407. aapq;
  1408. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1409. r__2)));
  1410. mxsinj = f2cmax(mxsinj,*sfmin);
  1411. } else {
  1412. scopy_(m, &a[q * a_dim1 + 1], &
  1413. c__1, &work[1], &c__1);
  1414. slascl_("G", &c__0, &c__0, &aaqq,
  1415. &c_b42, m, &c__1, &work[1]
  1416. , lda, &ierr);
  1417. slascl_("G", &c__0, &c__0, &aapp,
  1418. &c_b42, m, &c__1, &a[p *
  1419. a_dim1 + 1], lda, &ierr);
  1420. temp1 = -aapq * d__[q] / d__[p];
  1421. saxpy_(m, &temp1, &work[1], &c__1,
  1422. &a[p * a_dim1 + 1], &
  1423. c__1);
  1424. slascl_("G", &c__0, &c__0, &c_b42,
  1425. &aapp, m, &c__1, &a[p *
  1426. a_dim1 + 1], lda, &ierr);
  1427. /* Computing MAX */
  1428. r__1 = 0.f, r__2 = 1.f - aapq *
  1429. aapq;
  1430. sva[p] = aapp * sqrt((f2cmax(r__1,
  1431. r__2)));
  1432. mxsinj = f2cmax(mxsinj,*sfmin);
  1433. }
  1434. }
  1435. /* END IF ROTOK THEN ... ELSE */
  1436. /* In the case of cancellation in updating SVA(q) */
  1437. /* Computing 2nd power */
  1438. r__1 = sva[q] / aaqq;
  1439. if (r__1 * r__1 <= rooteps) {
  1440. if (aaqq < rootbig && aaqq >
  1441. rootsfmin) {
  1442. sva[q] = snrm2_(m, &a[q * a_dim1
  1443. + 1], &c__1) * d__[q];
  1444. } else {
  1445. t = 0.f;
  1446. aaqq = 1.f;
  1447. slassq_(m, &a[q * a_dim1 + 1], &
  1448. c__1, &t, &aaqq);
  1449. sva[q] = t * sqrt(aaqq) * d__[q];
  1450. }
  1451. }
  1452. /* Computing 2nd power */
  1453. r__1 = aapp / aapp0;
  1454. if (r__1 * r__1 <= rooteps) {
  1455. if (aapp < rootbig && aapp >
  1456. rootsfmin) {
  1457. aapp = snrm2_(m, &a[p * a_dim1 +
  1458. 1], &c__1) * d__[p];
  1459. } else {
  1460. t = 0.f;
  1461. aapp = 1.f;
  1462. slassq_(m, &a[p * a_dim1 + 1], &
  1463. c__1, &t, &aapp);
  1464. aapp = t * sqrt(aapp) * d__[p];
  1465. }
  1466. sva[p] = aapp;
  1467. }
  1468. /* end of OK rotation */
  1469. } else {
  1470. ++notrot;
  1471. ++pskipped;
  1472. ++ijblsk;
  1473. }
  1474. } else {
  1475. ++notrot;
  1476. ++pskipped;
  1477. ++ijblsk;
  1478. }
  1479. if (i__ <= swband && ijblsk >= blskip) {
  1480. sva[p] = aapp;
  1481. notrot = 0;
  1482. goto L2011;
  1483. }
  1484. if (i__ <= swband && pskipped > rowskip) {
  1485. aapp = -aapp;
  1486. notrot = 0;
  1487. goto L2203;
  1488. }
  1489. /* L2200: */
  1490. }
  1491. /* end of the q-loop */
  1492. L2203:
  1493. sva[p] = aapp;
  1494. } else {
  1495. if (aapp == 0.f) {
  1496. /* Computing MIN */
  1497. i__5 = jgl + kbl - 1;
  1498. notrot = notrot + f2cmin(i__5,*n) - jgl + 1;
  1499. }
  1500. if (aapp < 0.f) {
  1501. notrot = 0;
  1502. }
  1503. }
  1504. /* L2100: */
  1505. }
  1506. /* end of the p-loop */
  1507. /* L2010: */
  1508. }
  1509. /* end of the jbc-loop */
  1510. L2011:
  1511. /* 2011 bailed out of the jbc-loop */
  1512. /* Computing MIN */
  1513. i__4 = igl + kbl - 1;
  1514. i__3 = f2cmin(i__4,*n);
  1515. for (p = igl; p <= i__3; ++p) {
  1516. sva[p] = (r__1 = sva[p], abs(r__1));
  1517. /* L2012: */
  1518. }
  1519. /* L2000: */
  1520. }
  1521. /* 2000 :: end of the ibr-loop */
  1522. if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
  1523. sva[*n] = snrm2_(m, &a[*n * a_dim1 + 1], &c__1) * d__[*n];
  1524. } else {
  1525. t = 0.f;
  1526. aapp = 1.f;
  1527. slassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
  1528. sva[*n] = t * sqrt(aapp) * d__[*n];
  1529. }
  1530. /* Additional steering devices */
  1531. if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
  1532. swband = i__;
  1533. }
  1534. if (i__ > swband + 1 && mxaapq < (real) (*n) * *tol && (real) (*n) *
  1535. mxaapq * mxsinj < *tol) {
  1536. goto L1994;
  1537. }
  1538. if (notrot >= emptsw) {
  1539. goto L1994;
  1540. }
  1541. /* L1993: */
  1542. }
  1543. /* end i=1:NSWEEP loop */
  1544. /* #:) Reaching this point means that the procedure has completed the given */
  1545. /* number of iterations. */
  1546. *info = *nsweep - 1;
  1547. goto L1995;
  1548. L1994:
  1549. /* #:) Reaching this point means that during the i-th sweep all pivots were */
  1550. /* below the given tolerance, causing early exit. */
  1551. *info = 0;
  1552. /* #:) INFO = 0 confirms successful iterations. */
  1553. L1995:
  1554. /* Sort the vector D. */
  1555. i__1 = *n - 1;
  1556. for (p = 1; p <= i__1; ++p) {
  1557. i__2 = *n - p + 1;
  1558. q = isamax_(&i__2, &sva[p], &c__1) + p - 1;
  1559. if (p != q) {
  1560. temp1 = sva[p];
  1561. sva[p] = sva[q];
  1562. sva[q] = temp1;
  1563. temp1 = d__[p];
  1564. d__[p] = d__[q];
  1565. d__[q] = temp1;
  1566. sswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
  1567. if (rsvec) {
  1568. sswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
  1569. c__1);
  1570. }
  1571. }
  1572. /* L5991: */
  1573. }
  1574. return;
  1575. } /* sgsvj0_ */