        SUBROUTINE SELDEV(LUN)
        CHARACTER*1 BNAME(40)
C
C       Show the device numbers and their names and ask for
C       a device number. Attempt to select that device. If
C       not successful, display an error message and ask for
C       a new device number.
C
        EXTERNAL LEN
C
C       Display device numbers and names.
C
        IDEV = 1
1       CALL GSDNAM(IDEV,BNAME)
        L = LEN(BNAME)
        IF (L .EQ. 0) GO TO 5
        WRITE(9,1111) IDEV, (BNAME(I), I=1,L)
1111    FORMAT(' Device ',I2,' is ',40A1,/)
        IDEV = IDEV + 1
        GO TO 1
5       WRITE(9,'(A\)') ' Number of the graphics device to use? '
        READ(9,'(I5)') IDEV
6       CALL DEVSEL(IDEV,LUN,IERR)
        IF (IERR .EQ. 0) GO TO 10
        TYPE *, ' THAT DEVICE DOES NOT EXIST'
        GO TO 5
10      Continue
        Return
        END
