C******************************************************************************
	SUBROUTINE AK$TOTALS(ISTAT)
C******************************************************************************
C  AKTOTALS.FOR
C
C  written by:  M. Serrer
C  date:        March 1984
C
	INCLUDE 'AK.INC/NOLIST'
C
C_Open old and new AKCOUNT.TOT files, ie. create a new version which
C_contains all the info from the old file and the new info just
C_gathered.
C
	OPEN(UNIT=O_TOT_FIL,NAME='SYS$ACCOUNT:AKCOUNT.TOT',
     &	     STATUS='OLD',CARRIAGECONTROL='LIST',ERR=5)
   5	OPEN(UNIT=N_TOT_FIL,NAME='SYS$ACCOUNT:AKCOUNT.TOT',
     &	     STATUS='NEW',CARRIAGECONTROL='LIST')
C
C_Change old LAST_BLOCK identifier from 1 to -1
C
  10	READ(O_TOT_FIL,'(128A1)',END=20,ERR=20) (DUMMY_LOG(I),I=1,128)
	IF (DUMMY_LOG(1).EQ.1) DUMMY_LOG(1)=-1
C
C_Fix problem where AKCOUNT.TOT file may have null's in username or
C_account name by changing the nulls to spaces.  June 25/84 K. Trumbley
C
	IF (DUMMY_LOG(1).EQ.0) THEN
	  N=1
	  DO I=1,12
	    N=N+1
	    IF (DUMMY_LOG(N).EQ.0) DUMMY_LOG(N)=32
	  END DO
	  N=17
	  DO I=1,8
	    N=N+1
	    IF (DUMMY_LOG(N).EQ.0) DUMMY_LOG(N)=32
	  END DO
	END IF
	WRITE(N_TOT_FIL,'(128A1)') (DUMMY_LOG(I),I=1,128)
	GOTO 10
C
  20	CONTINUE
C
C_New LAST_BLOCK identifier is 1
C	
	AK$AKREC_TYP1=1
	CALL WRITE_FILE(AK$HEADER)
C
	AK$AKREC_TYP0=0
	DO I=1,TOT_USR
	  CALL WRITE_FILE(AK$SUMMARY(I))
	END DO
C
	CLOSE(UNIT=O_TOT_FIL,DISPOSE='DELETE')
	CLOSE(UNIT=N_TOT_FIL,DISPOSE='KEEP')
C
	RETURN
	END

C
C******************************************************************************
	SUBROUTINE WRITE_FILE(OUT_STR)
C******************************************************************************
C
	INCLUDE 'AK.INC/NOLIST'
C
	CHARACTER*128 OUT_STR
	EQUIVALENCE (DUMMY_LOG,DUMMY_STR)
C
	DUMMY_STR=OUT_STR
C
	WRITE(N_TOT_FIL,'(128A1)') (DUMMY_LOG(I),I=1,128)
C
	RETURN
	END
