      subroutine maxallo
      use module
      use mod_tijkl
      use mod_licost
      implicit real*8 (a-h,o-x,z),logical*1(y)

!
! one symmetry
!
      idim=0
      do is=1,nsym
         nisoa=isymoa(is)
         nis=isym(is)
         idim=max(idim,num1(nisoa+1)*nisoa*nis)
      enddo
!
!iikk
!
      do is=1,nsym
         nisoa=isymoa(is)
         nis=isym(is)
         do ks=1,nsym
            if(ks==is) cycle
            nksoa=isymoa(ks)
            nks=isym(ks)
            idim=max(idim,num1(nisoa+1)*nksoa*nks)
            idim=max(idim,num1(nks+1)*nisoa*nis)
         enddo
      enddo
!
!ijij
!
      do is=1,nsym
         nisoa=isymoa(is)
         nis=isym(is)
         do js=1,nsym
            if(js==is) cycle
            njsoa=isymoa(js)
            njs=isym(js)
            idim=max(idim,nisoa*nisoa*njsoa*njs)
            idim=max(idim,nisoa*njsoa*nis*njs)
            idim=max(idim,num1(njs+1)*nisoa*nis)
         enddo
      enddo
!
!ijkl
!
      do is=1,nsym
         nisoa=isymoa(is)
         nis=isym(is)
         do js=1,is-1
            njsoa=isymoa(js)
            njs=isym(js)
            do ks=1,is-1
               nksoa=isymoa(ks)
               nks=isym(ks)
               lfin=ks-1
               if(is==ks) lfin=js-1
               do ls=1,lfin
                  nlsoa=isymoa(ls)
                  nls=isym(ls)
                  idim=max(idim,nisoa*njsoa*nksoa*nls)
                  idim=max(idim,nisoa*njsoa*nks*nlsoa)
                  idim=max(idim,nisoa*njs*nksoa*nlsoa)
                  idim=max(idim,nis*njsoa*nksoa*nlsoa)
               enddo
            enddo
         enddo
      enddo
!
! Frozen orbitals
!
      if(any(frozen/=0)) then
         nfr=sum(frozen)
         idimfr=0
         do is=1,nsym
            idimfr=idimfr+num1(isymoa(is)+1)
         enddo
         idim=max(idim,idimfr*nfr)
      endif
!
! Allocation
!
      yhhh=.true.
      if(idim*8>memb) then
         yhhh=.false.
         idim=(memb)/8
      endif
      allocate(hhh(idim))
      do while (.not.allocated(hhh))
         idim=idim-idim/10
         allocate(hhh(idim))
         yhhh=.false.
      enddo
!
! The integrals with frozen indices must be stored in memory
!
      if(idimfr*nfr*2>idim) then
         print*,'insufficient memory for frozen part'
         print*,'memb',memb
         print*,'idimfr,nfr,idimfr*nfr,idim',
     *   idimfr,nfr,idimfr*nfr*2,idim
         stop
      endif
         
              





!
!
!
!
!
!!
!! 4 larger orbital dimensions for ao's
!!
!      call maxallo1(js1oa,js2oa,js3oa,js4oa,isymoa)
!      print*,'maxallo',js1oa,js2oa,js3oa,js4oa
!      call maxallo1(js1,js2,js3,js4,isym)
!      print*,'maxallo',js1,js2,js3,js4
!!
!! 1 symmetry
!!
!      idim=num1(js1oa+1)*js1oa*js1
!      idim=max(idim,num1(js1oa+1)**2)
!!
!!iikk
!!
!      if(nsym>=2) then
!         idim=max(idim,num1(js1oa+1)**2)
!         num1(js1oa+1)*js2oa*js1
!      stop
      return
      end
!       subroutine maxallo1(js1oa,js2oa,js3oa,js4oa,jsymoa)
!      use module
!      use mod_tijkl
!      use mod_licost
!      implicit real*8 (a-h,o-x,z),logical*1(y)
!      dimension lsoa(1),jsym(8),jsymoa(8)
!      jsym(1:nsym)=isymoa(1:nsym)
!      js1oa=maxval(jsym)
!      if(nsym>1) then
!         lsoa=maxloc(jsym)
!         jsym(lsoa(1))=0
!         js2oa=maxval(jsym)
!         if(nsym>2) then
!            lsoa=maxloc(jsym)
!            jsym(lsoa(1))=0
!            js3oa=maxval(jsym)
!            lsoa=maxloc(jsym)
!            jsym(lsoa(1))=0
!            js4oa=maxval(jsym)
!         endif
!      endif
!      return
!      end
      

