*-----------------------------------------------------------------------
*        Find an avaiable I/O unit
*-----------------------------------------------------------------------
      FUNCTION IOUNIT ()
       IMPLICIT NONE
       INTEGER IOUNIT

       INTEGER J, IFAULT
       LOGICAL ISOPEN, ISXIST

       IOUNIT = -1
       DO 10 J = 1, 99
         IF (J .EQ. 5 .OR. J .EQ. 6 .OR. J .EQ. 7) GO TO 10
         INQUIRE (UNIT=J, EXIST=ISXIST, OPENED=ISOPEN, IOSTAT=IFAULT)
         IF (IFAULT .EQ. 0 .AND. ISXIST .AND. .NOT. ISOPEN) THEN
           IOUNIT = J
           RETURN  ! success
         END IF
  10   CONTINUE
       RETURN  ! failure
      END  ! of iounit
