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.

sgtsvx.c 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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 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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static integer c__1 = 1;
  236. /* > \brief <b> SGTSVX computes the solution to system of linear equations A * X = B for GT matrices </b> */
  237. /* =========== DOCUMENTATION =========== */
  238. /* Online html documentation available at */
  239. /* http://www.netlib.org/lapack/explore-html/ */
  240. /* > \htmlonly */
  241. /* > Download SGTSVX + dependencies */
  242. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgtsvx.
  243. f"> */
  244. /* > [TGZ]</a> */
  245. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgtsvx.
  246. f"> */
  247. /* > [ZIP]</a> */
  248. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgtsvx.
  249. f"> */
  250. /* > [TXT]</a> */
  251. /* > \endhtmlonly */
  252. /* Definition: */
  253. /* =========== */
  254. /* SUBROUTINE SGTSVX( FACT, TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, */
  255. /* DU2, IPIV, B, LDB, X, LDX, RCOND, FERR, BERR, */
  256. /* WORK, IWORK, INFO ) */
  257. /* CHARACTER FACT, TRANS */
  258. /* INTEGER INFO, LDB, LDX, N, NRHS */
  259. /* REAL RCOND */
  260. /* INTEGER IPIV( * ), IWORK( * ) */
  261. /* REAL B( LDB, * ), BERR( * ), D( * ), DF( * ), */
  262. /* $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ), */
  263. /* $ FERR( * ), WORK( * ), X( LDX, * ) */
  264. /* > \par Purpose: */
  265. /* ============= */
  266. /* > */
  267. /* > \verbatim */
  268. /* > */
  269. /* > SGTSVX uses the LU factorization to compute the solution to a real */
  270. /* > system of linear equations A * X = B or A**T * X = B, */
  271. /* > where A is a tridiagonal matrix of order N and X and B are N-by-NRHS */
  272. /* > matrices. */
  273. /* > */
  274. /* > Error bounds on the solution and a condition estimate are also */
  275. /* > provided. */
  276. /* > \endverbatim */
  277. /* > \par Description: */
  278. /* ================= */
  279. /* > */
  280. /* > \verbatim */
  281. /* > */
  282. /* > The following steps are performed: */
  283. /* > */
  284. /* > 1. If FACT = 'N', the LU decomposition is used to factor the matrix A */
  285. /* > as A = L * U, where L is a product of permutation and unit lower */
  286. /* > bidiagonal matrices and U is upper triangular with nonzeros in */
  287. /* > only the main diagonal and first two superdiagonals. */
  288. /* > */
  289. /* > 2. If some U(i,i)=0, so that U is exactly singular, then the routine */
  290. /* > returns with INFO = i. Otherwise, the factored form of A is used */
  291. /* > to estimate the condition number of the matrix A. If the */
  292. /* > reciprocal of the condition number is less than machine precision, */
  293. /* > INFO = N+1 is returned as a warning, but the routine still goes on */
  294. /* > to solve for X and compute error bounds as described below. */
  295. /* > */
  296. /* > 3. The system of equations is solved for X using the factored form */
  297. /* > of A. */
  298. /* > */
  299. /* > 4. Iterative refinement is applied to improve the computed solution */
  300. /* > matrix and calculate error bounds and backward error estimates */
  301. /* > for it. */
  302. /* > \endverbatim */
  303. /* Arguments: */
  304. /* ========== */
  305. /* > \param[in] FACT */
  306. /* > \verbatim */
  307. /* > FACT is CHARACTER*1 */
  308. /* > Specifies whether or not the factored form of A has been */
  309. /* > supplied on entry. */
  310. /* > = 'F': DLF, DF, DUF, DU2, and IPIV contain the factored */
  311. /* > form of A; DL, D, DU, DLF, DF, DUF, DU2 and IPIV */
  312. /* > will not be modified. */
  313. /* > = 'N': The matrix will be copied to DLF, DF, and DUF */
  314. /* > and factored. */
  315. /* > \endverbatim */
  316. /* > */
  317. /* > \param[in] TRANS */
  318. /* > \verbatim */
  319. /* > TRANS is CHARACTER*1 */
  320. /* > Specifies the form of the system of equations: */
  321. /* > = 'N': A * X = B (No transpose) */
  322. /* > = 'T': A**T * X = B (Transpose) */
  323. /* > = 'C': A**H * X = B (Conjugate transpose = Transpose) */
  324. /* > \endverbatim */
  325. /* > */
  326. /* > \param[in] N */
  327. /* > \verbatim */
  328. /* > N is INTEGER */
  329. /* > The order of the matrix A. N >= 0. */
  330. /* > \endverbatim */
  331. /* > */
  332. /* > \param[in] NRHS */
  333. /* > \verbatim */
  334. /* > NRHS is INTEGER */
  335. /* > The number of right hand sides, i.e., the number of columns */
  336. /* > of the matrix B. NRHS >= 0. */
  337. /* > \endverbatim */
  338. /* > */
  339. /* > \param[in] DL */
  340. /* > \verbatim */
  341. /* > DL is REAL array, dimension (N-1) */
  342. /* > The (n-1) subdiagonal elements of A. */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[in] D */
  346. /* > \verbatim */
  347. /* > D is REAL array, dimension (N) */
  348. /* > The n diagonal elements of A. */
  349. /* > \endverbatim */
  350. /* > */
  351. /* > \param[in] DU */
  352. /* > \verbatim */
  353. /* > DU is REAL array, dimension (N-1) */
  354. /* > The (n-1) superdiagonal elements of A. */
  355. /* > \endverbatim */
  356. /* > */
  357. /* > \param[in,out] DLF */
  358. /* > \verbatim */
  359. /* > DLF is REAL array, dimension (N-1) */
  360. /* > If FACT = 'F', then DLF is an input argument and on entry */
  361. /* > contains the (n-1) multipliers that define the matrix L from */
  362. /* > the LU factorization of A as computed by SGTTRF. */
  363. /* > */
  364. /* > If FACT = 'N', then DLF is an output argument and on exit */
  365. /* > contains the (n-1) multipliers that define the matrix L from */
  366. /* > the LU factorization of A. */
  367. /* > \endverbatim */
  368. /* > */
  369. /* > \param[in,out] DF */
  370. /* > \verbatim */
  371. /* > DF is REAL array, dimension (N) */
  372. /* > If FACT = 'F', then DF is an input argument and on entry */
  373. /* > contains the n diagonal elements of the upper triangular */
  374. /* > matrix U from the LU factorization of A. */
  375. /* > */
  376. /* > If FACT = 'N', then DF is an output argument and on exit */
  377. /* > contains the n diagonal elements of the upper triangular */
  378. /* > matrix U from the LU factorization of A. */
  379. /* > \endverbatim */
  380. /* > */
  381. /* > \param[in,out] DUF */
  382. /* > \verbatim */
  383. /* > DUF is REAL array, dimension (N-1) */
  384. /* > If FACT = 'F', then DUF is an input argument and on entry */
  385. /* > contains the (n-1) elements of the first superdiagonal of U. */
  386. /* > */
  387. /* > If FACT = 'N', then DUF is an output argument and on exit */
  388. /* > contains the (n-1) elements of the first superdiagonal of U. */
  389. /* > \endverbatim */
  390. /* > */
  391. /* > \param[in,out] DU2 */
  392. /* > \verbatim */
  393. /* > DU2 is REAL array, dimension (N-2) */
  394. /* > If FACT = 'F', then DU2 is an input argument and on entry */
  395. /* > contains the (n-2) elements of the second superdiagonal of */
  396. /* > U. */
  397. /* > */
  398. /* > If FACT = 'N', then DU2 is an output argument and on exit */
  399. /* > contains the (n-2) elements of the second superdiagonal of */
  400. /* > U. */
  401. /* > \endverbatim */
  402. /* > */
  403. /* > \param[in,out] IPIV */
  404. /* > \verbatim */
  405. /* > IPIV is INTEGER array, dimension (N) */
  406. /* > If FACT = 'F', then IPIV is an input argument and on entry */
  407. /* > contains the pivot indices from the LU factorization of A as */
  408. /* > computed by SGTTRF. */
  409. /* > */
  410. /* > If FACT = 'N', then IPIV is an output argument and on exit */
  411. /* > contains the pivot indices from the LU factorization of A; */
  412. /* > row i of the matrix was interchanged with row IPIV(i). */
  413. /* > IPIV(i) will always be either i or i+1; IPIV(i) = i indicates */
  414. /* > a row interchange was not required. */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[in] B */
  418. /* > \verbatim */
  419. /* > B is REAL array, dimension (LDB,NRHS) */
  420. /* > The N-by-NRHS right hand side matrix B. */
  421. /* > \endverbatim */
  422. /* > */
  423. /* > \param[in] LDB */
  424. /* > \verbatim */
  425. /* > LDB is INTEGER */
  426. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  427. /* > \endverbatim */
  428. /* > */
  429. /* > \param[out] X */
  430. /* > \verbatim */
  431. /* > X is REAL array, dimension (LDX,NRHS) */
  432. /* > If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. */
  433. /* > \endverbatim */
  434. /* > */
  435. /* > \param[in] LDX */
  436. /* > \verbatim */
  437. /* > LDX is INTEGER */
  438. /* > The leading dimension of the array X. LDX >= f2cmax(1,N). */
  439. /* > \endverbatim */
  440. /* > */
  441. /* > \param[out] RCOND */
  442. /* > \verbatim */
  443. /* > RCOND is REAL */
  444. /* > The estimate of the reciprocal condition number of the matrix */
  445. /* > A. If RCOND is less than the machine precision (in */
  446. /* > particular, if RCOND = 0), the matrix is singular to working */
  447. /* > precision. This condition is indicated by a return code of */
  448. /* > INFO > 0. */
  449. /* > \endverbatim */
  450. /* > */
  451. /* > \param[out] FERR */
  452. /* > \verbatim */
  453. /* > FERR is REAL array, dimension (NRHS) */
  454. /* > The estimated forward error bound for each solution vector */
  455. /* > X(j) (the j-th column of the solution matrix X). */
  456. /* > If XTRUE is the true solution corresponding to X(j), FERR(j) */
  457. /* > is an estimated upper bound for the magnitude of the largest */
  458. /* > element in (X(j) - XTRUE) divided by the magnitude of the */
  459. /* > largest element in X(j). The estimate is as reliable as */
  460. /* > the estimate for RCOND, and is almost always a slight */
  461. /* > overestimate of the true error. */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[out] BERR */
  465. /* > \verbatim */
  466. /* > BERR is REAL array, dimension (NRHS) */
  467. /* > The componentwise relative backward error of each solution */
  468. /* > vector X(j) (i.e., the smallest relative change in */
  469. /* > any element of A or B that makes X(j) an exact solution). */
  470. /* > \endverbatim */
  471. /* > */
  472. /* > \param[out] WORK */
  473. /* > \verbatim */
  474. /* > WORK is REAL array, dimension (3*N) */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[out] IWORK */
  478. /* > \verbatim */
  479. /* > IWORK is INTEGER array, dimension (N) */
  480. /* > \endverbatim */
  481. /* > */
  482. /* > \param[out] INFO */
  483. /* > \verbatim */
  484. /* > INFO is INTEGER */
  485. /* > = 0: successful exit */
  486. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  487. /* > > 0: if INFO = i, and i is */
  488. /* > <= N: U(i,i) is exactly zero. The factorization */
  489. /* > has not been completed unless i = N, but the */
  490. /* > factor U is exactly singular, so the solution */
  491. /* > and error bounds could not be computed. */
  492. /* > RCOND = 0 is returned. */
  493. /* > = N+1: U is nonsingular, but RCOND is less than machine */
  494. /* > precision, meaning that the matrix is singular */
  495. /* > to working precision. Nevertheless, the */
  496. /* > solution and error bounds are computed because */
  497. /* > there are a number of situations where the */
  498. /* > computed solution can be more accurate than the */
  499. /* > value of RCOND would suggest. */
  500. /* > \endverbatim */
  501. /* Authors: */
  502. /* ======== */
  503. /* > \author Univ. of Tennessee */
  504. /* > \author Univ. of California Berkeley */
  505. /* > \author Univ. of Colorado Denver */
  506. /* > \author NAG Ltd. */
  507. /* > \date December 2016 */
  508. /* > \ingroup realGTsolve */
  509. /* ===================================================================== */
  510. /* Subroutine */ void sgtsvx_(char *fact, char *trans, integer *n, integer *
  511. nrhs, real *dl, real *d__, real *du, real *dlf, real *df, real *duf,
  512. real *du2, integer *ipiv, real *b, integer *ldb, real *x, integer *
  513. ldx, real *rcond, real *ferr, real *berr, real *work, integer *iwork,
  514. integer *info)
  515. {
  516. /* System generated locals */
  517. integer b_dim1, b_offset, x_dim1, x_offset, i__1;
  518. /* Local variables */
  519. char norm[1];
  520. extern logical lsame_(char *, char *);
  521. real anorm;
  522. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  523. integer *);
  524. extern real slamch_(char *);
  525. logical nofact;
  526. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  527. extern real slangt_(char *, integer *, real *, real *, real *);
  528. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  529. integer *, real *, integer *), sgtcon_(char *, integer *,
  530. real *, real *, real *, real *, integer *, real *, real *, real *,
  531. integer *, integer *);
  532. logical notran;
  533. extern /* Subroutine */ void sgtrfs_(char *, integer *, integer *, real *,
  534. real *, real *, real *, real *, real *, real *, integer *, real *,
  535. integer *, real *, integer *, real *, real *, real *, integer *,
  536. integer *), sgttrf_(integer *, real *, real *, real *,
  537. real *, integer *, integer *), sgttrs_(char *, integer *, integer
  538. *, real *, real *, real *, real *, integer *, real *, integer *,
  539. integer *);
  540. /* -- LAPACK driver routine (version 3.7.0) -- */
  541. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  542. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  543. /* December 2016 */
  544. /* ===================================================================== */
  545. /* Parameter adjustments */
  546. --dl;
  547. --d__;
  548. --du;
  549. --dlf;
  550. --df;
  551. --duf;
  552. --du2;
  553. --ipiv;
  554. b_dim1 = *ldb;
  555. b_offset = 1 + b_dim1 * 1;
  556. b -= b_offset;
  557. x_dim1 = *ldx;
  558. x_offset = 1 + x_dim1 * 1;
  559. x -= x_offset;
  560. --ferr;
  561. --berr;
  562. --work;
  563. --iwork;
  564. /* Function Body */
  565. *info = 0;
  566. nofact = lsame_(fact, "N");
  567. notran = lsame_(trans, "N");
  568. if (! nofact && ! lsame_(fact, "F")) {
  569. *info = -1;
  570. } else if (! notran && ! lsame_(trans, "T") && !
  571. lsame_(trans, "C")) {
  572. *info = -2;
  573. } else if (*n < 0) {
  574. *info = -3;
  575. } else if (*nrhs < 0) {
  576. *info = -4;
  577. } else if (*ldb < f2cmax(1,*n)) {
  578. *info = -14;
  579. } else if (*ldx < f2cmax(1,*n)) {
  580. *info = -16;
  581. }
  582. if (*info != 0) {
  583. i__1 = -(*info);
  584. xerbla_("SGTSVX", &i__1, (ftnlen)6);
  585. return;
  586. }
  587. if (nofact) {
  588. /* Compute the LU factorization of A. */
  589. scopy_(n, &d__[1], &c__1, &df[1], &c__1);
  590. if (*n > 1) {
  591. i__1 = *n - 1;
  592. scopy_(&i__1, &dl[1], &c__1, &dlf[1], &c__1);
  593. i__1 = *n - 1;
  594. scopy_(&i__1, &du[1], &c__1, &duf[1], &c__1);
  595. }
  596. sgttrf_(n, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[1], info);
  597. /* Return if INFO is non-zero. */
  598. if (*info > 0) {
  599. *rcond = 0.f;
  600. return;
  601. }
  602. }
  603. /* Compute the norm of the matrix A. */
  604. if (notran) {
  605. *(unsigned char *)norm = '1';
  606. } else {
  607. *(unsigned char *)norm = 'I';
  608. }
  609. anorm = slangt_(norm, n, &dl[1], &d__[1], &du[1]);
  610. /* Compute the reciprocal of the condition number of A. */
  611. sgtcon_(norm, n, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[1], &anorm,
  612. rcond, &work[1], &iwork[1], info);
  613. /* Compute the solution vectors X. */
  614. slacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  615. sgttrs_(trans, n, nrhs, &dlf[1], &df[1], &duf[1], &du2[1], &ipiv[1], &x[
  616. x_offset], ldx, info);
  617. /* Use iterative refinement to improve the computed solutions and */
  618. /* compute error bounds and backward error estimates for them. */
  619. sgtrfs_(trans, n, nrhs, &dl[1], &d__[1], &du[1], &dlf[1], &df[1], &duf[1],
  620. &du2[1], &ipiv[1], &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1]
  621. , &berr[1], &work[1], &iwork[1], info);
  622. /* Set INFO = N+1 if the matrix is singular to working precision. */
  623. if (*rcond < slamch_("Epsilon")) {
  624. *info = *n + 1;
  625. }
  626. return;
  627. /* End of SGTSVX */
  628. } /* sgtsvx_ */