Fix mmio_impl

maint-3.9.0
sfilippone 21 hours ago
parent cddb5bd40c
commit fd2883375c

@ -36,12 +36,13 @@ subroutine mm_cvet_read(b, info, iunit, filename)
integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile
real(psb_spk_) :: bre, bim
character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& character :: mmheader*15, fmt*15, object*10, type*10, sym*15,&
& line*1024 & line*1024
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -52,6 +53,7 @@ subroutine mm_cvet_read(b, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -76,15 +78,15 @@ subroutine mm_cvet_read(b, info, iunit, filename)
read(line,fmt=*)nrow,ncol read(line,fmt=*)nrow,ncol
if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
allocate(b(nrow),stat = ircode) allocate(b(nrow),stat = ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
do i=1, nrow do i=1,nrow
read(infile,fmt=*,end=902) bre,bim read(infile,fmt=*,end=902) b(i)
b(i) = cmplx(bre,bim,kind=psb_spk_)
end do end do
end if ! read right hand sides end if ! read right hand sides
if (infile /= 5) close(infile) if (opened) close(infile)
return return
! open failed ! open failed
@ -109,12 +111,13 @@ subroutine mm_cvet2_read(b, info, iunit, filename)
integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile
real(psb_spk_) :: bre, bim
character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& character :: mmheader*15, fmt*15, object*10, type*10, sym*15,&
& line*1024 & line*1024
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -125,6 +128,7 @@ subroutine mm_cvet2_read(b, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -152,15 +156,10 @@ subroutine mm_cvet2_read(b, info, iunit, filename)
if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
allocate(b(nrow,ncol),stat = ircode) allocate(b(nrow,ncol),stat = ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
do j=1, ncol read(infile,fmt=*,end=902) ((b(i,j), i=1,nrow),j=1,ncol)
do i=1, nrow
read(infile,fmt=*,end=902) bre,bim
b(i,j) = cmplx(bre,bim,kind=psb_spk_)
end do
end do
end if ! read right hand sides end if ! read right hand sides
if (infile /= 5) close(infile) if (opened) close(infile)
return return
! open failed ! open failed
@ -189,8 +188,10 @@ subroutine mm_cvet2_write(b, header, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile
character(len=80) :: frmtv character(len=80) :: frmtv
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
outfile=6 outfile=6
@ -201,6 +202,7 @@ subroutine mm_cvet2_write(b, header, info, iunit, filename)
outfile=99 outfile=99
endif endif
open(outfile,file=filename, err=901, action='WRITE') open(outfile,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -209,17 +211,19 @@ subroutine mm_cvet2_write(b, header, info, iunit, filename)
outfile=6 outfile=6
endif endif
endif endif
write(outfile,'(a)') '%%MatrixMarket matrix array complex general' write(outfile,'(a)') '%%MatrixMarket matrix array real general'
write(outfile,'(a)') '% '//trim(header) write(outfile,'(a)') '% '//trim(header)
write(outfile,'(a)') '% ' write(outfile,'(a)') '% '
nrow = size(b,1) nrow = size(b,1)
ncol = size(b,2) ncol = size(b,2)
write(outfile,*) nrow,ncol write(outfile,*) nrow, ncol
write(frmtv,'(a,i0,a)') '(',ncol,'(es26.18,1x))'
write(outfile,fmt='(2(es26.18,1x))') ((b(i,j), i=1,nrow),j=1,ncol) write(outfile,fmt=frmtv) ((b(i,j), i=1,nrow),j=1,ncol)
if (outfile /= 6) close(outfile) if (opened) close(outfile)
return return
! open failed ! open failed
@ -241,8 +245,10 @@ subroutine mm_cvet1_write(b, header, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile
character(len=80) :: frmtv character(len=80) :: frmtv
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
outfile=6 outfile=6
@ -253,6 +259,7 @@ subroutine mm_cvet1_write(b, header, info, iunit, filename)
outfile=99 outfile=99
endif endif
open(outfile,file=filename, err=901, action='WRITE') open(outfile,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -262,20 +269,20 @@ subroutine mm_cvet1_write(b, header, info, iunit, filename)
endif endif
endif endif
write(outfile,'(a)') '%%MatrixMarket matrix array complex general' write(outfile,'(a)') '%%MatrixMarket matrix array real general'
write(outfile,'(a)') '% '//trim(header) write(outfile,'(a)') '% '//trim(header)
write(outfile,'(a)') '% ' write(outfile,'(a)') '% '
nrow = size(b,1) nrow = size(b,1)
ncol = 1 ncol = 1
write(outfile,*) nrow,ncol write(outfile,*) nrow,ncol
write(frmtv,'(a,i0,a)') '(',2*ncol,'(es26.18,1x))' write(frmtv,'(a,i0,a)') '(',ncol,'(es26.18,1x))'
do i=1,size(b,1) do i=1,size(b,1)
write(outfile,frmtv) b(i) write(outfile,frmtv) b(i)
end do end do
if (outfile /= 6) close(outfile) if (opened) close(outfile)
return return
! open failed ! open failed
@ -298,7 +305,7 @@ subroutine mm_cvect_read(b, info, iunit, filename)
complex(psb_spk_), allocatable :: bv(:) complex(psb_spk_), allocatable :: bv(:)
call mm_array_read(bv, info, iunit, filename) call mm_array_read(bv, info, iunit, filename)
call b%bld(bv) if (info == 0) call b%bld(bv)
end subroutine mm_cvect_read end subroutine mm_cvect_read
@ -331,9 +338,10 @@ subroutine cmm_mat_read(a, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, nnzero integer(psb_ipk_) :: nrow, ncol, nnzero
integer(psb_ipk_) :: ircode, i,nzr,infile integer(psb_ipk_) :: ircode, i,nzr,infile
type(psb_c_coo_sparse_mat), allocatable :: acoo type(psb_c_coo_sparse_mat), allocatable :: acoo
real(psb_spk_) :: are, aim logical :: opened
info = psb_success_
info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -344,6 +352,7 @@ subroutine cmm_mat_read(a, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -369,24 +378,27 @@ subroutine cmm_mat_read(a, info, iunit, filename)
allocate(acoo, stat=ircode) allocate(acoo, stat=ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero) call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_spk_)
end do end do
call acoo%set_nzeros(nnzero) call acoo%set_nzeros(nnzero)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = cone
call acoo%set_nzeros(nnzero)
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'symmetric')) then else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then
! we are generally working with non-symmetric matrices, so ! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read ! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_spk_)
end do end do
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
@ -398,37 +410,34 @@ subroutine cmm_mat_read(a, info, iunit, filename)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'symmetric')) then
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'hermitian')) then
! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
acoo%val(i) = cmplx(are,aim,kind=psb_spk_)
end do end do
acoo%val(:) = cone
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
if (acoo%ia(i) /= acoo%ja(i)) then if (acoo%ia(i) /= acoo%ja(i)) then
nzr = nzr + 1 nzr = nzr + 1
acoo%val(nzr) = conjg(acoo%val(i))
acoo%ia(nzr) = acoo%ja(i) acoo%ia(nzr) = acoo%ja(i)
acoo%ja(nzr) = acoo%ia(i) acoo%ja(nzr) = acoo%ia(i)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo)
else else
write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' write(psb_err_unit,*) 'read_matrix: matrix type not yet supported'
info=904 info=904
end if end if
if (infile /= 5) close(infile)
if (info == 0) then
call acoo%fix(info)
call a%mv_from(acoo)
end if
if (opened) close(infile)
return return
! open failed ! open failed
@ -456,10 +465,11 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename)
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: iout integer(psb_ipk_) :: iout
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
iout=6 iout=6
@ -470,6 +480,7 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename)
iout=99 iout=99
endif endif
open(iout,file=filename, err=901, action='WRITE') open(iout,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -481,7 +492,7 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename)
call a%print(iout,head=mtitle) call a%print(iout,head=mtitle)
if (iout /= 6) close(iout) if (opened) close(iout)
return return
@ -492,6 +503,7 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename)
return return
end subroutine cmm_mat_write end subroutine cmm_mat_write
subroutine lcmm_mat_read(a, info, iunit, filename) subroutine lcmm_mat_read(a, info, iunit, filename)
use psb_base_mod use psb_base_mod
implicit none implicit none
@ -501,12 +513,13 @@ subroutine lcmm_mat_read(a, info, iunit, filename)
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
character :: mmheader*15, fmt*15, object*10, type*10, sym*15 character :: mmheader*15, fmt*15, object*10, type*10, sym*15
character(1024) :: line character(1024) :: line
integer(psb_lpk_) :: nrow, ncol, nnzero, i,nzr integer(psb_lpk_) :: nrow, ncol, nnzero, i, nzr
integer(psb_ipk_) :: ircode,infile integer(psb_ipk_) :: ircode, infile
type(psb_lc_coo_sparse_mat), allocatable :: acoo type(psb_lc_coo_sparse_mat), allocatable :: acoo
real(psb_spk_) :: are, aim logical :: opened
info = psb_success_
info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -517,6 +530,7 @@ subroutine lcmm_mat_read(a, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -542,24 +556,27 @@ subroutine lcmm_mat_read(a, info, iunit, filename)
allocate(acoo, stat=ircode) allocate(acoo, stat=ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero) call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_spk_)
end do end do
call acoo%set_nzeros(nnzero) call acoo%set_nzeros(nnzero)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = cone
call acoo%set_nzeros(nnzero)
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'symmetric')) then else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then
! we are generally working with non-symmetric matrices, so ! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read ! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_spk_)
end do end do
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
@ -571,37 +588,34 @@ subroutine lcmm_mat_read(a, info, iunit, filename)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'symmetric')) then
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'hermitian')) then
! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
acoo%val(i) = cmplx(are,aim,kind=psb_spk_)
end do end do
acoo%val(:) = cone
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
if (acoo%ia(i) /= acoo%ja(i)) then if (acoo%ia(i) /= acoo%ja(i)) then
nzr = nzr + 1 nzr = nzr + 1
acoo%val(nzr) = conjg(acoo%val(i))
acoo%ia(nzr) = acoo%ja(i) acoo%ia(nzr) = acoo%ja(i)
acoo%ja(nzr) = acoo%ia(i) acoo%ja(nzr) = acoo%ia(i)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo)
else else
write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' write(psb_err_unit,*) 'read_matrix: matrix type not yet supported'
info=904 info=904
end if end if
if (infile /= 5) close(infile)
if (info == 0) then
call acoo%fix(info)
call a%mv_from(acoo)
end if
if (opened) close(infile)
return return
! open failed ! open failed
@ -629,10 +643,10 @@ subroutine lcmm_mat_write(a,mtitle,info,iunit,filename)
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: iout integer(psb_ipk_) :: iout
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
iout=6 iout=6
@ -643,6 +657,7 @@ subroutine lcmm_mat_write(a,mtitle,info,iunit,filename)
iout=99 iout=99
endif endif
open(iout,file=filename, err=901, action='WRITE') open(iout,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -654,7 +669,7 @@ subroutine lcmm_mat_write(a,mtitle,info,iunit,filename)
call a%print(iout,head=mtitle) call a%print(iout,head=mtitle)
if (iout /= 6) close(iout) if (opened) close(iout)
return return

@ -211,7 +211,7 @@ subroutine mm_dvet2_write(b, header, info, iunit, filename)
outfile=6 outfile=6
endif endif
endif endif
write(outfile,'(a)') '%%MatrixMarket matrix array real general' write(outfile,'(a)') '%%MatrixMarket matrix array real general'
write(outfile,'(a)') '% '//trim(header) write(outfile,'(a)') '% '//trim(header)
write(outfile,'(a)') '% ' write(outfile,'(a)') '% '
@ -219,7 +219,9 @@ subroutine mm_dvet2_write(b, header, info, iunit, filename)
ncol = size(b,2) ncol = size(b,2)
write(outfile,*) nrow, ncol write(outfile,*) nrow, ncol
write(outfile,fmt='(es26.18,1x)') ((b(i,j), i=1,nrow),j=1,ncol) write(frmtv,'(a,i0,a)') '(',ncol,'(es26.18,1x))'
write(outfile,fmt=frmtv) ((b(i,j), i=1,nrow),j=1,ncol)
if (opened) close(outfile) if (opened) close(outfile)

@ -36,11 +36,13 @@ subroutine mm_svet_read(b, info, iunit, filename)
integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile
character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& character :: mmheader*15, fmt*15, object*10, type*10, sym*15,&
& line*1024 & line*1024
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -51,6 +53,7 @@ subroutine mm_svet_read(b, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -83,8 +86,7 @@ subroutine mm_svet_read(b, info, iunit, filename)
end do end do
end if ! read right hand sides end if ! read right hand sides
if (opened) close(infile)
if (infile /= 5) close(infile)
return return
! open failed ! open failed
@ -109,11 +111,13 @@ subroutine mm_svet2_read(b, info, iunit, filename)
integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile
character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& character :: mmheader*15, fmt*15, object*10, type*10, sym*15,&
& line*1024 & line*1024
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -124,6 +128,7 @@ subroutine mm_svet2_read(b, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -154,8 +159,7 @@ subroutine mm_svet2_read(b, info, iunit, filename)
read(infile,fmt=*,end=902) ((b(i,j), i=1,nrow),j=1,ncol) read(infile,fmt=*,end=902) ((b(i,j), i=1,nrow),j=1,ncol)
end if ! read right hand sides end if ! read right hand sides
if (opened) close(infile)
if (infile /= 5) close(infile)
return return
! open failed ! open failed
@ -184,8 +188,10 @@ subroutine mm_svet2_write(b, header, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile
character(len=80) :: frmtv character(len=80) :: frmtv
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
outfile=6 outfile=6
@ -196,6 +202,7 @@ subroutine mm_svet2_write(b, header, info, iunit, filename)
outfile=99 outfile=99
endif endif
open(outfile,file=filename, err=901, action='WRITE') open(outfile,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -204,17 +211,19 @@ subroutine mm_svet2_write(b, header, info, iunit, filename)
outfile=6 outfile=6
endif endif
endif endif
write(outfile,'(a)') '%%MatrixMarket matrix array real general' write(outfile,'(a)') '%%MatrixMarket matrix array real general'
write(outfile,'(a)') '% '//trim(header) write(outfile,'(a)') '% '//trim(header)
write(outfile,'(a)') '% ' write(outfile,'(a)') '% '
nrow = size(b,1) nrow = size(b,1)
ncol = size(b,2) ncol = size(b,2)
write(outfile,*) nrow,ncol write(outfile,*) nrow, ncol
write(frmtv,'(a,i0,a)') '(',ncol,'(es26.18,1x))'
write(outfile,fmt='(es26.18,1x)') ((b(i,j), i=1,nrow),j=1,ncol) write(outfile,fmt=frmtv) ((b(i,j), i=1,nrow),j=1,ncol)
if (outfile /= 6) close(outfile) if (opened) close(outfile)
return return
! open failed ! open failed
@ -236,8 +245,10 @@ subroutine mm_svet1_write(b, header, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile
character(len=80) :: frmtv character(len=80) :: frmtv
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
outfile=6 outfile=6
@ -248,6 +259,7 @@ subroutine mm_svet1_write(b, header, info, iunit, filename)
outfile=99 outfile=99
endif endif
open(outfile,file=filename, err=901, action='WRITE') open(outfile,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -270,7 +282,7 @@ subroutine mm_svet1_write(b, header, info, iunit, filename)
write(outfile,frmtv) b(i) write(outfile,frmtv) b(i)
end do end do
if (outfile /= 6) close(outfile) if (opened) close(outfile)
return return
! open failed ! open failed
@ -326,9 +338,10 @@ subroutine smm_mat_read(a, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, nnzero integer(psb_ipk_) :: nrow, ncol, nnzero
integer(psb_ipk_) :: ircode, i,nzr,infile integer(psb_ipk_) :: ircode, i,nzr,infile
type(psb_s_coo_sparse_mat), allocatable :: acoo type(psb_s_coo_sparse_mat), allocatable :: acoo
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -339,6 +352,7 @@ subroutine smm_mat_read(a, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -370,9 +384,14 @@ subroutine smm_mat_read(a, info, iunit, filename)
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
end do end do
call acoo%set_nzeros(nnzero) call acoo%set_nzeros(nnzero)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = sone
call acoo%set_nzeros(nnzero)
else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then
! we are generally working with non-symmetric matrices, so ! we are generally working with non-symmetric matrices, so
@ -391,17 +410,34 @@ subroutine smm_mat_read(a, info, iunit, filename)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'symmetric')) then
call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = sone
nzr = nnzero
do i=1,nnzero
if (acoo%ia(i) /= acoo%ja(i)) then
nzr = nzr + 1
acoo%ia(nzr) = acoo%ja(i)
acoo%ja(nzr) = acoo%ia(i)
end if
end do
call acoo%set_nzeros(nzr)
else else
write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' write(psb_err_unit,*) 'read_matrix: matrix type not yet supported'
info=904 info=904
end if end if
if (info == 0) then
call acoo%fix(info)
call a%mv_from(acoo)
end if
if (infile /= 5) close(infile) if (opened) close(infile)
return return
! open failed ! open failed
@ -429,10 +465,11 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename)
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: iout integer(psb_ipk_) :: iout
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
iout=6 iout=6
@ -443,6 +480,7 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename)
iout=99 iout=99
endif endif
open(iout,file=filename, err=901, action='WRITE') open(iout,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -454,7 +492,7 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename)
call a%print(iout,head=mtitle) call a%print(iout,head=mtitle)
if (iout /= 6) close(iout) if (opened) close(iout)
return return
@ -465,6 +503,7 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename)
return return
end subroutine smm_mat_write end subroutine smm_mat_write
subroutine lsmm_mat_read(a, info, iunit, filename) subroutine lsmm_mat_read(a, info, iunit, filename)
use psb_base_mod use psb_base_mod
implicit none implicit none
@ -474,12 +513,13 @@ subroutine lsmm_mat_read(a, info, iunit, filename)
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
character :: mmheader*15, fmt*15, object*10, type*10, sym*15 character :: mmheader*15, fmt*15, object*10, type*10, sym*15
character(1024) :: line character(1024) :: line
integer(psb_lpk_) :: nrow, ncol, nnzero, i,nzr integer(psb_lpk_) :: nrow, ncol, nnzero, i, nzr
integer(psb_ipk_) :: ircode,infile integer(psb_ipk_) :: ircode, infile
type(psb_ls_coo_sparse_mat), allocatable :: acoo type(psb_ls_coo_sparse_mat), allocatable :: acoo
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -490,6 +530,7 @@ subroutine lsmm_mat_read(a, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -521,9 +562,14 @@ subroutine lsmm_mat_read(a, info, iunit, filename)
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
end do end do
call acoo%set_nzeros(nnzero) call acoo%set_nzeros(nnzero)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = sone
call acoo%set_nzeros(nnzero)
else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then
! we are generally working with non-symmetric matrices, so ! we are generally working with non-symmetric matrices, so
@ -542,17 +588,34 @@ subroutine lsmm_mat_read(a, info, iunit, filename)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'symmetric')) then
call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = sone
nzr = nnzero
do i=1,nnzero
if (acoo%ia(i) /= acoo%ja(i)) then
nzr = nzr + 1
acoo%ia(nzr) = acoo%ja(i)
acoo%ja(nzr) = acoo%ia(i)
end if
end do
call acoo%set_nzeros(nzr)
else else
write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' write(psb_err_unit,*) 'read_matrix: matrix type not yet supported'
info=904 info=904
end if end if
if (info == 0) then
call acoo%fix(info)
call a%mv_from(acoo)
end if
if (infile /= 5) close(infile) if (opened) close(infile)
return return
! open failed ! open failed
@ -580,10 +643,10 @@ subroutine lsmm_mat_write(a,mtitle,info,iunit,filename)
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: iout integer(psb_ipk_) :: iout
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
iout=6 iout=6
@ -594,6 +657,7 @@ subroutine lsmm_mat_write(a,mtitle,info,iunit,filename)
iout=99 iout=99
endif endif
open(iout,file=filename, err=901, action='WRITE') open(iout,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -605,7 +669,7 @@ subroutine lsmm_mat_write(a,mtitle,info,iunit,filename)
call a%print(iout,head=mtitle) call a%print(iout,head=mtitle)
if (iout /= 6) close(iout) if (opened) close(iout)
return return

@ -36,12 +36,13 @@ subroutine mm_zvet_read(b, info, iunit, filename)
integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile
real(psb_dpk_) :: bre, bim
character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& character :: mmheader*15, fmt*15, object*10, type*10, sym*15,&
& line*1024 & line*1024
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -52,6 +53,7 @@ subroutine mm_zvet_read(b, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -76,15 +78,15 @@ subroutine mm_zvet_read(b, info, iunit, filename)
read(line,fmt=*)nrow,ncol read(line,fmt=*)nrow,ncol
if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
allocate(b(nrow),stat = ircode) allocate(b(nrow),stat = ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
do i=1, nrow do i=1,nrow
read(infile,fmt=*,end=902) bre,bim read(infile,fmt=*,end=902) b(i)
b(i) = cmplx(bre,bim,kind=psb_dpk_)
end do end do
end if ! read right hand sides end if ! read right hand sides
if (infile /= 5) close(infile) if (opened) close(infile)
return return
! open failed ! open failed
@ -109,12 +111,13 @@ subroutine mm_zvet2_read(b, info, iunit, filename)
integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile
real(psb_dpk_) :: bre, bim
character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& character :: mmheader*15, fmt*15, object*10, type*10, sym*15,&
& line*1024 & line*1024
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -125,6 +128,7 @@ subroutine mm_zvet2_read(b, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -149,18 +153,13 @@ subroutine mm_zvet2_read(b, info, iunit, filename)
read(line,fmt=*)nrow,ncol read(line,fmt=*)nrow,ncol
if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
allocate(b(nrow,ncol),stat = ircode) allocate(b(nrow,ncol),stat = ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
do j=1, ncol read(infile,fmt=*,end=902) ((b(i,j), i=1,nrow),j=1,ncol)
do i=1, nrow
read(infile,fmt=*,end=902) bre,bim
b(i,j) = cmplx(bre,bim,kind=psb_dpk_)
end do
end do
end if ! read right hand sides end if ! read right hand sides
if (infile /= 5) close(infile) if (opened) close(infile)
return return
! open failed ! open failed
@ -189,8 +188,10 @@ subroutine mm_zvet2_write(b, header, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile
character(len=80) :: frmtv character(len=80) :: frmtv
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
outfile=6 outfile=6
@ -201,6 +202,7 @@ subroutine mm_zvet2_write(b, header, info, iunit, filename)
outfile=99 outfile=99
endif endif
open(outfile,file=filename, err=901, action='WRITE') open(outfile,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -209,17 +211,19 @@ subroutine mm_zvet2_write(b, header, info, iunit, filename)
outfile=6 outfile=6
endif endif
endif endif
write(outfile,'(a)') '%%MatrixMarket matrix array complex general' write(outfile,'(a)') '%%MatrixMarket matrix array real general'
write(outfile,'(a)') '% '//trim(header) write(outfile,'(a)') '% '//trim(header)
write(outfile,'(a)') '% ' write(outfile,'(a)') '% '
nrow = size(b,1) nrow = size(b,1)
ncol = size(b,2) ncol = size(b,2)
write(outfile,*) nrow,ncol write(outfile,*) nrow, ncol
write(frmtv,'(a,i0,a)') '(',ncol,'(es26.18,1x))'
write(outfile,fmt='(2(es26.18,1x))') ((b(i,j), i=1,nrow),j=1,ncol) write(outfile,fmt=frmtv) ((b(i,j), i=1,nrow),j=1,ncol)
if (outfile /= 6) close(outfile) if (opened) close(outfile)
return return
! open failed ! open failed
@ -241,8 +245,10 @@ subroutine mm_zvet1_write(b, header, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, outfile
character(len=80) :: frmtv character(len=80) :: frmtv
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
outfile=6 outfile=6
@ -253,6 +259,7 @@ subroutine mm_zvet1_write(b, header, info, iunit, filename)
outfile=99 outfile=99
endif endif
open(outfile,file=filename, err=901, action='WRITE') open(outfile,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -269,13 +276,13 @@ subroutine mm_zvet1_write(b, header, info, iunit, filename)
ncol = 1 ncol = 1
write(outfile,*) nrow,ncol write(outfile,*) nrow,ncol
write(frmtv,'(a,i0,a)') '(',2*ncol,'(es26.18,1x))' write(frmtv,'(a,i0,a)') '(',ncol,'(es26.18,1x))'
do i=1,size(b,1) do i=1,size(b,1)
write(outfile,frmtv) b(i) write(outfile,frmtv) b(i)
end do end do
if (outfile /= 6) close(outfile) if (opened) close(outfile)
return return
! open failed ! open failed
@ -331,9 +338,10 @@ subroutine zmm_mat_read(a, info, iunit, filename)
integer(psb_ipk_) :: nrow, ncol, nnzero integer(psb_ipk_) :: nrow, ncol, nnzero
integer(psb_ipk_) :: ircode, i,nzr,infile integer(psb_ipk_) :: ircode, i,nzr,infile
type(psb_z_coo_sparse_mat), allocatable :: acoo type(psb_z_coo_sparse_mat), allocatable :: acoo
real(psb_dpk_) :: are, aim logical :: opened
info = psb_success_
info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -344,6 +352,7 @@ subroutine zmm_mat_read(a, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -369,24 +378,27 @@ subroutine zmm_mat_read(a, info, iunit, filename)
allocate(acoo, stat=ircode) allocate(acoo, stat=ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero) call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_dpk_)
end do end do
call acoo%set_nzeros(nnzero) call acoo%set_nzeros(nnzero)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = zone
call acoo%set_nzeros(nnzero)
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'symmetric')) then else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then
! we are generally working with non-symmetric matrices, so ! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read ! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_dpk_)
end do end do
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
@ -398,37 +410,34 @@ subroutine zmm_mat_read(a, info, iunit, filename)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo)
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'hermitian')) then else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'symmetric')) then
! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
acoo%val(i) = cmplx(are,aim,kind=psb_dpk_)
end do end do
acoo%val(:) = zone
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
if (acoo%ia(i) /= acoo%ja(i)) then if (acoo%ia(i) /= acoo%ja(i)) then
nzr = nzr + 1 nzr = nzr + 1
acoo%val(nzr) = conjg(acoo%val(i))
acoo%ia(nzr) = acoo%ja(i) acoo%ia(nzr) = acoo%ja(i)
acoo%ja(nzr) = acoo%ia(i) acoo%ja(nzr) = acoo%ia(i)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo)
else else
write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' write(psb_err_unit,*) 'read_matrix: matrix type not yet supported'
info=904 info=904
end if end if
if (infile /= 5) close(infile)
if (info == 0) then
call acoo%fix(info)
call a%mv_from(acoo)
end if
if (opened) close(infile)
return return
! open failed ! open failed
@ -446,6 +455,7 @@ subroutine zmm_mat_read(a, info, iunit, filename)
return return
end subroutine zmm_mat_read end subroutine zmm_mat_read
subroutine zmm_mat_write(a,mtitle,info,iunit,filename) subroutine zmm_mat_write(a,mtitle,info,iunit,filename)
use psb_base_mod use psb_base_mod
implicit none implicit none
@ -455,10 +465,11 @@ subroutine zmm_mat_write(a,mtitle,info,iunit,filename)
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: iout integer(psb_ipk_) :: iout
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
iout=6 iout=6
@ -469,6 +480,7 @@ subroutine zmm_mat_write(a,mtitle,info,iunit,filename)
iout=99 iout=99
endif endif
open(iout,file=filename, err=901, action='WRITE') open(iout,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -480,7 +492,7 @@ subroutine zmm_mat_write(a,mtitle,info,iunit,filename)
call a%print(iout,head=mtitle) call a%print(iout,head=mtitle)
if (iout /= 6) close(iout) if (opened) close(iout)
return return
@ -501,12 +513,13 @@ subroutine lzmm_mat_read(a, info, iunit, filename)
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
character :: mmheader*15, fmt*15, object*10, type*10, sym*15 character :: mmheader*15, fmt*15, object*10, type*10, sym*15
character(1024) :: line character(1024) :: line
integer(psb_lpk_) :: nrow, ncol, nnzero, i,nzr integer(psb_lpk_) :: nrow, ncol, nnzero, i, nzr
integer(psb_ipk_) :: ircode,infile integer(psb_ipk_) :: ircode, infile
type(psb_lz_coo_sparse_mat), allocatable :: acoo type(psb_lz_coo_sparse_mat), allocatable :: acoo
real(psb_dpk_) :: are, aim logical :: opened
info = psb_success_
info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
infile=5 infile=5
@ -517,6 +530,7 @@ subroutine lzmm_mat_read(a, info, iunit, filename)
infile=99 infile=99
endif endif
open(infile,file=filename, status='OLD', err=901, action='READ') open(infile,file=filename, status='OLD', err=901, action='READ')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -542,24 +556,27 @@ subroutine lzmm_mat_read(a, info, iunit, filename)
allocate(acoo, stat=ircode) allocate(acoo, stat=ircode)
if (ircode /= 0) goto 993 if (ircode /= 0) goto 993
if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'general')) then if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero) call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_dpk_)
end do end do
call acoo%set_nzeros(nnzero) call acoo%set_nzeros(nnzero)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'general')) then
call acoo%allocate(nrow,ncol,nnzero)
do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
end do
acoo%val(:) = zone
call acoo%set_nzeros(nnzero)
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'symmetric')) then else if ((psb_tolower(type) == 'real').and.(psb_tolower(sym) == 'symmetric')) then
! we are generally working with non-symmetric matrices, so ! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read ! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i)
acoo%val(i) = cmplx(are,aim,kind=psb_dpk_)
end do end do
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
@ -571,37 +588,34 @@ subroutine lzmm_mat_read(a, info, iunit, filename)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo) else if ((psb_tolower(type) == 'pattern').and.(psb_tolower(sym) == 'symmetric')) then
else if ((psb_tolower(type) == 'complex').and.(psb_tolower(sym) == 'hermitian')) then
! we are generally working with non-symmetric matrices, so
! we de-symmetrize what we are about to read
call acoo%allocate(nrow,ncol,2*nnzero) call acoo%allocate(nrow,ncol,2*nnzero)
do i=1,nnzero do i=1,nnzero
read(infile,fmt=*,end=902) acoo%ia(i),acoo%ja(i),are,aim read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i)
acoo%val(i) = cmplx(are,aim,kind=psb_dpk_)
end do end do
acoo%val(:) = zone
nzr = nnzero nzr = nnzero
do i=1,nnzero do i=1,nnzero
if (acoo%ia(i) /= acoo%ja(i)) then if (acoo%ia(i) /= acoo%ja(i)) then
nzr = nzr + 1 nzr = nzr + 1
acoo%val(nzr) = conjg(acoo%val(i))
acoo%ia(nzr) = acoo%ja(i) acoo%ia(nzr) = acoo%ja(i)
acoo%ja(nzr) = acoo%ia(i) acoo%ja(nzr) = acoo%ia(i)
end if end if
end do end do
call acoo%set_nzeros(nzr) call acoo%set_nzeros(nzr)
call acoo%fix(info)
call a%mv_from(acoo)
else else
write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' write(psb_err_unit,*) 'read_matrix: matrix type not yet supported'
info=904 info=904
end if end if
if (infile /= 5) close(infile)
if (info == 0) then
call acoo%fix(info)
call a%mv_from(acoo)
end if
if (opened) close(infile)
return return
! open failed ! open failed
@ -619,6 +633,7 @@ subroutine lzmm_mat_read(a, info, iunit, filename)
return return
end subroutine lzmm_mat_read end subroutine lzmm_mat_read
subroutine lzmm_mat_write(a,mtitle,info,iunit,filename) subroutine lzmm_mat_write(a,mtitle,info,iunit,filename)
use psb_base_mod use psb_base_mod
implicit none implicit none
@ -628,10 +643,10 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename)
integer(psb_ipk_), optional, intent(in) :: iunit integer(psb_ipk_), optional, intent(in) :: iunit
character(len=*), optional, intent(in) :: filename character(len=*), optional, intent(in) :: filename
integer(psb_ipk_) :: iout integer(psb_ipk_) :: iout
logical :: opened
info = psb_success_ info = psb_success_
opened = .false.
if (present(filename)) then if (present(filename)) then
if (filename == '-') then if (filename == '-') then
iout=6 iout=6
@ -642,6 +657,7 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename)
iout=99 iout=99
endif endif
open(iout,file=filename, err=901, action='WRITE') open(iout,file=filename, err=901, action='WRITE')
opened = .true.
endif endif
else else
if (present(iunit)) then if (present(iunit)) then
@ -653,7 +669,7 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename)
call a%print(iout,head=mtitle) call a%print(iout,head=mtitle)
if (iout /= 6) close(iout) if (opened) close(iout)
return return
@ -663,4 +679,3 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename)
write(psb_err_unit,*) 'Error while opening ',filename write(psb_err_unit,*) 'Error while opening ',filename
return return
end subroutine lzmm_mat_write end subroutine lzmm_mat_write

Loading…
Cancel
Save