      subroutine diff1p
     *(nca,ica,ncb,icb,nt,it,ispt,np,ip,ispp,iadr1,
     *b,ab,coef)
      parameter(maxsym=8,maxorbcas=16)
      include 'maxorb.prm'
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
c    |-*-*-*-*-*-*-*-|-*-*-*-*-*-*-*-|
c    |      b        |      ab       |
c
      common/dim/iadri ; integer(8) iadri
      common/opt/ihab,calcul
      character*3 calcul
      common/sym/ itsym(maxorb*2),its(maxsym,maxsym),nsym
      common /orb/ enuc,eref,norb,noca,nocb
     *,iorb(2*maxorb),ninac,nvirt,noca0
      common/orb2/numina(maxorb),numvir(maxorb),iordo(maxorb*2)
     *,iodro(maxorb*2)
     *,numinb(maxorb),numvib(maxorb)
      common/l40/ hmono(maxorb*(maxorb+1)/2),aj(maxorb*(maxorb+1)/2)
     *,ak(maxorb*(maxorb+1)/2),f(maxorb*(maxorb+1)/2),e0
     *,ajk(maxorb*(maxorb+1)/2),escf
      dimension ica(maxorbcas),icb(maxorbcas),it(2),ip(2)
      dimension iptemp(maxorb),ipd(maxorb)
      dimension b(iadri),ab(iadri)
      common/test/itest(100)
      yw=.false.
      if(yw)write(6,*)'entree diff1p'
c
c-----------------------------------------------------------
c     une difference  deplacement d'une particule
c-----------------------------------------------------------
c
      nta=(nt+ispt)/2
      npa=(np+ispp)/2
      ntb=nt-nta
      npb=np-npa
      b0=b(iadr1)
      call comple(nvirt,numvir,npa,ip,npd,ipd)
c--------boucle sur la part supprime
      do i=1,npa
         is1=itsym(ip(i))
c        ip(i) est la part supprimee
         if(yw)write(6,*)'diff1p part supprimee',ip(i)
c-------------boucle sur la part creee
         do j=1,npd
            if(ipd(j).lt.ip(i)) goto 1
            if(is1.ne.itsym(ipd(j))) goto 1
            if(yw)write(6,*)'diff1p part creee',ipd(j)
c           ipd(j) est la part creee
            mini=min(ip(i),ipd(j))
            maxi=max0(ip(i),ipd(j))
            do k=1,np
               iptemp(k)=ip(k)
            enddo
            iptemp(i)=ipd(j)
            isgn=1
            if(npa.gt.1) then
               if(iptemp(1).gt.iptemp(2))then
                  ii=iptemp(1)
                  iptemp(1)=iptemp(2)
                  iptemp(2)=ii
                  isgn=-1
               endif
            endif
            if(yw)write(6,*)'iptemp',(iptemp(kk),kk=1,np)
            call adrdet
     *      (nca,ica,ncb,icb,nt,it,ispt,np,iptemp,ispp,iadr2,
     *      mhdum,mtdum)
c------------------calcul de l'integrale
c           yw=(iadr1.eq.73).or.(iadr2.eq.73)
            a=f(maxi*(maxi-1)/2+mini)
c------------------
            if(yw)write(6,*)'diff1p adresses,int',iadr1,iadr2,a,isgn
            if(calcul.eq.'M') then
               call stover(iadr1,iadr2,a*isgn*coef)
            else
               aa=a*isgn*coef
CYSGN               if(.not.yeqy(ysgn(iadr1),ysgn(iadr2))) aa=-aa
CIT17           if(itest(17).eq.iadr2)write(6,'('' diff1p it17'',i5,2f12
CIT17        *   iadr1,aa,b(iadr1)
CIT17           if(itest(17).eq.iadr1)write(6,'('' diff1p it17'',i5,2f12
CIT17        *   iadr2,aa,b(iadr2)
               ab(iadr2)=ab(iadr2)+aa*b0
               ab(iadr1)=ab(iadr1)+aa*b(iadr2)
            endif
 1          continue
         enddo
      enddo
      if(npa.eq.2) return
      call comple(nvirt,numvib,npb,ip(npa+1),npd,ipd)
c--------boucle sur la part supprimee
      do i=1,npb
         is1=itsym(ip(npa+i))
c        ip(npa+i) est la part supprimee
         if(yw)write(6,*)'diff1p part b supprimee',ip(npa+i)
c-------------boucle sur la part cree
         do j=1,npd
            if(ipd(j).lt.ip(npa+i)) goto 2
            if(is1.ne.itsym(ipd(j))) goto 2
            if(yw)write(6,*)'diff1p part b creee',ipd(j)
c           ipd(j) est la part creee
            mini=min(iorb(ip(npa+i)),iorb(ipd(j)))
            maxi=max0(iorb(ip(npa+i)),iorb(ipd(j)))
            do k=1,np
               iptemp(k)=ip(k)
            enddo
            iptemp(npa+i)=ipd(j)
            isgn=1
            if(npb.gt.1) then
               if(iptemp(1).gt.iptemp(2))then
                  ii=iptemp(1)
                  iptemp(1)=iptemp(2)
                  iptemp(2)=ii
                  isgn=-1
               endif
            endif
            if(yw)write(6,*)'iptemp',(iptemp(kk),kk=1,np)
            call adrdet
     *      (nca,ica,ncb,icb,nt,it,ispt,np,iptemp,ispp,iadr2,
     *      mhdum,mtdum)
c------------------calcul de l'integrale
c           yw=(iadr1.eq.73).or.(iadr2.eq.73)
c          if(yw)write(98,*)'iadr1,iadr2',iadr1,iadr2
            a=f(maxi*(maxi-1)/2+mini)
c------------------
            if(yw)write(6,*)'diff1p adresses,int',iadr1,iadr2,a,isgn
c           if(yw)write(98,*)'diff1p adresses,int',iadr1,iadr2,a,isgn
c           if(yw)write(98,*)'calcul',calcul
            if(calcul.eq.'M') then
               call stover(iadr1,iadr2,a*isgn*coef)
            else
               aa=a*isgn*coef
CYSGN               if(.not.yeqy(ysgn(iadr1),ysgn(iadr2))) aa=-aa
CIT17           if(itest(17).eq.iadr2)write(6,'('' diff1p it17'',i5,2f12
CIT17        *   iadr1,aa,b(iadr1)
CIT17           if(itest(17).eq.iadr1)write(6,'('' diff1p it17'',i5,2f12
CIT17        *   iadr2,aa,b(iadr2)
               ab(iadr2)=ab(iadr2)+aa*b0
               ab(iadr1)=ab(iadr1)+aa*b(iadr2)
            endif
 2          continue
         enddo
      enddo
      return
      end
