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 35 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #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++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #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]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c__1 = 1;
  381. static real c_b36 = .5f;
  382. /* > \brief \b SLATBS solves a triangular banded system of equations. */
  383. /* =========== DOCUMENTATION =========== */
  384. /* Online html documentation available at */
  385. /* http://www.netlib.org/lapack/explore-html/ */
  386. /* > \htmlonly */
  387. /* > Download SLATBS + dependencies */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slatbs.
  389. f"> */
  390. /* > [TGZ]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slatbs.
  392. f"> */
  393. /* > [ZIP]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slatbs.
  395. f"> */
  396. /* > [TXT]</a> */
  397. /* > \endhtmlonly */
  398. /* Definition: */
  399. /* =========== */
  400. /* SUBROUTINE SLATBS( UPLO, TRANS, DIAG, NORMIN, N, KD, AB, LDAB, X, */
  401. /* SCALE, CNORM, INFO ) */
  402. /* CHARACTER DIAG, NORMIN, TRANS, UPLO */
  403. /* INTEGER INFO, KD, LDAB, N */
  404. /* REAL SCALE */
  405. /* REAL AB( LDAB, * ), CNORM( * ), X( * ) */
  406. /* > \par Purpose: */
  407. /* ============= */
  408. /* > */
  409. /* > \verbatim */
  410. /* > */
  411. /* > SLATBS solves one of the triangular systems */
  412. /* > */
  413. /* > A *x = s*b or A**T*x = s*b */
  414. /* > */
  415. /* > with scaling to prevent overflow, where A is an upper or lower */
  416. /* > triangular band matrix. Here A**T denotes the transpose of A, x and b */
  417. /* > are n-element vectors, and s is a scaling factor, usually less than */
  418. /* > or equal to 1, chosen so that the components of x will be less than */
  419. /* > the overflow threshold. If the unscaled problem will not cause */
  420. /* > overflow, the Level 2 BLAS routine STBSV is called. If the matrix A */
  421. /* > is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
  422. /* > non-trivial solution to A*x = 0 is returned. */
  423. /* > \endverbatim */
  424. /* Arguments: */
  425. /* ========== */
  426. /* > \param[in] UPLO */
  427. /* > \verbatim */
  428. /* > UPLO is CHARACTER*1 */
  429. /* > Specifies whether the matrix A is upper or lower triangular. */
  430. /* > = 'U': Upper triangular */
  431. /* > = 'L': Lower triangular */
  432. /* > \endverbatim */
  433. /* > */
  434. /* > \param[in] TRANS */
  435. /* > \verbatim */
  436. /* > TRANS is CHARACTER*1 */
  437. /* > Specifies the operation applied to A. */
  438. /* > = 'N': Solve A * x = s*b (No transpose) */
  439. /* > = 'T': Solve A**T* x = s*b (Transpose) */
  440. /* > = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose) */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[in] DIAG */
  444. /* > \verbatim */
  445. /* > DIAG is CHARACTER*1 */
  446. /* > Specifies whether or not the matrix A is unit triangular. */
  447. /* > = 'N': Non-unit triangular */
  448. /* > = 'U': Unit triangular */
  449. /* > \endverbatim */
  450. /* > */
  451. /* > \param[in] NORMIN */
  452. /* > \verbatim */
  453. /* > NORMIN is CHARACTER*1 */
  454. /* > Specifies whether CNORM has been set or not. */
  455. /* > = 'Y': CNORM contains the column norms on entry */
  456. /* > = 'N': CNORM is not set on entry. On exit, the norms will */
  457. /* > be computed and stored in CNORM. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in] N */
  461. /* > \verbatim */
  462. /* > N is INTEGER */
  463. /* > The order of the matrix A. N >= 0. */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[in] KD */
  467. /* > \verbatim */
  468. /* > KD is INTEGER */
  469. /* > The number of subdiagonals or superdiagonals in the */
  470. /* > triangular matrix A. KD >= 0. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[in] AB */
  474. /* > \verbatim */
  475. /* > AB is REAL array, dimension (LDAB,N) */
  476. /* > The upper or lower triangular band matrix A, stored in the */
  477. /* > first KD+1 rows of the array. The j-th column of A is stored */
  478. /* > in the j-th column of the array AB as follows: */
  479. /* > if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for f2cmax(1,j-kd)<=i<=j; */
  480. /* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(n,j+kd). */
  481. /* > \endverbatim */
  482. /* > */
  483. /* > \param[in] LDAB */
  484. /* > \verbatim */
  485. /* > LDAB is INTEGER */
  486. /* > The leading dimension of the array AB. LDAB >= KD+1. */
  487. /* > \endverbatim */
  488. /* > */
  489. /* > \param[in,out] X */
  490. /* > \verbatim */
  491. /* > X is REAL array, dimension (N) */
  492. /* > On entry, the right hand side b of the triangular system. */
  493. /* > On exit, X is overwritten by the solution vector x. */
  494. /* > \endverbatim */
  495. /* > */
  496. /* > \param[out] SCALE */
  497. /* > \verbatim */
  498. /* > SCALE is REAL */
  499. /* > The scaling factor s for the triangular system */
  500. /* > A * x = s*b or A**T* x = s*b. */
  501. /* > If SCALE = 0, the matrix A is singular or badly scaled, and */
  502. /* > the vector x is an exact or approximate solution to A*x = 0. */
  503. /* > \endverbatim */
  504. /* > */
  505. /* > \param[in,out] CNORM */
  506. /* > \verbatim */
  507. /* > CNORM is REAL array, dimension (N) */
  508. /* > */
  509. /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  510. /* > contains the norm of the off-diagonal part of the j-th column */
  511. /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  512. /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  513. /* > must be greater than or equal to the 1-norm. */
  514. /* > */
  515. /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  516. /* > returns the 1-norm of the offdiagonal part of the j-th column */
  517. /* > of A. */
  518. /* > \endverbatim */
  519. /* > */
  520. /* > \param[out] INFO */
  521. /* > \verbatim */
  522. /* > INFO is INTEGER */
  523. /* > = 0: successful exit */
  524. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  525. /* > \endverbatim */
  526. /* Authors: */
  527. /* ======== */
  528. /* > \author Univ. of Tennessee */
  529. /* > \author Univ. of California Berkeley */
  530. /* > \author Univ. of Colorado Denver */
  531. /* > \author NAG Ltd. */
  532. /* > \date December 2016 */
  533. /* > \ingroup realOTHERauxiliary */
  534. /* > \par Further Details: */
  535. /* ===================== */
  536. /* > */
  537. /* > \verbatim */
  538. /* > */
  539. /* > A rough bound on x is computed; if that is less than overflow, STBSV */
  540. /* > is called, otherwise, specific code is used which checks for possible */
  541. /* > overflow or divide-by-zero at every operation. */
  542. /* > */
  543. /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */
  544. /* > if A is lower triangular is */
  545. /* > */
  546. /* > x[1:n] := b[1:n] */
  547. /* > for j = 1, ..., n */
  548. /* > x(j) := x(j) / A(j,j) */
  549. /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
  550. /* > end */
  551. /* > */
  552. /* > Define bounds on the components of x after j iterations of the loop: */
  553. /* > M(j) = bound on x[1:j] */
  554. /* > G(j) = bound on x[j+1:n] */
  555. /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */
  556. /* > */
  557. /* > Then for iteration j+1 we have */
  558. /* > M(j+1) <= G(j) / | A(j+1,j+1) | */
  559. /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
  560. /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
  561. /* > */
  562. /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */
  563. /* > column j+1 of A, not counting the diagonal. Hence */
  564. /* > */
  565. /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
  566. /* > 1<=i<=j */
  567. /* > and */
  568. /* > */
  569. /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
  570. /* > 1<=i< j */
  571. /* > */
  572. /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine STBSV if the */
  573. /* > reciprocal of the largest M(j), j=1,..,n, is larger than */
  574. /* > f2cmax(underflow, 1/overflow). */
  575. /* > */
  576. /* > The bound on x(j) is also used to determine when a step in the */
  577. /* > columnwise method can be performed without fear of overflow. If */
  578. /* > the computed bound is greater than a large constant, x is scaled to */
  579. /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
  580. /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
  581. /* > */
  582. /* > Similarly, a row-wise scheme is used to solve A**T*x = b. The basic */
  583. /* > algorithm for A upper triangular is */
  584. /* > */
  585. /* > for j = 1, ..., n */
  586. /* > x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j) */
  587. /* > end */
  588. /* > */
  589. /* > We simultaneously compute two bounds */
  590. /* > G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j */
  591. /* > M(j) = bound on x(i), 1<=i<=j */
  592. /* > */
  593. /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */
  594. /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
  595. /* > Then the bound on x(j) is */
  596. /* > */
  597. /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
  598. /* > */
  599. /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
  600. /* > 1<=i<=j */
  601. /* > */
  602. /* > and we can safely call STBSV if 1/M(n) and 1/G(n) are both greater */
  603. /* > than f2cmax(underflow, 1/overflow). */
  604. /* > \endverbatim */
  605. /* > */
  606. /* ===================================================================== */
  607. /* Subroutine */ int slatbs_(char *uplo, char *trans, char *diag, char *
  608. normin, integer *n, integer *kd, real *ab, integer *ldab, real *x,
  609. real *scale, real *cnorm, integer *info)
  610. {
  611. /* System generated locals */
  612. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
  613. real r__1, r__2, r__3;
  614. /* Local variables */
  615. integer jinc, jlen;
  616. real xbnd;
  617. integer imax;
  618. real tmax, tjjs;
  619. extern real sdot_(integer *, real *, integer *, real *, integer *);
  620. real xmax, grow, sumj;
  621. integer i__, j, maind;
  622. extern logical lsame_(char *, char *);
  623. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
  624. real tscal, uscal;
  625. integer jlast;
  626. extern real sasum_(integer *, real *, integer *);
  627. logical upper;
  628. extern /* Subroutine */ int stbsv_(char *, char *, char *, integer *,
  629. integer *, real *, integer *, real *, integer *), saxpy_(integer *, real *, real *, integer *, real *,
  630. integer *);
  631. real xj;
  632. extern real slamch_(char *);
  633. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  634. real bignum;
  635. extern integer isamax_(integer *, real *, integer *);
  636. logical notran;
  637. integer jfirst;
  638. real smlnum;
  639. logical nounit;
  640. real rec, tjj;
  641. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  642. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  643. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  644. /* December 2016 */
  645. /* ===================================================================== */
  646. /* Parameter adjustments */
  647. ab_dim1 = *ldab;
  648. ab_offset = 1 + ab_dim1 * 1;
  649. ab -= ab_offset;
  650. --x;
  651. --cnorm;
  652. /* Function Body */
  653. *info = 0;
  654. upper = lsame_(uplo, "U");
  655. notran = lsame_(trans, "N");
  656. nounit = lsame_(diag, "N");
  657. /* Test the input parameters. */
  658. if (! upper && ! lsame_(uplo, "L")) {
  659. *info = -1;
  660. } else if (! notran && ! lsame_(trans, "T") && !
  661. lsame_(trans, "C")) {
  662. *info = -2;
  663. } else if (! nounit && ! lsame_(diag, "U")) {
  664. *info = -3;
  665. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  666. "N")) {
  667. *info = -4;
  668. } else if (*n < 0) {
  669. *info = -5;
  670. } else if (*kd < 0) {
  671. *info = -6;
  672. } else if (*ldab < *kd + 1) {
  673. *info = -8;
  674. }
  675. if (*info != 0) {
  676. i__1 = -(*info);
  677. xerbla_("SLATBS", &i__1, (ftnlen)6);
  678. return 0;
  679. }
  680. /* Quick return if possible */
  681. if (*n == 0) {
  682. return 0;
  683. }
  684. /* Determine machine dependent parameters to control overflow. */
  685. smlnum = slamch_("Safe minimum") / slamch_("Precision");
  686. bignum = 1.f / smlnum;
  687. *scale = 1.f;
  688. if (lsame_(normin, "N")) {
  689. /* Compute the 1-norm of each column, not including the diagonal. */
  690. if (upper) {
  691. /* A is upper triangular. */
  692. i__1 = *n;
  693. for (j = 1; j <= i__1; ++j) {
  694. /* Computing MIN */
  695. i__2 = *kd, i__3 = j - 1;
  696. jlen = f2cmin(i__2,i__3);
  697. cnorm[j] = sasum_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1], &
  698. c__1);
  699. /* L10: */
  700. }
  701. } else {
  702. /* A is lower triangular. */
  703. i__1 = *n;
  704. for (j = 1; j <= i__1; ++j) {
  705. /* Computing MIN */
  706. i__2 = *kd, i__3 = *n - j;
  707. jlen = f2cmin(i__2,i__3);
  708. if (jlen > 0) {
  709. cnorm[j] = sasum_(&jlen, &ab[j * ab_dim1 + 2], &c__1);
  710. } else {
  711. cnorm[j] = 0.f;
  712. }
  713. /* L20: */
  714. }
  715. }
  716. }
  717. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  718. /* greater than BIGNUM. */
  719. imax = isamax_(n, &cnorm[1], &c__1);
  720. tmax = cnorm[imax];
  721. if (tmax <= bignum) {
  722. tscal = 1.f;
  723. } else {
  724. tscal = 1.f / (smlnum * tmax);
  725. sscal_(n, &tscal, &cnorm[1], &c__1);
  726. }
  727. /* Compute a bound on the computed solution vector to see if the */
  728. /* Level 2 BLAS routine STBSV can be used. */
  729. j = isamax_(n, &x[1], &c__1);
  730. xmax = (r__1 = x[j], abs(r__1));
  731. xbnd = xmax;
  732. if (notran) {
  733. /* Compute the growth in A * x = b. */
  734. if (upper) {
  735. jfirst = *n;
  736. jlast = 1;
  737. jinc = -1;
  738. maind = *kd + 1;
  739. } else {
  740. jfirst = 1;
  741. jlast = *n;
  742. jinc = 1;
  743. maind = 1;
  744. }
  745. if (tscal != 1.f) {
  746. grow = 0.f;
  747. goto L50;
  748. }
  749. if (nounit) {
  750. /* A is non-unit triangular. */
  751. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  752. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  753. grow = 1.f / f2cmax(xbnd,smlnum);
  754. xbnd = grow;
  755. i__1 = jlast;
  756. i__2 = jinc;
  757. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  758. /* Exit the loop if the growth factor is too small. */
  759. if (grow <= smlnum) {
  760. goto L50;
  761. }
  762. /* M(j) = G(j-1) / abs(A(j,j)) */
  763. tjj = (r__1 = ab[maind + j * ab_dim1], abs(r__1));
  764. /* Computing MIN */
  765. r__1 = xbnd, r__2 = f2cmin(1.f,tjj) * grow;
  766. xbnd = f2cmin(r__1,r__2);
  767. if (tjj + cnorm[j] >= smlnum) {
  768. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  769. grow *= tjj / (tjj + cnorm[j]);
  770. } else {
  771. /* G(j) could overflow, set GROW to 0. */
  772. grow = 0.f;
  773. }
  774. /* L30: */
  775. }
  776. grow = xbnd;
  777. } else {
  778. /* A is unit triangular. */
  779. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  780. /* Computing MIN */
  781. r__1 = 1.f, r__2 = 1.f / f2cmax(xbnd,smlnum);
  782. grow = f2cmin(r__1,r__2);
  783. i__2 = jlast;
  784. i__1 = jinc;
  785. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  786. /* Exit the loop if the growth factor is too small. */
  787. if (grow <= smlnum) {
  788. goto L50;
  789. }
  790. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  791. grow *= 1.f / (cnorm[j] + 1.f);
  792. /* L40: */
  793. }
  794. }
  795. L50:
  796. ;
  797. } else {
  798. /* Compute the growth in A**T * x = b. */
  799. if (upper) {
  800. jfirst = 1;
  801. jlast = *n;
  802. jinc = 1;
  803. maind = *kd + 1;
  804. } else {
  805. jfirst = *n;
  806. jlast = 1;
  807. jinc = -1;
  808. maind = 1;
  809. }
  810. if (tscal != 1.f) {
  811. grow = 0.f;
  812. goto L80;
  813. }
  814. if (nounit) {
  815. /* A is non-unit triangular. */
  816. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  817. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  818. grow = 1.f / f2cmax(xbnd,smlnum);
  819. xbnd = grow;
  820. i__1 = jlast;
  821. i__2 = jinc;
  822. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  823. /* Exit the loop if the growth factor is too small. */
  824. if (grow <= smlnum) {
  825. goto L80;
  826. }
  827. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  828. xj = cnorm[j] + 1.f;
  829. /* Computing MIN */
  830. r__1 = grow, r__2 = xbnd / xj;
  831. grow = f2cmin(r__1,r__2);
  832. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  833. tjj = (r__1 = ab[maind + j * ab_dim1], abs(r__1));
  834. if (xj > tjj) {
  835. xbnd *= tjj / xj;
  836. }
  837. /* L60: */
  838. }
  839. grow = f2cmin(grow,xbnd);
  840. } else {
  841. /* A is unit triangular. */
  842. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  843. /* Computing MIN */
  844. r__1 = 1.f, r__2 = 1.f / f2cmax(xbnd,smlnum);
  845. grow = f2cmin(r__1,r__2);
  846. i__2 = jlast;
  847. i__1 = jinc;
  848. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  849. /* Exit the loop if the growth factor is too small. */
  850. if (grow <= smlnum) {
  851. goto L80;
  852. }
  853. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  854. xj = cnorm[j] + 1.f;
  855. grow /= xj;
  856. /* L70: */
  857. }
  858. }
  859. L80:
  860. ;
  861. }
  862. if (grow * tscal > smlnum) {
  863. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  864. /* elements of X is not too small. */
  865. stbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1);
  866. } else {
  867. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  868. if (xmax > bignum) {
  869. /* Scale X so that its components are less than or equal to */
  870. /* BIGNUM in absolute value. */
  871. *scale = bignum / xmax;
  872. sscal_(n, scale, &x[1], &c__1);
  873. xmax = bignum;
  874. }
  875. if (notran) {
  876. /* Solve A * x = b */
  877. i__1 = jlast;
  878. i__2 = jinc;
  879. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  880. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  881. xj = (r__1 = x[j], abs(r__1));
  882. if (nounit) {
  883. tjjs = ab[maind + j * ab_dim1] * tscal;
  884. } else {
  885. tjjs = tscal;
  886. if (tscal == 1.f) {
  887. goto L95;
  888. }
  889. }
  890. tjj = abs(tjjs);
  891. if (tjj > smlnum) {
  892. /* abs(A(j,j)) > SMLNUM: */
  893. if (tjj < 1.f) {
  894. if (xj > tjj * bignum) {
  895. /* Scale x by 1/b(j). */
  896. rec = 1.f / xj;
  897. sscal_(n, &rec, &x[1], &c__1);
  898. *scale *= rec;
  899. xmax *= rec;
  900. }
  901. }
  902. x[j] /= tjjs;
  903. xj = (r__1 = x[j], abs(r__1));
  904. } else if (tjj > 0.f) {
  905. /* 0 < abs(A(j,j)) <= SMLNUM: */
  906. if (xj > tjj * bignum) {
  907. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  908. /* to avoid overflow when dividing by A(j,j). */
  909. rec = tjj * bignum / xj;
  910. if (cnorm[j] > 1.f) {
  911. /* Scale by 1/CNORM(j) to avoid overflow when */
  912. /* multiplying x(j) times column j. */
  913. rec /= cnorm[j];
  914. }
  915. sscal_(n, &rec, &x[1], &c__1);
  916. *scale *= rec;
  917. xmax *= rec;
  918. }
  919. x[j] /= tjjs;
  920. xj = (r__1 = x[j], abs(r__1));
  921. } else {
  922. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  923. /* scale = 0, and compute a solution to A*x = 0. */
  924. i__3 = *n;
  925. for (i__ = 1; i__ <= i__3; ++i__) {
  926. x[i__] = 0.f;
  927. /* L90: */
  928. }
  929. x[j] = 1.f;
  930. xj = 1.f;
  931. *scale = 0.f;
  932. xmax = 0.f;
  933. }
  934. L95:
  935. /* Scale x if necessary to avoid overflow when adding a */
  936. /* multiple of column j of A. */
  937. if (xj > 1.f) {
  938. rec = 1.f / xj;
  939. if (cnorm[j] > (bignum - xmax) * rec) {
  940. /* Scale x by 1/(2*abs(x(j))). */
  941. rec *= .5f;
  942. sscal_(n, &rec, &x[1], &c__1);
  943. *scale *= rec;
  944. }
  945. } else if (xj * cnorm[j] > bignum - xmax) {
  946. /* Scale x by 1/2. */
  947. sscal_(n, &c_b36, &x[1], &c__1);
  948. *scale *= .5f;
  949. }
  950. if (upper) {
  951. if (j > 1) {
  952. /* Compute the update */
  953. /* x(f2cmax(1,j-kd):j-1) := x(f2cmax(1,j-kd):j-1) - */
  954. /* x(j)* A(f2cmax(1,j-kd):j-1,j) */
  955. /* Computing MIN */
  956. i__3 = *kd, i__4 = j - 1;
  957. jlen = f2cmin(i__3,i__4);
  958. r__1 = -x[j] * tscal;
  959. saxpy_(&jlen, &r__1, &ab[*kd + 1 - jlen + j * ab_dim1]
  960. , &c__1, &x[j - jlen], &c__1);
  961. i__3 = j - 1;
  962. i__ = isamax_(&i__3, &x[1], &c__1);
  963. xmax = (r__1 = x[i__], abs(r__1));
  964. }
  965. } else if (j < *n) {
  966. /* Compute the update */
  967. /* x(j+1:f2cmin(j+kd,n)) := x(j+1:f2cmin(j+kd,n)) - */
  968. /* x(j) * A(j+1:f2cmin(j+kd,n),j) */
  969. /* Computing MIN */
  970. i__3 = *kd, i__4 = *n - j;
  971. jlen = f2cmin(i__3,i__4);
  972. if (jlen > 0) {
  973. r__1 = -x[j] * tscal;
  974. saxpy_(&jlen, &r__1, &ab[j * ab_dim1 + 2], &c__1, &x[
  975. j + 1], &c__1);
  976. }
  977. i__3 = *n - j;
  978. i__ = j + isamax_(&i__3, &x[j + 1], &c__1);
  979. xmax = (r__1 = x[i__], abs(r__1));
  980. }
  981. /* L100: */
  982. }
  983. } else {
  984. /* Solve A**T * x = b */
  985. i__2 = jlast;
  986. i__1 = jinc;
  987. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  988. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  989. /* k<>j */
  990. xj = (r__1 = x[j], abs(r__1));
  991. uscal = tscal;
  992. rec = 1.f / f2cmax(xmax,1.f);
  993. if (cnorm[j] > (bignum - xj) * rec) {
  994. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  995. rec *= .5f;
  996. if (nounit) {
  997. tjjs = ab[maind + j * ab_dim1] * tscal;
  998. } else {
  999. tjjs = tscal;
  1000. }
  1001. tjj = abs(tjjs);
  1002. if (tjj > 1.f) {
  1003. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1004. /* Computing MIN */
  1005. r__1 = 1.f, r__2 = rec * tjj;
  1006. rec = f2cmin(r__1,r__2);
  1007. uscal /= tjjs;
  1008. }
  1009. if (rec < 1.f) {
  1010. sscal_(n, &rec, &x[1], &c__1);
  1011. *scale *= rec;
  1012. xmax *= rec;
  1013. }
  1014. }
  1015. sumj = 0.f;
  1016. if (uscal == 1.f) {
  1017. /* If the scaling needed for A in the dot product is 1, */
  1018. /* call SDOT to perform the dot product. */
  1019. if (upper) {
  1020. /* Computing MIN */
  1021. i__3 = *kd, i__4 = j - 1;
  1022. jlen = f2cmin(i__3,i__4);
  1023. sumj = sdot_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1],
  1024. &c__1, &x[j - jlen], &c__1);
  1025. } else {
  1026. /* Computing MIN */
  1027. i__3 = *kd, i__4 = *n - j;
  1028. jlen = f2cmin(i__3,i__4);
  1029. if (jlen > 0) {
  1030. sumj = sdot_(&jlen, &ab[j * ab_dim1 + 2], &c__1, &
  1031. x[j + 1], &c__1);
  1032. }
  1033. }
  1034. } else {
  1035. /* Otherwise, use in-line code for the dot product. */
  1036. if (upper) {
  1037. /* Computing MIN */
  1038. i__3 = *kd, i__4 = j - 1;
  1039. jlen = f2cmin(i__3,i__4);
  1040. i__3 = jlen;
  1041. for (i__ = 1; i__ <= i__3; ++i__) {
  1042. sumj += ab[*kd + i__ - jlen + j * ab_dim1] *
  1043. uscal * x[j - jlen - 1 + i__];
  1044. /* L110: */
  1045. }
  1046. } else {
  1047. /* Computing MIN */
  1048. i__3 = *kd, i__4 = *n - j;
  1049. jlen = f2cmin(i__3,i__4);
  1050. i__3 = jlen;
  1051. for (i__ = 1; i__ <= i__3; ++i__) {
  1052. sumj += ab[i__ + 1 + j * ab_dim1] * uscal * x[j +
  1053. i__];
  1054. /* L120: */
  1055. }
  1056. }
  1057. }
  1058. if (uscal == tscal) {
  1059. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  1060. /* was not used to scale the dotproduct. */
  1061. x[j] -= sumj;
  1062. xj = (r__1 = x[j], abs(r__1));
  1063. if (nounit) {
  1064. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1065. tjjs = ab[maind + j * ab_dim1] * tscal;
  1066. } else {
  1067. tjjs = tscal;
  1068. if (tscal == 1.f) {
  1069. goto L135;
  1070. }
  1071. }
  1072. tjj = abs(tjjs);
  1073. if (tjj > smlnum) {
  1074. /* abs(A(j,j)) > SMLNUM: */
  1075. if (tjj < 1.f) {
  1076. if (xj > tjj * bignum) {
  1077. /* Scale X by 1/abs(x(j)). */
  1078. rec = 1.f / xj;
  1079. sscal_(n, &rec, &x[1], &c__1);
  1080. *scale *= rec;
  1081. xmax *= rec;
  1082. }
  1083. }
  1084. x[j] /= tjjs;
  1085. } else if (tjj > 0.f) {
  1086. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1087. if (xj > tjj * bignum) {
  1088. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1089. rec = tjj * bignum / xj;
  1090. sscal_(n, &rec, &x[1], &c__1);
  1091. *scale *= rec;
  1092. xmax *= rec;
  1093. }
  1094. x[j] /= tjjs;
  1095. } else {
  1096. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1097. /* scale = 0, and compute a solution to A**T*x = 0. */
  1098. i__3 = *n;
  1099. for (i__ = 1; i__ <= i__3; ++i__) {
  1100. x[i__] = 0.f;
  1101. /* L130: */
  1102. }
  1103. x[j] = 1.f;
  1104. *scale = 0.f;
  1105. xmax = 0.f;
  1106. }
  1107. L135:
  1108. ;
  1109. } else {
  1110. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  1111. /* product has already been divided by 1/A(j,j). */
  1112. x[j] = x[j] / tjjs - sumj;
  1113. }
  1114. /* Computing MAX */
  1115. r__2 = xmax, r__3 = (r__1 = x[j], abs(r__1));
  1116. xmax = f2cmax(r__2,r__3);
  1117. /* L140: */
  1118. }
  1119. }
  1120. *scale /= tscal;
  1121. }
  1122. /* Scale the column norms by 1/TSCAL for return. */
  1123. if (tscal != 1.f) {
  1124. r__1 = 1.f / tscal;
  1125. sscal_(n, &r__1, &cnorm[1], &c__1);
  1126. }
  1127. return 0;
  1128. /* End of SLATBS */
  1129. } /* slatbs_ */