      module potnp
      real*8,dimension(:,:,:),allocatable :: vnp
      
      contains 
      
      subroutine nnforce()
      use channels
      use grids_module
      use potNN
      implicit none 
      integer :: iforcein 
      integer :: alpha, alphap,nch
      integer :: j, lp,l,s,lfix
      integer :: ip, ipp
      real*8 :: V00,V02,V20,V22
      
      allocate(vnp(1:np,1:np,1:abarmax))
      
      iforcein=2
      do alpha=1,alphanp%nchmax
         do alphap=1,alphanp%nchmax
            if (alphabar(alphap,alpha)==0) cycle
            nch=alphabar(alphap,alpha)
            j=nint(alphanp%j(alphap))
            lp=alphanp%l(alphap)
            l=alphanp%l(alpha)
            s=nint(alphanp%s(alphap))

              lfix=j-1
              do ip=1,np
                do ipp=1,np
                  call potNNlsj(pp(ipp),pp(ip),lfix,s,j,V00,V02,V20,V22,iforcein)
                  if (lp==j-1 .and. l==j-1) vnp(ipp,ip,nch)=V00
                  if (lp==j+1 .and. l==j-1) vnp(ipp,ip,nch)=V20
                  if (lp==j-1 .and. l==j+1) vnp(ipp,ip,nch)=V02
                  if (lp==j+1 .and. l==j+1) vnp(ipp,ip,nch)=V22
                end do
              end do
          end do
        end do
        
        
        do ip=1, np 
            write(21,*) pp(ip),  vnp(ip,ip,1)
            write(22,*) pp(ip),  vnp(ip,ip,2)
            write(23,*) pp(ip),  vnp(ip,ip,3)
            write(24,*) pp(ip),  vnp(ip,ip,4)
        end do 
        
  

      end subroutine 
      
      
      
      
      end module 