      program exaphs0kp3
C.................................................Aug. 2022
C Extract Aph daily peak at SSN=0, Kp>=3 instead pf Kp index
C
C
      CHARACTER*64 infile, outfile,infilap
C	DIMENSION xhpo(0:23),imap(0:23)
C
      infile='wules0kp3jm.txt'
	outfile='exaphs0.txt'
	infilap='d:\Apkp\Hpo19952022.txt'
C
       OPEN(10,file=infile,action='READ')
       OPEN(11,file=infilap,action='READ')
      OPEN(12,file=outfile)
C
        DO 41 iev=1,548  ! Events
    	read(10,*,end=50) ryear,lda,imn,idy,tkp,xkpmax,twu,wumax,twl,wlmin
	+,twe,wemax,isumkp,ndy
	iyear=int(ryear)
    1	read(11,*,end=51) kyear,kmn,kdy,ut1,uth,xyr32,xhr32,hkpo,kapo,ki
      IF ((kyear.eq.iyear).and.(kmn.eq.imn).and.(kdy.eq.idy)) THEN
	hpomax=hpo
	kapmax=kapo
	iutmax=0
	DO kut=1,23 
	read(11,*,end=50) kyear,kmn,kdy,ut1,uth,xyr32,xhr32,hpo,kapo,ki
	if (kapmax.lt.kapo) then
	kapmax=kapo
	hpomax=hpo
	iutmax=kut
	endif
	ENDDO
	utmax=iutmax+0.5
      write(*,32) ryear,lda,imn,idy,utmax,hpomax,kapmax,ndy
      write(12,32) ryear,lda,imn,idy,utmax,hpomax,kapmax,ndy
	                                      ELSE
	GOTO 1
	ENDIF
   41 CONTINUE
   50 close(10)  
   51   close(11)
	close(12)
   32 format(1X,F8.3,1X,I3,2(1X,I2),1X,F4.1,1X,F6.3,2(1X,I4))
	pause ' '
	STOP
	END