      SUBROUTINE FILCLO
      character*80 GETNAM
*
*
*                 new       |||||    subroutine closing all currently
*                 and        |||     opened MOPAC v. 6.0 files
*              improved       |
*                             |      normally used when expecting
*                             V      stop
*
c
c
      include 'MOP6FILE'            ! Get parameters common to all the
                                    ! MOPAC v. 6 files
c
c
      character*50 FILnames(Nfiles) ! <== true names of files to be used
c
      character*50 FORnames(Nfiles) ! <==        FORTRAN,
     %    /
     %       'FOR005'  ,            !     system and/or symbolic names
     %       'FOR006'  ,            !     as used in the program
     %       'FOR009'  ,
     %       'FOR010'  ,
     %       'FOR011'  ,
     %       'FOR012'  ,            ! there are Nfiles such names
     %       'FOR013'  ,            ! currently used in the AMPAC program
     %       'FOR014'  ,
     %       'FOR015'  ,
     %       'FOR016'  ,
     %       'FOR020'  ,
     %       'SETUP'   ,
     %       'SHUTDOWN',
     %       '?Setup2' ,
     %       'FOR021'    /
c
      common /dt_file/ dt_fname    ! this keeps the name of our
      character*50 dt_fname        ! time_lord file
c
c
c       local variables
c
       logical ajar, living
       character *80 line, tfname*65, wchar*1
       equivalence (ajar,living)
c
       save FILnames, FORnames  ! we need some trace of warranty
                           ! that our marvel of technology
                           ! will not forget the data it read in
                           ! after being called as GETNAMES
c
c
                         ! We are closing whatever is opened
c
      do j=1,Nfiles-1       ! -1 because unit #4 is serving both
                            ! as a SETUP, and if necessary as
                            ! a Secondary SETUP logical unit
        i = loguni(j)
c
        inquire(unit=i,opened=ajar)  ! checking the status
c
        if (ajar) then
                 ! this one was opened
c
                         ! Let us pass the sad news to the output
                         ! files once they are still opened ...
           if (j.eq.2 .or. j.eq.5)  then
              write(i,*) '  Closing files '
           end if
c
           close(unit=i)      ! closing
        end if
c
      end do                ! loop checking regular channels ends here
c
                         ! now scratch files
      do j=1,Nscratch
c
         i = luscr(j)
c
         inquire(unit=i,opened=ajar)  ! checking the status
         if (ajar) close(unit=i)       ! killing when opened
c
      end do                ! end killing scratch files
c
c     now comes the last of our janitorial tasks - killing
c     our famous time and date file ZzZzQwhatever_comes_next
c
c
      inquire(file=dt_fname,exist=living)    ! does this file exist ?
c
      if (living) then                       ! if yes ... then
        open (unit=99,   file=dt_fname)      ! get the file first
        close(unit=99, status='delete')      ! and kill it next
      end if
c
      return ! Done, going back to the caller
c
      end
