10  COM D0,D1,S0,S1
20  REM*** THIS PROGRAM CREATES MONTH END SYSTEM USAGE FILES
30  REM*** FROM SYSTEM DAILY FILES.  UP TO 640 ACTIVE I.D.'S
40  REM*** PER SYSTEM CAN BE PROCESSED.
50  REM***
60  REM*** TIME FOR AN I.D. IS FROM LAST DAILY FILE.
70  REM*** DISC FOR AN I.D. IS AVERAGED OVER DAILY FILES.
80  REM***
90  DIM N$[10],U$[6],D$[5]
100  N$="0123456789"
110  U$="USFIL"
120  D$="F"
130  DIM U[640,3],X[3],Y[3]
140  FILES *,*
150  FOR I=S1 TO S0
160  REM*** D = COUNT OF EXISTING DAILY FILES FOR SYSTEM I.
170  D=0
180  REM*** CHECK STATUS OF SYSTEM I USAGE FILE.
190  U$[6,6]=N$[I+1,I+1]
200  ASSIGN U$,1,R8
210  IF R8=0 THEN 240
220  PRINT "FILE "U$" STATUS= "R8
230  STOP 
240  PRINT #1,1; END 
250  PRINT "SYSTEM "I
260  D$[2,2]=N$[I+1,I+1]
270  FOR J=D1 TO D0
280  T=999
290  REM*** ESTABLISH DAILY FILE NAME, ASSIGN, AND CHECK STATUS
300  X[1]=INT(J/100)
310  X[2]=INT((J-X[1]*100)/10)
320  X[3]=J-X[1]*100-X[2]*10
330  FOR J1=1 TO 3
340  D$[J1+2,J1+2]=N$[X[J1]+1,X[J1]+1]
350  NEXT J1
360  ASSIGN D$,2,R8
370  IF R8<3 THEN 410
390  PRINT "FILE "D$" STATUS ="R8
400  GOTO 1100
410  REM
420  PRINT "MERGING "D$
430  MAT U=ZER[640,3]
440  REM*** MERGE DAILY FILE AND USFIL TO U ARRAY
450  J2=X0=Y0=F0=0
460  READ #1,1
470  READ #2,2
480  IF  END #1 THEN 790
490  IF  END #2 THEN 890
500  MAT  READ #1;X
510  IF X[1]=0 THEN 790
520  X0=1
530  MAT  READ #2;Y
540  GOSUB 1240
550  Y0=1
560  IF X[1]<Y[1] THEN 640
570  IF Y[1]<X[1] THEN 730
580  GOSUB 1430
590  U[J2,1]=X[1]
600  U[J2,2]=Y[2]
610  U[J2,3]=X[3]+Y[3]
620  X0=Y0=0
630  GOTO 500
640  GOSUB 1430
650  U[J2,1]=X[1]
660  U[J2,2]=X[2]
670  U[J2,3]=X[3]
680  X0=0
690  MAT  READ #1;X
700  IF X[1]=0 THEN 790
710  X0=1
720  GOTO 560
730  GOSUB 1430
740  U[J2,1]=Y[1]
750  U[J2,2]=Y[2]
760  U[J2,3]=Y[3]
770  Y0=0
780  GOTO 530
790  REM*** EOF 1: FILL U WITH REMAINDER OF FILE 2.
800  IF  END #2 THEN 1000
810  IF Y0=0 THEN 860
820  GOSUB 1430
830  U[J2,1]=Y[1]
840  U[J2,2]=Y[2]
850  U[J2,3]=Y[3]
860  MAT  READ #2;Y
870  GOSUB 1240
880  GOTO 820
890  REM*** EOF 2: FILL U WITH REMAINDER OF FILE 1.
900  IF F0=0 THEN 1100
910  IF  END #1 THEN 1000
920  IF X0=0 THEN 970
930  GOSUB 1430
940  U[J2,1]=X[1]
950  U[J2,2]=X[2]
960  U[J2,3]=X[3]
970  MAT  READ #1;X
980  IF X[1]=0 THEN 1000
990  GOTO 930
1000  REM*** WRITE U ARRAY TO USFIL I
1010  IF F0=0 THEN 1100
1020  READ #1,1
1030  IF  END #1 THEN 1050
1040  GOTO 1070
1050  PRINT "FILE "U$" TOO SMALL. KIL AND RE-OPEN TO 15 RECORDS."
1060  STOP 
1070  MAT  PRINT #1;U
1080  PRINT #1; END 
1090  D=D+1
1100  NEXT J
1110  IF D=0 THEN 1220
1120  REM*** PUT EOF AFTER NON-ZERO DATA IN USFIL I.
1130  READ #1,1
1140  MAT  READ #1;U[J2,3]
1150  READ #1,1
1160  REM*** COMPUTE AVERAGE DISC
1170  FOR J1=1 TO J2
1180  U[J1,3]=U[J1,3]/D
1190  NEXT J1
1200  MAT  PRINT #1;U
1210  PRINT #1; END 
1220  NEXT I
1230  CHAIN "COMBIN"
1240  REM*** THIS GOSUB CHECKS VALIDITY OF DATA READ FROM DAILY FILE
1250  REM***
1260  REM*** I.D. SEQUENCE
1270  IF Y[1] <= T THEN 1360
1280  T=Y[1]
1290  REM*** I.D. MAGNITUDE
1300  IF Y[1]<1000 OR Y[1]>26999 THEN 1360
1310  REM*** TIME MAGNITUDE
1320  IF Y[2]<0 OR Y[2]>65000. THEN 1360
1330  REM*** DISC MAGNITUDE
1340  IF Y[3]<0 OR Y[3]>65000. THEN 1360
1350  GOTO 1400
1360  PRINT "ERROR IN FILE "D$
1370  PRINT "ID","TIME","DISC"
1380  PRINT Y[1],Y[2],Y[3]
1390  STOP 
1400  REM*** SET FLAG - DATA HAS BEEN RECEIVED FROM DAILY FILE D$.
1410  F0=1
1420  RETURN 
1430  REM*** THIS GOSUB HANDLES SUBSCRIPT OF U ARRAY
1440  REM*** DURING MERGE OF DAILY FILE AND USFIL I.
1450  J2=J2+1
1460  IF J2 <= 640 THEN 1490
1470  PRINT "TOO MUCH DATA FOR U ARRAY"
1480  STOP 
1490  RETURN 
1500  END 
