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.

slatbs.c 38 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  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 real c_b36 = .5f;
  486. /* > \brief \b SLATBS solves a triangular banded system of equations. */
  487. /* =========== DOCUMENTATION =========== */
  488. /* Online html documentation available at */
  489. /* http://www.netlib.org/lapack/explore-html/ */
  490. /* > \htmlonly */
  491. /* > Download SLATBS + dependencies */
  492. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slatbs.
  493. f"> */
  494. /* > [TGZ]</a> */
  495. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slatbs.
  496. f"> */
  497. /* > [ZIP]</a> */
  498. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slatbs.
  499. f"> */
  500. /* > [TXT]</a> */
  501. /* > \endhtmlonly */
  502. /* Definition: */
  503. /* =========== */
  504. /* SUBROUTINE SLATBS( UPLO, TRANS, DIAG, NORMIN, N, KD, AB, LDAB, X, */
  505. /* SCALE, CNORM, INFO ) */
  506. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  507. /* INTEGER INFO, KD, LDAB, N */
  508. /* REAL SCALE */
  509. /* REAL AB( LDAB, * ), CNORM( * ), X( * ) */
  510. /* > \par Purpose: */
  511. /* ============= */
  512. /* > */
  513. /* > \verbatim */
  514. /* > */
  515. /* > SLATBS solves one of the triangular systems */
  516. /* > */
  517. /* > A *x = s*b or A**T*x = s*b */
  518. /* > */
  519. /* > with scaling to prevent overflow, where A is an upper or lower */
  520. /* > triangular band matrix. Here A**T denotes the transpose of A, x and b */
  521. /* > are n-element vectors, and s is a scaling factor, usually less than */
  522. /* > or equal to 1, chosen so that the components of x will be less than */
  523. /* > the overflow threshold. If the unscaled problem will not cause */
  524. /* > overflow, the Level 2 BLAS routine STBSV is called. If the matrix A */
  525. /* > is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
  526. /* > non-trivial solution to A*x = 0 is returned. */
  527. /* > \endverbatim */
  528. /* Arguments: */
  529. /* ========== */
  530. /* > \param[in] UPLO */
  531. /* > \verbatim */
  532. /* > UPLO is CHARACTER*1 */
  533. /* > Specifies whether the matrix A is upper or lower triangular. */
  534. /* > = 'U': Upper triangular */
  535. /* > = 'L': Lower triangular */
  536. /* > \endverbatim */
  537. /* > */
  538. /* > \param[in] TRANS */
  539. /* > \verbatim */
  540. /* > TRANS is CHARACTER*1 */
  541. /* > Specifies the operation applied to A. */
  542. /* > = 'N': Solve A * x = s*b (No transpose) */
  543. /* > = 'T': Solve A**T* x = s*b (Transpose) */
  544. /* > = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose) */
  545. /* > \endverbatim */
  546. /* > */
  547. /* > \param[in] DIAG */
  548. /* > \verbatim */
  549. /* > DIAG is CHARACTER*1 */
  550. /* > Specifies whether or not the matrix A is unit triangular. */
  551. /* > = 'N': Non-unit triangular */
  552. /* > = 'U': Unit triangular */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] NORMIN */
  556. /* > \verbatim */
  557. /* > NORMIN is CHARACTER*1 */
  558. /* > Specifies whether CNORM has been set or not. */
  559. /* > = 'Y': CNORM contains the column norms on entry */
  560. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  561. /* > be computed and stored in CNORM. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[in] N */
  565. /* > \verbatim */
  566. /* > N is INTEGER */
  567. /* > The order of the matrix A. N >= 0. */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in] KD */
  571. /* > \verbatim */
  572. /* > KD is INTEGER */
  573. /* > The number of subdiagonals or superdiagonals in the */
  574. /* > triangular matrix A. KD >= 0. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[in] AB */
  578. /* > \verbatim */
  579. /* > AB is REAL array, dimension (LDAB,N) */
  580. /* > The upper or lower triangular band matrix A, stored in the */
  581. /* > first KD+1 rows of the array. The j-th column of A is stored */
  582. /* > in the j-th column of the array AB as follows: */
  583. /* > if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for f2cmax(1,j-kd)<=i<=j; */
  584. /* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(n,j+kd). */
  585. /* > \endverbatim */
  586. /* > */
  587. /* > \param[in] LDAB */
  588. /* > \verbatim */
  589. /* > LDAB is INTEGER */
  590. /* > The leading dimension of the array AB. LDAB >= KD+1. */
  591. /* > \endverbatim */
  592. /* > */
  593. /* > \param[in,out] X */
  594. /* > \verbatim */
  595. /* > X is REAL array, dimension (N) */
  596. /* > On entry, the right hand side b of the triangular system. */
  597. /* > On exit, X is overwritten by the solution vector x. */
  598. /* > \endverbatim */
  599. /* > */
  600. /* > \param[out] SCALE */
  601. /* > \verbatim */
  602. /* > SCALE is REAL */
  603. /* > The scaling factor s for the triangular system */
  604. /* > A * x = s*b or A**T* x = s*b. */
  605. /* > If SCALE = 0, the matrix A is singular or badly scaled, and */
  606. /* > the vector x is an exact or approximate solution to A*x = 0. */
  607. /* > \endverbatim */
  608. /* > */
  609. /* > \param[in,out] CNORM */
  610. /* > \verbatim */
  611. /* > CNORM is REAL array, dimension (N) */
  612. /* > */
  613. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  614. /* > contains the norm of the off-diagonal part of the j-th column */
  615. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  616. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  617. /* > must be greater than or equal to the 1-norm. */
  618. /* > */
  619. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  620. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  621. /* > of A. */
  622. /* > \endverbatim */
  623. /* > */
  624. /* > \param[out] INFO */
  625. /* > \verbatim */
  626. /* > INFO is INTEGER */
  627. /* > = 0: successful exit */
  628. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  629. /* > \endverbatim */
  630. /* Authors: */
  631. /* ======== */
  632. /* > \author Univ. of Tennessee */
  633. /* > \author Univ. of California Berkeley */
  634. /* > \author Univ. of Colorado Denver */
  635. /* > \author NAG Ltd. */
  636. /* > \date December 2016 */
  637. /* > \ingroup realOTHERauxiliary */
  638. /* > \par Further Details: */
  639. /* ===================== */
  640. /* > */
  641. /* > \verbatim */
  642. /* > */
  643. /* > A rough bound on x is computed; if that is less than overflow, STBSV */
  644. /* > is called, otherwise, specific code is used which checks for possible */
  645. /* > overflow or divide-by-zero at every operation. */
  646. /* > */
  647. /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */
  648. /* > if A is lower triangular is */
  649. /* > */
  650. /* > x[1:n] := b[1:n] */
  651. /* > for j = 1, ..., n */
  652. /* > x(j) := x(j) / A(j,j) */
  653. /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
  654. /* > end */
  655. /* > */
  656. /* > Define bounds on the components of x after j iterations of the loop: */
  657. /* > M(j) = bound on x[1:j] */
  658. /* > G(j) = bound on x[j+1:n] */
  659. /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
  660. /* > */
  661. /* > Then for iteration j+1 we have */
  662. /* > M(j+1) <= G(j) / | A(j+1,j+1) | */
  663. /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
  664. /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
  665. /* > */
  666. /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */
  667. /* > column j+1 of A, not counting the diagonal. Hence */
  668. /* > */
  669. /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
  670. /* > 1<=i<=j */
  671. /* > and */
  672. /* > */
  673. /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
  674. /* > 1<=i< j */
  675. /* > */
  676. /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine STBSV if the */
  677. /* > reciprocal of the largest M(j), j=1,..,n, is larger than */
  678. /* > f2cmax(underflow, 1/overflow). */
  679. /* > */
  680. /* > The bound on x(j) is also used to determine when a step in the */
  681. /* > columnwise method can be performed without fear of overflow. If */
  682. /* > the computed bound is greater than a large constant, x is scaled to */
  683. /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
  684. /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
  685. /* > */
  686. /* > Similarly, a row-wise scheme is used to solve A**T*x = b. The basic */
  687. /* > algorithm for A upper triangular is */
  688. /* > */
  689. /* > for j = 1, ..., n */
  690. /* > x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j) */
  691. /* > end */
  692. /* > */
  693. /* > We simultaneously compute two bounds */
  694. /* > G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j */
  695. /* > M(j) = bound on x(i), 1<=i<=j */
  696. /* > */
  697. /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
  698. /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
  699. /* > Then the bound on x(j) is */
  700. /* > */
  701. /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
  702. /* > */
  703. /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
  704. /* > 1<=i<=j */
  705. /* > */
  706. /* > and we can safely call STBSV if 1/M(n) and 1/G(n) are both greater */
  707. /* > than f2cmax(underflow, 1/overflow). */
  708. /* > \endverbatim */
  709. /* > */
  710. /* ===================================================================== */
  711. /* Subroutine */ void slatbs_(char *uplo, char *trans, char *diag, char *
  712. normin, integer *n, integer *kd, real *ab, integer *ldab, real *x,
  713. real *scale, real *cnorm, integer *info)
  714. {
  715. /* System generated locals */
  716. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
  717. real r__1, r__2, r__3;
  718. /* Local variables */
  719. integer jinc, jlen;
  720. real xbnd;
  721. integer imax;
  722. real tmax, tjjs;
  723. extern real sdot_(integer *, real *, integer *, real *, integer *);
  724. real xmax, grow, sumj;
  725. integer i__, j, maind;
  726. extern logical lsame_(char *, char *);
  727. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  728. real tscal, uscal;
  729. integer jlast;
  730. extern real sasum_(integer *, real *, integer *);
  731. logical upper;
  732. extern /* Subroutine */ void stbsv_(char *, char *, char *, integer *,
  733. integer *, real *, integer *, real *, integer *), saxpy_(integer *, real *, real *, integer *, real *,
  734. integer *);
  735. real xj;
  736. extern real slamch_(char *);
  737. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  738. real bignum;
  739. extern integer isamax_(integer *, real *, integer *);
  740. logical notran;
  741. integer jfirst;
  742. real smlnum;
  743. logical nounit;
  744. real rec, tjj;
  745. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  746. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  747. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  748. /* December 2016 */
  749. /* ===================================================================== */
  750. /* Parameter adjustments */
  751. ab_dim1 = *ldab;
  752. ab_offset = 1 + ab_dim1 * 1;
  753. ab -= ab_offset;
  754. --x;
  755. --cnorm;
  756. /* Function Body */
  757. *info = 0;
  758. upper = lsame_(uplo, "U");
  759. notran = lsame_(trans, "N");
  760. nounit = lsame_(diag, "N");
  761. /* Test the input parameters. */
  762. if (! upper && ! lsame_(uplo, "L")) {
  763. *info = -1;
  764. } else if (! notran && ! lsame_(trans, "T") && !
  765. lsame_(trans, "C")) {
  766. *info = -2;
  767. } else if (! nounit && ! lsame_(diag, "U")) {
  768. *info = -3;
  769. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  770. "N")) {
  771. *info = -4;
  772. } else if (*n < 0) {
  773. *info = -5;
  774. } else if (*kd < 0) {
  775. *info = -6;
  776. } else if (*ldab < *kd + 1) {
  777. *info = -8;
  778. }
  779. if (*info != 0) {
  780. i__1 = -(*info);
  781. xerbla_("SLATBS", &i__1, (ftnlen)6);
  782. return;
  783. }
  784. /* Quick return if possible */
  785. if (*n == 0) {
  786. return;
  787. }
  788. /* Determine machine dependent parameters to control overflow. */
  789. smlnum = slamch_("Safe minimum") / slamch_("Precision");
  790. bignum = 1.f / smlnum;
  791. *scale = 1.f;
  792. if (lsame_(normin, "N")) {
  793. /* Compute the 1-norm of each column, not including the diagonal. */
  794. if (upper) {
  795. /* A is upper triangular. */
  796. i__1 = *n;
  797. for (j = 1; j <= i__1; ++j) {
  798. /* Computing MIN */
  799. i__2 = *kd, i__3 = j - 1;
  800. jlen = f2cmin(i__2,i__3);
  801. cnorm[j] = sasum_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1], &
  802. c__1);
  803. /* L10: */
  804. }
  805. } else {
  806. /* A is lower triangular. */
  807. i__1 = *n;
  808. for (j = 1; j <= i__1; ++j) {
  809. /* Computing MIN */
  810. i__2 = *kd, i__3 = *n - j;
  811. jlen = f2cmin(i__2,i__3);
  812. if (jlen > 0) {
  813. cnorm[j] = sasum_(&jlen, &ab[j * ab_dim1 + 2], &c__1);
  814. } else {
  815. cnorm[j] = 0.f;
  816. }
  817. /* L20: */
  818. }
  819. }
  820. }
  821. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  822. /* greater than BIGNUM. */
  823. imax = isamax_(n, &cnorm[1], &c__1);
  824. tmax = cnorm[imax];
  825. if (tmax <= bignum) {
  826. tscal = 1.f;
  827. } else {
  828. tscal = 1.f / (smlnum * tmax);
  829. sscal_(n, &tscal, &cnorm[1], &c__1);
  830. }
  831. /* Compute a bound on the computed solution vector to see if the */
  832. /* Level 2 BLAS routine STBSV can be used. */
  833. j = isamax_(n, &x[1], &c__1);
  834. xmax = (r__1 = x[j], abs(r__1));
  835. xbnd = xmax;
  836. if (notran) {
  837. /* Compute the growth in A * x = b. */
  838. if (upper) {
  839. jfirst = *n;
  840. jlast = 1;
  841. jinc = -1;
  842. maind = *kd + 1;
  843. } else {
  844. jfirst = 1;
  845. jlast = *n;
  846. jinc = 1;
  847. maind = 1;
  848. }
  849. if (tscal != 1.f) {
  850. grow = 0.f;
  851. goto L50;
  852. }
  853. if (nounit) {
  854. /* A is non-unit triangular. */
  855. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  856. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  857. grow = 1.f / f2cmax(xbnd,smlnum);
  858. xbnd = grow;
  859. i__1 = jlast;
  860. i__2 = jinc;
  861. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  862. /* Exit the loop if the growth factor is too small. */
  863. if (grow <= smlnum) {
  864. goto L50;
  865. }
  866. /* M(j) = G(j-1) / abs(A(j,j)) */
  867. tjj = (r__1 = ab[maind + j * ab_dim1], abs(r__1));
  868. /* Computing MIN */
  869. r__1 = xbnd, r__2 = f2cmin(1.f,tjj) * grow;
  870. xbnd = f2cmin(r__1,r__2);
  871. if (tjj + cnorm[j] >= smlnum) {
  872. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  873. grow *= tjj / (tjj + cnorm[j]);
  874. } else {
  875. /* G(j) could overflow, set GROW to 0. */
  876. grow = 0.f;
  877. }
  878. /* L30: */
  879. }
  880. grow = xbnd;
  881. } else {
  882. /* A is unit triangular. */
  883. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  884. /* Computing MIN */
  885. r__1 = 1.f, r__2 = 1.f / f2cmax(xbnd,smlnum);
  886. grow = f2cmin(r__1,r__2);
  887. i__2 = jlast;
  888. i__1 = jinc;
  889. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  890. /* Exit the loop if the growth factor is too small. */
  891. if (grow <= smlnum) {
  892. goto L50;
  893. }
  894. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  895. grow *= 1.f / (cnorm[j] + 1.f);
  896. /* L40: */
  897. }
  898. }
  899. L50:
  900. ;
  901. } else {
  902. /* Compute the growth in A**T * x = b. */
  903. if (upper) {
  904. jfirst = 1;
  905. jlast = *n;
  906. jinc = 1;
  907. maind = *kd + 1;
  908. } else {
  909. jfirst = *n;
  910. jlast = 1;
  911. jinc = -1;
  912. maind = 1;
  913. }
  914. if (tscal != 1.f) {
  915. grow = 0.f;
  916. goto L80;
  917. }
  918. if (nounit) {
  919. /* A is non-unit triangular. */
  920. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  921. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  922. grow = 1.f / f2cmax(xbnd,smlnum);
  923. xbnd = grow;
  924. i__1 = jlast;
  925. i__2 = jinc;
  926. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  927. /* Exit the loop if the growth factor is too small. */
  928. if (grow <= smlnum) {
  929. goto L80;
  930. }
  931. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  932. xj = cnorm[j] + 1.f;
  933. /* Computing MIN */
  934. r__1 = grow, r__2 = xbnd / xj;
  935. grow = f2cmin(r__1,r__2);
  936. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  937. tjj = (r__1 = ab[maind + j * ab_dim1], abs(r__1));
  938. if (xj > tjj) {
  939. xbnd *= tjj / xj;
  940. }
  941. /* L60: */
  942. }
  943. grow = f2cmin(grow,xbnd);
  944. } else {
  945. /* A is unit triangular. */
  946. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  947. /* Computing MIN */
  948. r__1 = 1.f, r__2 = 1.f / f2cmax(xbnd,smlnum);
  949. grow = f2cmin(r__1,r__2);
  950. i__2 = jlast;
  951. i__1 = jinc;
  952. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  953. /* Exit the loop if the growth factor is too small. */
  954. if (grow <= smlnum) {
  955. goto L80;
  956. }
  957. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  958. xj = cnorm[j] + 1.f;
  959. grow /= xj;
  960. /* L70: */
  961. }
  962. }
  963. L80:
  964. ;
  965. }
  966. if (grow * tscal > smlnum) {
  967. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  968. /* elements of X is not too small. */
  969. stbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1);
  970. } else {
  971. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  972. if (xmax > bignum) {
  973. /* Scale X so that its components are less than or equal to */
  974. /* BIGNUM in absolute value. */
  975. *scale = bignum / xmax;
  976. sscal_(n, scale, &x[1], &c__1);
  977. xmax = bignum;
  978. }
  979. if (notran) {
  980. /* Solve A * x = b */
  981. i__1 = jlast;
  982. i__2 = jinc;
  983. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  984. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  985. xj = (r__1 = x[j], abs(r__1));
  986. if (nounit) {
  987. tjjs = ab[maind + j * ab_dim1] * tscal;
  988. } else {
  989. tjjs = tscal;
  990. if (tscal == 1.f) {
  991. goto L95;
  992. }
  993. }
  994. tjj = abs(tjjs);
  995. if (tjj > smlnum) {
  996. /* abs(A(j,j)) > SMLNUM: */
  997. if (tjj < 1.f) {
  998. if (xj > tjj * bignum) {
  999. /* Scale x by 1/b(j). */
  1000. rec = 1.f / xj;
  1001. sscal_(n, &rec, &x[1], &c__1);
  1002. *scale *= rec;
  1003. xmax *= rec;
  1004. }
  1005. }
  1006. x[j] /= tjjs;
  1007. xj = (r__1 = x[j], abs(r__1));
  1008. } else if (tjj > 0.f) {
  1009. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1010. if (xj > tjj * bignum) {
  1011. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  1012. /* to avoid overflow when dividing by A(j,j). */
  1013. rec = tjj * bignum / xj;
  1014. if (cnorm[j] > 1.f) {
  1015. /* Scale by 1/CNORM(j) to avoid overflow when */
  1016. /* multiplying x(j) times column j. */
  1017. rec /= cnorm[j];
  1018. }
  1019. sscal_(n, &rec, &x[1], &c__1);
  1020. *scale *= rec;
  1021. xmax *= rec;
  1022. }
  1023. x[j] /= tjjs;
  1024. xj = (r__1 = x[j], abs(r__1));
  1025. } else {
  1026. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1027. /* scale = 0, and compute a solution to A*x = 0. */
  1028. i__3 = *n;
  1029. for (i__ = 1; i__ <= i__3; ++i__) {
  1030. x[i__] = 0.f;
  1031. /* L90: */
  1032. }
  1033. x[j] = 1.f;
  1034. xj = 1.f;
  1035. *scale = 0.f;
  1036. xmax = 0.f;
  1037. }
  1038. L95:
  1039. /* Scale x if necessary to avoid overflow when adding a */
  1040. /* multiple of column j of A. */
  1041. if (xj > 1.f) {
  1042. rec = 1.f / xj;
  1043. if (cnorm[j] > (bignum - xmax) * rec) {
  1044. /* Scale x by 1/(2*abs(x(j))). */
  1045. rec *= .5f;
  1046. sscal_(n, &rec, &x[1], &c__1);
  1047. *scale *= rec;
  1048. }
  1049. } else if (xj * cnorm[j] > bignum - xmax) {
  1050. /* Scale x by 1/2. */
  1051. sscal_(n, &c_b36, &x[1], &c__1);
  1052. *scale *= .5f;
  1053. }
  1054. if (upper) {
  1055. if (j > 1) {
  1056. /* Compute the update */
  1057. /* x(f2cmax(1,j-kd):j-1) := x(f2cmax(1,j-kd):j-1) - */
  1058. /* x(j)* A(f2cmax(1,j-kd):j-1,j) */
  1059. /* Computing MIN */
  1060. i__3 = *kd, i__4 = j - 1;
  1061. jlen = f2cmin(i__3,i__4);
  1062. r__1 = -x[j] * tscal;
  1063. saxpy_(&jlen, &r__1, &ab[*kd + 1 - jlen + j * ab_dim1]
  1064. , &c__1, &x[j - jlen], &c__1);
  1065. i__3 = j - 1;
  1066. i__ = isamax_(&i__3, &x[1], &c__1);
  1067. xmax = (r__1 = x[i__], abs(r__1));
  1068. }
  1069. } else if (j < *n) {
  1070. /* Compute the update */
  1071. /* x(j+1:f2cmin(j+kd,n)) := x(j+1:f2cmin(j+kd,n)) - */
  1072. /* x(j) * A(j+1:f2cmin(j+kd,n),j) */
  1073. /* Computing MIN */
  1074. i__3 = *kd, i__4 = *n - j;
  1075. jlen = f2cmin(i__3,i__4);
  1076. if (jlen > 0) {
  1077. r__1 = -x[j] * tscal;
  1078. saxpy_(&jlen, &r__1, &ab[j * ab_dim1 + 2], &c__1, &x[
  1079. j + 1], &c__1);
  1080. }
  1081. i__3 = *n - j;
  1082. i__ = j + isamax_(&i__3, &x[j + 1], &c__1);
  1083. xmax = (r__1 = x[i__], abs(r__1));
  1084. }
  1085. /* L100: */
  1086. }
  1087. } else {
  1088. /* Solve A**T * x = b */
  1089. i__2 = jlast;
  1090. i__1 = jinc;
  1091. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  1092. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  1093. /* k<>j */
  1094. xj = (r__1 = x[j], abs(r__1));
  1095. uscal = tscal;
  1096. rec = 1.f / f2cmax(xmax,1.f);
  1097. if (cnorm[j] > (bignum - xj) * rec) {
  1098. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  1099. rec *= .5f;
  1100. if (nounit) {
  1101. tjjs = ab[maind + j * ab_dim1] * tscal;
  1102. } else {
  1103. tjjs = tscal;
  1104. }
  1105. tjj = abs(tjjs);
  1106. if (tjj > 1.f) {
  1107. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1108. /* Computing MIN */
  1109. r__1 = 1.f, r__2 = rec * tjj;
  1110. rec = f2cmin(r__1,r__2);
  1111. uscal /= tjjs;
  1112. }
  1113. if (rec < 1.f) {
  1114. sscal_(n, &rec, &x[1], &c__1);
  1115. *scale *= rec;
  1116. xmax *= rec;
  1117. }
  1118. }
  1119. sumj = 0.f;
  1120. if (uscal == 1.f) {
  1121. /* If the scaling needed for A in the dot product is 1, */
  1122. /* call SDOT to perform the dot product. */
  1123. if (upper) {
  1124. /* Computing MIN */
  1125. i__3 = *kd, i__4 = j - 1;
  1126. jlen = f2cmin(i__3,i__4);
  1127. sumj = sdot_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1],
  1128. &c__1, &x[j - jlen], &c__1);
  1129. } else {
  1130. /* Computing MIN */
  1131. i__3 = *kd, i__4 = *n - j;
  1132. jlen = f2cmin(i__3,i__4);
  1133. if (jlen > 0) {
  1134. sumj = sdot_(&jlen, &ab[j * ab_dim1 + 2], &c__1, &
  1135. x[j + 1], &c__1);
  1136. }
  1137. }
  1138. } else {
  1139. /* Otherwise, use in-line code for the dot product. */
  1140. if (upper) {
  1141. /* Computing MIN */
  1142. i__3 = *kd, i__4 = j - 1;
  1143. jlen = f2cmin(i__3,i__4);
  1144. i__3 = jlen;
  1145. for (i__ = 1; i__ <= i__3; ++i__) {
  1146. sumj += ab[*kd + i__ - jlen + j * ab_dim1] *
  1147. uscal * x[j - jlen - 1 + i__];
  1148. /* L110: */
  1149. }
  1150. } else {
  1151. /* Computing MIN */
  1152. i__3 = *kd, i__4 = *n - j;
  1153. jlen = f2cmin(i__3,i__4);
  1154. i__3 = jlen;
  1155. for (i__ = 1; i__ <= i__3; ++i__) {
  1156. sumj += ab[i__ + 1 + j * ab_dim1] * uscal * x[j +
  1157. i__];
  1158. /* L120: */
  1159. }
  1160. }
  1161. }
  1162. if (uscal == tscal) {
  1163. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  1164. /* was not used to scale the dotproduct. */
  1165. x[j] -= sumj;
  1166. xj = (r__1 = x[j], abs(r__1));
  1167. if (nounit) {
  1168. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1169. tjjs = ab[maind + j * ab_dim1] * tscal;
  1170. } else {
  1171. tjjs = tscal;
  1172. if (tscal == 1.f) {
  1173. goto L135;
  1174. }
  1175. }
  1176. tjj = abs(tjjs);
  1177. if (tjj > smlnum) {
  1178. /* abs(A(j,j)) > SMLNUM: */
  1179. if (tjj < 1.f) {
  1180. if (xj > tjj * bignum) {
  1181. /* Scale X by 1/abs(x(j)). */
  1182. rec = 1.f / xj;
  1183. sscal_(n, &rec, &x[1], &c__1);
  1184. *scale *= rec;
  1185. xmax *= rec;
  1186. }
  1187. }
  1188. x[j] /= tjjs;
  1189. } else if (tjj > 0.f) {
  1190. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1191. if (xj > tjj * bignum) {
  1192. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1193. rec = tjj * bignum / xj;
  1194. sscal_(n, &rec, &x[1], &c__1);
  1195. *scale *= rec;
  1196. xmax *= rec;
  1197. }
  1198. x[j] /= tjjs;
  1199. } else {
  1200. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1201. /* scale = 0, and compute a solution to A**T*x = 0. */
  1202. i__3 = *n;
  1203. for (i__ = 1; i__ <= i__3; ++i__) {
  1204. x[i__] = 0.f;
  1205. /* L130: */
  1206. }
  1207. x[j] = 1.f;
  1208. *scale = 0.f;
  1209. xmax = 0.f;
  1210. }
  1211. L135:
  1212. ;
  1213. } else {
  1214. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  1215. /* product has already been divided by 1/A(j,j). */
  1216. x[j] = x[j] / tjjs - sumj;
  1217. }
  1218. /* Computing MAX */
  1219. r__2 = xmax, r__3 = (r__1 = x[j], abs(r__1));
  1220. xmax = f2cmax(r__2,r__3);
  1221. /* L140: */
  1222. }
  1223. }
  1224. *scale /= tscal;
  1225. }
  1226. /* Scale the column norms by 1/TSCAL for return. */
  1227. if (tscal != 1.f) {
  1228. r__1 = 1.f / tscal;
  1229. sscal_(n, &r__1, &cnorm[1], &c__1);
  1230. }
  1231. return;
  1232. /* End of SLATBS */
  1233. } /* slatbs_ */