      subroutine mulccood(x1,y1,i,j,aaa1,aaa2)
      use module
      use mod_ena
      use mod_ena2
      use mod_itp
      use mod_mula
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer i,x1,y1,j,j3,x,y,i1,a,b,aa,bb
      integer,allocatable,dimension(:) :: idetc1,idetc2,isgnc
      dimension ntp(0:10),aal(4),isec1(4),isec2(4)
      character(31) elmat(27)
      !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! Preparation des listes d'adresses du CAS et des TP
      !
      ! i,j,k,l,aa = indices et valeur de l'integrale
      ! ,itp4 : adresses de la partie T/P
      ! ntp,ntp1,ntp2       : nombre d'adresses T/P
      !  det1 : ij--->[xy...] -->       det2 :
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      !i et j doivent etre lies au cas
      ! on n'ajoute rien
      !
      !Rem :  on a toujours i>=j et x1>=y1
      if(igener<2) return
!      if(iter>=iterh)print*,'subr mulccood classhab(2,0)'
      if (iter>=iterh) call classhab(2,0)
      aa1=aaa1
      aa2=aaa2
      !symetrie de spin
      if(x1==y1.and.i==j) then
         ysp1=.false.
         ysp0=.true.
      else
         ysp1=itest(21)==1
         ysp0=itest(21)==0
      endif
      if(ysp1) then
         aa1=aa1*2
         aa2=aa2*2
      endif
      !
      i1=num_oav(i)
      j3=num_oav(j)
      x=num_oav(x1)
      y=num_oav(y1)
      !
      ! signe : saut i-C   j-C
      jsgn1=1-mod(num_oav(i)+num_oav(j),2)*2
      !///////////////////////////////////////////////////////////
      if(w)print*,'mulccood 0',x1,y1,i,j
      !///////////////////////////////////////////////////////////
      n=0
      nntp=0
      call caldfc(idist,2,0)
      call caldfc(idist2,0,0)
      if ((ilc1(i).ne.0).and.(ilc1(j).ne.0)) then
         n=1
         ii1=ilc1(i)
         ii2=ilc1(j)
         itp2(1)=1
         if (i>j) then
            itp1(1)=num1(ii1)+ii2
            ltp1(1)=2
         elseif (i==j) then
            itp1(1)=ii1
            ltp1(1)=3
         else
            itp1(1)=num1(ii2)+ii1
            ltp1(1)=1
         endif
         nntp(ltp1(1))=nntp(ltp1(1))+1
         call reoitp(n,3,nntp)
         if(w)print'(a,20i3)','ITP',itp1(1)
         if(w)print'(a,20i3)','ITP',itp2(1)
         !!
         !
         elmat(1:3)=(/'I+ J+ ->       |       ->      ',
     *   'J+ I+ ->       |       ->      ',
     *   'I+=J+ ->       |       ->      '/)
         aa3=aa1
         call mula0(x,y,0,0)
         !
         if(w)print*,'icas1',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,3,jsgn1,'J-')
         if(ysp0.and.(i/=j.or.x/=y))
     *   call mula(aa3,'-+oo',elmat,n,3,jsgn1,'I-')
         !
         !==================
         !
         if(i/=j.and.x/=y) then
            aa3=aa1-aa2
            ydir=.false.
            yoci((/x,y/))=.true.
            if(w)print*,'icas3',jsgn,aa3,aa1,aa2
            call mula(aa3,'++oo',elmat,n,2,jsgn1)
            if(ysp0)call mula(aa3,'--oo',elmat,n,2,jsgn1,'I-','J-')
            ydir=.true.
            yoci((/x,y/))=.false.
            !
            !==================
            !
            aa3=aa2
            !
            if(w)print*,'icas5',jsgn,aa3
            call mula(aa3,'+-oo',elmat,n,3,jsgn1,'I-')
            if(ysp0)call mula(aa3,'-+oo',elmat,n,3,jsgn1,'J-')
         endif
         !
      endif
 
      hab=0
      !
      !
      !On va rajouter une particule a
      !det1 ij--->[xy....]--->a det2 --->a
      if(igener<3) return
      if(itest(22)==1.and.iter==1) return
      !///////////////////////////////////////////////////////////
      if(w)print*,'mulccood on ajoute une particule',x1,y1,i,j
      !///////////////////////////////////////////////////////////
      n=0
      nntp=0
      call caldfc(idist,2,1)
      call caldfc(idist2,0,1)
      do aa=1,nlcv
         a=ilc(nlco+aa)
         apair=ilp(i,a)
         bpair=ilp(j,a)
         if ((apair==0).and.(bpair==0)) cycle
         if ((apair/=0).and.(ilc1(j)/=0)) then
            !a liee a i et j liee au cas
            if(ipc(ilp(i,a),ilc1(j))==0) cycle
            n=n+1
            itp2(n)=ilc1(a)
            itp1(n)=abs(ipc(ilp(i,a),ilc1(j)))
            if (i>j) then
               ltp1(n)=2
            elseif (i==j) then
               ltp1(n)=3
            else
               ltp1(n)=1
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j',a,i,j,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         elseif ((bpair/=0).and.(ilc1(i)/=0)) then
            if(ipc(ilp(j,a),ilc1(i))==0) cycle
            n=n+1
            itp2(n)=ilc1(a)
            itp1(n)=abs(ipc(ilp(j,a),ilc1(i)))
            if (i>j) then
               ltp1(n)=2
            elseif (i==j) then
               ltp1(n)=3
            else
               ltp1(n)=1
            endif
            nntp(ltp1(n))=nntp(ltp1(n))+1
            if(w)print'(a,20i4)','a,i,j',a,i,j,n,
     *      ltp1(n),nntp(ltp1(n)),
     *      itp1(n),itp2(n)
         endif
      enddo
      if(n>0) then
         call reoitp(n,3,nntp)
         if(w)print'(a,20i3)','ITP',itp1(1:n)
         if(w)print'(a,20i3)','ITP',itp2(1:n)
         !!
         !
         elmat(1:3)=(/'I+ J+ -> a+    |       -> a+   ',
     *   'J+ I+ -> a+    |       -> a+   ',
     *   'I+=J+ -> a+    |       -> a+   '/)
         aa3=aa1
         call mula0(x,y,0,0)
         !
         if(w)print*,'icas1',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,3,jsgn1,'J-')
         if(ysp0)call mula(aa3,'-+oo',elmat,n,3,jsgn1,'I-','a-')
         !
         if(i/=j.or.x/=y) then
            if(w)print*,'icas2',jsgn1,aa3
            call mula(aa3,'+-oo',elmat,n,3,jsgn1,'J-','a-')
            if(ysp0)call mula(aa3,'-+oo',elmat,n,3,jsgn1,'I-')
         endif
            !
            !!!!!!!!!!!!!!!!!!
            !
         if(i/=j.and.x/=y) then
            aa3=aa1-aa2
            if(w)print*,'icas3',jsgn1,aa3
            ydir=.false.
            yoci((/x,y/))=.true.
            call mula(aa3,'++oo',elmat,n,3,jsgn1)
            if(ysp0)call mula(aa3,'--oo',elmat,n,3,jsgn1,'I-','J-','a-')
            !
            if(w)print*,'icas4',jsgn1,aa3
            call mula(aa3,'++oo',elmat,n,3,jsgn1,'a-')
            if(ysp0)call mula(aa3,'--oo',elmat,n,3,jsgn1,'I-','J-')
            ydir=.true.
            yoci((/x,y/))=.false.
            !
            !!!!!!!!!!!!!!!!!!
            !
            aa3=aa2
            if(w)print*,'icas3',jsgn1,aa3
            call mula(aa3,'+-oo',elmat,n,3,jsgn1,'I-')
            if(ysp0)call mula(aa3,'-+oo',elmat,n,3,jsgn1,'J-','a-')
            !
            if(w)print*,'icas3',jsgn1,aa3
            call mula(aa3,'+-oo',elmat,n,3,jsgn1,'I-','a-')
            if(ysp0)call mula(aa3,'-+oo',elmat,n,3,jsgn1,'J-')
            !
         endif
      endif
 
      !On va rajouter deux particules a et b
      !det1 ij--->[xy....]--->ab det2 --->ab
      if(igener<4) return
      !///////////////////////////////////////////////////////////
      if(w)print*,'mulccood on ajoute deux particules',x1,y1,i,j
      !///////////////////////////////////////////////////////////
      !a et b doivent etre lies au cas et lies a i ou j
      !if(x==y.and.i>j) return
      !if(x>y.and.i==j) return
