      subroutine iadri(loci,iadr,icas,i2,j2,it)
      use module
      use moddi
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      integer,dimension(4) :: loci
      ! recherche des indices egaux
      if(loci(1).eq.loci(2)) then
         if(loci(2).eq.loci(3)) then
            if(loci(3).eq.loci(4)) then    !iiii
               icas=4
               i2=loci(1)
               j2=loci(1)
            else                           !iiij
               icas=5
               i2=loci(4)
               j2=loci(1)
            endif
         else
            if(loci(3).eq.loci(4)) then    !iijj
               if(it.eq.0) then
                  icas=4
                  i2=loci(3)
                  j2=loci(1)
               else
                  icas=4
                  i2=loci(1)
                  j2=loci(3)
               endif
            else                           !iikl
               if(it==0) then
                  icas=3                      !iikl
               else
                  icas=2                      !ijil
               endif
               i2=loci(1)
               iadr=num1(loci(3))+loci(4)
            endif
         endif
      else
         if(loci(2).eq.loci(3)) then
            if(loci(3).eq.loci(4)) then    !ijjj
               icas=5
               i2=loci(1)
               j2=loci(2)
            else                           !ijjl
               if(it==0) then
                  icas=3                      !ijjl
               else
                  icas=2                      !ijil
               endif
               i2=loci(2)
               iadr=num1(loci(1))+loci(4)
            endif
         else
            if(loci(3).eq.loci(4)) then    !ijkk
               if(it==0) then
                  icas=3
               else
                  icas=2
               endif
               i2=loci(3)
               iadr=num1(loci(1))+loci(2)
            else                           !ijkl
               icas=1
               if(itest(1)==1) then
!                  iadr=(numa(loci(1))+num2(loci(2))+num1(loci(3))
!     *            +loci(4))*3+it-2
                  iadr=(num2(loci(2))+num1(loci(3))
     *            +loci(4))*3+it-2
!                  print*,'dans iadri',loci,numa(loci(1)),
!     *            num2(loci(2)),num1(loci(3)),+loci(4),it
               else
                  iadr=(num3(loci(1))+num2(loci(2))+num1(loci(3))
     *            +loci(4))*3+it-2-incr4(loci(1))
                  !print*,'loci',loci(1),incr4(loci(1))
               endif
            endif
         endif
      endif
      return
      end
       subroutine reori(loci,it,opt)
      integer,dimension(4) :: loci
      character(*) opt
! On reordonne pour arriver a l'ordre canonique
      !print'('' entree reori'',4i4)',loci
!      if(opt.eq.'CAN') then
      if(loci(1)<loci(3)) loci((/1,3/))=loci((/3,1/))
      if(loci(2)<loci(4)) loci((/2,4/))=loci((/4,2/))
      if(loci(1)<loci(2)) loci((/1,2,3,4/))=loci((/2,1,4,3/))
      if(loci(1)==loci(2).and.loci(3)<loci(4)) 
     *loci((/3,4/))=loci((/4,3/))
!      else
      if(opt.eq.'CAN') return
! On reordonne les indices en ordre decroissant
      if(loci(4)>loci(3)) then
         loci((/3,4/))=loci((/4,3/))
         it=1
      else if(loci(3)>loci(2)) then
         loci((/3,2/))=loci((/2,3/))
         it=2
      else
         it=0
      endif
!      endif
      !print'('' sortie reori'',4i4)',loci
      return
      end
      
