      program addeqhpo0
C.............................................................................Oct 2022
C Hpo <3.0 SSN = 0 982 events
C....................................................
C..Add EQ daily Mmax, Dkm, Mav, glat,glon set, for the day of Kpmax...........May 2022
C
      CHARACTER*64 infile,outfile,infileq
		CHARACTER*4 AYEAR
	DIMENSION eqs(90),glats(90),glons(90),kmds(90),kms(90)
	+,kuts(90),kmms(90)
C
      outfile='cateqhpo0.txt'
	infile='cathpostrm0.txt'
	infileq='d:\Apkp\Equak\Obninsk\eqYEAR.txt'
C
       OPEN(10,file=infile,action='READ')
       OPEN(11,file=outfile)
   30 format(1X,F8.3,1X,I3,3(1X,I2),1X,F4.1,1X,F6.1,1X,F5.0,1X,I4)
   33 format(1X,F8.3,1X,I3,2(1X,I2),1X,F5.3,1X,I2,1X,F5.3,1X,I4)
   31 format(I4,A64)
C
	ndy=0
C
	DO 41 iev=1,982
    	read(10,30,end=50) ryear,lda,imn,idy,iut,hpomax,shp,apomax,nn
CTEMP:
C-       ndy=nn-1
C
      iyear=int(ryear)
	do k=1,90
	eqs(k)=0.0
	glats(k)=0.0
	glons(k)=0.0
	kmds(k)=0
	kms(k)=0
	enddo
	eqav=0.0
	aeqmax=0.0
	knum=0
	kk=0
	if (iyear.eq.2021) goto 2 ! no EQ file for 2021
C
C 
       call blet4(iyear,AYEAR)
	infileq(25:28)=AYEAR
 	OPEN(12,file=infileq,action='READ')
	kk=0
  1	read(12,*,end=55) kyear,kmn,kdy,dut,glat,glon,kmd,eqmag,knum
      if (kmn.gt.imn) goto 55
	      if ((kmn.eq.imn).and.(kdy.gt.idy)) goto 55
      if ((kmn.eq.imn).and.(kdy.eq.idy)) then
	kutmmss=nint(dut)
	kuth=int(kutmmss/10000.)
	rmmss=kutmmss-kuth*10000.
	kmm=int(rmmss/100.)
	rss=rmmss-kmm*100.
      rmm=kmm+rss/60.
	kmm=nint(rmm)
	kk=kk+1
	glats(kk)=glat
	glons(kk)=glon
	kmds(kk)=kmd
	eqs(kk)=eqmag
	kms(kk)=knum
	kuts(kk)=kuth
	kmms(kk)=kmm
	eqav=eqav+eqmag
	endif
C
	 goto 1
C
   55	close(12)
      eqav=eqav/kk
C
C select daily peak
	aeqmax=0.
        do jj=1,kk
	if (aeqmax.lt.eqs(jj)) then 
	aeqmax=eqs(jj)
	knum=kms(jj)
	jm=jj
	endif
	 enddo

C Output
    2  ndy=ndy+1
      write(*,32) ryear,lda,imn,idy,kuts(jm),kmms(jm),glats(jm)
	+,glons(jm),kmds(jm),aeqmax,eqav,kk,knum,ndy
	write(11,32) ryear,lda,imn,idy,kuts(jm),kmms(jm),glats(jm)
	+,glons(jm),kmds(jm),aeqmax,eqav,kk,knum,ndy
C
   41 continue
   32 format(1X,F8.3,1X,I3,4(1X,I2),2(1X,F6.2),1X,I4,2(1X,F4.1)
     +,3(1X,I4))
   50	close(unit=11)
	pause ' '
	STOP
	END