1
c=======================================================================
2
c=== RBio/RBcread ======================================================
3
c=======================================================================
5
c RBio: a MATLAB toolbox for reading and writing sparse matrices in
6
c Rutherford/Boeing format.
7
c Copyright (c) 2006, Timothy A. Davis, Univ. Florida. Version 1.0.
10
c-----------------------------------------------------------------------
11
c RB*read: read a Rutherford/Boeing matrix
12
c-----------------------------------------------------------------------
15
$ (nrow, ncol, nnz, ptrfmt, indfmt, valfmt,
16
$ mkind, skind, Ap, Ai, Ax, nzeros, w, cp, info, nw, nnz1)
18
$ nrow, ncol, nnz, mkind, skind, p, j, i, alen, llen, k,
19
$ ilast, nzeros, info, nw, nnz1
21
$ Ap (ncol+1), Ai (nnz1), w (nw), cp (ncol+1)
22
complex*16 Ax (nnz1), x
23
character ptrfmt*16, indfmt*16, valfmt*20
25
c ----------------------------------------------------------------
26
c read the column pointers and row indices
27
c ----------------------------------------------------------------
29
call RBpattern (ptrfmt, indfmt, nrow, ncol, nnz, skind,
30
$ Ap, Ai, w, cp, info, nw)
32
c error: pattern is invalid
36
c ----------------------------------------------------------------
38
c ----------------------------------------------------------------
41
read (7, valfmt, err = 94, end = 94) (Ax (p), p = 1, nnz)
43
c ----------------------------------------------------------------
44
c construct upper triangular part for symmetric matrices
45
c ----------------------------------------------------------------
47
c If skind is zero, then the upper part is not constructed. This
48
c allows the caller to skip this part, and create the upper part
49
c of a symmetric (S,H,Z) matrix. Just pass skind = 0.
51
if (skind .gt. 0) then
53
c ------------------------------------------------------------
54
c shift the matrix by adding gaps to the top of each column
55
c ------------------------------------------------------------
59
c number of entries in lower tri. part (incl. diagonal)
60
llen = Ap (j+1) - Ap (j)
62
c number of entries in entire column
63
alen = cp (j+1) - cp (j)
65
c move the column from Ai (Ap(j) ... Ap(j+1)-1)
66
c down to Ai (cp(j+1)-llen ... cp(j+1)-1), leaving a gap
67
c at Ai (Ap(j) ... cp(j+1)-llen)
70
Ai (cp (j+1) - k) = Ai (Ap (j+1) - k)
71
Ax (cp (j+1) - k) = Ax (Ap (j+1) - k)
75
c ------------------------------------------------------------
76
c populate the upper triangular part
77
c ------------------------------------------------------------
79
c create temporary column pointers to point to the gaps
86
c scan the entries in the lower tri. part, in
87
c Ai (cp(j+1)-llen ... cp(j+1)-1)
88
llen = Ap (j+1) - Ap (j)
91
c get the A(i,j) entry in the lower triangular part
95
c add A(j,i) as the next entry in column i (excl diag)
101
if (skind .eq. 1) then
104
elseif (skind .eq. 2) then
117
c finalize the column pointers
124
c ----------------------------------------------------------------
125
c count the number of explicit zeros
126
c ----------------------------------------------------------------
131
do 80 p = Ap (j), Ap (j+1)-1
132
if (Ax (p) .eq. 0) then
137
cp (ncol+1) = nzeros + 1
139
c ----------------------------------------------------------------
141
c ----------------------------------------------------------------
146
c ----------------------------------------------------------------
148
c ----------------------------------------------------------------
155
c-----------------------------------------------------------------------
156
c RB*zeros: extract explicit zero entries
157
c-----------------------------------------------------------------------
159
c nrow-by-ncol: size of A and Z
160
c cp: column pointers of Z on input
161
c Ap, Ai, Ax: matrix with zeros on input, pruned on output
162
c Zp, Zi, Zx: empty matrix on input, pattern of zeros on output
164
c-----------------------------------------------------------------------
167
$ (nrow, ncol, cp, Ap, Ai, Ax, Zp, Zi, Zx)
169
$ nrow, ncol, Ap (ncol+1), Ai (*), Zp (ncol+1), Zi (*),
170
$ cp (*), i, j, p, pa, pz, p1
172
double precision Zx (*)
174
c ----------------------------------------------------------------
175
c copy the column pointers if Z is being constructed
176
c ----------------------------------------------------------------
182
c ----------------------------------------------------------------
184
c ----------------------------------------------------------------
189
c save the new start of column j of A
193
c split column j of A
194
do 20 p = p1, Ap (j+1)-1
216
c-----------------------------------------------------------------------
217
c RB*prune: discard explicit zero entries
218
c-----------------------------------------------------------------------
220
c nrow-by-ncol: size of A
221
c Ap, Ai, Ax: matrix with zeros on input, pruned on output
223
c-----------------------------------------------------------------------
226
$ (nrow, ncol, Ap, Ai, Ax)
228
$ nrow, ncol, Ap (ncol+1), Ai (*), i, j, p, pa, pz, p1
231
c ----------------------------------------------------------------
233
c ----------------------------------------------------------------
237
c save the new start of column j of A
240
c prune column j of A
241
do 10 p = p1, Ap (j+1)-1