      subroutine fin
      integer(8) ndet ; common/det/ndet,mdet(50),nbdet_cas
      common/test/itest(100)
      common/stp/stop
      character*8 stop
      common/opt/ihab,calcul
      character*3 calcul
      close(25,status='DELETE')
      close(28,status='DELETE')
      close(34,status='DELETE')
      if(itest(31).eq.0.and.itest(34).eq.0) close(87,status='DELETE')
      close(88,status='DELETE')
c      close(32,status='DELETE')
      close(75,status='DELETE')
      if(itest(31).eq.0.and.itest(35).eq.0) close(85,status='DELETE')
      close(86,status='DELETE')
!      close(93,status='DELETE')
      close(95,status='DELETE')
      close(8,status='DELETE')
      !close(29,status='DELETE')
      close(21,status='DELETE')
      close(22,status='DELETE')
      close(23,status='DELETE')
      close(24,status='DELETE')
      if(stop.eq.'ITERNAT') then
         print*,'stop ITERNAT'
         stop
      endif
      if(itest(31).eq.0.and.itest(28).ne.1) close(61,status='DELETE')
      close(27,status='DELETE')
      close(33,status='DELETE')
      close(76,status='DELETE')
      close(77,status='DELETE')
      close(78,status='DELETE')
      close(79,status='DELETE')
      if(calcul.eq.'MD') call delfil('CD_SYSPIN')
      if(calcul.eq.'MD') call delfil('CD_SYSPIN')
      !if(calcul.eq.'MD') print*,'destruction CD_SYSPIN'
      call delfil('CDI_INT0')
      call delfil('CDI_3333')
      call delfil('CDI_1111')
      call delfil('CDI_3131')
      call delfil('CDI_3311')
      call delfil('CDI_3331')
      call delfil('CDI_1113')
      call delfil('CDI_2333')
      call delfil('CDI_2000')
      call delfil('CDI_1122')
      call delfil('CDI_1212')
      call delfil('CDI_2123')
      call delfil('CDI_2131')
      call delfil('CDI_2133')
      call delfil('CDI_2213')
      call delfil('CDI_2233')
      call delfil('CDI_2311')
      call delfil('CDI_2313')
      call delfil('CDI_2323')
      call delfil('CDI_2111')
      call delfil('CDI_211a')
      call delfil('CDI_211b')
      call delfil('CDI_211c')
      call delfil('CDE_INT0')
      call delfil('CDE_3333')
      call delfil('CDE_1111')
      call delfil('CDE_3131')
      call delfil('CDE_3311')
      call delfil('CDE_3331')
      call delfil('CDE_1113')
      call delfil('CDE_2333')
      call delfil('CDE_2000')
      call delfil('CDE_1122')
      call delfil('CDE_1212')
      call delfil('CDE_2123')
      call delfil('CDE_2131')
      call delfil('CDE_2133')
      call delfil('CDE_2213')
      call delfil('CDE_2233')
      call delfil('CDE_2311')
      call delfil('CDE_2313')
      call delfil('CDE_2323')
      call delfil('CDE_2111')
      call delfil('CDE_1122L')
      call delfil('CDE_1212L')
      call delfil('CDE_2111L')
      call delfil('CDE_2123L')
      call delfil('CDE_2131L')
      call delfil('CDE_2133L')
      call delfil('CDE_2213L')
      call delfil('CDE_2221')
      call delfil('CDE_2221L')
      call delfil('CDE_2223')
      call delfil('CDE_2223L')
      call delfil('CDE_2233L')
      call delfil('CDE_2311L')
      call delfil('CDE_2313L')
      call delfil('CDE_2323L')
      call delfil('CDI_1122L')
      call delfil('CDI_1212L')
      call delfil('CDI_2111L')
      call delfil('CDI_2123L')
      call delfil('CDI_2131L')
      call delfil('CDI_2133L')
      call delfil('CDI_2213L')
      call delfil('CDI_2221')
      call delfil('CDI_2221L')
      call delfil('CDI_2223')
      call delfil('CDI_2223L')
      call delfil('CDI_2233L')
      call delfil('CDI_2311L')
      call delfil('CDI_2313L')
      call delfil('CDI_2323L')
      call delfil('CD_ADRR28')
      call delfil('CD_ADRR9')
      call delfil('CD_DEBL1')
      call delfil('CD_DEBL28')
      call delfil('CD_DEBL9')
      call delfil('CD_DS8')
      call delfil('CD_RESTd')
      call delfil('CD_RESTi')
      call delfil('CD_IJIK')
      call delfil('CD_IJIKd')
      call delfil('CD_IJIKx')
      !print*,'fin delfil'
      goto 20
      close(2,status='delete')
c      call delfil('t1_fok')
      call delfil('CD_JKF')
      call delfil('TEMPMR')
 
c      call delfil('CD_RESTd')
c      call delfil('CD_RESTi')
 20   continue
      return
      end
       subroutine delfil(fil)
      character*(*) fil
      logical y
      inquire(file=fil,opened=y)
      if(y) then
         inquire(file=fil,number=n)
         close(n,status='delete')
      else
         open(34,file=fil,status='unknown',form='unformatted')
         close(34,status='delete')
c         write(6,*)'fichier ',fil,' detruit'
      endif
      return
      end
