      program histkpapaa
C..............................................................Dec. 2019
C
      character*64 infile,outfile 
	character*4 AYEAR
	character*2 AYR
	dimension ithkp(5),icnkp(5),icnap(5),icnaa(5),minap(5),minaa(5)
	data ithkp/30,50,60,70,80/
	infile='d:/apkp/aa/aakpYEAR'
	outfile='histkpapaa.txt'
	OPEN(11,FILE=outfile)
C
		iyear=1963   !START+++++++++++++++++++++
	icntot=0
	do i=1,5
	icnkp(i)=0
	icnap(i)=0
	icnaa(i)=0
	minap(i)=0
	minaa(i)=0
	enddo
	do 400 KK=1,56	! 1964-2019
	iyear=iyear+1
	call blet4(iyear,AYEAR)
	ryear=float(iyear)
	AYR=AYEAR(3:4)
	read(ayr,*) ryr
	iyr=int(ryr)
		if(int(ryr/4.)*4.eq.iyr) THEN 
	ndnyr=366
	                          ELSE
	ndnyr=365
	ENDIF
	infile(18:19)=AYR
	if (iyear.lt.2000) then
	infile(16:17)='19'
	else
      infile(16:17)='20'
	endif
36	format(I4,3(1X,I2),1X,I2,2(1X,I3))
	OPEN(10,FILE=infile,action='READ')
    1 read(10,36,end=21) kyear,kmn,kdy,kut,kpind,iap,iaa
      icntot=icntot+1
C
	if (kpind.ge.ithkp(5)) then
	icnkp(5)=icnkp(5)+1
	icnap(5)=icnap(5)+1
	icnaa(5)=icnaa(5)+1
C	if (minap(5).gt.iap) minap(5)=minap(5)+iap
      minap(5)=minap(5)+iap
C	if (minaa(5).gt.iaa) minaa(5)=minaa(5)+iaa
      minaa(5)=minaa(5)+iaa
	      goto 1
	endif

C
	do k=1,4
	if ((kpind.ge.ithkp(k)).and.(kpind.lt.ithkp(k+1))) then
	icnkp(k)=icnkp(k)+1
	icnap(k)=icnap(k)+1
	icnaa(k)=icnaa(k)+1
C	if (minap(k).gt.iap) minap(k)=minap(k)+iap
      minap(k)=minap(k)+iap
C	if (minaa(k).gt.iaa) minaa(k)=minaa(k)+iaa
       minaa(k)=minaa(k)+iaa
	endif
	enddo
C
	goto 1
   21 close(unit=10)
 400  continue
C
       write(*,*) icntot
	 write(11,*) icntot
      do kk=1,5
	perkp=float(icnkp(kk))/icntot*100.0
      perap=float(icnap(kk))/icntot*100.0
	peraa=float(icnaa(kk))/icntot*100.0
	minap(kk)=minap(kk)/icnap(kk)
	minaa(kk)=minaa(kk)/icnaa(kk)
	write(*,35) ithkp(kk),icnkp(kk),perkp,minap(kk),icnap(kk),perap
	+,minaa(kk),icnaa(kk),peraa
	write(11,35) ithkp(kk),icnkp(kk),perkp,minap(kk),icnap(kk),perap
	+,minaa(kk),icnaa(kk),peraa
	enddo
   35 format(1X,3(1X,I3,1X,I8,1X,F7.2))
      pause ' '
	stop
	end

