dbhin.f 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. *DECK DBHIN
  2. SUBROUTINE DBHIN (N, NELT, IA, JA, A, ISYM, SOLN, RHS, IUNIT, JOB)
  3. C***BEGIN PROLOGUE DBHIN
  4. C***PURPOSE Read a Sparse Linear System in the Boeing/Harwell Format.
  5. C The matrix is read in and if the right hand side is also
  6. C present in the input file then it too is read in. The
  7. C matrix is then modified to be in the SLAP Column format.
  8. C***LIBRARY SLATEC (SLAP)
  9. C***CATEGORY N1
  10. C***TYPE DOUBLE PRECISION (SBHIN-S, DBHIN-D)
  11. C***KEYWORDS LINEAR SYSTEM, MATRIX READ, SLAP SPARSE
  12. C***AUTHOR Seager, Mark K., (LLNL)
  13. C Lawrence Livermore National Laboratory
  14. C PO BOX 808, L-60
  15. C Livermore, CA 94550 (510) 423-3141
  16. C seager@llnl.gov
  17. C***DESCRIPTION
  18. C
  19. C *Usage:
  20. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM, IUNIT, JOB
  21. C DOUBLE PRECISION A(NELT), SOLN(N), RHS(N)
  22. C
  23. C CALL DBHIN( N, NELT, IA, JA, A, ISYM, SOLN, RHS, IUNIT, JOB )
  24. C
  25. C *Arguments:
  26. C N :OUT Integer
  27. C Order of the Matrix.
  28. C NELT :INOUT Integer.
  29. C On input NELT is the maximum number of non-zeros that
  30. C can be stored in the IA, JA, A arrays.
  31. C On output NELT is the number of non-zeros stored in A.
  32. C IA :OUT Integer IA(NELT).
  33. C JA :OUT Integer JA(NELT).
  34. C A :OUT Double Precision A(NELT).
  35. C On output these arrays hold the matrix A in the SLAP
  36. C Triad format. See "Description", below.
  37. C ISYM :OUT Integer.
  38. C Flag to indicate symmetric storage format.
  39. C If ISYM=0, all non-zero entries of the matrix are stored.
  40. C If ISYM=1, the matrix is symmetric, and only the lower
  41. C triangle of the matrix is stored.
  42. C SOLN :OUT Double Precision SOLN(N).
  43. C The solution to the linear system, if present. This array
  44. C is accessed if and only if JOB is set to read it in, see
  45. C below. If the user requests that SOLN be read in, but it is
  46. C not in the file, then it is simply zeroed out.
  47. C RHS :OUT Double Precision RHS(N).
  48. C The right hand side vector. This array is accessed if and
  49. C only if JOB is set to read it in, see below.
  50. C If the user requests that RHS be read in, but it is not in
  51. C the file, then it is simply zeroed out.
  52. C IUNIT :IN Integer.
  53. C Fortran logical I/O device unit number to read the matrix
  54. C from. This unit must be connected in a system dependent
  55. C fashion to a file, or you will get a nasty message
  56. C from the Fortran I/O libraries.
  57. C JOB :INOUT Integer.
  58. C Flag indicating what I/O operations to perform.
  59. C On input JOB indicates what Input operations to try to
  60. C perform.
  61. C JOB = 0 => Read only the matrix.
  62. C JOB = 1 => Read matrix and RHS (if present).
  63. C JOB = 2 => Read matrix and SOLN (if present).
  64. C JOB = 3 => Read matrix, RHS and SOLN (if present).
  65. C On output JOB indicates what operations were actually
  66. C performed.
  67. C JOB = -3 => Unable to parse matrix "CODE" from input file
  68. C to determine if only the lower triangle of matrix
  69. C is stored.
  70. C JOB = -2 => Number of non-zeros (NELT) too large.
  71. C JOB = -1 => System size (N) too large.
  72. C JOB = 0 => Read in only the matrix.
  73. C JOB = 1 => Read in the matrix and RHS.
  74. C JOB = 2 => Read in the matrix and SOLN.
  75. C JOB = 3 => Read in the matrix, RHS and SOLN.
  76. C JOB = 10 => Read in only the matrix *STRUCTURE*, but no
  77. C non-zero entries. Hence, A(*) is not referenced
  78. C and has the return values the same as the input.
  79. C JOB = 11 => Read in the matrix *STRUCTURE* and RHS.
  80. C JOB = 12 => Read in the matrix *STRUCTURE* and SOLN.
  81. C JOB = 13 => Read in the matrix *STRUCTURE*, RHS and SOLN.
  82. C
  83. C *Description:
  84. C The format for the input is as follows. The first line contains
  85. C a title to identify the data file. On the second line (5I4) are
  86. C counters: NLINE, NPLS, NRILS, NNVLS, NRHSLS.
  87. C NLINE Number of data lines (after the header) in the file.
  88. C NPLS Number of lines for the Column Pointer data in the file.
  89. C NRILS Number of lines for the Row indices in the file.
  90. C NNVLS Number of lines for the Matrix elements in the file.
  91. C NRHSLS Number of lines for the RHS in the file.
  92. C The third line (A3,11X,4I4) contains a symmetry code and some
  93. C additional counters: CODE, NROW, NCOL, NIND, NELE.
  94. C On the fourth line (2A16,2A20) are formats to be used to read
  95. C the following data: PNTFNT, RINFMT, NVLFMT, RHSFMT.
  96. C Following that are the blocks of data in the order indicated.
  97. C
  98. C =================== S L A P Triad format ===================
  99. C This routine requires that the matrix A be stored in the
  100. C SLAP Triad format. In this format only the non-zeros are
  101. C stored. They may appear in *ANY* order. The user supplies
  102. C three arrays of length NELT, where NELT is the number of
  103. C non-zeros in the matrix: (IA(NELT), JA(NELT), A(NELT)). For
  104. C each non-zero the user puts the row and column index of that
  105. C matrix element in the IA and JA arrays. The value of the
  106. C non-zero matrix element is placed in the corresponding
  107. C location of the A array. This is an extremely easy data
  108. C structure to generate. On the other hand it is not too
  109. C efficient on vector computers for the iterative solution of
  110. C linear systems. Hence, SLAP changes this input data
  111. C structure to the SLAP Column format for the iteration (but
  112. C does not change it back).
  113. C
  114. C Here is an example of the SLAP Triad storage format for a
  115. C 5x5 Matrix. Recall that the entries may appear in any order.
  116. C
  117. C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
  118. C 1 2 3 4 5 6 7 8 9 10 11
  119. C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
  120. C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
  121. C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
  122. C | 0 0 0 44 0|
  123. C |51 0 53 0 55|
  124. C
  125. C *Portability:
  126. C You must make sure that IUNIT is a valid Fortran logical
  127. C I/O device unit number and that the unit number has been
  128. C associated with a file or the console. This is a system
  129. C dependent function.
  130. C
  131. C *Implementation note:
  132. C SOLN is not read by this version. It will simply be
  133. C zeroed out if JOB = 2 or 3 and the returned value of
  134. C JOB will indicate SOLN has not been read.
  135. C***REFERENCES (NONE)
  136. C***ROUTINES CALLED (NONE)
  137. C***REVISION HISTORY (YYMMDD)
  138. C 881107 DATE WRITTEN
  139. C 881213 Previous REVISION DATE
  140. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  141. C 890922 Numerous changes to prologue to make closer to SLATEC
  142. C standard. (FNF)
  143. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  144. C 910411 Prologue converted to Version 4.0 format. (BAB)
  145. C 911122 Added loop to zero out RHS if user wants to read RHS, but
  146. C it's not in the input file. (MKS)
  147. C 911125 Minor improvements to prologue. (FNF)
  148. C 920511 Added complete declaration section. (WRB)
  149. C 921007 Corrected description of input format. (FNF)
  150. C 921208 Added Implementation Note and code to zero out SOLN. (FNF)
  151. C 930701 Updated CATEGORY section. (FNF, WRB)
  152. C***END PROLOGUE DBHIN
  153. C .. Scalar Arguments ..
  154. INTEGER ISYM, IUNIT, JOB, N, NELT
  155. C .. Array Arguments ..
  156. DOUBLE PRECISION A(NELT), RHS(N), SOLN(N)
  157. INTEGER IA(NELT), JA(NELT)
  158. C .. Local Scalars ..
  159. DOUBLE PRECISION TEMP
  160. INTEGER I, IBGN, ICOL, IEND, ITEMP, J, JOBRET, NCOL, NELE, NIND,
  161. + NLINE, NNVLS, NPLS, NRHSLS, NRILS, NROW
  162. CHARACTER CODE*3, PNTFMT*16, RINFMT*16, NVLFMT*20, RHSFMT*20,
  163. + TITLE*80
  164. C .. Intrinsic Functions ..
  165. INTRINSIC MOD
  166. C***FIRST EXECUTABLE STATEMENT DBHIN
  167. C
  168. C Read Matrices In BOEING-HARWELL format.
  169. C
  170. C TITLE Header line to identify data file.
  171. C NLINE Number of data lines (after the header) in the file.
  172. C NPLS Number of lines for the Column Pointer data in the file.
  173. C NRILS Number of lines for the Row indices in the data file.
  174. C NNVLS Number of lines for the Matrix elements in the data file.
  175. C NRHSLS Number of lines for the RHS in the data file.
  176. C ---- Only those variables needed by SLAP are referenced. ----
  177. C
  178. READ(IUNIT,9000) TITLE
  179. READ(IUNIT,9010) NLINE, NPLS, NRILS, NNVLS, NRHSLS
  180. READ(IUNIT,9020) CODE, NROW, NCOL, NIND, NELE
  181. READ(IUNIT,9030) PNTFMT, RINFMT, NVLFMT, RHSFMT
  182. C
  183. IF( NROW.GT.N ) THEN
  184. N = NROW
  185. JOBRET = -1
  186. GOTO 999
  187. ENDIF
  188. IF( NIND.GT.NELT ) THEN
  189. NELT = NIND
  190. JOBRET = -2
  191. GOTO 999
  192. ENDIF
  193. C
  194. C Set the parameters.
  195. C
  196. N = NROW
  197. NELT = NIND
  198. IF( CODE.EQ.'RUA' ) THEN
  199. ISYM = 0
  200. ELSE IF( CODE.EQ.'RSA' ) THEN
  201. ISYM = 1
  202. ELSE
  203. JOBRET = -3
  204. GOTO 999
  205. ENDIF
  206. READ(IUNIT,PNTFMT) (JA(I), I = 1, N+1)
  207. READ(IUNIT,RINFMT) (IA(I), I = 1, NELT)
  208. JOBRET = 10
  209. IF( NNVLS.GT.0 ) THEN
  210. READ(IUNIT,NVLFMT) (A(I), I = 1, NELT)
  211. JOBRET = 0
  212. ENDIF
  213. IF( MOD(JOB,2).EQ.1 ) THEN
  214. C
  215. C User requests that the RHS be read in. If it is in the input
  216. C file, read it in; otherwise just zero it out.
  217. C
  218. IF( NRHSLS.GT.0 ) THEN
  219. READ(5,RHSFMT) (RHS(I), I = 1, N)
  220. JOBRET = JOBRET + 1
  221. ELSE
  222. DO 10 I = 1, N
  223. RHS(I) = 0
  224. 10 CONTINUE
  225. ENDIF
  226. ENDIF
  227. IF ( (JOB.EQ.2).OR.(JOB.EQ.3) ) THEN
  228. C
  229. C User requests that the SOLN be read in.
  230. C Just zero out the array.
  231. C
  232. DO 20 I = 1, N
  233. SOLN(I) = 0
  234. 20 CONTINUE
  235. ENDIF
  236. C
  237. C Now loop through the IA array making sure that the diagonal
  238. C matrix element appears first in the column. Then sort the
  239. C rest of the column in ascending order.
  240. C
  241. CVD$R NOCONCUR
  242. CVD$R NOVECTOR
  243. DO 70 ICOL = 1, N
  244. IBGN = JA(ICOL)
  245. IEND = JA(ICOL+1)-1
  246. DO 30 I = IBGN, IEND
  247. IF( IA(I).EQ.ICOL ) THEN
  248. C
  249. C Swap the diagonal element with the first element in the
  250. C column.
  251. C
  252. ITEMP = IA(I)
  253. IA(I) = IA(IBGN)
  254. IA(IBGN) = ITEMP
  255. TEMP = A(I)
  256. A(I) = A(IBGN)
  257. A(IBGN) = TEMP
  258. GOTO 40
  259. ENDIF
  260. 30 CONTINUE
  261. 40 IBGN = IBGN + 1
  262. IF( IBGN.LT.IEND ) THEN
  263. DO 60 I = IBGN, IEND
  264. DO 50 J = I+1, IEND
  265. IF( IA(I).GT.IA(J) ) THEN
  266. ITEMP = IA(I)
  267. IA(I) = IA(J)
  268. IA(J) = ITEMP
  269. TEMP = A(I)
  270. A(I) = A(J)
  271. A(J) = TEMP
  272. ENDIF
  273. 50 CONTINUE
  274. 60 CONTINUE
  275. ENDIF
  276. 70 CONTINUE
  277. C
  278. C Set return flag.
  279. 999 JOB = JOBRET
  280. RETURN
  281. 9000 FORMAT( A80 )
  282. 9010 FORMAT( 5I14 )
  283. 9020 FORMAT( A3, 11X, 4I14 )
  284. 9030 FORMAT( 2A16, 2A20 )
  285. C------------- LAST LINE OF DBHIN FOLLOWS ------------------------------
  286. END