! $Id$ !------------------------------------------------------------------------------ !S+ ! NAME: ! get_lun ! ! PURPOSE: ! PUBLIC function to obtain a free logical unit number for file access ! ! CALLING SEQUENCE: ! result = get_lun() ! ! INPUT ARGUMENTS: ! None. ! ! OUTPUT ARGUMENTS: ! None. ! ! FUNCTION RESULT: ! Function returns a default integer that can be used as a logical unit ! number to open and access a file. ! ! CALLS: ! None. ! ! EXTERNALS: ! None ! ! COMMON BLOCKS: ! None. ! ! SIDE EFFECTS: ! None known. ! ! RESTRICTIONS: ! None. ! ! PROCEDURE: ! The search for a free logical unit number begins at 10. The logical ! unit number if tested to see if it is connected to an open file. If ! so, it is incremented by 1. This is repeated until a free logical ! unit number is found. !S- !------------------------------------------------------------------------------ FUNCTION get_lun() RESULT( lun ) ! ----------------- ! Type declarations ! ----------------- INTEGER :: lun LOGICAL :: file_open ! -------------------------------------------- ! Initialise logical unit number and file_open ! -------------------------------------------- lun = 9 file_open = .TRUE. ! ------------------------------ ! Start open loop for lun search ! ------------------------------ lun_search: DO ! -- Increment logical unit number lun = lun + 1 ! -- Check if file is open INQUIRE( lun, OPENED = file_open ) ! -- Is this lun available? IF ( .NOT. file_open ) EXIT lun_search END DO lun_search END FUNCTION get_lun