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.

dlatbs.c 35 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  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 doublereal c_b36 = .5;
  382. /* > \brief \b DLATBS 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 DLATBS + dependencies */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlatbs.
  389. f"> */
  390. /* > [TGZ]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlatbs.
  392. f"> */
  393. /* > [ZIP]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlatbs.
  395. f"> */
  396. /* > [TXT]</a> */
  397. /* > \endhtmlonly */
  398. /* Definition: */
  399. /* =========== */
  400. /* SUBROUTINE DLATBS( 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. /* DOUBLE PRECISION SCALE */
  405. /* DOUBLE PRECISION AB( LDAB, * ), CNORM( * ), X( * ) */
  406. /* > \par Purpose: */
  407. /* ============= */
  408. /* > */
  409. /* > \verbatim */
  410. /* > */
  411. /* > DLATBS 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 DTBSV 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION */
  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 DOUBLE PRECISION 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 doubleOTHERauxiliary */
  534. /* > \par Further Details: */
  535. /* ===================== */
  536. /* > */
  537. /* > \verbatim */
  538. /* > */
  539. /* > A rough bound on x is computed; if that is less than overflow, DTBSV */
  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 DTBSV 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 DTBSV if 1/M(n) and 1/G(n) are both greater */
  603. /* > than f2cmax(underflow, 1/overflow). */
  604. /* > \endverbatim */
  605. /* > */
  606. /* ===================================================================== */
  607. /* Subroutine */ int dlatbs_(char *uplo, char *trans, char *diag, char *
  608. normin, integer *n, integer *kd, doublereal *ab, integer *ldab,
  609. doublereal *x, doublereal *scale, doublereal *cnorm, integer *info)
  610. {
  611. /* System generated locals */
  612. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
  613. doublereal d__1, d__2, d__3;
  614. /* Local variables */
  615. integer jinc, jlen;
  616. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  617. integer *);
  618. doublereal xbnd;
  619. integer imax;
  620. doublereal tmax, tjjs, xmax, grow, sumj;
  621. integer i__, j;
  622. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  623. integer *);
  624. integer maind;
  625. extern logical lsame_(char *, char *);
  626. doublereal tscal, uscal;
  627. extern doublereal dasum_(integer *, doublereal *, integer *);
  628. integer jlast;
  629. extern /* Subroutine */ int dtbsv_(char *, char *, char *, integer *,
  630. integer *, doublereal *, integer *, doublereal *, integer *), daxpy_(integer *, doublereal *,
  631. doublereal *, integer *, doublereal *, integer *);
  632. logical upper;
  633. extern doublereal dlamch_(char *);
  634. doublereal xj;
  635. extern integer idamax_(integer *, doublereal *, integer *);
  636. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  637. doublereal bignum;
  638. logical notran;
  639. integer jfirst;
  640. doublereal smlnum;
  641. logical nounit;
  642. doublereal rec, tjj;
  643. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  644. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  645. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  646. /* December 2016 */
  647. /* ===================================================================== */
  648. /* Parameter adjustments */
  649. ab_dim1 = *ldab;
  650. ab_offset = 1 + ab_dim1 * 1;
  651. ab -= ab_offset;
  652. --x;
  653. --cnorm;
  654. /* Function Body */
  655. *info = 0;
  656. upper = lsame_(uplo, "U");
  657. notran = lsame_(trans, "N");
  658. nounit = lsame_(diag, "N");
  659. /* Test the input parameters. */
  660. if (! upper && ! lsame_(uplo, "L")) {
  661. *info = -1;
  662. } else if (! notran && ! lsame_(trans, "T") && !
  663. lsame_(trans, "C")) {
  664. *info = -2;
  665. } else if (! nounit && ! lsame_(diag, "U")) {
  666. *info = -3;
  667. } else if (! lsame_(normin, "Y") && ! lsame_(normin,
  668. "N")) {
  669. *info = -4;
  670. } else if (*n < 0) {
  671. *info = -5;
  672. } else if (*kd < 0) {
  673. *info = -6;
  674. } else if (*ldab < *kd + 1) {
  675. *info = -8;
  676. }
  677. if (*info != 0) {
  678. i__1 = -(*info);
  679. xerbla_("DLATBS", &i__1, (ftnlen)6);
  680. return 0;
  681. }
  682. /* Quick return if possible */
  683. if (*n == 0) {
  684. return 0;
  685. }
  686. /* Determine machine dependent parameters to control overflow. */
  687. smlnum = dlamch_("Safe minimum") / dlamch_("Precision");
  688. bignum = 1. / smlnum;
  689. *scale = 1.;
  690. if (lsame_(normin, "N")) {
  691. /* Compute the 1-norm of each column, not including the diagonal. */
  692. if (upper) {
  693. /* A is upper triangular. */
  694. i__1 = *n;
  695. for (j = 1; j <= i__1; ++j) {
  696. /* Computing MIN */
  697. i__2 = *kd, i__3 = j - 1;
  698. jlen = f2cmin(i__2,i__3);
  699. cnorm[j] = dasum_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1], &
  700. c__1);
  701. /* L10: */
  702. }
  703. } else {
  704. /* A is lower triangular. */
  705. i__1 = *n;
  706. for (j = 1; j <= i__1; ++j) {
  707. /* Computing MIN */
  708. i__2 = *kd, i__3 = *n - j;
  709. jlen = f2cmin(i__2,i__3);
  710. if (jlen > 0) {
  711. cnorm[j] = dasum_(&jlen, &ab[j * ab_dim1 + 2], &c__1);
  712. } else {
  713. cnorm[j] = 0.;
  714. }
  715. /* L20: */
  716. }
  717. }
  718. }
  719. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  720. /* greater than BIGNUM. */
  721. imax = idamax_(n, &cnorm[1], &c__1);
  722. tmax = cnorm[imax];
  723. if (tmax <= bignum) {
  724. tscal = 1.;
  725. } else {
  726. tscal = 1. / (smlnum * tmax);
  727. dscal_(n, &tscal, &cnorm[1], &c__1);
  728. }
  729. /* Compute a bound on the computed solution vector to see if the */
  730. /* Level 2 BLAS routine DTBSV can be used. */
  731. j = idamax_(n, &x[1], &c__1);
  732. xmax = (d__1 = x[j], abs(d__1));
  733. xbnd = xmax;
  734. if (notran) {
  735. /* Compute the growth in A * x = b. */
  736. if (upper) {
  737. jfirst = *n;
  738. jlast = 1;
  739. jinc = -1;
  740. maind = *kd + 1;
  741. } else {
  742. jfirst = 1;
  743. jlast = *n;
  744. jinc = 1;
  745. maind = 1;
  746. }
  747. if (tscal != 1.) {
  748. grow = 0.;
  749. goto L50;
  750. }
  751. if (nounit) {
  752. /* A is non-unit triangular. */
  753. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  754. /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */
  755. grow = 1. / f2cmax(xbnd,smlnum);
  756. xbnd = grow;
  757. i__1 = jlast;
  758. i__2 = jinc;
  759. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  760. /* Exit the loop if the growth factor is too small. */
  761. if (grow <= smlnum) {
  762. goto L50;
  763. }
  764. /* M(j) = G(j-1) / abs(A(j,j)) */
  765. tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
  766. /* Computing MIN */
  767. d__1 = xbnd, d__2 = f2cmin(1.,tjj) * grow;
  768. xbnd = f2cmin(d__1,d__2);
  769. if (tjj + cnorm[j] >= smlnum) {
  770. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  771. grow *= tjj / (tjj + cnorm[j]);
  772. } else {
  773. /* G(j) could overflow, set GROW to 0. */
  774. grow = 0.;
  775. }
  776. /* L30: */
  777. }
  778. grow = xbnd;
  779. } else {
  780. /* A is unit triangular. */
  781. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  782. /* Computing MIN */
  783. d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
  784. grow = f2cmin(d__1,d__2);
  785. i__2 = jlast;
  786. i__1 = jinc;
  787. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  788. /* Exit the loop if the growth factor is too small. */
  789. if (grow <= smlnum) {
  790. goto L50;
  791. }
  792. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  793. grow *= 1. / (cnorm[j] + 1.);
  794. /* L40: */
  795. }
  796. }
  797. L50:
  798. ;
  799. } else {
  800. /* Compute the growth in A**T * x = b. */
  801. if (upper) {
  802. jfirst = 1;
  803. jlast = *n;
  804. jinc = 1;
  805. maind = *kd + 1;
  806. } else {
  807. jfirst = *n;
  808. jlast = 1;
  809. jinc = -1;
  810. maind = 1;
  811. }
  812. if (tscal != 1.) {
  813. grow = 0.;
  814. goto L80;
  815. }
  816. if (nounit) {
  817. /* A is non-unit triangular. */
  818. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  819. /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */
  820. grow = 1. / f2cmax(xbnd,smlnum);
  821. xbnd = grow;
  822. i__1 = jlast;
  823. i__2 = jinc;
  824. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  825. /* Exit the loop if the growth factor is too small. */
  826. if (grow <= smlnum) {
  827. goto L80;
  828. }
  829. /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  830. xj = cnorm[j] + 1.;
  831. /* Computing MIN */
  832. d__1 = grow, d__2 = xbnd / xj;
  833. grow = f2cmin(d__1,d__2);
  834. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  835. tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
  836. if (xj > tjj) {
  837. xbnd *= tjj / xj;
  838. }
  839. /* L60: */
  840. }
  841. grow = f2cmin(grow,xbnd);
  842. } else {
  843. /* A is unit triangular. */
  844. /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */
  845. /* Computing MIN */
  846. d__1 = 1., d__2 = 1. / f2cmax(xbnd,smlnum);
  847. grow = f2cmin(d__1,d__2);
  848. i__2 = jlast;
  849. i__1 = jinc;
  850. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  851. /* Exit the loop if the growth factor is too small. */
  852. if (grow <= smlnum) {
  853. goto L80;
  854. }
  855. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  856. xj = cnorm[j] + 1.;
  857. grow /= xj;
  858. /* L70: */
  859. }
  860. }
  861. L80:
  862. ;
  863. }
  864. if (grow * tscal > smlnum) {
  865. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  866. /* elements of X is not too small. */
  867. dtbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1);
  868. } else {
  869. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  870. if (xmax > bignum) {
  871. /* Scale X so that its components are less than or equal to */
  872. /* BIGNUM in absolute value. */
  873. *scale = bignum / xmax;
  874. dscal_(n, scale, &x[1], &c__1);
  875. xmax = bignum;
  876. }
  877. if (notran) {
  878. /* Solve A * x = b */
  879. i__1 = jlast;
  880. i__2 = jinc;
  881. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  882. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  883. xj = (d__1 = x[j], abs(d__1));
  884. if (nounit) {
  885. tjjs = ab[maind + j * ab_dim1] * tscal;
  886. } else {
  887. tjjs = tscal;
  888. if (tscal == 1.) {
  889. goto L100;
  890. }
  891. }
  892. tjj = abs(tjjs);
  893. if (tjj > smlnum) {
  894. /* abs(A(j,j)) > SMLNUM: */
  895. if (tjj < 1.) {
  896. if (xj > tjj * bignum) {
  897. /* Scale x by 1/b(j). */
  898. rec = 1. / xj;
  899. dscal_(n, &rec, &x[1], &c__1);
  900. *scale *= rec;
  901. xmax *= rec;
  902. }
  903. }
  904. x[j] /= tjjs;
  905. xj = (d__1 = x[j], abs(d__1));
  906. } else if (tjj > 0.) {
  907. /* 0 < abs(A(j,j)) <= SMLNUM: */
  908. if (xj > tjj * bignum) {
  909. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  910. /* to avoid overflow when dividing by A(j,j). */
  911. rec = tjj * bignum / xj;
  912. if (cnorm[j] > 1.) {
  913. /* Scale by 1/CNORM(j) to avoid overflow when */
  914. /* multiplying x(j) times column j. */
  915. rec /= cnorm[j];
  916. }
  917. dscal_(n, &rec, &x[1], &c__1);
  918. *scale *= rec;
  919. xmax *= rec;
  920. }
  921. x[j] /= tjjs;
  922. xj = (d__1 = x[j], abs(d__1));
  923. } else {
  924. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  925. /* scale = 0, and compute a solution to A*x = 0. */
  926. i__3 = *n;
  927. for (i__ = 1; i__ <= i__3; ++i__) {
  928. x[i__] = 0.;
  929. /* L90: */
  930. }
  931. x[j] = 1.;
  932. xj = 1.;
  933. *scale = 0.;
  934. xmax = 0.;
  935. }
  936. L100:
  937. /* Scale x if necessary to avoid overflow when adding a */
  938. /* multiple of column j of A. */
  939. if (xj > 1.) {
  940. rec = 1. / xj;
  941. if (cnorm[j] > (bignum - xmax) * rec) {
  942. /* Scale x by 1/(2*abs(x(j))). */
  943. rec *= .5;
  944. dscal_(n, &rec, &x[1], &c__1);
  945. *scale *= rec;
  946. }
  947. } else if (xj * cnorm[j] > bignum - xmax) {
  948. /* Scale x by 1/2. */
  949. dscal_(n, &c_b36, &x[1], &c__1);
  950. *scale *= .5;
  951. }
  952. if (upper) {
  953. if (j > 1) {
  954. /* Compute the update */
  955. /* x(f2cmax(1,j-kd):j-1) := x(f2cmax(1,j-kd):j-1) - */
  956. /* x(j)* A(f2cmax(1,j-kd):j-1,j) */
  957. /* Computing MIN */
  958. i__3 = *kd, i__4 = j - 1;
  959. jlen = f2cmin(i__3,i__4);
  960. d__1 = -x[j] * tscal;
  961. daxpy_(&jlen, &d__1, &ab[*kd + 1 - jlen + j * ab_dim1]
  962. , &c__1, &x[j - jlen], &c__1);
  963. i__3 = j - 1;
  964. i__ = idamax_(&i__3, &x[1], &c__1);
  965. xmax = (d__1 = x[i__], abs(d__1));
  966. }
  967. } else if (j < *n) {
  968. /* Compute the update */
  969. /* x(j+1:f2cmin(j+kd,n)) := x(j+1:f2cmin(j+kd,n)) - */
  970. /* x(j) * A(j+1:f2cmin(j+kd,n),j) */
  971. /* Computing MIN */
  972. i__3 = *kd, i__4 = *n - j;
  973. jlen = f2cmin(i__3,i__4);
  974. if (jlen > 0) {
  975. d__1 = -x[j] * tscal;
  976. daxpy_(&jlen, &d__1, &ab[j * ab_dim1 + 2], &c__1, &x[
  977. j + 1], &c__1);
  978. }
  979. i__3 = *n - j;
  980. i__ = j + idamax_(&i__3, &x[j + 1], &c__1);
  981. xmax = (d__1 = x[i__], abs(d__1));
  982. }
  983. /* L110: */
  984. }
  985. } else {
  986. /* Solve A**T * x = b */
  987. i__2 = jlast;
  988. i__1 = jinc;
  989. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  990. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  991. /* k<>j */
  992. xj = (d__1 = x[j], abs(d__1));
  993. uscal = tscal;
  994. rec = 1. / f2cmax(xmax,1.);
  995. if (cnorm[j] > (bignum - xj) * rec) {
  996. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  997. rec *= .5;
  998. if (nounit) {
  999. tjjs = ab[maind + j * ab_dim1] * tscal;
  1000. } else {
  1001. tjjs = tscal;
  1002. }
  1003. tjj = abs(tjjs);
  1004. if (tjj > 1.) {
  1005. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  1006. /* Computing MIN */
  1007. d__1 = 1., d__2 = rec * tjj;
  1008. rec = f2cmin(d__1,d__2);
  1009. uscal /= tjjs;
  1010. }
  1011. if (rec < 1.) {
  1012. dscal_(n, &rec, &x[1], &c__1);
  1013. *scale *= rec;
  1014. xmax *= rec;
  1015. }
  1016. }
  1017. sumj = 0.;
  1018. if (uscal == 1.) {
  1019. /* If the scaling needed for A in the dot product is 1, */
  1020. /* call DDOT to perform the dot product. */
  1021. if (upper) {
  1022. /* Computing MIN */
  1023. i__3 = *kd, i__4 = j - 1;
  1024. jlen = f2cmin(i__3,i__4);
  1025. sumj = ddot_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1],
  1026. &c__1, &x[j - jlen], &c__1);
  1027. } else {
  1028. /* Computing MIN */
  1029. i__3 = *kd, i__4 = *n - j;
  1030. jlen = f2cmin(i__3,i__4);
  1031. if (jlen > 0) {
  1032. sumj = ddot_(&jlen, &ab[j * ab_dim1 + 2], &c__1, &
  1033. x[j + 1], &c__1);
  1034. }
  1035. }
  1036. } else {
  1037. /* Otherwise, use in-line code for the dot product. */
  1038. if (upper) {
  1039. /* Computing MIN */
  1040. i__3 = *kd, i__4 = j - 1;
  1041. jlen = f2cmin(i__3,i__4);
  1042. i__3 = jlen;
  1043. for (i__ = 1; i__ <= i__3; ++i__) {
  1044. sumj += ab[*kd + i__ - jlen + j * ab_dim1] *
  1045. uscal * x[j - jlen - 1 + i__];
  1046. /* L120: */
  1047. }
  1048. } else {
  1049. /* Computing MIN */
  1050. i__3 = *kd, i__4 = *n - j;
  1051. jlen = f2cmin(i__3,i__4);
  1052. i__3 = jlen;
  1053. for (i__ = 1; i__ <= i__3; ++i__) {
  1054. sumj += ab[i__ + 1 + j * ab_dim1] * uscal * x[j +
  1055. i__];
  1056. /* L130: */
  1057. }
  1058. }
  1059. }
  1060. if (uscal == tscal) {
  1061. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  1062. /* was not used to scale the dotproduct. */
  1063. x[j] -= sumj;
  1064. xj = (d__1 = x[j], abs(d__1));
  1065. if (nounit) {
  1066. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  1067. tjjs = ab[maind + j * ab_dim1] * tscal;
  1068. } else {
  1069. tjjs = tscal;
  1070. if (tscal == 1.) {
  1071. goto L150;
  1072. }
  1073. }
  1074. tjj = abs(tjjs);
  1075. if (tjj > smlnum) {
  1076. /* abs(A(j,j)) > SMLNUM: */
  1077. if (tjj < 1.) {
  1078. if (xj > tjj * bignum) {
  1079. /* Scale X by 1/abs(x(j)). */
  1080. rec = 1. / xj;
  1081. dscal_(n, &rec, &x[1], &c__1);
  1082. *scale *= rec;
  1083. xmax *= rec;
  1084. }
  1085. }
  1086. x[j] /= tjjs;
  1087. } else if (tjj > 0.) {
  1088. /* 0 < abs(A(j,j)) <= SMLNUM: */
  1089. if (xj > tjj * bignum) {
  1090. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  1091. rec = tjj * bignum / xj;
  1092. dscal_(n, &rec, &x[1], &c__1);
  1093. *scale *= rec;
  1094. xmax *= rec;
  1095. }
  1096. x[j] /= tjjs;
  1097. } else {
  1098. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  1099. /* scale = 0, and compute a solution to A**T*x = 0. */
  1100. i__3 = *n;
  1101. for (i__ = 1; i__ <= i__3; ++i__) {
  1102. x[i__] = 0.;
  1103. /* L140: */
  1104. }
  1105. x[j] = 1.;
  1106. *scale = 0.;
  1107. xmax = 0.;
  1108. }
  1109. L150:
  1110. ;
  1111. } else {
  1112. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  1113. /* product has already been divided by 1/A(j,j). */
  1114. x[j] = x[j] / tjjs - sumj;
  1115. }
  1116. /* Computing MAX */
  1117. d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
  1118. xmax = f2cmax(d__2,d__3);
  1119. /* L160: */
  1120. }
  1121. }
  1122. *scale /= tscal;
  1123. }
  1124. /* Scale the column norms by 1/TSCAL for return. */
  1125. if (tscal != 1.) {
  1126. d__1 = 1. / tscal;
  1127. dscal_(n, &d__1, &cnorm[1], &c__1);
  1128. }
  1129. return 0;
  1130. /* End of DLATBS */
  1131. } /* dlatbs_ */