CC	
      SUBROUTINE SUBKPCAc
C..........................................................Dec 2023
C
C T.L.Gulyaeva.............................................Mar. 2014
C Using only kpyr.txt
C
C T.L.Gulyaeva.............................................Dec. 2009
C
      DIMENSION rxx(0:7),IM(12)
	 REAL rkp(0:366,0:7),prekp(0:7)
	 integer*2 iyr,imn,idy,ID1,ID2
	CHARACTER*2 AMN,DY1,DY2,dd1,dd2,AYR
	+,CYR,CMN,CDY
	+,SC,DY22
	CHARACTER*4	YEAR
	CHARACTER*1	Y1
	CHARACTER*36 infilekp
	CHARACTER*6 yymmdd
	CHARACTER(10) DD
	CHARACTER(5) ZZ
	CHARACTER(10) TT
	COMMON /FIKP/rkp,prekp
	COMMON /BL1/SC,YEAR,AYR,AMN,DY1,DY2,DD1,DD2,ID1,ID2,JF,JH,JT,DY22
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
		CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
 
C
	CYR=DD(3:4)
	 CMN=DD(5:6)
	CDY=DD(7:8)
	iflag=1   ! for current date
	if ((CYR.eq.AYR).and.(CMN.eq.AMN).and.(CDY.eq.DY2)) goto 123
	CYR=AYR
	CMN=AMN
	CDY=DY2
  123	DD2=DY2
  161     infilekp='c:\web\graf\2014\kpyr.txt'
  	infilekp(15:16)=AYR        ! 
	infilekp(20:21)=AYR        ! 
	do j=0,366
	do i=0,7
	rkp(j,i)=0.
	enddo
	enddo
C
	y1=AYR(2:2)
	read(AYR,*) ryr
	iyr=int(ryr)
	     	z1=iyr/4.0
      jz=int(z1)*4

      IF(jz.EQ.iyr) THEN
               IM(2)=29
					idnr=366
        ELSE
                IM(2)=28
	  	idnr=365
	       ENDIF

	read(amn,*) rmn
	imn=int(rmn)
	read(dd2,*) dend
	idy=int(dend)
	idend=int(dend)
C
	ldaend=ndoy(iyr,imn,idy)
	id1=idend

C
	OPEN(19,file=infilekp)
	icnt=-1
	do j=0,ldaend
	READ(19,100,err=139,end=101) yymmdd,(rxx(k),k=0,7)
  100 format(A6,6X,8(F2.1))
	goto 138
  139	write(*,*) 'No k-index file'
	pause ' '
      stop
  138 cnone=8
    	icnt=icnt+1
      do i=0,7
	if (rxx(i).gt.9.) then
	 cnone=cnone-1
	rxx(i)=10.
	endif
	rkp(j,i)=rxx(i)
	enddo
	enddo
  101 continue
      close(unit=19)

	goto 162
  30	close(unit=19)
 162     return
      end

C
C-----------------------------------------------------------------
C
      subroutine blet2(ilet,alet2)
c

	CHARACTER*1 IN(0:9)
	integer*2 ilet
	DATA IN/'0','1','2','3','4','5','6','7','8','9'/
	CHARACTER*2 alet2
	a2='00'
	j10=ilet/10
	j1=ilet-j10*10
    5	do i=0,9
	if (j10.eq.i) then
	alet2(1:1)=IN(i)
	endif
	enddo
   7	do i=0,9 
     	if (j1.eq.i) then
 	alet2(2:2)=IN(i)
	endif
	enddo 
	return
	end
C-----------------------------------------------------------------
C
      subroutine blet3(ilet,alet3)
c     nn=1,2,3,4 

	CHARACTER*1 IN(0:9)
	DATA IN/'0','1','2','3','4','5','6','7','8','9'/
	CHARACTER*3 alet3
	a3='000'
C
	j100=ilet/100
	      j10=(ilet-j100*100)/10
	j1=ilet-j100*100-j10*10
    3	do i=0,9
		if (j100.eq.i) then
	alet3(1:1)=IN(i)
	endif
	enddo
    5	do i=0,9
	if (j10.eq.i) then
	alet3(2:2)=IN(i)
	endif
	enddo
   7	do i=0,9 
     	if (j1.eq.i) then
 	alet3(3:3)=IN(i)
	endif
	enddo 
	return
	end
C-----------------------------------------------------------------
      integer function ndoy(iyr,imn,idy)
C To define day-of-year
C
	       DIMENSION IM(12)
	integer*2 iyr,imn,idy
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
	z1=iyr/4.0
      jz1=int(z1)*4
      IF(jz1.EQ.iyr) THEN
               IM(2)=29
        ELSE
                IM(2)=28
	       ENDIF
C Day-of-year LDA1
		mosum=0
      if(imn.gt.1) then
         do 1234 i=1,imn-1
1234    mosum=mosum+im(i)
         endif
      ndoy=mosum+idy	
	END FUNCTION
C ===============================================================
