      subroutine adrt(nt,it,ispt,iadrt)
c
c----------------------------------------------------------
c    subroutine d'adressage des determinants des trous
c
c    nt,it,ispt : nb de trous, numero des trous, spin des trous
c----------------------------------------------------------
c
      IMPLICIT REAL*8(A-H,O-X,Z),LOGICAL*1 (Y)
      PARAMETER (maxorb=500,maxsym=8,MNEL=5,maxorbcas=16)
      PARAMETER (MAXELCAS=20)
      dimension it(2)
      common /cs/ noac,nelac,numac(maxorbcas),itype(maxorb),is0,ms2
      common/cas_spin/isz0
      common/sym/itsym(2*maxorb),its(maxsym,maxsym),nsym
      common/mxdetc/maxc(-2:2,maxsym,-2:2),
     *maxca(-2:2,maxsym,maxsym,-2:2)
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      common/sy2/nts(maxsym),ncs(maxsym),nps(maxsym)
     *,norbs(maxsym)
      common /prep/ nca0,ncb0,ic0(maxorbcas),icamun(maxorb+maxorb)
     *,numt(maxorb),nump(maxorb),nv
     *,gener,yoc(maxorb+maxorb),yrefc(maxorbcas),yac(maxorb)
     *,ygmono,ygddci,ygddc2,ygcas,ygtous
      character*4 gener
      common /prep2/ icatt(2,maxsym,maxsym,-1:1),
     *icatp(2,maxsym,maxsym,-1:1)
     *,itorb(maxorb*2),icatc(maxsym,maxsym,0:maxorbcas,0:maxorbcas)
      common/test/itest(50)
      yw=.false.
      if(nt.eq.0)then
         iadrt=1
         return
      endif
      if(yw)write(6,*)'entree adrt it',it
      it1=iorb(it(1))
      if(it(1).gt.norb) it1=it(1)-norb
      if(nt.eq.1) then
         if(yw)write(6,*)'it no orb trous',it1
         ist=itsym(it1)
         iadrt=icatt(1,ist,ist,ispt)+itorb(it1)
         if(yw)write(6,*)'icatt,itorb',icatt(1,ist,ist,ispt),itorb(it1)
         if(yw)write(6,*)'adrt 0 icatt,itorb'
     *   ,icatt(1,ist,ist,ispt),itorb(it1)
      else
         ispt1=ispt/2
c         write(6,*)'it(2)',it(2)
         it2=iorb(it(2))
         if(it(2).gt.norb)it2=it(2)-norb
c write(6,*)'adrt it1',it1
         if(yw)write(6,*)'it12 no orb trous',it1,it2
         is1=itsym(it1)
         is2=itsym(it2)
         itorb2=itorb(it2)
         itorb1=itorb(it1)
         ist=its(is1,is2)
ctest
         if(ispt.ne.0.and.it1.gt.it2) then
            write(6,*)'dans adrt it1,it2',it1,it2
            kkkk=0
            iiii=itest(kkkk)
            stop
         endif
ctestf
         if(is1.ne.is2.or.ispt.eq.0) then
c             write(6,*)'ist,is1,ispt1,is2,itorb1',ist,is1,ispt1,
c     *           is2,itorb1
            iadrt=icatt(2,ist,is1,ispt1)+itorb2+(itorb1-1)*nts(is2)
            if(yw)write(6,*)'adrt 1 icatt,itorb1,2'
     *      ,icatt(2,ist,is1,ispt1),itorb1,itorb2
         else
            iadrt=icatt(2,ist,is1,ispt1)+(itorb2-1)*(itorb2-2)/2+itorb1
            if(yw)write(6,*)'adrt 2 ist,is1,ispt1,icatt,itorb1,itorb2'
     *      ,ist,is1,ispt1,icatt(2,ist,is1,ispt1),itorb1,itorb2
         endif
      endif
      if(yw)write(6,*)'iadrt ',iadrt
      return
      end
