      program readwulekp3jm
C.........................................................May. 2022
C Wu, WL, WE 3h indices based on JPL monthly median
C Enter dates of SSN=0 ,kp>=3 'kp3ssn0.txt'
C Output only data for kp >=3!!!!!!!!!!!!!!!!!!!!
C Arbitrary dates 3h WU,WL,WE
	DIMENSION IM(12),wneg(0:7),wpos(0:7),wran(0:7),xkp(0:7),xkp3(0:7)
	CHARACTER*2 AYR,AMN,ADY
	CHARACTER*64 infile,outfile,txt,infikp3 
	+,infilekp
		CHARACTER*4 AYEAR
            DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/

C-      infile='d:\web\graf\datw\qtcYR.txt'   ! 3hUT WU,WL,We
      infile='d:\web\graf\datm\wjmYR_3.txt'   ! 3hUT WU,WL,We 
	infilekp='d:\Apkp\kpap\kpYEAR'

	infikp3='kp3ssn0.txt'
	OPEN(13,file=infikp3,action='READ')

C      outfile='d:\web\graf\datw\wuleYRkp3.txt' 
Crem      outfile='d:\web\graf\datw\wulessn0kp3.txt'  !all 3h kp for days SSN=0
	    outfile='d:\web\graf\datm\wulessn0kp3jm.txt'  ! kp < 3 for days SSN=0
	OPEN(12,file=outfile,access='APPEND')

c-	WRITE(*,*)' ENTER AYEAR OF INPUT FILE=	'
c-	read(*,*) AYEAR
   31 format(3A2,6X,8(F2.1))
   32 format(3A2,8(1X,F4.2),8(1X,F5.2),8(1X,F4.2))
C+   33 format(3A2,1X,I2,3(1X,F6.2),2X,F3.1)
   33 format(1X,F8.3,1X,2A2,1X,I2,3(1X,F6.2),2X,F3.1)
   34 format(6X,3I2,8(2X,F2.1))
C
C cycle of SSN=0,kp < 3 days
         DO 150 iev=1,665
	read(13,34,end=3) iyr,imn,idy,xkp3
	call blet2(iyr,AYR)
	z1=iyr/4.0
      jz=int(z1)*4

      IF(jz.EQ.iyr) THEN
               IM(2)=29
	dnr=366.
        ELSE
                IM(2)=28
	  	dnr=365.
	       ENDIF
	del=1./dnr
	infile(21:22)=ayr
	AYEAR='2000'
      iyear=2000+iyr
	AYEAR(3:4)=AYR
	if (iyr.gt.30) then
	AYEAR(1:2)='19'
	iyear=1900+iyr
	endif
	infilekp(16:19)=Ayear
       call blet2(imn,AMN)
	mndy=im(imn)
C
      lda=ndoy(iyr,imn,idy)
C
	call blet2(idy,ADY)
	OPEN(10,file=infile,action='READ')
	read(10,*) txt ! title line
	OPEN(11,file=infilekp,action='READ')
	do jj=1,lda
      read(10,32) AYR,AMN,ADY,(wpos(k),k=0,7),(wneg(k),k=0,7)
	+,(wran(k),k=0,7)
      read(11,31) AYR,AMN,ADY,(xkp(k),k=0,7)
	enddo
      close(unit=10)
	close(unit=11)
C
C Output:
C
	do kk=0,7
	kut=kk*3
	if (xkp3(kk).gt.0.) then
	ryear=iyear+(lda-1)*del
C+	write(*,33) AYR,AMN,ADY,kut,wpos(kk),wneg(kk),wran(kk),xkp(kk)
C+	write(12,33) AYR,AMN,ADY,kut,wpos(kk),wneg(kk),wran(kk),xkp(kk)
	write(*,33) ryear,AMN,ADY,kut,wpos(kk),wneg(kk),wran(kk),xkp(kk)
	write(12,33) ryear,AMN,ADY,kut,wpos(kk),wneg(kk),wran(kk),xkp(kk)
	endif
	enddo
  150 CONTINUE
    3	close(unit=13)
    2      close(unit=12)
	pause ' '
	STOP
	END