      subroutine fai3ijcl3
      use mod_casdint
      IMPLICIT REAL*8(A-H,O-x,z),logical*1(y)
      integer(2),dimension(4096) :: iint,jnt,knt
      dimension aa(2,4096)
      allocatable aijkli(:),iadrijkli(:)

!
!---------------------------------------------------
! On lit les fichiers d'integrales a 3 indices
! (1 par symetrie is)
!---------------------------------------------------
!
      yw=.false.
      call titre('Stockage des integrales a 2 et 3 indices#',40)
      allocate(aijkli(maxval(max_stolong3(:))))
      allocate(iadrijkli(maxval(max_stolong3(:))))
      open(11,form='unformatted',file=ijcl31,status='unknown')
      n=0
      do is=1,nsym
         if(yw)print*,'****************fai3ijcl3 is=',is
         rewind(11+is)
         ifin=0
         do
            ideb=ifin+1
            ifin=ifin+4096
            ifin=min(ifin,max_stolong3(is))
            if(yw)print*,'3ideb,ifin',ideb,ifin
            read(11+is,end=1) iadrijkli(ideb:ifin)
            read(11+is) (aijkli(iadrijkli(k)),k=ideb,ifin)
         enddo
 1       continue
!
! On genere les int dans l'ordre de leurs adresses
! On stocke sur 11
!
         m=0
         do js=1,nsym
                  do ii=1,nts(is)
                   i1=ntstot(is-1)+ii
            do jj=2,nts(js)
               j1=ntstot(js-1)+jj
               do kk=1,jj-1
                  k1=ntstot(js-1)+kk
                     if(i1==j1.or.i1==k1) cycle
                     i=iord(i1)
                     j=iord(j1)
                     k=iord(k1)
                     n=n+1
                     if(n>4096) then
                        write(11)iint,jnt,knt,aa
                        n=1
                     endif
                     iint(n)=i
                     jnt(n)=j
                     knt(n)=k
                     m=m+1
                     aa(1,n)=aijkli(m)
                     m=m+1
                     aa(2,n)=aijkli(m)
                     if(yw)print'(''INT3 '',3i4,2f12.8,2i4,4x,4i4)',
     *                  i1,j1,k1,aa(:,n),is,js,i,j,k
                  enddo
               enddo
            enddo
         enddo
         close(11+is,status='delete')
         if(yw)print*,'3destruction  ',11+is
      enddo
      n=n+1
      if(n>4096) then
         write(11)iint,jnt,knt,aa
         n=1
      endif
      iint(n)=0
      jnt(n)=0
      knt(n)=0
      aa(:,n)=0.d0
      write(11)iint,jnt,knt,aa
      close(11)
      return
      end
