      program readgecssn0
C.........................................................May. 2022
C Enter dates of SSN=0 , 'kpssn0.txt'
C Output only data for kp >=3!!!!!!!!!!!!!!!!!!!!
C
	DIMENSION IM(12),gec(0:23),igec(0:23)
	CHARACTER*2 AYR,AMN,ADY
	CHARACTER*64 infile,outfile,txt
	+,infikp
            DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/

      infile='d:\web\dat0\YR\eoYRMNj.txt'   ! GEC
	infikp='kpssn0.txt'

	OPEN(13,file=infikp,action='READ')
    1	read(13,30) nn,kyr,kmn,kdy,txt 
      if (kyr.lt.94) then 
	goto 1   ! start list SSN0 from 1994 to 2021 (GEC)
	else
	backspace(13)
	endif
	ndy=0
C
	    outfile='gecssn0.txt'  ! GEC(SSN=0)
	OPEN(12,file=outfile)

   30 format(1X,I4,1X,i2,2I2,A32)
c   32 format(3I2,24(1X,F4.2))
   32 format(3I2,24(1X,I4))
C
C cycle of SSN=0,kp>=3 days
    2 read(13,30,end=53) nn,iyr,imn,idy,txt     
C    
	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
		KYEAR=2000+iyr
	if (iyr.gt.30) KYEAR=1900+iyr
C
	infile(13:14)=ayr
	infile(18:19)=ayr
       call blet2(imn,AMN)
		infile(20:21)=amn
	OPEN(11,file=infile,action='READ')
	do k=1,4
	read(11,*) txt ! title line
	enddo
	mndy=im(imn)
C
      lda=ndoy(iyr,imn,idy)
	ryear=float(kyear)+(lda-1)*del
C
	call blet2(idy,ADY)
C
	DO jdy=1,mndy
      read(11,32,end=55) JYR,JMN,JDY,(igec(k),k=0,23)
      if (jdy.eq.idy) then
	 gecav=0.
	gecmax=0.
	  do k=0,23
	gec(k)=igec(k)/100.
	gecav=gecav+gec(k)
	if (gec(k).gt.gecmax) then
	gecmax=gec(k)
	kutgec=k
	endif
	  enddo
	gecav=gecav/24.
	exit
	              endif
	ENDDO
   55   close(unit=11)
C
C Output:
C
       ndy=ndy+1
	write(*,33) ryear,lda,AMN,ADY,gecav,kutgec,gecmax,ndy
	write(12,33) ryear,lda,AMN,ADY,gecav,kutgec,gecmax,ndy
      goto 2  ! next day SSN=0
   33 format(1X,F8.3,1X,I3,2(1X,A2),1X,F5.3,1X,I2,1X,F5.3,1X,I4)
C
   53	close(unit=13)
          close(unit=12)
	pause ' '
	STOP
	END