      subroutine deletefile(filename,status)
c
c     a simple little routine to delete a fits file
c     author:  T. Bridgman
c
      implicit none
      integer status,unit,blocksize
      character*(*) filename
c
c     simply return if status is greater than zero
      if (status .gt. 0)return
c
c     get an unused logical unit number to use to open the fits file
      call ftgiou(unit,status)
c
c     try to open the file, to see if it exists
      call ftopen(unit,filename,1,blocksize,status)
c
      if (status .eq. 0)then
c         file was opened;  so now delete it
          call ftdelt(unit,status)
      else if (status .eq. 103)then
c         file doesn't exist, so just reset status to zero and clear errors
          status=0
          call ftcmsg
      else
c         there was some other error opening the file; delete the file anyway
          status=0
          call ftcmsg
          call ftdelt(unit,status)
      end if

c     free the unit number for later reuse
      call ftfiou(unit, status)
c
      end
