Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/umfpack/demo/readhb_nozeros.f
3196 views
1
c=======================================================================
2
c== readhb_nozeros =====================================================
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_nozeros:
12
c read a sparse matrix in the Harwell/Boeing format and
13
c output a matrix in triplet format.
14
c Identical to readhb, except that this version removes explicit
15
c zero entries from the matrix.
16
c
17
c usage (for example):
18
c
19
c in a Unix shell:
20
c readhb_nozeros < HB/arc130.rua > tmp/A
21
c
22
c Then, in MATLAB, you can do the following:
23
c >> load tmp/A
24
c >> A = spconvert (A) ;
25
c >> spy (A)
26
27
integer nzmax, nmax
28
parameter (nzmax = 10000000, nmax = 250000)
29
integer Ptr (nmax), Index (nzmax), n, nz, totcrd, ptrcrd,
30
$ indcrd, valcrd, rhscrd, ncol, nrow, nrhs, row, col, p
31
character title*72, key*30, type*3, ptrfmt*16,
32
$ indfmt*16, valfmt*20, rhsfmt*20
33
logical sym
34
double precision Value (nzmax), skew
35
character rhstyp*3
36
integer nzrhs, nel
37
38
integer ne, nnz
39
40
c-----------------------------------------------------------------------
41
42
c read header information from Harwell/Boeing matrix
43
44
read (5, 10, err = 998)
45
$ title, key,
46
$ totcrd, ptrcrd, indcrd, valcrd, rhscrd,
47
$ type, nrow, ncol, nz, nel,
48
$ ptrfmt, indfmt, valfmt, rhsfmt
49
if (rhscrd .gt. 0) then
50
c new Harwell/Boeing format:
51
read (5, 20, err = 998) rhstyp,nrhs,nzrhs
52
endif
53
10 format (a72, a8 / 5i14 / a3, 11x, 4i14 / 2a16, 2a20)
54
20 format (a3, 11x, 2i14)
55
56
skew = 0.0
57
if (type (2:2) .eq. 'Z' .or. type (2:2) .eq. 'z') skew = -1.0
58
if (type (2:2) .eq. 'S' .or. type (2:2) .eq. 's') skew = 1.0
59
sym = skew .ne. 0.0
60
61
write (0, 31) key
62
31 format ('Matrix key: ', a8)
63
64
n = max (nrow, ncol)
65
66
if (n .ge. nmax .or. nz .gt. nzmax) then
67
write (0, *) 'Matrix too big!'
68
write (0, *) '(recompile readhb_nozeros.f with larger',
69
$ ' nzmax, nmax)'
70
stop
71
endif
72
73
read (5, ptrfmt, err = 998) (Ptr (p), p = 1, ncol+1)
74
read (5, indfmt, err = 998) (Index (p), p = 1, nz)
75
76
do 55 col = ncol+2, n+1
77
Ptr (col) = Ptr (ncol+1)
78
55 continue
79
80
c read the values
81
if (valcrd .gt. 0) then
82
read (5, valfmt, err = 998) (Value (p), p = 1, nz)
83
else
84
do 50 p = 1, nz
85
Value (p) = 1
86
50 continue
87
endif
88
89
c create the triplet form of the input matrix
90
91
ne = 0
92
nnz = 0
93
do 100 col = 1, n
94
do 90 p = Ptr (col), Ptr (col+1) - 1
95
row = Index (p)
96
97
c remove zeros, to compare fairly with LU in MATLAB
98
c (MATLAB always removes explicit zeros)
99
ne = ne + 1
100
if (Value (p) .ne. 0) then
101
nnz = nnz + 1
102
write (6, 200) row, col, Value (p)
103
endif
104
105
if (sym .and. row .ne. col) then
106
ne = ne + 1
107
if (Value (p) .ne. 0) then
108
nnz = nnz + 1
109
write (6, 200) col, row, skew * Value (p)
110
endif
111
endif
112
113
90 continue
114
100 continue
115
200 format (2i7, e30.18e3)
116
117
c write (0,*) 'Number of entries: ',ne,' True nonzeros: ', nnz
118
stop
119
120
998 write (0,*) 'Read error: Harwell/Boeing matrix'
121
stop
122
end
123
124