      subroutine subcursbc
C.........................................................Jan 2024
C use subroutine subssn1tau27 produce ssn1(tau27) and cov(tau27) for current day
C
C.........................................................Dec 2023
C.........................................................Mar 2022
C extract SSN2 F10.7 for d-1, d = current day
C
      use portlib
      CHARACTER*64 infissn,inficov,outssn,outcov,indate,infile1,infile2
	+,infipre,txt
	CHARACTER*4 AYEAR,AYEAR_pre
	CHARACTER*2 AYR,AMN,ADY,AYR_pre,AMN_pre,ADY_pre,BMN,BDY
C
   99	format(A4,2(1X,A2),1X,A4,2(1X,A2),2(1X,I3))		
C
	indate='c:/web/graf/date'    !!! Tamara !!!!!!!
C=	indate='/var/www/izmiran/ionosphere/weather/graf/date' !!! LIUBA !!!!!!!
C
	open(10,file=indate)
	read(10,99) AYEAR,AMN,ADY,AYEAR_pre,AMN_pre,ADY_pre,ldaend,lda_pre	  !MAR2022
	WRITE(*,*) 'YEAR, AMN, ADY = ',AYEAR, AMN, ADY,AYEAR_pre,AMN_pre
	+,ADY_pre,ldaend,lda_pre														  !MAR2022
	close(unit=10)													  !+
C
C Prediction_pre
      infipre='predict45d.txt'
	open(10,file=infipre)
	do k=1,3
	read(10,*) txt
	enddo
	read(10,*) ryearp,imnp,idyp,ssnp,covp
	close(unit=10)
C
	AYR=AYEAR(3:4)
	AYR_pre=AYEAR_pre(3:4)
	read(AYR,*) ryr
	kyr=int(ryr)
	kyear=2000+kyr
	read(AYR_pre,*) ryr_pre
	kyr_pre=int(ryr_pre)
	kyear_pre=2000+kyr_pre
	read(AMN,*) rmn
	kmn=int(rmn)
	read(AMN_pre,*) rmn_pre
	kmn_pre=int(rmn_pre)
	read(ADY,*) rdy2
	kdy2=int(rdy2)
	read(ADY_pre,*) rdy1
	kdy_pre=int(rdy1)
C
      covtau=0.
	ssntau=0.
      call subtau27c(KYEAR,kmn,kdy2,covtau,ssntau1)	 !SSN!(tau27),Cov(tau27)
	ssntau=ssntau1/0.7
C
       infile1='solphasessn25.txt'  ! SSN2 SC25
       infile2='solphasecov25.txt'  ! F10.7 SC25
	OPEN(13,file=infile1,action='READ')
	OPEN(14,file=infile2,action='READ')
      inficov='c:\web\graf\kpyear'
	infissn='c:\web\graf\2022\MN\YYMMDDsilso.txt'
C
	inficov(15:18)=AYEAR
	infissn(13:16)=AYEAR
	infissn(18:19)=AMN
	infissn(21:22)=AYR
	infissn(23:24)=AMN
	infissn(25:26)=ADY
	OPEN(15,file=infissn,action='READ')
	outssn=infile1
      outssn(15:17)='res'
	OPEN(16,file=outssn)
      OPEN(17,file=inficov,action='READ')
	outcov=infile2
	outcov(15:17)='res'
	OPEN(18,file=outcov)
   30 format(1X,F8.3,2(1X,A2),1X,F8.4,2(1X,F6.2))
   31 format(I4,2(1X,I2),1X,F8.3,1X,F3.0)
C
   1	read(13,*,end=51) xyears,imns,idys,xfis,xinds  !SSN2(solphase)
      iyears=int(xyears)
      if ((iyears.eq.kyear_pre).and.(imns.eq.kmn_pre).and.
	+(idys.eq.kdy_pre)) then 
      goto 2
	                    else
	 call blet2(imns,BMN)
       call blet2(idys,BDY)
	write(*,30) xyears,BMN,BDY,xfis,xinds
	write(16,30) xyears,BMN,BDY,xfis,xinds
	goto 1
	endif
   2	read(14,*,end=52) xyearc,imnc,idyc,xfic,xindc  !F10.7(solphase)
      iyearc=int(xyearc)
      if ((iyearc.eq.kyear_pre).and.(imnc.eq.kmn_pre).and
	+.(idyc.eq.kdy_pre)) then 
