      program laghpohkp0jm
C..Add Hpo peak for the day of Kpmax.............................................May 2022
C
      CHARACTER*64 infile,outfile,infileq,txt
	DIMENSION hp(0:23),kap(0:23)
C
      outfile='wuleshpokp3jm.txt'
	infile='wulessw0kp3jm.txt'
	infileq='hpo19952022.txt'
C
       OPEN(10,file=infile,action='READ')
       OPEN(11,file=outfile,access='APPEND')
C+	do k=1,30
C+	read(12,*) txt
C+	if (txt(1:4).eq.'1995') exit
C+	enddo
   30 format(1X,F8.3,1X,I3,3(1X,I2),1X,F4.1,4(1X,I3,1X,F6.2),1X,I3
     +,1X,F6.1,1X,I3,1X,I4)
   33 format(I4,2(1X,I2),1X,I2,32X,F7.3,1X,I4)
   31 format(I4,A64)
C
	DO k=0,23
	hp(k)=0.
	ENDDO
	ndy=0
C
	DO 41 iev=1,563
    	read(10,30,end=50) ryear,lda,imn,idy,itkp,xkpmax,jtwu,wumax
     +,jtwl,wlmin,jtwe,wemax,jtwp,wpmax,jtsw,swmax,isumkp,nn
CTEMP:
       ndy=nn-1
CREM	if (iev.lt.486) GOTO 41  !TEMP
C
C++ READ 1h hp
      iyear=int(ryear)
c	iyr=iyear-iyear/100*100
C
	OPEN(12,file=infileq,action='READ')
   1	read(12,31,end=55) kyear,txt
      IF (kyear.ne.iyear) then 
	goto 1
	ELSE
	backspace(12)
	ENDIF
C
	do kk=1,lda            !1
   	DO j=0,23					!3
	read(12,33,end=55) kyear,kmn,kdy,kut,hp(j),kap(j)
	 ENDDO						!3
	 enddo					  !1
   55	close(12)
C
C hpmax
      hpmax=0.
	hpsum=0.
	kapmax=0
	ithp=0
	do k=0,23
	hpsum=hpsum+hp(k)
	if (hp(k).gt.hpmax) then
	hpmax=hp(k)
	kapmax=kap(k)
	ithp=k
	endif
	enddo
	jthp=ithp-itkp
	hpav=hpsum/24.
C
C Output
      ndy=ndy+1
      write(*,32) ryear,lda,imn,idy,itkp,xkpmax,jtwu,wumax,jtwl,wlmin
	+,jtwe,wemax,jtwp,wpmax,jtsw,swmax,jthp,hpmax,hpav,kapmax,isumkp
     +,ndy
	write(11,32) ryear,lda,imn,idy,itkp,xkpmax,jtwu,wumax,jtwl,wlmin
	+,jtwe,wemax,jtwp,wpmax,jtsw,swmax,jthp,hpmax,hpav,kapmax,isumkp
     +,ndy
C
   41 continue
   32 format(1X,F8.3,1X,I3,3(1X,I2),1X,F4.1,4(1X,I3,1X,F6.2),1X,I3
     +,1X,F6.1,1X,I3,2F7.3,2(1X,I4),1X,I4)
   50	close(unit=10)
	close(unit=11)
	pause ' '
	STOP
	END