comparison liboctave/UMFPACK/UMFPACK/Demo/readhb.f @ 5164:57077d0ddc8e

[project @ 2005-02-25 19:55:24 by jwe]
author jwe
date Fri, 25 Feb 2005 19:55:28 +0000
parents
children
comparison
equal deleted inserted replaced
5163:9f3299378193 5164:57077d0ddc8e
1 c=======================================================================
2 c== readhb =============================================================
3 c=======================================================================
4
5 c-----------------------------------------------------------------------
6 c UMFPACK Version 4.4, Copyright (c) 2005 by Timothy A. Davis. CISE
7 c Dept, Univ. of Florida. All Rights Reserved. See ../Doc/License for
8 c License. web: http://www.cise.ufl.edu/research/sparse/umfpack
9 c-----------------------------------------------------------------------
10
11 c readhb:
12 c read a sparse matrix in the Harwell/Boeing format and
13 c output a matrix in triplet format.
14 c
15 c usage (for example):
16 c
17 c in a Unix shell:
18 c readhb < HB/arc130.rua > tmp/A
19 c
20 c Then, in MATLAB, you can do the following:
21 c >> load tmp/A
22 c >> A = spconvert (A) ;
23 c >> spy (A)
24
25 integer nzmax, nmax
26 parameter (nzmax = 10000000, nmax = 250000)
27 integer Ptr (nmax), Index (nzmax), n, nz, totcrd, ptrcrd,
28 $ indcrd, valcrd, rhscrd, ncol, nrow, nrhs, row, col, p
29 character title*72, key*30, type*3, ptrfmt*16,
30 $ indfmt*16, valfmt*20, rhsfmt*20
31 logical sym
32 double precision Value (nzmax), skew
33 character rhstyp*3
34 integer nzrhs, nel
35
36 integer ne, nnz
37
38 c-----------------------------------------------------------------------
39
40 c read header information from Harwell/Boeing matrix
41
42 read (5, 10, err = 998)
43 $ title, key,
44 $ totcrd, ptrcrd, indcrd, valcrd, rhscrd,
45 $ type, nrow, ncol, nz, nel,
46 $ ptrfmt, indfmt, valfmt, rhsfmt
47 if (rhscrd .gt. 0) then
48 c new Harwell/Boeing format:
49 read (5, 20, err = 998) rhstyp,nrhs,nzrhs
50 endif
51 10 format (a72, a8 / 5i14 / a3, 11x, 4i14 / 2a16, 2a20)
52 20 format (a3, 11x, 2i14)
53
54 skew = 0.0
55 if (type (2:2) .eq. 'Z' .or. type (2:2) .eq. 'z') skew = -1.0
56 if (type (2:2) .eq. 'S' .or. type (2:2) .eq. 's') skew = 1.0
57 sym = skew .ne. 0.0
58
59 write (0, 31) key
60 31 format ('Matrix key: ', a8)
61
62 n = max (nrow, ncol)
63
64 if (n .ge. nmax .or. nz .gt. nzmax) then
65 write (0, *) 'Matrix too big!'
66 write (0, *) '(recompile readhb.f with larger nzmax, nmax)'
67 stop
68 endif
69
70 read (5, ptrfmt, err = 998) (Ptr (p), p = 1, ncol+1)
71 read (5, indfmt, err = 998) (Index (p), p = 1, nz)
72
73 do 55 col = ncol+2, n+1
74 Ptr (col) = Ptr (ncol+1)
75 55 continue
76
77 c read the values
78 if (valcrd .gt. 0) then
79 read (5, valfmt, err = 998) (Value (p), p = 1, nz)
80 else
81 do 50 p = 1, nz
82 Value (p) = 1
83 50 continue
84 endif
85
86 c create the triplet form of the input matrix
87
88 ne = 0
89 nnz = 0
90 do 100 col = 1, n
91 do 90 p = Ptr (col), Ptr (col+1) - 1
92 row = Index (p)
93
94 ne = ne + 1
95 nnz = nnz + 1
96 write (6, 200) row, col, Value (p)
97
98 if (sym .and. row .ne. col) then
99 ne = ne + 1
100 if (Value (p) .ne. 0) then
101 nnz = nnz + 1
102 write (6, 200) col, row, skew * Value (p)
103 endif
104 endif
105
106 90 continue
107 100 continue
108 200 format (2i7, e30.18e3)
109
110 c write (0,*) 'Number of entries: ',ne,' True nonzeros: ', nnz
111 stop
112
113 998 write (0,*) 'Read error: Harwell/Boeing matrix'
114 stop
115 end