diff --git a/util/psb_c_mmio_impl.f90 b/util/psb_c_mmio_impl.f90 index 68690d06c..ad653462a 100644 --- a/util/psb_c_mmio_impl.f90 +++ b/util/psb_c_mmio_impl.f90 @@ -36,12 +36,13 @@ subroutine mm_cvet_read(b, info, iunit, filename) integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename - integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile - real(psb_spk_) :: bre, bim + integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& & line*1024 + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -52,6 +53,7 @@ subroutine mm_cvet_read(b, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -76,15 +78,15 @@ subroutine mm_cvet_read(b, info, iunit, filename) 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) if (ircode /= 0) goto 993 - do i=1, nrow - read(infile,fmt=*,end=902) bre,bim - b(i) = cmplx(bre,bim,kind=psb_spk_) + do i=1,nrow + read(infile,fmt=*,end=902) b(i) end do + end if ! read right hand sides - if (infile /= 5) close(infile) + if (opened) close(infile) return ! open failed @@ -109,12 +111,13 @@ subroutine mm_cvet2_read(b, info, iunit, filename) integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename - integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile - real(psb_spk_) :: bre, bim + integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& & line*1024 + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -125,6 +128,7 @@ subroutine mm_cvet2_read(b, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else 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 allocate(b(nrow,ncol),stat = ircode) if (ircode /= 0) goto 993 - do 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 + read(infile,fmt=*,end=902) ((b(i,j), i=1,nrow),j=1,ncol) end if ! read right hand sides - if (infile /= 5) close(infile) + if (opened) close(infile) return ! 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 character(len=80) :: frmtv + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then outfile=6 @@ -201,6 +202,7 @@ subroutine mm_cvet2_write(b, header, info, iunit, filename) outfile=99 endif open(outfile,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -209,17 +211,19 @@ subroutine mm_cvet2_write(b, header, info, iunit, filename) outfile=6 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)') '% ' nrow = size(b,1) 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 ! 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 character(len=80) :: frmtv + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then outfile=6 @@ -253,6 +259,7 @@ subroutine mm_cvet1_write(b, header, info, iunit, filename) outfile=99 endif open(outfile,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -262,20 +269,20 @@ subroutine mm_cvet1_write(b, header, info, iunit, filename) 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)') '% ' nrow = size(b,1) ncol = 1 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) write(outfile,frmtv) b(i) end do - if (outfile /= 6) close(outfile) + if (opened) close(outfile) return ! open failed @@ -298,7 +305,7 @@ subroutine mm_cvect_read(b, info, iunit, filename) complex(psb_spk_), allocatable :: bv(:) call mm_array_read(bv, info, iunit, filename) - call b%bld(bv) + if (info == 0) call b%bld(bv) 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_) :: ircode, i,nzr,infile type(psb_c_coo_sparse_mat), allocatable :: acoo - real(psb_spk_) :: are, aim - info = psb_success_ + logical :: opened + info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -344,6 +352,7 @@ subroutine cmm_mat_read(a, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -369,24 +378,27 @@ subroutine cmm_mat_read(a, info, iunit, filename) allocate(acoo, stat=ircode) 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) do i=1,nnzero - read(infile,fmt=*,end=902) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_spk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do 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 de-symmetrize what we are about to read call acoo%allocate(nrow,ncol,2*nnzero) do i=1,nnzero - read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_spk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do nzr = nnzero do i=1,nnzero @@ -398,37 +410,34 @@ subroutine cmm_mat_read(a, info, iunit, filename) end if end do 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 - ! we are generally working with non-symmetric matrices, so - ! we de-symmetrize what we are about to read + 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),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_spk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i) end do + acoo%val(:) = cone nzr = nnzero do i=1,nnzero if (acoo%ia(i) /= acoo%ja(i)) then nzr = nzr + 1 - acoo%val(nzr) = conjg(acoo%val(i)) acoo%ia(nzr) = acoo%ja(i) acoo%ja(nzr) = acoo%ia(i) end if end do call acoo%set_nzeros(nzr) - call acoo%fix(info) - - call a%mv_from(acoo) else write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' info=904 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 ! open failed @@ -456,10 +465,11 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename) integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename integer(psb_ipk_) :: iout + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then iout=6 @@ -470,6 +480,7 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename) iout=99 endif open(iout,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -481,7 +492,7 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename) call a%print(iout,head=mtitle) - if (iout /= 6) close(iout) + if (opened) close(iout) return @@ -492,6 +503,7 @@ subroutine cmm_mat_write(a,mtitle,info,iunit,filename) return end subroutine cmm_mat_write + subroutine lcmm_mat_read(a, info, iunit, filename) use psb_base_mod implicit none @@ -501,12 +513,13 @@ subroutine lcmm_mat_read(a, info, iunit, filename) character(len=*), optional, intent(in) :: filename character :: mmheader*15, fmt*15, object*10, type*10, sym*15 character(1024) :: line - integer(psb_lpk_) :: nrow, ncol, nnzero, i,nzr - integer(psb_ipk_) :: ircode,infile + integer(psb_lpk_) :: nrow, ncol, nnzero, i, nzr + integer(psb_ipk_) :: ircode, infile type(psb_lc_coo_sparse_mat), allocatable :: acoo - real(psb_spk_) :: are, aim - info = psb_success_ + logical :: opened + info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -517,6 +530,7 @@ subroutine lcmm_mat_read(a, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -542,24 +556,27 @@ subroutine lcmm_mat_read(a, info, iunit, filename) allocate(acoo, stat=ircode) 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) do i=1,nnzero - read(infile,fmt=*,end=902) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_spk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do 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 de-symmetrize what we are about to read call acoo%allocate(nrow,ncol,2*nnzero) do i=1,nnzero - read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_spk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do nzr = nnzero do i=1,nnzero @@ -571,37 +588,34 @@ subroutine lcmm_mat_read(a, info, iunit, filename) end if end do 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 - ! we are generally working with non-symmetric matrices, so - ! we de-symmetrize what we are about to read + 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),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_spk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i) end do + acoo%val(:) = cone nzr = nnzero do i=1,nnzero if (acoo%ia(i) /= acoo%ja(i)) then nzr = nzr + 1 - acoo%val(nzr) = conjg(acoo%val(i)) acoo%ia(nzr) = acoo%ja(i) acoo%ja(nzr) = acoo%ia(i) end if end do call acoo%set_nzeros(nzr) - call acoo%fix(info) - - call a%mv_from(acoo) else write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' info=904 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 ! open failed @@ -629,10 +643,10 @@ subroutine lcmm_mat_write(a,mtitle,info,iunit,filename) integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename integer(psb_ipk_) :: iout - + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then iout=6 @@ -643,6 +657,7 @@ subroutine lcmm_mat_write(a,mtitle,info,iunit,filename) iout=99 endif open(iout,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -654,7 +669,7 @@ subroutine lcmm_mat_write(a,mtitle,info,iunit,filename) call a%print(iout,head=mtitle) - if (iout /= 6) close(iout) + if (opened) close(iout) return diff --git a/util/psb_d_mmio_impl.f90 b/util/psb_d_mmio_impl.f90 index c5423f02d..4fc917a61 100644 --- a/util/psb_d_mmio_impl.f90 +++ b/util/psb_d_mmio_impl.f90 @@ -211,7 +211,7 @@ subroutine mm_dvet2_write(b, header, info, iunit, filename) outfile=6 endif endif - + write(outfile,'(a)') '%%MatrixMarket matrix array real general' write(outfile,'(a)') '% '//trim(header) write(outfile,'(a)') '% ' @@ -219,7 +219,9 @@ subroutine mm_dvet2_write(b, header, info, iunit, filename) ncol = size(b,2) 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) diff --git a/util/psb_s_mmio_impl.f90 b/util/psb_s_mmio_impl.f90 index 94e886849..0ffd9a93d 100644 --- a/util/psb_s_mmio_impl.f90 +++ b/util/psb_s_mmio_impl.f90 @@ -36,11 +36,13 @@ subroutine mm_svet_read(b, info, iunit, filename) integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), optional, intent(in) :: iunit 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,& & line*1024 + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -51,6 +53,7 @@ subroutine mm_svet_read(b, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -83,8 +86,7 @@ subroutine mm_svet_read(b, info, iunit, filename) end do end if ! read right hand sides - - if (infile /= 5) close(infile) + if (opened) close(infile) return ! open failed @@ -109,11 +111,13 @@ subroutine mm_svet2_read(b, info, iunit, filename) integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), optional, intent(in) :: iunit 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,& & line*1024 + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -124,6 +128,7 @@ subroutine mm_svet2_read(b, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else 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) end if ! read right hand sides - - if (infile /= 5) close(infile) + if (opened) close(infile) return ! 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 character(len=80) :: frmtv + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then outfile=6 @@ -196,6 +202,7 @@ subroutine mm_svet2_write(b, header, info, iunit, filename) outfile=99 endif open(outfile,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -204,17 +211,19 @@ subroutine mm_svet2_write(b, header, info, iunit, filename) outfile=6 endif endif - + write(outfile,'(a)') '%%MatrixMarket matrix array real general' write(outfile,'(a)') '% '//trim(header) write(outfile,'(a)') '% ' nrow = size(b,1) 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 ! 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 character(len=80) :: frmtv + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then outfile=6 @@ -248,6 +259,7 @@ subroutine mm_svet1_write(b, header, info, iunit, filename) outfile=99 endif open(outfile,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -270,7 +282,7 @@ subroutine mm_svet1_write(b, header, info, iunit, filename) write(outfile,frmtv) b(i) end do - if (outfile /= 6) close(outfile) + if (opened) close(outfile) return ! open failed @@ -326,9 +338,10 @@ subroutine smm_mat_read(a, info, iunit, filename) integer(psb_ipk_) :: nrow, ncol, nnzero integer(psb_ipk_) :: ircode, i,nzr,infile type(psb_s_coo_sparse_mat), allocatable :: acoo + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -339,6 +352,7 @@ subroutine smm_mat_read(a, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else 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) end do 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 ! we are generally working with non-symmetric matrices, so @@ -391,17 +410,34 @@ subroutine smm_mat_read(a, info, iunit, filename) end if end do 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 write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' info=904 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 ! open failed @@ -429,10 +465,11 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename) integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename integer(psb_ipk_) :: iout + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then iout=6 @@ -443,6 +480,7 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename) iout=99 endif open(iout,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -454,7 +492,7 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename) call a%print(iout,head=mtitle) - if (iout /= 6) close(iout) + if (opened) close(iout) return @@ -465,6 +503,7 @@ subroutine smm_mat_write(a,mtitle,info,iunit,filename) return end subroutine smm_mat_write + subroutine lsmm_mat_read(a, info, iunit, filename) use psb_base_mod implicit none @@ -474,12 +513,13 @@ subroutine lsmm_mat_read(a, info, iunit, filename) character(len=*), optional, intent(in) :: filename character :: mmheader*15, fmt*15, object*10, type*10, sym*15 character(1024) :: line - integer(psb_lpk_) :: nrow, ncol, nnzero, i,nzr - integer(psb_ipk_) :: ircode,infile + integer(psb_lpk_) :: nrow, ncol, nnzero, i, nzr + integer(psb_ipk_) :: ircode, infile type(psb_ls_coo_sparse_mat), allocatable :: acoo + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -490,6 +530,7 @@ subroutine lsmm_mat_read(a, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else 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) end do 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 ! we are generally working with non-symmetric matrices, so @@ -542,17 +588,34 @@ subroutine lsmm_mat_read(a, info, iunit, filename) end if end do 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 write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' info=904 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 ! open failed @@ -580,10 +643,10 @@ subroutine lsmm_mat_write(a,mtitle,info,iunit,filename) integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename integer(psb_ipk_) :: iout - + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then iout=6 @@ -594,6 +657,7 @@ subroutine lsmm_mat_write(a,mtitle,info,iunit,filename) iout=99 endif open(iout,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -605,7 +669,7 @@ subroutine lsmm_mat_write(a,mtitle,info,iunit,filename) call a%print(iout,head=mtitle) - if (iout /= 6) close(iout) + if (opened) close(iout) return diff --git a/util/psb_z_mmio_impl.f90 b/util/psb_z_mmio_impl.f90 index 948de2833..aa66f0edd 100644 --- a/util/psb_z_mmio_impl.f90 +++ b/util/psb_z_mmio_impl.f90 @@ -36,12 +36,13 @@ subroutine mm_zvet_read(b, info, iunit, filename) integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename - integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile - real(psb_dpk_) :: bre, bim + integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& & line*1024 + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -52,6 +53,7 @@ subroutine mm_zvet_read(b, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -76,15 +78,15 @@ subroutine mm_zvet_read(b, info, iunit, filename) 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) if (ircode /= 0) goto 993 - do i=1, nrow - read(infile,fmt=*,end=902) bre,bim - b(i) = cmplx(bre,bim,kind=psb_dpk_) + do i=1,nrow + read(infile,fmt=*,end=902) b(i) end do + end if ! read right hand sides - if (infile /= 5) close(infile) + if (opened) close(infile) return ! open failed @@ -109,12 +111,13 @@ subroutine mm_zvet2_read(b, info, iunit, filename) integer(psb_ipk_), intent(out) :: info integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename - integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j,infile - real(psb_dpk_) :: bre, bim + integer(psb_ipk_) :: nrow, ncol, i,root, np, me, ircode, j, infile character :: mmheader*15, fmt*15, object*10, type*10, sym*15,& & line*1024 + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -125,6 +128,7 @@ subroutine mm_zvet2_read(b, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -149,18 +153,13 @@ subroutine mm_zvet2_read(b, info, iunit, filename) 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) if (ircode /= 0) goto 993 - do 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 + read(infile,fmt=*,end=902) ((b(i,j), i=1,nrow),j=1,ncol) end if ! read right hand sides - if (infile /= 5) close(infile) + if (opened) close(infile) return ! 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 character(len=80) :: frmtv + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then outfile=6 @@ -201,6 +202,7 @@ subroutine mm_zvet2_write(b, header, info, iunit, filename) outfile=99 endif open(outfile,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -209,17 +211,19 @@ subroutine mm_zvet2_write(b, header, info, iunit, filename) outfile=6 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)') '% ' nrow = size(b,1) 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 ! 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 character(len=80) :: frmtv + logical :: opened info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then outfile=6 @@ -253,6 +259,7 @@ subroutine mm_zvet1_write(b, header, info, iunit, filename) outfile=99 endif open(outfile,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -269,13 +276,13 @@ subroutine mm_zvet1_write(b, header, info, iunit, filename) ncol = 1 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) write(outfile,frmtv) b(i) end do - if (outfile /= 6) close(outfile) + if (opened) close(outfile) return ! open failed @@ -331,9 +338,10 @@ subroutine zmm_mat_read(a, info, iunit, filename) integer(psb_ipk_) :: nrow, ncol, nnzero integer(psb_ipk_) :: ircode, i,nzr,infile type(psb_z_coo_sparse_mat), allocatable :: acoo - real(psb_dpk_) :: are, aim - info = psb_success_ + logical :: opened + info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -344,6 +352,7 @@ subroutine zmm_mat_read(a, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -369,24 +378,27 @@ subroutine zmm_mat_read(a, info, iunit, filename) allocate(acoo, stat=ircode) 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) do i=1,nnzero - read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_dpk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do 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 de-symmetrize what we are about to read call acoo%allocate(nrow,ncol,2*nnzero) do i=1,nnzero - read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_dpk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do nzr = nnzero do i=1,nnzero @@ -398,37 +410,34 @@ subroutine zmm_mat_read(a, info, iunit, filename) end if end do 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 - ! we are generally working with non-symmetric matrices, so - ! we de-symmetrize what we are about to read + 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) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_dpk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i) end do + acoo%val(:) = zone nzr = nnzero do i=1,nnzero if (acoo%ia(i) /= acoo%ja(i)) then nzr = nzr + 1 - acoo%val(nzr) = conjg(acoo%val(i)) acoo%ia(nzr) = acoo%ja(i) acoo%ja(nzr) = acoo%ia(i) end if end do call acoo%set_nzeros(nzr) - call acoo%fix(info) - - call a%mv_from(acoo) else write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' info=904 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 ! open failed @@ -446,6 +455,7 @@ subroutine zmm_mat_read(a, info, iunit, filename) return end subroutine zmm_mat_read + subroutine zmm_mat_write(a,mtitle,info,iunit,filename) use psb_base_mod implicit none @@ -455,10 +465,11 @@ subroutine zmm_mat_write(a,mtitle,info,iunit,filename) integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename integer(psb_ipk_) :: iout + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then iout=6 @@ -469,6 +480,7 @@ subroutine zmm_mat_write(a,mtitle,info,iunit,filename) iout=99 endif open(iout,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -480,7 +492,7 @@ subroutine zmm_mat_write(a,mtitle,info,iunit,filename) call a%print(iout,head=mtitle) - if (iout /= 6) close(iout) + if (opened) close(iout) return @@ -501,12 +513,13 @@ subroutine lzmm_mat_read(a, info, iunit, filename) character(len=*), optional, intent(in) :: filename character :: mmheader*15, fmt*15, object*10, type*10, sym*15 character(1024) :: line - integer(psb_lpk_) :: nrow, ncol, nnzero, i,nzr - integer(psb_ipk_) :: ircode,infile + integer(psb_lpk_) :: nrow, ncol, nnzero, i, nzr + integer(psb_ipk_) :: ircode, infile type(psb_lz_coo_sparse_mat), allocatable :: acoo - real(psb_dpk_) :: are, aim - info = psb_success_ + logical :: opened + info = psb_success_ + opened = .false. if (present(filename)) then if (filename == '-') then infile=5 @@ -517,6 +530,7 @@ subroutine lzmm_mat_read(a, info, iunit, filename) infile=99 endif open(infile,file=filename, status='OLD', err=901, action='READ') + opened = .true. endif else if (present(iunit)) then @@ -542,24 +556,27 @@ subroutine lzmm_mat_read(a, info, iunit, filename) allocate(acoo, stat=ircode) 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) do i=1,nnzero - read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_dpk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do 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 de-symmetrize what we are about to read call acoo%allocate(nrow,ncol,2*nnzero) do i=1,nnzero - read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_dpk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i),acoo%val(i) end do nzr = nnzero do i=1,nnzero @@ -571,37 +588,34 @@ subroutine lzmm_mat_read(a, info, iunit, filename) end if end do 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 - ! we are generally working with non-symmetric matrices, so - ! we de-symmetrize what we are about to read + 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) acoo%ia(i),acoo%ja(i),are,aim - acoo%val(i) = cmplx(are,aim,kind=psb_dpk_) + read(infile,fmt=*,end=902,err=905) acoo%ia(i),acoo%ja(i) end do + acoo%val(:) = zone nzr = nnzero do i=1,nnzero if (acoo%ia(i) /= acoo%ja(i)) then nzr = nzr + 1 - acoo%val(nzr) = conjg(acoo%val(i)) acoo%ia(nzr) = acoo%ja(i) acoo%ja(nzr) = acoo%ia(i) end if end do call acoo%set_nzeros(nzr) - call acoo%fix(info) - - call a%mv_from(acoo) else write(psb_err_unit,*) 'read_matrix: matrix type not yet supported' info=904 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 ! open failed @@ -619,6 +633,7 @@ subroutine lzmm_mat_read(a, info, iunit, filename) return end subroutine lzmm_mat_read + subroutine lzmm_mat_write(a,mtitle,info,iunit,filename) use psb_base_mod implicit none @@ -628,10 +643,10 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename) integer(psb_ipk_), optional, intent(in) :: iunit character(len=*), optional, intent(in) :: filename integer(psb_ipk_) :: iout - + logical :: opened info = psb_success_ - + opened = .false. if (present(filename)) then if (filename == '-') then iout=6 @@ -642,6 +657,7 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename) iout=99 endif open(iout,file=filename, err=901, action='WRITE') + opened = .true. endif else if (present(iunit)) then @@ -653,7 +669,7 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename) call a%print(iout,head=mtitle) - if (iout /= 6) close(iout) + if (opened) close(iout) return @@ -663,4 +679,3 @@ subroutine lzmm_mat_write(a,mtitle,info,iunit,filename) write(psb_err_unit,*) 'Error while opening ',filename return end subroutine lzmm_mat_write -