      program cntssn0kp3
C...............................................Nov 2022
C cnt SSN=0
C
      CHARACTER*64 infile,outfile,infilekp,txt
	REAL rkp(0:7),xutm(0:7)
C
      infile='cntssn0.txt'
	infilekp='d:\Apkp\kpap\kpap19322022.txt'
	outfile='cntssn0kp3.txt'
	ndykp=0  
	icnt1=0	 ! 3<=Kp<4 
      icnt2=0	 ! 5<=Kp<6 
	icnt3=0	 ! Kp>=6 
	OPEN(10,file=infile,action='READ')
	OPEN(11,file=outfile)
   31 format(F8.3,1X,I3,2(1X,I2),1X,I4)
C
	OPEN(12,file=infilekp,action='READ')
	do k=1,36
	read(12,*) txt  ! title lines
	enddo
    2    read(12,*) kyear,kmn,kdy,hr3,hr3m,dys,dysm,rrkp,iap,inn
       	if (kyear.lt.1994) then 
		GOTO 2
	else
	backspace(12)
	endif
C
    1	read(10,31,end=50) ryear,lda,imn,idy,ndy
      iyear=int(ryear)
	 iyr=iyear-iyear/100*100
	lda=ndoy(iyr,imn,idy)
C
C
    3  read(12,*,end=51) kyear,kmn,kdy,hr3,hr3m,dys,dysm,rrkp,iap,inn
C
	IF ((kyear.eq.iyear).and.(kmn.eq.imn).and.(kdy.eq.idy).and.
	+(hr3.eq.0.0)) THEN                                           	!1
	backspace(12)
    	DO iut3=0,7
      read(12,*,end=51) kyear,kmn,kdy,hr3,xutm(iut3),dys,dysm,rkp(iut3)
	+,iap,inn
	ENDDO
C
   	xkpmax=0.
	do k=0,7
	if (rkp(k).gt.xkpmax) then	  !2
	xkpmax=rkp(k)
	utkpmax=xutm(k)
	endif						  !2
	enddo
   		  IF (xkpmax.gt.3.0) THEN	!3
C
       ndykp=ndykp+1
	if (xkpmax.lt.5.0) icnt1=icnt1+1
	if (xkpmax.ge.6.0) icnt3=icnt3+1
	write(*,32)	ryear,lda,imn,idy,utkpmax,xkpmax,ndykp
	write(11,32) ryear,lda,imn,idy,utkpmax,xkpmax,ndykp
	goto 1
	          ENDIF					 !3
	                  ELSE		  !1
	GOTO 3
	endif                          !1
      goto 1
   51	close(12)
   50 close(10)
      close(11)
   32 format(F8.3,1X,I3,2(1X,I2),1X,F4.1,1X,F6.3,1X,I4)
        write(*,*) icnt1,icnt3
	pause ' '
	STOP
	 END

     