      program cat1kp0int
C..Catalog 3h indices.....................................Sep 2022
C
C  Daily integral Skp for SSN=0,
C 
C
      CHARACTER*64 infile,outfile
	DIMENSION kp(0:7)
C
	infile='kpssn0.txt'
	outfile='cat0skp0int.txt'
C
       OPEN(10,file=infile,action='READ')
       OPEN(14,file=outfile,access='APPEND')
C
   30 format(1X,I4,1X,3I2,8(1X,I3))
   31 format(I4,A64)
   32 format(I4,2(1X,I2),1X,I2,32X,F7.3,1X,F4.0)
   33 format(3I2,24(1X,F4.2))
C
C
	ndy=0	!norm
C
      lda_out=0
C
C SSN=0 Kp all events
        DO 41 iev=1,3089  ! Events
C 
C
C_Apo    	read(10,*,end=50) ryear,lda,imn,idy,thpo,hpomax,iapo,nn
  101	read(10,30,end=59) nn,iyr,imn,idy,kp
C
       if (nn.le.3083) GOTO 41  !TEMP
	if (iyr.lt.30) then
	iyear=2000+iyr
	           else
	iyear=1900+iyr
	endif
		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
C
C Kpmax, Rkp
      kpmax=kp(0)
	itkp3=0
	skp=kp(0)/20.
              DO j=1,7
	skp=skp+kp(j)/10.
	if (kpmax.lt.kp(j)) then
	kpmax=kp(j)
	itkp3=j*3
	endif
	           enddo
	skp=(skp-kp(7)/20.)*3.0
	tkp3=itkp3+1.5
C
C Output Kp-3h results
        write(*,29) ryear,lda,imn,idy,tkp3,kpmax,skp,(kp(k),k=0,7),nn
      write(14,29) ryear,lda,imn,idy,tkp3,kpmax,skp,(kp(k),k=0,7),nn
C
   41 continue
   59	close(10)
C
   29 format(1X,F8.3,1X,I3,2(1X,I2),1X,F4.1,1X,I3,1X,F6.2,8(1X,I2)
     +,1X,I4)
   50	close(unit=14)
	pause ' '
	STOP
	END