      subroutine openf
      use module
      use mod_lirorb
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      character(100000) namel,namel1
      character(80) info,info1,file,mono,mono1,inporb,ijcl
      character(80) ijclloc2,ijclloc3,ijclloc4
      include '../../param/maxlong.prm'
      integer fsize
      logical opened
c
c---------------------------------------------------------------
c lecture des donnees
      !
      ! mem    : memoire dispo sur la machine (en Mo)
      ! ycdloc : T  Ecriture des int pour casdiloc
      ! ycd    : T Ecriture des int pour casdi
      ! ycl1   : si (ycd) : ecriture des int pour casdi en clair
      ! sint   : seuil de selection des integrales. L'integrale
      !          est mise a zero si elle est inferieure a sint
      !          (elle n'est pas stockee dans la DAF)
      ! sint3  :  seuil de selection des integrales. Le triplet
      !           d'integrales est elimine les 3 sont inferieures
      !           a sint
c---------------------------------------------------------------
c
      yw=.false.
      call titre('Read Data#',60)
 1000 format(a20,20i4)
      nprint=0
      sint=1.d-12
      sint3=1.d-8
      ijcl1=' '
      ijclloc41=' '
      ijclloc31=' '
      ijclloc21=' '
      ijclloc2='ijclloc2'
      ijclloc3='ijclloc3'
      ijclloc4='ijclloc4'
      itest(1)=1
      fsize=maxlong/1000   ! max lenth of integral file (in Mbytes)
      mono='Mono      '
      mono1=' '
      info='Info      '
      info1=' '
      inporb='INPORB'
      mem=500
      ycdloc=.true.
      ycd=.false.
      desymact=.true.
      notwo=.false.
      rewind 93
      print*, ' avant lecnam dans openf'
      call LECNAM('&IJKLOC ',namel,93,ierr,1)
      print*, 'lecnam: ierr=',ierr
      if(ierr.eq.1) then
         print*,'namelist IJKLOC non trouvee'
         stop
      endif
!      sym=' '
      stop=' '
      ycombinorb=.false.
      mprint=0
      sl1=1.d-3
      sl2=1.d-4
      sl=1.d-3
      maxlong_modif=-1
      all_linked=.false.
      call namela(namel,prefix,'PREFIX')
      call namela(namel,INFO1,'INFO1')
      call namela(namel,INFO,'INFO')
      call namela(namel,IJCLLOC21,'IJCLLOC21')
      call namela(namel,IJCLLOC2,'IJCLLOC2')
      call namela(namel,IJCLLOC31,'IJCLLOC31')
      call namela(namel,IJCLLOC3,'IJCLLOC3')
      call namela(namel,IJCLLOC41,'IJCLLOC41')
      call namela(namel,IJCLLOC4,'IJCLLOC4')
      call namela(namel,IJCL1,'IJCL1')
      call namela(namel,IJCL,'IJCL')
      call namela(namel,MONO1,'MONO1')
      call namela(namel,MONO,'MONO')
      call namela(namel,INPORB,'INPORB')
      call namela(namel,STOP,'STOP')
      call nameli(namel,maxlong_modif,'MAXLONG',4)
      call nameli(namel,MPRINT,'MPRINT',4)
      call nameli(namel,MAXLONG,'MAXLONG',4)
      call nameli(namel,MEM,'MEM',4)
      call nameli(namel,FSIZE,'FSIZE',4)
      call nameli(namel,NPRINT,'NPRINT',4)
      call nameli(namel,itest,'ITEST',4)
      call namell(namel,NOTWO,'NOTWO',1)
      call namell(namel,YCL1,'YCL1',1)
      call namell(namel,YCDLOC,'YCDLOC',1)
      call namell(namel,YCD,'YCD',1)
      call namell(namel,ALL_LINKED,'ALL_LINKED',4)
      call nameld(namel,SINT3,'SINT3',8)
      call nameld(namel,SINT,'SINT',8)
      call namell(namel,DESYMACT,'DESYMACT',4)
      call namell(namel,YCOMBINORB,'YCOMBINORB',1)
      call namell(namel,YCL,'YCL',1)
      if(itest(1)==1.and.ycd) then
         print*,'itest(1)==1 (symmetry calculation in) .and.ycd'
         print*,'the ijclloc (generated ifycd) file is not correct'
         print*,'if  itest(1)==1'
         print*,'if ycd, put itest(1)=0'
         stop
      endif
!      call namela(namel,SYM,'SYM')
      call maj(stop,80)
      if(ijclloc21==' ') ijclloc21=trim(prefix)//trim(ijclloc2)
      if(ijclloc31==' ') ijclloc31=trim(prefix)//trim(ijclloc3)
      if(ijclloc41==' ') ijclloc41=trim(prefix)//trim(ijclloc4)
      ! nb_ijcloc=nb of records of 4096 triplets of int in a ijcl41 file
      nb_ijcloc=fsize*1000000.d0/(32*4096)
      if(nprint>0) print*,'nb_ijcloc',nb_ijcloc
c
c---------------------------------------------------------------
c lecture des fichiers de molcost et des orbitales
c---------------------------------------------------------------
c
      if(info1==' ') info1=trim(prefix)//info
      if(mono1==' ') mono1=trim(prefix)//mono
!      l=len_trim(sym)
!      sym(2:l+1)=sym(1:l)
!      sym(1:1)=' '
      open(1,file=info1,form='formatted',status='old')
      call LECNAM('&COST_AO',namel1,1,ierr,0)
      call nameli(namel1,noa,'NORB',4)
      call nameli(namel1,nsym,'NSYM',4)
      call nameli(namel1,JTSR,'JTSR',4)
      sxyz=' '
      call namela(namel1,SXYZ,'SXYZ')
      allocate(orbi(noa))
      ylabel=index(namel1,'LABEL')/=0
      call namela(namel1,ORBI,'LABEL')
      do k=1,nsym
         if(sxyz(k).ne.' ') write(6,'(" sxyz(",i1,")=''",a,"''")') 
     *   k,trim(sxyz(k))
      enddo
      call nameli(namel1,natom0,'NATOM',4)
      if(nprint>0) print*,'natom0   ',natom0
      allocate(coor(3,natom0),atom0(natom0))
      call nameld(namel1,COOR,'COOR',8)
      call namela(namel1,ATOM0,'ATOM')
      frozen=0
      delete=0
      call LECNAM('&COST_MO',namel1,1,ierr,0)
      if(ierr==1) then
         print*,'namelist COST_MO absente dans Info'
         stop
      endif
      call nameli(namel1,norb,'NORB',4)
      call nameli(namel1,nb_ijcl,'N_IJCL',4)
      call nameli(namel1,FROZEN,'FROZEN',4)
      if(yw)print*,'FROZEN',FROZEN
      call nameli(namel1,DELETE,'DELETE',4)
      call nameld(namel1,ENUC,'ENUC',8)
      ychol=.false.
      call namell(namel1,YCHOL,'YCHOL',4)
      if(.not.ychol) then
         ycl=.false.
         call namell(namel1,YCL,'YCL',1)
      endif
      allocate
     *(itsym(norb),iord(norb),tipo(norb),iordng(noa),tipong(noa))
      call nameli(namel1,itsym(1),'ITSYM',4)
      !
      open(2,file=mono1,form='unformatted',status='old')
      !
      inquire(3,opened=opened)
      if(opened) close(3)
      open(3,file=inporb,form='formatted',status='old')
      !
      if(.not.notwo) then
         if(ycl) then
            ijcl='IJCL      '
         else
            ijcl='ijcl      '
         endif
         if(ijcl1==' ') ijcl1=trim(prefix)//ijcl
         if(ycl.and..not.ychol)
     *   open(26,file=ijcl1,form='formatted',status='old')
         if(.not.ycl.and..not.ychol)
     *   open(26,file=ijcl1,form='unformatted',status='old')
      endif
      !
      call lirorb(inporb,norbbid,ibid,isym,4,3)
      print 1000, ' &COST_AO'
      print 1000, 'Natom    ',natom0
      print 1000, 'Nsym     ',Nsym
      print 1000, 'Isym     ',Isym(1:nsym)
      if(nprint>0) then
         print 1000,'jtsr'
         do k=1,nsym
            write(6,'(20x,8i3)') jtsr(k,1:nsym)
         enddo
      endif
      print 1000, '-----------------------------------'
      open(8,file='SCH_FERMI',form='formatted',status='old')
      call LECNAM('&FERM',namel,8,ierr,1)
      call nameli(namel,fermi(1),'FERMI',4)
      fermi=fermi-frozen
      isymng=isym
      isym=isym-frozen-delete
      virt=isym-fermi
      noc=sum(fermi(1:nsym))
      ngel=sum(frozen(1:nsym))
      ndel=sum(delete(1:nsym))
      print 1000, ' &COST_MO'
      print 1000, 'Norb     ',Norb
      print 1000, 'Noc      ',Noc
      print 1000, 'Frozen   ',frozen(1:nsym)
      print 1000, 'Delete   ',Delete(1:nsym)
      print 1000, 'Fermi    ',Fermi(1:nsym)
      print*,'******************************************************'
      print*,' '
      print*,' '
      print*,' '
      return
      end
