      subroutine prede2(iesp,idebd,iadrr,mh,mt,
     *nor1,nor2,nordeb,num1
     *,num2,ispi1,ispi2,inddet,is)
      implicit real*8(a-h,o-x,z),logical*1 (y)
      parameter(maxsym=8)
      include 'maxorb.prm'
      common/dim/iadri ; integer(8) iadri
      parameter(maxorbcas=16,maxdetc=12870)
c
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |     iadrr     |  mh   |  mt   |
c
 
      common/test/itest(100)
      common/sym/ itsym(maxorb*2),its(maxsym,maxsym),nsym
      dimension idebd(norb,norb),ilond(maxsym)
      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 /det/ndet,mdet(50),nbdet_cas
      dimension iesp(maxorbcas*maxdetc*2),iadrr(iadri*4),num1(*),num2(*)
      dimension mh(iadri),mt(iadri)
      integer(8) ndet8
cdcor
ccor      common/bidvr/ibidv(10000),ibidr(10000,20),icor
cfcor
      yw=.false.
      yw1=.false.
      if(itest(44).eq.2.and.inddet.le.6) then
         call prede2s(iesp,idebd,iadrr,mh,mt,nordeb,num1
     *   ,num2,ispi1,ispi2,inddet,is)
         return
      endif
c
      if(yw1)print*,'entree prede2',inddet
      ndet8=ndet
      do k=1,min(ndet8*2,iadri*4)
         iadrr(k)=0
      enddo
      kdet=0
      do k=1,norb
         do l=1,norb
            idebd(l,k)=0
         enddo
      enddo
      do k=1,nor1
         io1=num1(k)
         ldeb=1
         if(nordeb.eq.-1) ldeb=k+1
         do l=ldeb,nor2
            io2=num2(l)
            idebd(io1,io2)=kdet+1
c           si is=1 on symetrise idebd
            if(is.eq.1) idebd(io2,io1)=kdet+1
            if(yw1)write(6,'('' ----prede2 orb,k,l,io1,io2'',4i5)')
     *      k,l,io1,io2
            if(yw1)call flush(6)
            call gendet(iesp,
     *      iesp(maxorbcas*maxdetc+1),iadrr,io1,io2,ispi1,ispi2
     *      ,kdet,inddet,mhdum,mtdum)
            if(kdet.gt.iadri*4) then
               write(6,*)'kdet,iadri',kdet,iadri
               stop 29
            endif
            ilond(its(itsym(io1),itsym(io2)))=kdet-idebd(io1,io2)
         enddo
      enddo
      mdet(inddet)=kdet
      if(yw) then
         print*,'prede2 inddet',inddet
         do k=1,norb
            write(75,*)'prede2 idebd',(idebd(k,l),l=1,norb),'$'
            call scril
         enddo
         write(6,*)'prede2 ilond',(ilond(k),k=1,nsym)
         do k=1,kdet
            write(6,*)'prede2 k,iadrr(k)',k,iadrr(k)
         enddo
      endif
      call ecri(idebd,norb*norb,77)
      call ecri(ilond,maxsym,77)
      call ecribl(iadrr,kdet,76)
      return
      end
