2
c convert csc matrix a to csr matrix b
3
c convert csr matrix a to csc matrix b
6
c all depends on how you interpret the results
8
subroutine <_c>transp(m,n,a,rowa,ptra,nnzamax,b,colb,ptrb)
9
<_t> a(0:nnzamax-1), b(0:nnzamax-1)
10
integer rowa(0:nnzamax-1), colb(0:nnzamax-1)
11
integer ptra(0:n), ptrb(0:m)
12
integer j, bnum, cola, ia, ra
18
do ia = ptra(cola), ptra(cola+1)-1
31
end subroutine <_c>transp
33
c returns the index into the data array
35
subroutine <_c>cscgetel(a,rowa,ptra,nnzamax,n,row,col,ind,val)
37
<_t> a(0:nnzamax-1), val
38
integer rowa(0:nnzamax-1), ptra(0:n)
39
integer nnzamax, row, col, ind
45
do ia = ptra(col), ptra(col+1)-1
46
if (rowa(ia).eq.row) then
56
end subroutine <_c>cscgetel
59
c set an element into the data array (assumes there is room)
61
subroutine <_c>cscsetel(a,rowa,ptra,nnzamax,n,row,col,val)
63
<_t> a(0:nnzamax-1), val
64
integer rowa(0:nnzamax-1), ptra(0:n)
65
integer nnza, n, row, col, nnzamax
71
do ia = newia, ptra(col+1)-1
74
c just replace and be done
77
else if (ra.gt.row) then
83
c we are past where it should be stored
84
c (assumes sorted) so make room for this new element
85
c here so that it will run if this is the first entry in the
89
do iia = nnza, ia+1, -1
91
rowa(iia) = rowa(iia-1)
96
ptra(iia) = ptra(iia)+1
104
end subroutine <_c>cscsetel
106
c assumes sorted by column and then row
108
subroutine <_c>cootocsc(n,vals,row,col,nnz,a,rowa,ptra,nnzamax,
111
<_t> vals(0:nnz-1), a(0:nnzamax-1)
112
integer rowa(0:nnzamax-1), ptra(0:n)
113
integer row(0:nnz-1), col(0:nnz-1)
114
integer n, nnzamax, nnz, ierr
119
if (nnz.gt.nnzamax) goto 999
135
ptra(j+1) = ptra(j+1) + 1
140
c successful completion (fix the ptr array)
143
cumsum = cumsum + ptra(k)
153
end subroutine <_c>cootocsc
155
subroutine <_c>csctocoo(n, vals, row, col, a, rowa, ptra, nnzamax)
156
<_t> vals(0:nnzamax-1), a(0:nnzamax-1)
157
integer rowa(0:nnzamax-1), ptra(0:n)
158
integer row(0:nnzamax-1), col(0:nnzamax-1)
165
do i = ptra(k), ptra(k+1)-1
174
end subroutine <_c>csctocoo
176
c intended for re-entry in case a is too small
178
subroutine <_c>fulltocsc(m,n,fulla,a,rowa,ptra,nnzamax,
181
<_t> fulla(0:m-1,0:n-1), a(0:nnzamax-1)
182
integer rowa(0:nnzamax-1), ptra(0:n)
183
integer m, n, nnzamax, irow, jcol, ierr
186
integer nnza, i, j, k, cumsum
194
if (nnza.ge.nnzamax) goto 999
197
ptra(j+1) = ptra(j+1) + 1
203
c successful completion (fix the ptr array)
206
cumsum = cumsum + ptra(k)
216
end subroutine <_c>fulltocsc
219
subroutine <_c>csctofull(m, n, fulla, a, rowa, ptra, nnzamax)
221
<_t> fulla(0:m-1, 0:n-1), a(0:nnzamax-1)
222
integer rowa(0:nnzamax-1), ptra(0:n)
223
integer m, n, nnzamax
235
do ia = ptra(k), ptra(k+1)-1
236
fulla(rowa(ia),k) = a(ia)
241
end subroutine <_c>csctofull
244
c extract a sub-matrix from a sparse matrix
245
c c = a(ibeg:iend, jbeg:jend) (inclusive of end-points)
247
c intended for re-entry if nnzcmax is not big enough
248
c irow and jcol should initially be 0 and 0
250
subroutine <_c>cscextract(n,a,rowa,ptra,nnzamax,ibeg,iend,jbeg,
251
$ jend, c, rowc, ptrc, nnzcmax, irow, jcol, ierr)
253
<_t> a(0:nnzamax-1), c(0:nnzcmax-1)
254
integer rowa(0:nnzamax-1), rowc(0:nnzamax-1)
255
integer ptra(0:n), ptrc(0:jend-jbeg+1)
256
integer ibeg, iend, jbeg, jend
257
integer nnzamax, nnzcmax, irow, jcol, ierr
259
integer nnza, nc, j, iabeg, ia, k, cumsum
266
if (jcol .lt. jbeg) jcol = jbeg
270
c look through row indices in this column, copy all those that are
272
iabeg = max(irow,ptra(j))
273
do ia = iabeg, ptra(j+1)-1
275
if ((ra.le.iend).and.(ra.ge.ibeg)) then
276
if (nnzc.ge.nnzcmax) goto 999
279
ptrc(jc+1) = ptrc(jc+1) + 1
285
c successful completion (fix the ptr array)
288
cumsum = cumsum + ptrc(k)
301
end subroutine <_c>cscextract
305
subroutine <_c>diatocsc(m,n,diags,numdia,diasize,offsets,
306
$ a,rowa,ptra,nzmax, ierr)
308
integer n, numdia, diasize, nzmax, ierr
309
<_t> diags(0:numdia-1, 0:diasize-1), a(0:nzmax-1)
311
integer offsets(0:numdia-1), rowa(0:nzmax-1)
314
integer col, nnza, jj, row, idiag, ia
318
c write (*,*) "SDSD", m, n, numdia, diasize, nzmax
320
c Loop through the offsets
322
row = col - offsets(jj)
323
if ((row.ge.0).and.(row.lt.m)) then
324
idiag = min(row, col)
325
val = diags(jj, idiag)
327
if (nnza.ge.nzmax) goto 999
328
c find place to insert this row (inserted in sorted order)
330
10 if ((ia.lt.ptra(col+1)).and.(rowa(ia).lt.row)) then
334
do iia = nnza, ia+1, -1
336
rowa(iia) = rowa(iia-1)
354
end subroutine <_c>diatocsc