      module MOLCOST
      real(8),allocatable :: chol_vec(:)
      logical ychol
      integer numcho(8)
      real(8) enuc
      character(3) chol_ord
      logical y64endonne
      end module molcost
       program MOLCOST1
      use molcost
      IMPLICIT REAL*8(A-H,O-X,Z),logical*1(y)
      character*1280 namel
      character*80 prefix,file
      common/proj/ prefix,ybas,ymo,ycl,ysym,yao
      common/version/molcas,i_rec,i_at,i_orb,i_coo,y64
      common/fin/yfin
      common/pr/nprint,mprint(10),filorb,blan40
      character(80) blan40,filorb
      integer c_open,c_read
      dimension tibuf(9600)
      print*,' '
      print*,'********************************************************'
      print*,'========================================================'
      print*,' #    #   ####   #        ####    ####    ####    #####'
      print*,' ##  ##  #    #  #       #    #  #    #  #          #'
      print*,' # ## #  #    #  #       #       #    #   ####      #'
      print*,' #    #  #    #  #       #       #    #       #     #'
      print*,' #    #  #    #  #       #    #  #    #  #    #     #'
      print*,' #    #   ####   ######   ####    ####    ####      #'
      print*,'========================================================'
      print*,'********************************************************'
      print*,' '
c
c     store the data in file 93
c
      yfin=.true.
      call sto5
c      jrc_traint=c_open('Fe2.TraInt'//char(0))
c      krc=c_lseek(jrc_traint,0)
c      krc=c_read(jrc_traint,tibuf,9600*8)
c      print*,'jrc_traint',jrc_traint,krc,tibuf(1)
c      jrc_traint=c_open('Fe2.TraInt1'//char(0))
c      krc=c_lseek(jrc_traint,0)
c      krc=c_read(jrc_traint,tibuf,9600*8)
c      print*,'jrc_traint',jrc_traint,krc,tibuf(1)
c      stop
c
c     open the namelist      
c     read the project
c
      call LECNAM('&COST ',namel,93,ierr,1)
      if(ierr.eq.1) then
         print*,'namelist COST not found'
         stop
      endif
      yok=.true.
      blan40='                                        '
     *//'                                        '
      prefix=blan40      
      ydip=.false.
      ybas=.false.
      ymo=.true.
      ycl=.false.
      ysym=.true.
      yao=.true.
      molcas=0
      ychol=.false.
      chol_ord='KPQ'
      if(index(namel,'PREFIX=')==0) then
         call system('echo $Project > PROJECT')
         open(1,file='PROJECT',status='old')
         read(1,'(a)') prefix
         prefix=trim(adjustl(prefix))//'.'
         close(1,status='delete')
      else
         call namela(namel,prefix,'PREFIX')
      endif
      call namell(namel,YBAS,'YBAS',1)
      call namell(namel,YCHOL,'YCHOL',1)
      call namela(namel,CHOL_ORD,'CHOL_ORD')
      call maj(chol_ord,3)
      call namell(namel,YMO,'YMO',1)
      call namell(namel,YAO,'YAO',1)
      call namell(namel,YCL,'YCL',1)
      call namell(namel,YSYM,'YSYM',1)
      call namell(namel,YDIP,'YDIP',1)
      call nameli(namel,MOLCAS,'MOLCAS',4)
      call nameli(namel,NPRINT,'NPRINT',4)
c
c      
      call openf
      if(yao) then
         call lirone(yok,ydip)
         if(.not.yok) then
            print*,
     *      '******ERROR BY READING THE ONE-ELECTRON ATOMIC INTEGRALS'
            stop
         endif
      else
         print *,' '
         print*,'BY REQUEST OR BECAUSE FILE ONEINT DOES NOT EXIST'
         print*,'THE NAMELIST COST_AO WAS NOT CREATED'
      endif
!              print'(a,2l2)','yok0',yok,ybas
      if(ybas.and.molcas.ne.60)then
         call lircom(yok)
         if(.not.yok) then
            print*,
     *      '******ERROR BY READING THE COMFILE'
            stop
         endif
      endif
      if(.not.yok) then
         print*,
     *   '******ERROR BY READING THE COMFILE'
         stop
      endif
      if(ymo) then
         call lirintm(yok) 
         if(.not.yok) then
            print*,
     *      '******ERROR BY READING THE '
     *      ,'MOLECULAR INTEGRALS******'
            stop
         endif
      else
         print *,' '
         print*,'BY REQUEST OR BECAUSE FILE TRAONE DOES NOT EXIST'
         print*,'THE NAMELIST COST_MO WAS NOT CREATED'
      endif
      print *,' '
      if(yfin) then
         call titre('MOLCOST: NORMAL ENDING#',60)
      else
         print*,'****************************************'
         print*,'Warning, some files could not be opened'
         print*,'****************************************'
      endif
      close(93,status='delete')
      close(75,status='delete')
      end

