subroutine trmpi_file_close(argstr)

  !  close an existing file; argstr of form <lun>

  use trmpi
  implicit NONE

  character*(*), intent(in) :: argstr

  integer :: ilun,iertmp
  character*10 :: zwk

  !---------------------------------------

  zwk = adjustr(argstr(1:len(zwk)))
  read(zwk,'(I10)',iostat=iertmp) ilun
  if(iertmp.ne.0) then
     write(trmpi_lunmsg,*) ' '
     write(trmpi_lunmsg,*) &
          ' ?trmpi_file_open_read: myid=',trmpi_myid, &
          ' LUN decode error in FILE_CLOSE: '
     write(trmpi_lunmsg,*) '    '//trim(argstr)
     write(trmpi_lunmsg,*) ' '
     call bad_exit
  endif

  close(unit=ilun)

end subroutine trmpi_file_close
