      program exthpostrm0
C........................................................Oct. 2022
C Produce catalog og Hpo <3.0 = testing set
C........................................................Sep 2022
C Select Hpo >=3.0 storms at SSN = 0
C
      CHARACTER*120 infile,infhpo,outfile
	CHARACTER*2 AYR,AMN,ADY,AUT
		CHARACTER*4 AYEAR
	DIMENSION hpo(0:71),apo(0:71)
C
      infile='kpssn0.txt' 
	infhpo='d:\Apkp\Hpo\HpoYEAR.txt'       !integral Apo,Hpo ! read(15
C	outfile='cathpostrm3.txt'  
      	outfile='cathpostrm0.txt'  !Hpo <3
	OPEN(10,file=infile,action='READ')
	OPEN(12,file=outfile,access='APPEND')
C
   30	format(1X,I4,1X,3(A2))
   32 format(I4,2(1X,I2),1X,I2,32X,F7.3,1X,F4.0)	 ! Hpo,Apo
C
	ndy=0
C
	      DO 41 iev=1,3089
    1	read(10,30,end=51) nn,ayr,amn,ady
      read(ayr,*) ryr
	iyr=int(ryr)
	if (amn(1:1).eq.' ') AMN(1:1)='0'
      read(amn,*) rmn
	imn=int(rmn)
	if (ady(1:1).eq.' ') ADY(1:1)='0'
      read(ady,*) rdy
	idy=int(rdy)
      if ((iyr.lt.95).and.(ndy.eq.0)) goto 1
	if (iyr.lt.30) then
	iyear=2000+iyr
	         else
	iyear=1900+iyr
	       endif
C
      		z1=iyear/4.0
      jz=int(z1)*4		  
	      IF(jz.EQ.iyear) THEN
		  	dnr=366.
		  ELSE
                dnr=365.
		       ENDIF
	del=1./dnr
      lda=ndoy(iyr,imn,idy)
        ryear=iyear+(lda-1)*del
	DO k=0,71
	hpo(k)=0.
	apo(k)=0.
	ENDDO
C
       call blet4(iyear,AYEAR)
	infhpo(16:19)=AYEAR
	OPEN(15,file=infhpo,action='READ')
C Read Hpo Apo for given day d(SSN=0), d-1,d+1
        do lz=1,lda-1
          	DO j=0,23					
 	read(15,32,end=58) kyear,kmn,kdy,kut,hpo(j),apo(j)  ! d-1
	 ENDDO		
	  enddo
          	DO j=24,47					
 	read(15,32,end=58) kyear,kmn,kdy,kut,hpo(j),apo(j)	!d(Wpmax)
	 ENDDO		
          	DO j=48,71					
 	read(15,32,end=58) kyear,kmn,kdy,kut,hpo(j),apo(j)	!d+1
	 ENDDO		
   58	 close(15)
      hpomax=0.
	apomax=0.
	ithpo=0
       DO j=24,47
	if (hpomax.lt.hpo(j)) then
	hpomax=hpo(j)
	apomax=apo(j)
	ithpo=j-24
	endif
	 enddo
C
C_pre      IF (hpomax.lt.3.0) GOTO 41  ! No selected Hpo>=3.0 events
      IF (hpomax.ge.3.0) GOTO 41  ! No selected Hpo<3.0 events
C
C selected Hpo event
C0      it1=ithpo
C0	it2=ithpo+47
      it1=ithpo+12
	it2=it1+23
	shp=(hpo(it1)+hpo(it2))/2.  !SHpo for t(WPmax)+-24h
              DO j=it1+1,it2-1
	shp=shp+hpo(j)
	           enddo
C
C output catalog Hpo >=3:
      ndy=ndy+1
	call blet2(ithpo,AUT)
      write(*,31) ryear,lda,amn,ady,aut,hpomax,shp,apomax
     +,ndy
      write(12,31) ryear,lda,amn,ady,aut,hpomax,shp,apomax
     +,ndy
  41  CONTINUE
  31	format(1X,F8.3,1X,I3,3(1X,A2),1X,F4.1,1X,F6.1,1X,F5.0,1X,I4)
  51  close(10)
      close(12)
C
	pause ' '
	STOP
	END