      SUBROUTINE CKANSI (IUNIT, LANSI)
C
C     CHECKS TO SEE IF THE TERMINAL CONNECTED TO IUNIT
C     RESPONDS TO ANSI COMMANDS
C     LANSI IS RETURNED .TRUE. IF AN ANSI RESPONSE
C     OCCURRED, OTHERWISE .FALSE.
C
      INTEGER IBUFF(5)
      CHARACTER CBUFF*15
      LOGICAL LANSI
C
C
C
      LANSI = .FALSE.
C
C     TURN ON HOT READ
      CALL CHRIT1 (IUNIT, IBUFF, 5)
C     FLUSH TYPE-AHEAD BUFFER
      CALL CHRFL1
C
C     CONSTRUCT A DSR (DATA STATUS REPORT) REQUEST FOR CURSOR POSITION
      CALL CHRWT1 (CHAR(27)//'[6n', 4)
C
C     NOW GO INTO A READ-WAIT LOOP FOR UP TO 2.5 SECONDS,
C     LOOKING FOR A REPORT CONTAINING THE CURSOR POSITION.
C     THIS IS RETURNED AS ^[[l;cR
C     IF THE R IS RETURNED, THEN LANSI = .TRUE.
C
      DO 20 I=1,50
      CALL CHRRI1 (CBUFF, NCHS)
      IF (NCHS.GT.0) THEN
C     Remove any parity bit
      DO 10 J=1,NCHS
      ICH = ICHAR(CBUFF(J:J))
C     ICH = ICH.AND.'00000177                                           H
C     ICH = IAND(ICH,8#177)                                             M
      ICH = IAND(ICH,127)                                               Llg
      CBUFF(J:J) = CHAR(ICH)
 10   CONTINUE
      K = INDEX(CBUFF(1:NCHS),'R')
      IF (K.GT.0) THEN
      LANSI = .TRUE.
      GO TO 40
      ENDIF
      ENDIF
      CALL WAIT ( 6, 0, J)
 20   CONTINUE
C
C     REPORT NOT FOUND (LANSI REMAINS .FALSE.)
      CALL CHRFN1
      RETURN
C
 40   CONTINUE
C     FLUSH BUFFER
      CALL WAIT (0, 5, J)
      CALL CHRRI1 (CBUFF, NCHS)
      CALL CHRFN1
      RETURN
      END
