C.........................................................Dec. 2016
C foF2 INPUT/OUTPUT files:   d:\web\dat1\stYRMN.txt    -4 title lines
      program extmisff2
	CHARACTER*2 AYR,AMN,ST,CC,ctxt(31,0:23),cres(0:23) ! Letter Characteristics
	DIMENSION iff2(31,0:23),ires(0:23),IM(12)
      CHARACTER*80 INFILE,OUTFILE,txt,ionex
	CHARACTER*128 title(4),titime
	CHARACTER*4 AYEAR,PARAM,TIT1,TIT2
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*1 fh
	CHARACTER*6 YRMNDY(31),YYMMDD
		DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
	fh='f'
C
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
	ionex='d:\web\dat1\YR\ionex.dat'
	write(*,*) ' Enter YR:'
	read(*,*) AYR
	ionex(13:14)=AYR
	OPEN(11,file=ionex,action='READ')
      read(11,*,ERR=981) lat0,dlat,nlat
      read(11,*,ERR=981) lon0,dlon,nlon
      read(11,*,ERR=981) hig0,dhig,nhig
	read(11,*,ERR=981) kyear,kmonth,kday,khour,iminute, tli,nt
	call blet2(kmonth,AMN)

			idayy=365
	      IM(2)=28			 
      if(kyear/4*4.eq.kyear) then
	  idayy=366
	   	 IM(2)=29
	 endif
	mndy=im(kmonth)
C
      read(11,*,ERR=981) txt
	read(11,*,ERR=981) txt
	read(11,*,ERR=981) txt
	read(11,*,ERR=981) txt
  101	format(F5.1,1X,F5.1,1X,A2)
  102	format(A128)
	infile='d:\web\dat1\YR\stYRMN.txt'
	infile(13:14)=AYR
	infile(18:19)=AYR
	infile(20:21)=AMN
C Read coords. & st
   1	read(11,101,end=982) glat,glon,st
C
C start reading infile in /dat1/:
      infile(16:17)=ST
	OPEN(12,file=infile,action='READ')
	DO i=1,4
	READ(12,102) title(i)
	ENDDO
	titime=' Date of issue: '
	titime(18:)=DD
	 titime(28:33),' Time='
	 title(34:)=TT
	title(2)=titime
      DO idy=1,MNDY
	read(12,103,end=980) YRMNDY(idy),(iff2(idy,k),ctxt(idy,k),k=0,23)
	enddo
  980 close(unit=12)
		OPEN(13,file=infile)  ! = outfile
	do i=1,4
	write(13,102) title(i)
	enddo
C
C Check and fill missed values:
	DO idy=1,mndy
	YYMMDD=YRMNDY(idy)
	BYR=YYMMDD(1:2)
	BMN=YYMMDD(3:4)
	BDY=YYMMDD(5:6)
	do iut=0,23
	 kfof2=iff2(idy,iut)
	if (kfof2.eq.0) then
	call subinterp4(fh,glat,glon,byr,bmn,bdy,rfof2)
	iff2(idy,iut)=nint(rfof2)
	cc=ctxt(idy,iut)
	cc(1:1)='/'
	ctxt(idy,iut)=cc
	endif
	enddo
C output filled foF2:
	write(*,103) YYMMDD,(iff2(idy,k),ctxt(idy,k),k=0,23)
	write(13,103) YYMMDD,(iff2(idy,k),ctxt(idy,k),k=0,23)
	ENDDO
  980 close(unit=13)
        GOTO 1 ! next ST
	goto 982
  981   write(*,*) ' Error in the input file'
  982   close(11)
      pause ' '
	STOP
	END
