stin.f 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. *DECK STIN
  2. SUBROUTINE STIN (N, NELT, IA, JA, A, ISYM, SOLN, RHS, IUNIT, JOB)
  3. C***BEGIN PROLOGUE STIN
  4. C***PURPOSE Read in SLAP Triad Format Linear System.
  5. C Routine to read in a SLAP Triad format matrix and right
  6. C hand side and solution to the system, if known.
  7. C***LIBRARY SLATEC (SLAP)
  8. C***CATEGORY N1
  9. C***TYPE SINGLE PRECISION (STIN-S, DTIN-D)
  10. C***KEYWORDS DIAGNOSTICS, LINEAR SYSTEM, SLAP SPARSE
  11. C***AUTHOR Seager, Mark K., (LLNL)
  12. C Lawrence Livermore National Laboratory
  13. C PO BOX 808, L-60
  14. C Livermore, CA 94550 (510) 423-3141
  15. C seager@llnl.gov
  16. C***DESCRIPTION
  17. C
  18. C *Usage:
  19. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM, IUNIT, JOB
  20. C REAL A(NELT), SOLN(N), RHS(N)
  21. C
  22. C CALL STIN( N, NELT, IA, JA, A, ISYM, SOLN, RHS, IUNIT, JOB )
  23. C
  24. C *Arguments:
  25. C N :OUT Integer
  26. C Order of the Matrix.
  27. C NELT :INOUT Integer.
  28. C On input NELT is the maximum number of non-zeros that
  29. C can be stored in the IA, JA, A arrays.
  30. C On output NELT is the number of non-zeros stored in A.
  31. C IA :OUT Integer IA(NELT).
  32. C JA :OUT Integer JA(NELT).
  33. C A :OUT Real A(NELT).
  34. C On output these arrays hold the matrix A in the SLAP
  35. C Triad format. See "Description", below.
  36. C ISYM :OUT Integer.
  37. C Flag to indicate symmetric storage format.
  38. C If ISYM=0, all non-zero entries of the matrix are stored.
  39. C If ISYM=1, the matrix is symmetric, and only the lower
  40. C triangle of the matrix is stored.
  41. C SOLN :OUT Real SOLN(N).
  42. C The solution to the linear system, if present. This array
  43. C is accessed if and only if JOB to read it in, see below.
  44. C If the user requests that SOLN be read in, but it is not in
  45. C the file, then it is simply zeroed out.
  46. C RHS :OUT Real RHS(N).
  47. C The right hand side vector. This array is accessed if and
  48. C only if JOB is set to read it in, see below.
  49. C If the user requests that RHS be read in, but it is not in
  50. C the file, then it is simply zeroed out.
  51. C IUNIT :IN Integer.
  52. C Fortran logical I/O device unit number to write the matrix
  53. C to. This unit must be connected in a system dependent fashion
  54. C to a file or the console or you will get a nasty message
  55. C from the Fortran I/O libraries.
  56. C JOB :INOUT Integer.
  57. C Flag indicating what I/O operations to perform.
  58. C On input JOB indicates what Input operations to try to
  59. C perform.
  60. C JOB = 0 => Read only the matrix.
  61. C JOB = 1 => Read matrix and RHS (if present).
  62. C JOB = 2 => Read matrix and SOLN (if present).
  63. C JOB = 3 => Read matrix, RHS and SOLN (if present).
  64. C On output JOB indicates what operations were actually
  65. C performed.
  66. C JOB = 0 => Read in only the matrix.
  67. C JOB = 1 => Read in the matrix and RHS.
  68. C JOB = 2 => Read in the matrix and SOLN.
  69. C JOB = 3 => Read in the matrix, RHS and SOLN.
  70. C
  71. C *Description:
  72. C The format for the input is as follows. On the first line
  73. C are counters and flags: N, NELT, ISYM, IRHS, ISOLN. N, NELT
  74. C and ISYM are described above. IRHS is a flag indicating if
  75. C the RHS was written out (1 is yes, 0 is no). ISOLN is a
  76. C flag indicating if the SOLN was written out (1 is yes, 0 is
  77. C no). The format for the fist line is: 5i10. Then comes the
  78. C NELT Triad's IA(I), JA(I) and A(I), I = 1, NELT. The format
  79. C for these lines is : 1X,I5,1X,I5,1X,E16.7. Then comes
  80. C RHS(I), I = 1, N, if IRHS = 1. Then comes SOLN(I), I = 1,
  81. C N, if ISOLN = 1. The format for these lines is: 1X,E16.7.
  82. C
  83. C =================== S L A P Triad format ===================
  84. C This routine requires that the matrix A be stored in the
  85. C SLAP Triad format. In this format only the non-zeros are
  86. C stored. They may appear in *ANY* order. The user supplies
  87. C three arrays of length NELT, where NELT is the number of
  88. C non-zeros in the matrix: (IA(NELT), JA(NELT), A(NELT)). For
  89. C each non-zero the user puts the row and column index of that
  90. C matrix element in the IA and JA arrays. The value of the
  91. C non-zero matrix element is placed in the corresponding
  92. C location of the A array. This is an extremely easy data
  93. C structure to generate. On the other hand it is not too
  94. C efficient on vector computers for the iterative solution of
  95. C linear systems. Hence, SLAP changes this input data
  96. C structure to the SLAP Column format for the iteration (but
  97. C does not change it back).
  98. C
  99. C Here is an example of the SLAP Triad storage format for a
  100. C 5x5 Matrix. Recall that the entries may appear in any order.
  101. C
  102. C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
  103. C 1 2 3 4 5 6 7 8 9 10 11
  104. C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
  105. C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
  106. C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
  107. C | 0 0 0 44 0|
  108. C |51 0 53 0 55|
  109. C
  110. C *Cautions:
  111. C This routine will attempt to write to the Fortran logical output
  112. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  113. C this logical unit is attached to a file or terminal before calling
  114. C this routine with a non-zero value for IUNIT. This routine does
  115. C not check for the validity of a non-zero IUNIT unit number.
  116. C***REFERENCES (NONE)
  117. C***ROUTINES CALLED (NONE)
  118. C***REVISION HISTORY (YYMMDD)
  119. C 871119 DATE WRITTEN
  120. C 881213 Previous REVISION DATE
  121. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  122. C 890922 Numerous changes to prologue to make closer to SLATEC
  123. C standard. (FNF)
  124. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  125. C 910411 Prologue converted to Version 4.0 format. (BAB)
  126. C 920511 Added complete declaration section. (WRB)
  127. C 930701 Updated CATEGORY section. (FNF, WRB)
  128. C***END PROLOGUE STIN
  129. C .. Scalar Arguments ..
  130. INTEGER ISYM, IUNIT, JOB, N, NELT
  131. C .. Array Arguments ..
  132. REAL A(NELT), RHS(N), SOLN(N)
  133. INTEGER IA(NELT), JA(NELT)
  134. C .. Local Scalars ..
  135. INTEGER I, IRHS, ISOLN, JOBRET, NELTMX
  136. C .. Intrinsic Functions ..
  137. INTRINSIC MIN
  138. C***FIRST EXECUTABLE STATEMENT STIN
  139. C
  140. C Read in the information heading.
  141. C
  142. NELTMX = NELT
  143. READ(IUNIT,1000) N, NELT, ISYM, IRHS, ISOLN
  144. NELT = MIN( NELT, NELTMX )
  145. C
  146. C Read in the matrix non-zeros in Triad format.
  147. DO 10 I = 1, NELT
  148. READ(IUNIT,1010) IA(I), JA(I), A(I)
  149. 10 CONTINUE
  150. C
  151. C If requested, read in the rhs.
  152. JOBRET = 0
  153. IF( JOB.EQ.1 .OR. JOB.EQ.3 ) THEN
  154. C
  155. C Check to see if rhs is in the file.
  156. IF( IRHS.EQ.1 ) THEN
  157. JOBRET = 1
  158. READ(IUNIT,1020) (RHS(I),I=1,N)
  159. ELSE
  160. DO 20 I = 1, N
  161. RHS(I) = 0
  162. 20 CONTINUE
  163. ENDIF
  164. ENDIF
  165. C
  166. C If requested, read in the solution.
  167. IF( JOB.GT.1 ) THEN
  168. C
  169. C Check to see if solution is in the file.
  170. IF( ISOLN.EQ.1 ) THEN
  171. JOBRET = JOBRET + 2
  172. READ(IUNIT,1020) (SOLN(I),I=1,N)
  173. ELSE
  174. DO 30 I = 1, N
  175. SOLN(I) = 0
  176. 30 CONTINUE
  177. ENDIF
  178. ENDIF
  179. C
  180. JOB = JOBRET
  181. RETURN
  182. 1000 FORMAT(5I10)
  183. 1010 FORMAT(1X,I5,1X,I5,1X,E16.7)
  184. 1020 FORMAT(1X,E16.7)
  185. C------------- LAST LINE OF STIN FOLLOWS ----------------------------
  186. END