	PROGRAM QUELOG

C	THIS PROGRAM WILL WRITE ALL MESSAGES FROM TASK 'QUEACP' TO
C	THE FILE 'QUEACPMSG.DAT'.  PROGRAM 'CLSMSG' WILL CLOSE THE 
C	FILE SO THAT IT MAY BE EXAMINED AND WILL CAUSE THIS PROGRAM
C	TO EXIT.

	PARAMETER	FLUN = 1	! FILE 'QUEACPMSG.DAT' LUN
	PARAMETER	EFN = 1		! EVENT FLAG FOR RECV DATA AST

	INTEGER * 2	RECBUF(15)	! RECEIVE BUFFER
	CHARACTER*9	DATBUF		! DATE BUFFER
	CHARACTER*8	TIMBUF		! TIME BUFFER
	INTEGER * 2	TOTMSG		! COUNT OF TOTAL NBR OF MESGS WRITTEN
					!   TO MESSAGE FILE
	CHARACTER*6	TSKNAM		! ASCII NAME OF TASK THAT SENT DATA

	CALL RCVAST(EFN,IDS)		! SPECIFY RECEIVE DATA AST
	IF (IDS.LE.0) THEN		! BAD STATUS
		WRITE (5,50)
50		FORMAT(' BAD DIRECTIVE STATUS SPECIFYING',
	1	       ' RECEIVE AST... STATUS = ',I4)
		CALL EXIT
	END IF

	TOTMSG = 0			! INIT TOTAL MESG COUNTER

	OPEN (UNIT=FLUN,ERR=9000,FILE='QUEACPMSG.DAT',
	1     STATUS='NEW')

100	CONTINUE
	CALL CLREF(EFN)			
	CALL RECEIV(,RECBUF,,IDS)	! CHECK FOR DATA IN RECV QUEUE
	IF (IDS.GE.0) GOTO 120		! RECEIVED DATA
	CALL STOPFR(EFN)		! NO DATA IN RECV QUEUE, WAIT FOR MORE
	GOTO 100

120	CALL R50ASC(6,RECBUF,TSKNAM)	! CHANGE TASK NAME TO ASCII
	IF (TSKNAM.EQ.'CLSMSG') GOTO 1100	! CLOSE FILE, MSG FROM CLOSE
						!   TASK	

	CALL DATE(DATBUF)		! GET DATE AND TIME
	CALL TIME(TIMBUF)

C	IF MSG ID LISTHEAD DATA IS LOGGED, ERROR: 93, THE LISTHEAD DATA
C	IS IN THE FOLLOWING ORDER:
C		M.FLK, M.BLK, M.RNA, M.BNA, M.CNT, M.NVC, M.NVL, M.LST

	IF (RECBUF(3).EQ.'93') THEN
	   WRITE (FLUN,1000,ERR=9100) DATBUF,TIMBUF,(RECBUF(I),I=3,15)
1000	   FORMAT(1X,A9,2X,A8,2X,'QUEACP ERROR: ',A2,' STATUS: ',2A2,
	1         5X,2A2,2X,8(2X,I6.6))
	ELSE
	   WRITE (FLUN,1050,ERR=9100) DATBUF,TIMBUF,(RECBUF(I),I=3,7)
1050	   FORMAT(1X,A9,2X,A8,2X,'QUEACP ERROR: ',A2,' STATUS: ',2A2,
	1	  5X,2A2)
	END IF

	TOTMSG = TOTMSG + 1		! INCREMENT TOTAL NBR MESSAGES WRITTEN
					!   TO MESG FILE

	IF (TOTMSG.LT.8000) GOTO 100	! REOPEN FOR APPEND

1100	CLOSE (UNIT=FLUN)		! CLOSE FILE SO IT CAN BE EXAMINED
	CALL EXIT

9000	WRITE (5,9010) 
9010	FORMAT(' ERROR OPENING FILE')
	CALL EXIT

9100	WRITE (5,9110) 
9110	FORMAT(' ERROR WRITING TO FILE')
	CALL EXIT

	END
