      subroutine stodir3(i,j,k,icas,b)
      use mod_casdint
      IMPLICIT REAL*8(A-H,O-x,z),logical*1(y)
c
c--------------------------------------------------------------------
c     stockage des int a moins de 4 indices
c--------------------------------------------------------------------
c
      yw=.false.
!
!--------------------------------------------------
! Traitement des integrales a 1 et 2 indices
!--------------------------------------------------
!
      if(i==j) then
         if(j==k) then
! i=j=k
            aijjj(i,i)=b
            ajk(i,i)=b
            return
         else
! i=j
            aijjj(k,i)=b
            return
         endif
      else
         if(j==k) then
! j=k
            if(icas==1) then
               ajk(k,i)=b
            else
               ajk(i,k)=b
            endif
            return
         endif
      endif
      if(i==k) then
! i=k
         aijjj(j,i)=b
         return
      endif
!
!--------------------------------------------------
! Traitement des integrales a 3 indices
!--------------------------------------------------
!--------------------------------------------------
! on calcule l'adresse de l'integrale dans sa classe
!--------------------------------------------------
!     

! i1,j1,k1 : indices d'orbitales quand elles sont ecrites 
! dans l'ordre des symetries
! (sans s'occuper de l'occupation)
      i1=inv_iord(i)
      j1=inv_iord(j)
      k1=inv_iord(k)
      is=itsym(i1)
      js=itsym(j1)
      ioi=io(i1)
      ioj=io(j1)
      iok=io(k1)
      ioi0=ioi
      ioj=max(io(j1),io(k1))
      iok=min(io(j1),io(k1))
      if(is==js) then
         if(ioi<ioj) ioj=ioj-1
         if(ioi<iok) iok=iok-1
      endif
      if(is==js) then
         iadr=iadr03(is,js)+(ioi-1)*jad2(nts(js))+jad2(ioj)+iok
      else
         iadr=iadr03(is,js)+(ioi-1)*jad2(nts(js)+1)+jad2(ioj)+iok
      endif
      if(yw)print'(a,3i4,2x,3i4,2x,2i4,2x,3i4,4i6,f14.8)',
     *'adr3',i1,j1,k1,i,j,k,is,js,
     *ioi0,ioj,iok,icas,iadr03(is,js),iadr,(iadr-1)*2+icas,b
      iadr=(iadr-1)*2+icas
      if(y_test_adressage) then
         if(y3(is,iadr)) then
            print*,'deja 3 indices';stop
         endif
         y3(is,iadr)=.true.
      endif
      if(iadr>max_stolong3(is)) then
         print*,'iadr3 trop grand',iadr,'  max=',
     *   max_stolong3(is)
         stop
      endif
!
! On stocke l'integrale
!
      jnd3=ninti(norb+is)
      jnd3=jnd3+1
      if(jnd3>4096) then
         jnd3=1
         write(11+is) stoad3(:,is)
         write(11+is) stoint3(:,is)
      endif
      !print*,'stoad3',is,jnd3,iadr
      stoad3(jnd3,is)=iadr
      stoint3(jnd3,is)= b
      ninti(norb+is)=jnd3
      return
      end
       subroutine stdirf3
      use mod_casdint
!
!---------------------------------------------------------
! On ecrit le dernier enregistrement
!---------------------------------------------------------
!
      IMPLICIT REAL*8(A-H,O-x,z),logical*1(y)
      do is=1,nsym
         write(11+is) stoad3(:,is)
         write(11+is) stoint3(:,is)
      enddo
      return
      end
 
 
 
 
 
 
