      module channels
        use precision  
! subsystem 2b channels
       Type nch_2b
!  |(ls)j>
         integer :: nchmax
         integer,dimension(:),allocatable :: l
         real*8,dimension(:),allocatable  :: s, j
       End type
       
       type(nch_2b) :: alphanp
       integer,dimension(:,:),allocatable :: alphabar
       integer :: abarmax
       
       
       contains
       
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      subroutine alpha_2b()
c     index of n p bound state 
c     index of {(l (sn sp)snp) Jd}
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      implicit none
      integer :: l
      real*8 :: s,J
      integer ::  nJ
      integer :: nch  ! channel index {(l (jb jx)s) J}

      alphanp%nchmax=0
      do l=0,2,2
            s=1.0_dpreal
            do nJ=nint(2.*abs(l-s)),nint(2.*(l+s)),2
               if (nJ /= 2) cycle
               J=nJ/2.0_dpreal
               alphanp%nchmax=alphanp%nchmax+1
            end do
      end do
       write(*,*) "nchmax=", alphanp%nchmax
       allocate(alphanp%l(1:alphanp%nchmax),alphanp%s(1:alphanp%nchmax))
       allocate(alphanp%j(1:alphanp%nchmax))
      nch=1
      do l=0,2,2
             s=1.0_dpreal
            do nJ=nint(2.*abs(l-s)),nint(2.*(l+s)),2
               if (nJ /= 2) cycle
               J=nJ/2.0_dpreal
               alphanp%l(nch)=l
               alphanp%s(nch)=s
               alphanp%j(nch)=J
               nch=nch+1
            end do
      end do
      end subroutine
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      subroutine alpha_couplings()
c     this subroutine is used to calculate the effect coupling channels
c     of alpha and alpha'
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      implicit none
      integer :: alpha, alphap
      integer :: l,lp,s,sp,j,jp
      integer :: nch
!!for np system
      allocate(alphabar(1:alphanp%nchmax,1:alphanp%nchmax))
      alphabar=0
      nch=1
      do alpha=1,alphanp%nchmax
         l=alphanp%l(alpha)
         s=alphanp%s(alpha)
         j=alphanp%j(alpha)
         do alphap=1,alphanp%nchmax
            lp=alphanp%l(alphap)
            sp=alphanp%s(alphap)
            jp=alphanp%j(alphap)
            if((-1)**lp == (-1)**l .and. j==jp .and. sp==s) then
               alphabar(alpha,alphap)=nch
               nch=nch+1
            else
               alphabar(alpha,alphap)=0
            end if
         end do
      end do
      abarmax=nch-1
      
      write(*,*) "abarmax=",abarmax
      
      end subroutine 
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      
      
      end module 