C+      goto 3
      goto 5
	                      else
	 call blet2(imnc,BMN)
       call blet2(idyc,BDY)
	write(*,30) xyearc,BMN,BDY,xfic,xindc
	write(18,30) xyearc,BMN,BDY,xfic,xindc
	goto 2
	endif
C
C F10.7....................................................
C
   5  iflags=0
         read(17,32,end=54) myrc,mmnc,mdyc,issn1,covm
	ssnm=issn1/0.7
      if ((myrc.eq.kyr_pre).and.(mmnc.eq.kmn_pre).and
	+.(mdyc.eq.kdy_pre)) then
	 	 call blet2(mmnc,BMN)
       call blet2(mdyc,BDY)	  
	write(*,30) xyearc,BMN,BDY,xfic,covm   !day_pre
	write(18,30) xyearc,BMN,BDY,xfic,covm	 !day_pre
	iflags=1
      read(14,*,end=52) xyearc,imnc,idyc,xfic,xindc  !F10.7(solphase)
      read(17,32,end=54) myrc,mmnc,mdyc,issn1,covm  ! cur_day	issn1
	ssnm=issn1/0.7
		iflags=2
C
 	goto 54
	                            else
	goto 5
	                    endif
  54	close(unit=17)
C
	covm=covtau
C		OPEN(17,file=infile1,action='READ')
C
C?      if (iflags.eq.1) then
C?	 covm=covp
C?	endif
	 	 call blet2(imnc,BMN)
       call blet2(idyc,BDY)	  
	write(*,30) xyearc,BMN,BDY,xfic,covm   !day_cur
	write(18,30) xyearc,BMN,BDY,xfic,covm	 !day_cur
   6   read(14,*,end=52) xyearc,BMN,BDY,xfic,xindc  !F10.7(solphase)
	write(*,30) xyearc,BMN,BDY,xfic,xindc
	write(18,30) xyearc,BMN,BDY,xfic,xindc
	goto 6
   52   close(unit=14)
      close(unit=18)
C
C read prec and current day indices
      OPEN(17,file=inficov,action='READ')
C	 SSN2.........................................................
   3  iflags=0
	if (AMN.eq.AMN_pre) then
      read(15,31,end=53) myears,mmns,mdys,yearm,ssnm
	else
            read(17,32,end=55) myrs,mmns,mdys,issn1,covm  ! cur_day	issn1
	myears=2000+myrs
C	ssnm=issn1/0.7
      ssn=ssntau
	endif
      if ((myears.eq.kyear_pre).and.(mmns.eq.kmn_pre).and
	+.(mdys.eq.kdy_pre)) then
	 call blet2(imns,BMN)
       call blet2(idys,BDY)
	write(*,30) xyears,BMN,BDY,xfis,ssnm   !day_pre
	write(16,30) xyears,BMN,BDY,xfis,ssnm	 !day_pre
	iflags=1
	read(13,*,end=51) xyears,imns,idys,xfis,xinds  !SSN2(solphase)
      read(15,31,end=57) myears,mmns,mdys,yearm,ssnm  ! cur_day
C   57	xinds=ssnm
   57	xinds=ssntau
   	iflags=2
	goto 53
	                    else
	goto 3
	                    endif
   53	close(unit=15)
   55	close(unit=17)
C
	ssnm=ssntau
C       if (iflags.eq.1) then
C      ssnm=ssnp
C	 endif 
	 call blet2(imns,BMN)
       call blet2(idys,BDY)
	 	write(*,30) xyears,BMN,BDY,xfis,ssnm   !day_cur
			write(16,30) xyears,BMN,BDY,xfis,ssnm	 !day_cur
   4	read(13,*,end=51) xyears,BMN,BDY,xfis,xinds  !SSN2(solphase)
	write(*,30) xyears,BMN,BDY,xfis,xinds
	write(16,30) xyears,BMN,BDY,xfis,xinds
      goto 4
   51	       close(unit=13)
      close(unit=16)
C
   32 format(3I2,56X,I3,F6.2)                        ! kpyear (cov)
	ISTATUS = RENAME (outssn,infile1)
      ISTATUS = RENAME (outcov,infile2)
C      pause ' '
	RETURN
	END