	PROGRAM TRACEQ

C	THIS PROGRAM WILL TRACE THROUGH AN ENTIRE MSG ID QUEUE AND DISPLAY
C	THE NUMBER OF ALL MESSAGE BLOCKS USED AND THE LINKS.  WHEN FINISHED,
C	IT WILL DISPLAY THE TOTAL BLOCK COUNT AND TOTAL MESSAGE COUNT.
C	THE USER IS ASKED TO ENTER THE STARTING BLOCK NUMBER (OBTAINED
C	FROM THE QMT/DID/ID:message_id SWITCH) AND THE TOTAL NUMBER
C	OF BLOCKS USED BY THE QUEUE HEADER.

	PARAMETER	ILUN = 1	

	INTEGER * 2	START			! FIRST BLOCK TO READ
	INTEGER * 2	HEADER			! NUMBER OF QUEUE HEADER BLOCKS
	INTEGER * 2	BLOCK(256)		! CONTENTS OF ONE DISK BLOCK
	INTEGER * 2	RECNBR			! BLOCK NUMBER TO READ
	INTEGER * 2	BLKCNT			! NUMBER OF BLOCKS USED
	INTEGER * 2	MSGCNT			! NUMBER OF MESSAGES FOUND


	OPEN (UNIT=ILUN,FILE='QU0:[7,5]MAQUEUE.DAT',
	1     ERR=9000,ACCESS='DIRECT',STATUS='OLD',
	2     RECL=128,FORM='UNFORMATTED',ORGANIZATION=
	3     'SEQUENTIAL',CARRIAGECONTROL='NONE',
	4     RECORDTYPE='FIXED')

	WRITE (5,1000)
1000	FORMAT('$ENTER STARTING BLOCK NUMBER > ')
	READ  (5,1010,END=9500) START
1010	FORMAT(I5)
	WRITE (5,1020)
1020	FORMAT('$ENTER SIZE OF QUEUE HEADER IN BLOCKS > ')
	READ  (5,1030,END=9500) HEADER
1030	FORMAT(I5)
	
	MSGCNT = 0
	BLKCNT = 0

	RECNBR = START + HEADER
1050	READ (ILUN'RECNBR,ERR=9010) BLOCK	! READ MESSAGE BLOCK

	IF (BLOCK(255).NE.0) THEN		! NOT LAST BLOCK OF MESSAGE
		RECNBR = RECNBR - HEADER	
		WRITE (5,1100) RECNBR,BLOCK(255),BLOCK(256)
1100		FORMAT(' BLOCK NBR = ',I5.5,'   NEXT BLOCK MSG = ',I5.5,
	1	       '   FIRST BLOCK NEXT MSG = ',I5.5)
		RECNBR = BLOCK(255) + HEADER
		BLKCNT = BLKCNT + 1		! INCREMENT TOTAL BLOCK COUNT
	ELSE IF (BLOCK(256).NE.0) THEN		! LAST BLOCK OF MESSAGE
		RECNBR = RECNBR - HEADER
		WRITE (5,1110) RECNBR,BLOCK(255),BLOCK(256)
1110		FORMAT(' BLOCK NBR = ',I5.5,'   NEXT BLOCK MSG = ',I5.5,
	1	       '   FIRST BLOCK NEXT MSG = ',I5.5)
		RECNBR = BLOCK(256) + HEADER	
		BLKCNT = BLKCNT + 1		! INCREMENT TOTAL BLOCK COUNT
		MSGCNT = MSGCNT + 1		! INCREMENT TOTAL MSG COUNT
	ELSE 					! LAST MESSAGE IN QUEUE
		RECNBR = RECNBR - HEADER
		WRITE (5,1120) RECNBR,BLOCK(255),BLOCK(256)
1120		FORMAT(' BLOCK NBR = ',I5.5,'   NEXT BLOCK MSG = ',I5.5,
	1	       '   FIRST BLOCK NEXT MSG = ',I5.5)
		BLKCNT = BLKCNT + 1		! INCREMENT TOTAL BLOCK COUNT
		MSGCNT = MSGCNT + 1		! INCREMENT TOTAL MSG COUNT
		WRITE (5,1130) BLKCNT,MSGCNT
1130		FORMAT(/' END OF TRACE....  BLOCK COUNT: ',I5.5,
	1		'  MESSAGE COUNT: ',I5.5)
		CALL EXIT			! FINISHED, SO EXIT
	END IF

	GOTO 1050				! READ NEXT BLOCK

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

9010	WRITE (5,9015)
9015	FORMAT(' ERROR READING FILE')
	CALL EXIT

9500	CONTINUE	
	END
