      program test
      integer nlines,n,l(3),l1,l2,l3,lmin(3),ni
      double precision rp(3),rc0(3),rc(3),pot,rl(3),dist,tmp,
     >                 a0,a1(3),a2(3),a3(3),har,loc,exc,sumi,
     >                 sumi2,au2ev,cutoff,chden
      au2ev=27.211652
      read(*,*) (rc0(i),i=1,3)
      read(*,*) cutoff
      read(*,*)  a0
      read(*,*) (a1(i),i=1,3)
      read(*,*) (a2(i),i=1,3)
      read(*,*) (a3(i),i=1,3)
      read(*,*) nlines
      write(*,*) "n,l1,l2,l3,dist,pot:"
      sumi=0.0d0
      sumi2=0.0d0
      ni=0
      do i=1,nlines
        read(*,*) n,(rp(j),j=1,3),har,loc,exc,chden
        pot=har+loc+exc
        dist=sqrt((rp(1)-rc0(1))**2+ 
     >            (rp(2)-rc0(2))**2+ 
     >            (rp(3)-rc0(3))**2)
        lmin(1)=0
        lmin(2)=0
        lmin(3)=0
        do l1=-1,1
        do l2=-1,1
        do l3=-1,1
           rl(1)=a0*(l1*a1(1)+l2*a2(1)+l3*a3(1))
           rl(2)=a0*(l1*a1(2)+l2*a2(2)+l3*a3(2))
           rl(3)=a0*(l1*a1(3)+l2*a2(3)+l3*a3(3))
           do j=1,3
             rc(j)=rl(j)+rc0(j)
           end do
           tmp=sqrt((rp(1)-rc(1))**2+
     >              (rp(2)-rc(2))**2+
     >              (rp(3)-rc(3))**2)
           if (tmp .lt. dist) then
             dist=tmp
             lmin(1)=l1
             lmin(2)=l2
             lmin(3)=l3
           end if
        end do
        end do
        end do
        write(*,10) n,(lmin(j),j=1,3),dist,pot
        if (dist .ge. cutoff) then
          ni=ni+1
          sumi=sumi+pot
          sumi2=sumi2+pot**2
        end if
      end do
      write(*,*) " "
      write(*,*) "n,ave,var:"
      write(*,20) ni,sumi/ni,sqrt((sumi2-((sumi)**2)/ni)/ni)
      write(*,30) ni,sumi/ni*au2ev,
     &            sqrt((sumi2-((sumi)**2)/ni)/ni)*au2ev
10    format(I8,3I4,2F16.8)
20    format(I8,2F16.8," (a.u.)")
30    format(I8,2F16.6," (eV)")
      stop
      end
