      program extkp3ssn0
C......................................................Aug. 2021
C extract Kp<3 for SSN2=0 1996-2021
C
      character*128 infilkp,outfile3,outfile0
      character*2 AYR,AMN,ADY
	character*4 AYEAR
	dimension inkp(0:7),inkp0(0:7),inkp3(0:7)
C
      infilkp='d:\apkp\kpap\kpYEAR'
	outfile3='kp3ssn0_.txt'
	outfile0='kp0ssn0_.txt'
      OPEN(12,file=outfile0,access='APPEND')
	OPEN(13,file=outfile3,access='APPEND')
	icnt0=0
	icnt3=0
C
C      DO 50 iyear=1996,2021
      DO 50 iyear=1954,1995
	call blet4(iyear,AYEAR)
	iyr=iyear-(iyear/100)*100
	AYR=AYEAR(3:4)
	infilkp(16:19)=AYEAR
	OPEN(10,file=infilkp,action='READ')

C
C
   30	format(3A2,6X,8(I2),34X,I3)
   31	format(1X,I4,1X,3A2,8(1X,I3))
   1	read(10,30,end=150) Ayr,Amn,Ady,inkp,issn
      if (issn.gt.0) GOTO 1
C exclude Kp >=3
       iflag0=0
   3   do j=0,7
       inkp0(j)=0
	inkp3(j)=0
         if (inkp(j).lt.30) then
	inkp0(j)=inkp(j)
	iflag0=iflag0+1
	                     else
	inkp3(j)=inkp(j)
	   endif
   	enddo
	if (iflag0.eq.8) then
		icnt0=icnt0+1
      write(*,31) icnt0,AYR,AMN,ADY,(inkp0(k),k=0,7)
	write(12,31) icnt0,AYR,AMN,ADY,(inkp0(k),k=0,7)
	                  else
	 icnt3=icnt3+1
      write(*,31) icnt3,AYR,AMN,ADY,(inkp3(k),k=0,7)
	write(13,31) icnt3,AYR,AMN,ADY,(inkp3(k),k=0,7)
	                  endif
	GOTO 1
  150 close(unit=10)
C
   50 CONTINUE
  151 close(unit=12)
      close(unit=13)
	pause ' '
	STOP
	END
