	SUBROUTINE TIMRB (LUN)! NOTE BEGINNING OF TIMED INTERVAL
C
C Version:	'V04-000'
C
C****************************************************************************
C*									    *
C*  COPYRIGHT (c) 1978, 1980, 1982, 1984 BY				    *
C*  DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS.		    *
C*  ALL RIGHTS RESERVED.						    *
C* 									    *
C*  THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED   *
C*  ONLY IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE   *
C*  INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR  ANY  OTHER   *
C*  COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY   *
C*  OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE IS  HEREBY   *
C*  TRANSFERRED.							    *
C* 									    *
C*  THE INFORMATION IN THIS SOFTWARE IS  SUBJECT TO CHANGE WITHOUT NOTICE   *
C*  AND  SHOULD  NOT  BE  CONSTRUED AS  A COMMITMENT BY DIGITAL EQUIPMENT   *
C*  CORPORATION.							    *
C* 									    *
C*  DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE  OR  RELIABILITY OF ITS   *
C*  SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.		    *
C* 									    *
C*									    *
C****************************************************************************
C
C++
C FACILITY:	ERF, Errorlog Report Formatter
C 
C ABSTRACT:
C
C	Runtime statistics timing package.
C
C ENVIRONMENT:
C
C	VAX/VMS operating system, unprivileged, user mode.
C
C MODIFIED BY:
C	
C	V03-002	SAR0212		Sharon A. Reynolds	22-Mar-1984
C		Changed the carriage control in a format statement for
C		use with output file.
C
C	V03-001	JMG0010		Joel M. Gringorten	02-Feb-1984
C		Rewrote the error handling from GETJPI system service to
C		utilize LIB$SIGNAL, and the ERFMSG file.
C
C
C	SAVE CURRENT PROCESS STATISTICS IN VARIABLES IN COMMON
C	USAGE:
C		CALL TIMRB	!START OF TIMED INTERVAL
C
C	EQUATED SYMBOLS:
C
 
	COMMON /STAT_VARS/ T0,BUFIO,CPUTIME,DIRIO,PFLTS
	INTEGER*4 BUFIO,CPUTIME,DIRIO,PFLTS

	COMMON /JOB_PARAM/ LEN4A,BUFIO_CODE,BUFIO_ADR,ZERO,
	2		LEN4B,CPUTIME_CODE,CPUTIME_ADR,ZERO1,
	2		LEN4C,DIRIO_CODE,DIRIO_ADR,ZERO2,
	2		LEN4D,PFLTS_CODE,PFLTS_ADR,ZERO3,
	2		ZERO4
	BYTE		LUN
	INTEGER*2 LEN4A,LEN4B,LEN4C,LEN4D
	INTEGER*2 BUFIO_CODE,CPUTIME_CODE,DIRIO_CODE,PFLTS_CODE
	INTEGER*4 BUFIO_ADR,CPUTIME_ADR,DIRIO_ADR,PFLTS_ADR
	INTEGER*4 NEW_BUFIO,NEW_CPUTIME,NEW_DIRIO,NEW_PFLTS
	INTEGER*4 ZERO,ZERO1,ZERO2,ZERO3,ZERO4,SYS$GETJPI,STATUS

	LOGICAL*1	ERROR

	EXTERNAL	ERF_NOSTATS, ERF_GETJPIERR

C
C	**** NOTE THE FOLLOWING CODES ARE VMS SYMBOLLIC PARAMS.
C	.... THEY MAY CHANGE IN FUTURE VERSIONS OF VMS...BEWARE!
	DATA BUFIO_CODE /1036/		! JPI$_BUFIO
	DATA CPUTIME_CODE /1031/	! JPI$_CPUTIM
	DATA DIRIO_CODE /1035/		! JPI$_DIRIO
	DATA PFLTS_CODE /1034/		! JPI$_PAGEFLTS
	DATA LEN4A,LEN4B,LEN4C,LEN4D /4,4,4,4/
C
C
C	==================================================
	T0 = SECNDS(0.)
	BUFIO_ADR	= %LOC(BUFIO)
	CPUTIME_ADR	= %LOC(CPUTIME)
	DIRIO_ADR	= %LOC(DIRIO)
	PFLTS_ADR	= %LOC(PFLTS)

	ERROR = .FALSE.

	STATUS =  SYS$GETJPI(,,,LEN4A,,,)
	IF (.NOT. STATUS) THEN
	CALL LIB$SIGNAL(ERF_GETJPIERR,%VAL(0),%VAL(STATUS))

	ERROR = .TRUE.
	ENDIF

	RETURN

	ENTRY TIMRE (LUN)! PRINT EXECUTION STATISTICS FOR INTERVAL

C	USAGE:
C		CALL TIMRE	!END OF TIMED INTERVAL
C	
C	TIMRE OBTAINS PROCESS STATISTICS AND SUBTRACTS THE
C	BEGINNING-OF-INTERVAL STATISTICS RECORDED BY TIMRB.
C	THE INCREMENTAL VALUES ARE WRITTEN TO UNIT "TTY"
C	(FORTRAN UNIT 6).
	BUFIO_ADR	= %LOC(NEW_BUFIO)
	CPUTIME_ADR	= %LOC(NEW_CPUTIME)
	DIRIO_ADR	= %LOC(NEW_DIRIO)
	PFLTS_ADR	= %LOC(NEW_PFLTS)

C

	STATUS =  SYS$GETJPI(,,,LEN4A,,,)
	IF (.NOT. STATUS) THEN
	CALL LIB$SIGNAL(ERF_GETJPIERR,%VAL(0),%VAL(STATUS))

	ERROR = .TRUE.
	ENDIF
C

	CLKTIME = SECNDS(T0)

	CPUSECS = (NEW_CPUTIME-CPUTIME)/100.
	BUFIO = NEW_BUFIO - BUFIO
	DIRIO = NEW_DIRIO - DIRIO
	PFLTS = NEW_PFLTS - PFLTS

	IF (ERROR) THEN
	CALL LIB$SIGNAL(ERF_NOSTATS)
	
	ELSE

	CALL LINCHK (LUN,7)

	WRITE(LUN,110) CPUSECS,CLKTIME,PFLTS,DIRIO,BUFIO
110	FORMAT(' ','PROGRAM RUNTIME STATISTICS',//,
	1 ' ',T8,'TIMES IN SECONDS',T29,'  PAGE',T39,'DIRECT',T49,'BUFFERED'/,
	2 ' ',T12,'CPU  ELAPSED',T29,'FAULTS',T39,'   I/O',T49,'     I/O',//,
	3 ' ',T6,F9.1,F9.1,T25,I10,T39,I6,T49,I8,/)
	ENDIF

C	SAVE STATE FOR NEXT TIME AROUND
C	THE USER IS SUPPOSED TO CALL TIMRB AGAIN, BUT IN CASE HE DOESN'T ...

	T0 = SECNDS(0.)
	CPUTIME = NEW_CPUTIME
	BUFIO = NEW_BUFIO
	DIRIO = NEW_DIRIO
	PFLTS = NEW_PFLTS
	RETURN
	END
