	PROGRAM GETDEV
C
C	Remove Device statistics and rectify them for graphing.
C
C	B. Z. Lederman	05-Jun-85
C
C	Program is needed only because production systems are started
C		with the wrong date and time and then the time is
C		re-set so that more than one record has the same date.
C
	IMPLICIT INTEGER (A-Z)
	DIMENSION TIME(3)
	INTEGER*4 NEW(6, 3), OLD(6, 3), DIF(6, 3)
	INTEGER*4 ANEW(18),  AOLD(18),  ADIF(18)
	INTEGER*4 IOCNT, WRDCNT, CYLCNT, DEV4(6), D4, T4
	LOGICAL*2 ABOFLG, FIRST
	BYTE DATE(8), FILNAM(64), DEVIN(6), DEVICE(4, 6), DB(4)
	BYTE INPUT(512), FILLER(18)
C
	DATA NEW, OLD / 18 * 0, 18 * 0 /
C
	COMMON / ABOCOM / ABOFLG
C
	EQUIVALENCE (INPUT(1), CODE), (INPUT(3), DATE), (INPUT(11), TIME),
     1		(INPUT(17), DEVIN), (INPUT(23), IOCNT),
     2		(INPUT(27), WRDCNT), (INPUT(39), CYLCNT)
	EQUIVALENCE (DEV4, DEVICE), (D4, DB)
	EQUIVALENCE (ANEW, NEW), (AOLD, OLD), (ADIF, DIF)
C
	CALL ABOINI
	FIRST = .TRUE.
	DEV = 0
	OTIME = 0
C
CC	WRITE (5, 100)
CC  100	FORMAT( '$ Input file name: ')
CC	READ (5, 110, END = 900) J, (FILNAM(I), I = 1, J)
CC  110	FORMAT( Q, 64A1)
CC	IF (J .LT. 64) J = J + 1
CC	FILNAM(J) = 0
C
CC	OPEN (UNIT = 1, FILE = FILNAM, STATUS = 'OLD', ERR = 810,
C
	OPEN (UNIT = 1, FILE = 'ACNTRN.SEQ', STATUS = 'OLD', ERR = 810,
     1		ORGANIZATION = 'SEQUENTIAL', FORM = 'UNFORMATTED',
     2		RECORDTYPE = 'VARIABLE', READONLY)
C
	OPEN (UNIT = 2, FILE = 'DEVCOR.SEQ', STATUS = 'NEW',
     1		ORGANIZATION = 'SEQUENTIAL', FORM = 'UNFORMATTED',
     2		ACCESS = 'SEQUENTIAL', RECL = 64,
     3		RECORDTYPE = 'VARIABLE',
     4		CARRIAGECONTROL = 'LIST')
C
C	Suppress error on input record too small
C
	CALL ERRSET (67, .TRUE., .FALSE., .TRUE., .FALSE.)
C
  200	IF (ABOFLG) GOTO 500
	READ (1, END = 500, ERR = 210) INPUT
C
  210	IF (CODE .NE. 21) GOTO 200
C
	NTIME = (TIME(1) * 60) + TIME(2)		! get hours and mints
	DO 220 I = 1, 4
	DB(I) = DEVIN(I)				! catch device name
  220	CONTINUE
C
CCC	write (5, 300) ntime, time, d4, iocnt, wrdcnt, cylcnt
CCC300	format( 2x, i6, 1x, i2, 2(':', i2.2), 1x, a4, 3(2x, i9))
C
	IF (FIRST) THEN					! first time through
		IF (OTIME .EQ. 0) OTIME = NTIME		! fix time
		IF (OTIME .EQ. NTIME) THEN		! still collecting
			DEV = DEV + 1			! next device
			IF (DEV .LE. 6) THEN		! still have room
				DEV4(DEV) = D4		! store name
				OLD(DEV, 1) = IOCNT	! store data
				OLD(DEV, 2) = WRDCNT
				OLD(DEV, 3) = CYLCNT
  230				CONTINUE
				MAXDEV = DEV		! number of devices
			ENDIF
		ELSE
			DO 235 I = 1, 18		! ready to write
			ANEW(I) = AOLD(I)
235			CONTINUE
			FIRST = .FALSE.			! not first set anymore
		ENDIF
	ENDIF
	IF (.NOT.FIRST) THEN
		IF (NTIME .NE. OTIME) THEN		! time to summarize
			DO 240 I = 1, 6
			T4 = NEW(I, 1) - OLD(I, 1)	! check I/O count
			DO 240 J = 1, 3			! for data items
			IF (T4 .GE. 0) THEN
				DIF(I, J) = NEW(I, J) - OLD(I, J) ! difference
			ELSE
				DIF(I, J) = OLD(I, J)	! reset
			ENDIF
			OLD(I, J) = NEW(I, J)
  240			CONTINUE
			OTIME = NTIME			! re-set time
			WRITE (2) DATE, TIME, FILLER, (DEV4(I),
     1				(DIF(I, J), J = 1, 3), I = 1, 6) ! output data
CCC
CCC	write (5, 700) time, (dev4(i), (dif(i, j), j = 1, 3), i = 1, 6)
CCC 700	format (1x / 1x i2, 2(':', i2.2), 6( / 1x, a4, 3(1x, i9)))
CCC
		ENDIF
C
		IF (NTIME .EQ. OTIME) THEN		! more data to store
			DO 280 I = 1, MAXDEV		! find matching device
			IF (D4 .EQ. DEV4(I)) THEN
				NEW(I, 1) = IOCNT	! store data
				NEW(I, 2) = WRDCNT
				NEW(I, 3) = CYLCNT
			ENDIF
  280			CONTINUE
		ENDIF
	ENDIF
C
	GOTO 200
C
  500	CLOSE (UNIT = 1)
	CLOSE (UNIT = 2)
	GOTO 900
C
  810	STOP '  Error opening input file.'
C
  900	STOP
C
	END