! Return the name associated with a Fortran Logical Unit Number.
! Written by Alastair McKinstry <mckinstry@debian.org> to replace 
! proprietary original inqlun(). 
! Released under the GNU GPL v2 or later.
! Copyright 2013 (C) Alastair McKinstry <mckinstry@debian.org>


! Subroutine very simple, really just a wrapper used from C
      subroutine inquire_lun(lun_num)
      integer  :: lun_num
      character(len=256) :: filename

      inquire(UNIT=lun_num, NAME=filename)
      end subroutine

!
      subroutine cond_close(lun_num)
      implicit none
      integer :: lun_num
      logical :: isopen, isnamed
      
      inquire(UNIT=lun_num, NAMED=isnamed,  OPENED=isopen)
      if (isopen .and. isnamed) then
         close(lun_num)
      end if
      end subroutine



