C******************** START FILE UERMSG.FOR ; GROUP URDUTS ******************
C-----------------------------------------------------------
C&  UERMSG UREAD WRITE ERROR MESSAGE, FLUSH TYPEAHEAD, ...
C
C  WRITE OUT ERROR MESSAGE
C
      SUBROUTINE UERMSG(TEXT,ITEM,ICOD)
      CHARACTER*(*) TEXT
      CHARACTER*(*) ITEM
C
      INCLUDE 'USERIO'
C
      CHARACTER*72 ZBUFF
C
C  TEXT - TEXT OF MESSAGE
C  ITEM - ITEM CAUSING MESAGE (IF NONBLANK)
C
C  ICOD:  =-1: CLEAR PAGE BEFORE WRITING MESSAGE
C         =0: NO PAGE CLEAR, NO UPAUST CALL
C         =1: CALL UPAUST(0)
C         =2: CALL UPAUST(1)
C
      IF(ICOD.LT.0) CALL NEUPAG
C
      ILT=ILNURD(ITEM)
C
      IF(ITEM(1:ILT).EQ.' ') THEN
        WRITE(LUNTRM,1001) TEXT
 1001 FORMAT(1X,A)
      ELSE
C
        ILTOT=LEN(TEXT)+ILT
        IF(ILTOT.LT.72) THEN
          WRITE(LUNTRM,1002) TEXT,ITEM(1:ILT)
        ELSE
          WRITE(LUNTRM,1004) TEXT,ITEM(1:ILT)
        ENDIF
 1002 FORMAT(1X,A,':  ',A)
 1004 FORMAT(1X,A,':'/1X,A)
      ENDIF
C--------------
      CALL URDBUF(ZBUFF,ILBUF,1)
      IF(NLINDI.AND.(NCHARA.GT.0)) WRITE(LUNTRM,1005) ABUFF(1:NCHARA)
      IF(ILBUF.GT.0) WRITE(LUNTRM,1003) ZBUFF(1:ILBUF)
 1003 FORMAT(' USER TYPEAHEAD BUFFER CONTENTS:'/1X,A)
 1005 FORMAT(' PROGRAM PROMPT WAS:'/1X,A)
C--------------
      IF(ICOD.LE.0) GO TO 100
      IPAUSE=ICOD-1
      CALL UPAUST(IPAUSE)
C  FLUSH BUFFER
 100  CONTINUE
      CALL UCLEAR
      RETURN
      END
C******************** END FILE UERMSG.FOR ; GROUP URDUTS ******************
