subroutine MANAGE_LUN ! ! ! *** Prologue *** ! ! Title: Manage_LUN ! ! Author: B. Knapp, 1994-12-13 ! ! Modification History: ! ! Date Programmer Comment ! ~~~~~~~~~ ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ! 2006-08-15 B. Knapp Chage LUN range to 10-99, as Gnu ! Fortran does not accept LUNs >= 100 ! ! Purpose: ! ! This Fortran subroutine is a package with two valid entry ! points, GET_LUN, and FREE_LUN, to allocate or deallocate ! (respectively) a Fortran I/O logical unit number. ! ! ! *** Declarations *** ! implicit none ! Define the allocation table and make it a persistent object: integer LOW, HIGH, N parameter (LOW=10, HIGH=99, N=HIGH-LOW+1) logical ALLOCATED(LOW:HIGH) /N*.false./ save ALLOCATED ! ! Input, output, local variables integer LUN, STATUS, K logical IN_USE ! ! ! *** Executable section *** ! (Not a valid entry point) return ! entry GET_LUN( LUN, STATUS ) ! ! Title: SPSS Utility GET_LUN ! ! Purpose: ! ! Allocate a Fortran logical unit number for I/O ! ! References: ! ! Input: None ! ! Output: ! ! LUN - Integer logical unit number (if STATUS is 0) ! ! STATUS - 0 (good) if and only if a logical unit number was ! successfully allocate. If STATUS is not 0, then ! LUN is not defined. ! ! *** begin GET_LUN *** ! do K=LOW,HIGH inquire(unit=K,opened=IN_USE) if (.not. (ALLOCATED(K) .or. IN_USE) ) then ALLOCATED(K) = .true. LUN = K STATUS = 0 return endif enddo ! ! All units allocated LUN = -1 STATUS = 1 return entry FREE_LUN( LUN, STATUS ) ! ! Title: SPSS Utility FREE_LUN ! ! Purpose: ! ! De-allocate a specified Fortran I/O logical unit number. ! ! References: ! ! Input: ! ! LUN - Integer variable or expression, the unit specifier ! to deallocate. The unit must have been closed prior ! to the call to FREE_LUN. ! ! Output: ! ! STATUS - 0 = successfully deallocated ! 1 = unit is open, cannot be deallocated ! 2 = unit is not in valid range for auxiliary files ! (110-119 for release 3.03) ! ! ! *** begin FREE_LUN *** ! if (LOW.le.LUN .and. LUN.le.HIGH) then !in valid range inquire(unit=LUN,opened=IN_USE) if (.not. IN_USE) then !okay to deallocate ALLOCATED(LUN) = .false. STATUS=0 else STATUS=1 endif else !out of range STATUS=2 endif return end