      PROGRAM SHOW_DEV
C
C     This program gives error and utilization
C     stats for any device on the system.
C
C     Note that all 3 of the following buffers
C        are the same size.
      BYTE BBUFFER(0:63)
      INTEGER*2 WBUFFER(0:31)
      INTEGER*4 LBUFFER(0:15)
      INTEGER*4 DESC(2)
      CHARACTER*80 DEVNAM,DNAM
C     Declare symbolic names for offsets within
C     the device information buffer.
C     Note that we assume that the word values
C        are aligned on word boundaries within
C        the buffer, and that longword values
C        are aligned on longword boundaries.
C     There is no guarantee that this
C        assumption will hold in future
C        relesases of VMS!
      EXTERNAL DIB$W_DEVNAMOFF,DIB$W_ERRCNT
      EXTERNAL DIB$L_OPCNT,DIB$W_UNIT
C     Equivalence all the buffers so we can easily
C        refer to byte, word, or longword entries
C        within them.
      EQUIVALENCE (BBUFFER,WBUFFER)
      EQUIVALENCE (BBUFFER,LBUFFER)
C     Make our own descriptor for the buffer.
      DESC(1) = 64
      DESC(2) = %LOC(BBUFFER)
10    TYPE 100,'Give me device name : '
100   FORMAT(1H$,A)
      READ(5,101,END=50)L,DEVNAM
101   FORMAT(Q,A)
      CALL IFERR(SYS$GETDEV(DEVNAM(1:L),,DESC,,))
C     Device name is returned as a counted string.
C     Get offset to the counted string
      ICA = WBUFFER(%LOC(DIB$W_DEVNAMOFF)/2)
C     Do zero extend conversion from word to long
      ICA = ICA.AND.'FFFF'X
C     Get the count
      IC = BBUFFER(ICA)
C     Do a zero extend conversion again,
C        this time from byte to long.
      IC = IC.AND.'FF'X
C     Now extract the string
      DO 20 I = 1 , IC
20    DNAM(I:I) = CHAR(BBUFFER(ICA+I))
C     Get the unit number
      IU = WBUFFER(%LOC(DIB$W_UNIT)/2)
      IU = IU.AND.'FFFF'X
C     And figure out how many characters it is.
      ILU = 1
      IF(IU.GT.0)ILU = ALOG10(FLOAT(IU)) + 1.
C     Get error count
      I_ERROR = WBUFFER(%LOC(DIB$W_ERRCNT)/2)
      I_ERROR = I_ERROR.AND.'FFFF'X
C     And operation count
      I_OPS = LBUFFER(%LOC(DIB$L_OPCNT)/4)
      TYPE 102,DNAM(1:IC),IU,I_ERROR,I_OPS
102   FORMAT(' Device _',A,I<ILU>,': has had',I6,
     &   ' errors in ',I10,' operations.')
      GOTO 10
50    STOP 'ALL DONE'
      END