!      call alloitp3(size(itp1))
!      call alloitp4(size(itp1))
!      call alloltp1(size(itp1))
      n=0
      nntp=0
      call caldfc(idist,2,2)
      call caldfc(idist2,0,2)
      do aa=1,nlcv
         do bb=aa,nlcv
            a=ilc(nlco+aa)
            b=ilc(nlco+bb)
            ipair_1=ilp(i,a)
            ipair_2=ilp(i,b)
            jpair_1=ilp(j,a)
            jpair_2=ilp(j,b)
            if ((ipair_1/=0).and.(jpair_2/=0)) then
               n=n+1
               ii1=ilp(i,a)
               ii2=ilp(j,b)
               iimax=max(ii1,ii2)
               iimin=min(ii1,ii2)
               iio=iimax*(iimax-1)/2+iimin
               if(ipp(iio)==0) then
                  n=n-1
                  cycle
               endif
               itp1(n)=abs(ipp(iio))
               if(a==b) then
                  itp2(n)=bb
               else
                  itp2(n)=num1(bb)+aa
               endif
               if(i==j) then
                  ltp1(n)=2
               else
                  ltp1(n)=1
               endif
               if(a==b) then
                  ltp1(n)=ltp1(n)+2
               endif
               nntp(ltp1(n))=nntp(ltp1(n))+1
               if(w)print'(a,20i4)','1i,j,a,b',
     *         i,j,a,b,n,ltp1(n),nntp(ltp1(n)),
     *         itp1(n),itp2(n),num_oav(i)
            elseif ((ipair_2/=0).and.(jpair_1/=0)) then
               n=n+1
               ii1=ilp(i,b)
               ii2=ilp(j,a)
               iimax=max(ii1,ii2)
               iimin=min(ii1,ii2)
               iio=iimax*(iimax-1)/2+iimin
               if(ipp(iio)==0) then
                  n=n-1
                  cycle
               endif
               itp1(n)=abs(ipp(iio))
               if(a==b) then
                  itp2(n)=bb
               else
                  itp2(n)=num1(bb)+aa
               endif
               if(i==j) then
                  ltp1(n)=2
               else
                  ltp1(n)=1
               endif
               if(a==b) then
                  ltp1(n)=ltp1(n)+2
               endif
               nntp(ltp1(n))=nntp(ltp1(n))+1
               if(w)print'(a,20i4)','2i,j,a,b',
     *         i,j,a,b,n,ltp1(n),nntp(ltp1(n)),
     *         itp1(n),itp2(n),num_oav(i)
            endif
         enddo
      enddo
      if(n==0) return
      call reoitp(n,4,nntp)
      if(w)print'(a,20i3)','ITP',itp1(1:n)
      if(w)print'(a,20i3)','ITP',itp2(1:n)
      !
      elmat(1:4)=(/'J+ I+ -> a+ b+ |       -> a+ b+',
     *'J+=I+ -> a+ b+ |       -> a+ b+',
     *'J+ I+ -> a+=b+ |       -> a+=b+',
     *'I+=J+ -> a+=b+ |       -> a+=b+'/)
      aa3=aa1
      call mula0(x,y,0,0)
      !
      if(w)print*,'icas1',jsgn1,aa3
      call mula(aa3,'+-oo',elmat,n,2,jsgn1,'J-')
      if(ysp0)call mula(aa3,'-+oo',elmat,n,2,jsgn1,'I-','a-','b-')
      !
      if(w)print*,'icas12',jsgn1,aa3
      call mula(aa3,'+-oo',elmat,n,4,jsgn1,'J-','b-')
      if(i/=j.or.x/=y) then
         if(ysp0)call mula(aa3,'-+oo',elmat,n,4,jsgn1,'I-','a-')
      else
         if(ysp0)call mula(aa3,'-+oo',elmat,n,2,jsgn1,'I-','a-')
      endif
      !
      if(i/=j.or.x/=y) then
         if(w)print*,'icas2',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,2,jsgn1,'J-','a-')
         if(ysp0)call mula(aa3,'-+oo',elmat,n,2,jsgn1,'I-','b-')
         !
         if(w)print*,'icas22',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,2,jsgn1,'J-','a-','b-')
         if(ysp0)call mula(aa3,'-+oo',elmat,n,2,jsgn1,'I-')
      endif
      !
      !!!!!!!!!!!!!!!!!!
      !
      if(i/=j.and.x/=y) then
         aa3=aa1-aa2
         ydir=.false.
         yoci((/x,y/))=.true.
         if(w)print*,'icas3',jsgn1,aa3
         call mula(aa3,'++oo',elmat,n,2,-jsgn1)
         if(ysp0)
     *   call mula(aa3,'--oo',elmat,n,2,-jsgn1,'I-','J-','a-','b-')
         !
         if(w)print*,'icas4',jsgn1,aa3
         call mula(aa3,'++oo',elmat,n,4,-jsgn1,'a-')
         if(ysp0)call mula(aa3,'--oo',elmat,n,4,-jsgn1,'I-','J-','b-')
         !
         if(w)print*,'icas5',jsgn1,aa3
         call mula(aa3,'++oo',elmat,n,2,-jsgn1,'b-')
         if(ysp0)call mula(aa3,'--oo',elmat,n,2,-jsgn1,'I-','J-','a-')
         !
         if(w)print*,'icas6',jsgn1,aa3
         call mula(aa3,'++oo',elmat,n,2,-jsgn1,'a-','b-')
         if(ysp0)call mula(aa3,'--oo',elmat,n,2,-jsgn1,'I-','J-')
         !
         ydir=.true.
         yoci((/x,y/))=.false.
         !
         !!!!!!!!!!!!!!!!!!
         !
         aa3=aa2
         if(w)print*,'icas7',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,2,jsgn1,'I-')
         if(ysp0)call mula(aa3,'-+oo',elmat,n,2,jsgn1,'J-','a-','b-')
         !
         if(w)print*,'icas8',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,4,jsgn1,'I-','a-')
         if(ysp0)call mula(aa3,'-+oo',elmat,n,4,jsgn1,'J-','b-')
         !
         if(w)print*,'icas9',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,2,jsgn1,'I-','b-')
         if(ysp0)call mula(aa3,'-+oo',elmat,n,2,jsgn1,'J-','a-')
         !
         if(w)print*,'icasa',jsgn1,aa3
         call mula(aa3,'+-oo',elmat,n,2,jsgn1,'I-','a-','b-')
         if(ysp0)call mula(aa3,'-+oo',elmat,n,2,jsgn1,'J-')
         !
      endif
 
      return
      end
