!     Last change:  RCD  27 Jul 2009    1:54 pm
!
	Program ASA Overlap and Gradient Similarity for atoms
	implicit double precision(a-h,o-z),INTEGER*4 (i-n)
	Parameter (PI=3.14159265358979D0)
        PARAMETER (Zero=0.0d0)
	parameter (NASAMAX=10)
	dimension Ap(NASAMAX),Cp(NASAMAX)
	Character*9 ASAFUN
	logical nollegit,LLORO
!
        LLORO=.true.
!
        do
!
	write(*,*)' Enter the ASA file: 1= 3-21g OR 2=6-311'
	read(*,*)nix
	nollegit=.true.
	do while (nollegit)
	 if(nix.eq.1)then
	  ASAFUN='3-21g.txt'
	  nollegit=.false.
	 elseif(nix.eq.2)then
	  ASAFUN='6-311.txt'
	  nollegit=.false.
	 else
	  write(*,*)' Enter the ASA file: 1= 3-21g OR 2=6-311'
	  read(*,*)nix
	 endif
	enddo
!
!       attach ASA functions to each atom
!
        WRITE(*,*)' Read atom nuclear charge: '
	READ(*,*)nzp
!
	Open(1,file=ASAFUN)
	 do
	  read(1,*)iz,nf
	  read(1,*)(Cp(i),Ap(i),i=1,nf)
          IF(iz==nzp)THEN; Nfunp=nf; EXIT; END if
	enddo
        REWIND(1)
        CLOSE(1)
!
!       write information on ASA functions
!
        IF(LLORO)then
	  Write(*,*)nzp,Nfunp
          check=zero
          do i=1,Nfunp
          check=check+Cp(i)
	  write(*,*)i,Cp(i),Ap(i)
          end do
          WRITE(*,*)' Check coefficients: ',check
          WRITE(*,*)'-'
        endif
!
!       Compute overlap and gradient selfsimilarity between s-type functions
!
        SSOVLP=ZERO
        SSGRAD=ZERO
        do k=1,nfunp
        AA=Ap(k)!/2
        CPK=Cp(k)
        do l=1,k
        BB=Ap(l)!/2
        term=CPK*Cp(l); IF(k/=l)term=term*2
        alam=2*AA*BB/(AA+BB); Fecit=SQRT(alam/PI)**3
        termp=term*Fecit
        Focit=6*alam*Fecit
        tormp=term*Focit
        SSOVLP=SSOVLP+termp
        SSGRAD=SSGRAD+tormp
        end do
        end do
!
        WRITE(*,*)' Overlap selfsimilarity : ',SSOVLP
        WRITE(*,*)'           in Z**2 units: ',SSOVLP/NZP**2
        WRITE(*,*)' Gradient selfsimilarity: ',SSGRAD
        WRITE(*,*)'           in Z**2 units: ',SSGRAD/NZP**2
!
        WRITE(*,*)'*'
        END do
!
	End !Program Overlap and Gradient Similarity for atoms
!

