      subroutine conv
      use module
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
      character(3) cc
      real(8),save :: e0
      yw=.false.
      if(iter==1) then
!         open(99,file=trim(prefix)//'Info',status='old')
!         call LECNAM('&COST_MO ',namel,99,ierr,1)
!         call nameld(namel,ENUC,'ENUC',8)
         e_conv=enuc
         e0=enuc
         !write(6,1001)iter,e_conv
!         close(99)
      endif
      !print*,'nmat',nmat
      ifin=0
      ii=0
      e_conv=0.d0
      do imat=1,nmat
         ii0=0
         !print*,'netat',netat(imat)
         write(cc,'(i3)') imat
         do k=1,2
            if(cc(k:k)==' ') cc(k:k)='0'
         enddo
         open(99,form='unformatted',file='DAVEC'//cc,status='old')
         do i1=1,netat(imat)
            i=metat(i1+sum(netat(1:imat-1)))
            if(yw)print*,'imat,i',imat,i
            rewind 99
 1          continue
            ii=ii+1
            ii0=ii0+1
            read(99)
            read(99) (ebid,k=1,i-1),e1,(ebid,k=i+1,nrac(imat)),e2,e3
            e=e1+e2+e3
            if(yw)print'(a,2i4,4f15.8)','E',imat,i,e,e1,e2,e3
            e_conv=e_conv+e*coef(ii)
            if(yw)print*,'coef',ii,coef(ii)
         enddo
         close(99)
      enddo
      if(iter==1) then
         write(6,1001)iter,e_conv
      else
         write(6,1000)iter,e_conv,e_conv-e0,convdm
      endif
      !print'(a,10f14.8)','EEE',e_conv,e0,e_conv-e0
 1000 format('##  iter=',i4,'    E  ',F20.8,'  CONV= ',d8.2,
     *'   DM extradiag= ',d8.2)
 1001 format('##  iter=',i4,'    E  ',F20.8)
      yconv=abs(e0-e_conv)<conv1
      e0=e_conv
      return
      end
