C........................................................Dec.2020
C Cnt Monthly Occurrence kp<3 1932-2020
C 
C 
      PROGRAM cntkpq1
C
C----------------------------------------------------------------
C
	DIMENSION kpq(12),imon(12),IM(12)
     +,jkp(0:7)
C
	CHARACTER*2 AYR,AMN
	CHARACTER*4 AYEAR
C	+,DYR(1132),DMN(1132),DDY(1132),DUT(1132)
      CHARACTER*128 INFILE,outfilkp
c/     +,outfilap,outfilaa !kp,ap,aa
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
      DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
C++
C
      ICALLS=0
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
	infile='d:/apkp/kpap/kpYEAR' !kp, ap
C
	outfilkp='cntkpq1.txt' ! monthly number of 3h kp<3, %
	OPEN(11,FILE=OUTFILKP)
C
C
   28 format(1X,F8.3,3(1X,I2),3(1X,F6.0))
C Cycle on year ====================================================
C
	DO 177 iyear=1932,2020
       call blet4(iyear,AYEAR)
	ryear=float(iyear)
	infile(16:19)=AYEAR
	open(15,file=infile,action='READ')
c
 	z1=iyear/4.0
      jz=int(z1)*4

      IF(jz.EQ.iyear) THEN
               IM(2)=29
	ndnyr=366
        ELSE
                IM(2)=28
	  ndnyr=365
	       ENDIF
	dev=1./12.
 	do k=1,12
	imon(k)=0
	kpq(k)=0
c/	inap(k)=0
c/	inaa(k)=0
	enddo
	iyr=iyear-iyear/100*100
	call blet2(iyr,AYR)
C
C
   29 format(3I2,6X,8(I2))      
	DO 101 k=1,ndnyr
	read(15,29,end=102) jyr,jmn,jdy,(jkp(k),k=0,7)
	imon(jmn)=imon(jmn)+8
	  do i=0,7
	if (jkp(i).lt.30) then
	kpq(jmn)=kpq(jmn)+1
	endif
	  enddo
  101	CONTINUE
  102	close(unit=15)
C
         
        do imn=1,12
	call blet2(imn,AMN)
      pkp=float(kpq(imn))/imon(imn)*100.
	xyear=ryear+dev*(imn-1.)
  138 format(1X,F8.3,1X,A2,1X,F7.2)
C Output matrices:
 	write(*,138) xyear,amn,pkp
	write(11,138) xyear,amn,pkp
	enddo
  177	CONTINUE
   27 close(unit=11)
C
C
   35      write(*,*) infile
      pause ' ' 
      STOP
       END

C***********************************************************
