      subroutine subinterpw(glat,glon,syr,smn,sdy,sut,res)
C.................................................................Jun. 2022
C Gulyaeva Tamara <gulyaeva@izmiran.ru>
C
C Subroutine to interpolate data from IONEX maps (W-index weights)
C Input : fm='w' means Wc from GIM-W JPL file
C         glat - geographic latitute
C         glon - geographic longitude
C         syr - YEAR = '99' for 1999,'00' for 2000, etc.
C         smn - month
C         sdy - day of month
C         sut - hour, UT
C.................................................................
C Output : res - value of TEC (0.1TECU)
C 
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C Use fc,hc,tc interpolated from directories dts maps - update addresses for input file
C
	DIMENSION idat(0:72,71),weg(4)	  ! maps fcF2,hcF2,TEC
	CHARACTER*1 fm
	CHARACTER*2 syr,smn,sdy,sut
      CHARACTER*45 infilef
	DATA WEG/0.,0.6931,1.0986,1.3863/  ! =ln1, ln2, ln3, ln4
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C 
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	fm='w'   ! wc .jYR file
	read(syr,*) ryr
	iyr=int(ryr)
	read(sdy,*) rdy1
	 ndy1=int(rdy1)
	read(smn,*) rmn1
	imn1=int(rmn1)
C 
	infilef='d:\web\graf\dwc\YR\MN\ut\wcMNDDUT.jYR' ! input GIM-W
	infilef(17:18)=SYR
	infilef(20:21)=SMN
	infilef(36:37)=SYR
	infilef(28:29)=SMN
	infilef(30:31)=sdy
	infilef(32:33)=sut
 204	format(73(1X,I4))
C
	OPEN(10,FILE=INFILEF,action='READ')		

		do ilat=1,71
	read(10,204) (idat(k,ilat),k=0,72)	
	enddo
	close(unit=10)
C
C      interpolate for glat,glon
C Linear Interpolation   
	aglat=-90.
	swe=0.
	icnt=0
	res=0.
	res11=0.
	res12=0.
	res21=0.
	res22=0.
	do 161 ilat=1,70 ! select pair of lats-lines (k) & (k+1)
c	aglat=-87.5,-85,...,87.5
	aglat=-90.+2.5*ilat
	aglat2=aglat+2.5
C
	if ((glat.ge.aglat).and.(glat.le.aglat2)) then  !   <<<<1
C Select pair of longs embracing glong
      elat= 1.0+0.0001235*aglat**2	  ! AD
	elat2= 1.0+0.0001235*aglat2**2	  ! AD
	 clon=-185.
	along=glon
	if (along.ge.180.) along=along-360.0
	do j=0,71 ! select pair of longs (j) & (j+1)
	clon=clon+5.
	clon2=clon+5.
	if ((along.ge.clon).and.(along.lt.clon2)) then  ! +++2
	iad=idat(j,ilat)
	if (iad.gt.1) then
	res11=elat*weg(iad)*iad
	icnt=icnt+1
	endif
	iad=idat(j+1,ilat)
	if (iad.gt.1) then
	res12=elat*weg(iad)*iad
	icnt=icnt+1
	endif
      iad=idat(j,ilat+1)
	if (iad.gt.1) then
	res21=elat2*weg(iad)*iad
	icnt=icnt+1
	endif
      iad=idat(j+1,ilat+1)
	if (iad.gt.1) then
	res22=elat2*weg(iad)*iad
	icnt=icnt+1
	endif
C
	iad=idat(j,ilat)
	if (iad.lt.-1) then
	res11=elat*weg(-iad)*iad
	icnt=icnt+1
	endif
	iad=idat(j+1,ilat)
	if (iad.lt.-1) then
	res12=elat*weg(-iad)*iad
	icnt=icnt+1
	endif
      iad=idat(j,ilat+1)
	if (iad.lt.-1) then
	res21=elat2*weg(-iad)*iad
	icnt=icnt+1
	endif
      iad=idat(j+1,ilat+1)
	if (iad.lt.-1) then
	res22=elat2*weg(-iad)*iad
	icnt=icnt+1
	endif
C
	res1=res11+(res12-res11)/5.*(along-clon)
	res2=res21+(res22-res21)/5.*(along-clon)
	res=res1+(res2-res1)/2.5*(glat-aglat)
	endif											 ! +++2
	enddo	! end select pair of longs (j) & (j+1)
	exit
	endif											 !   <<<<1
  161 continue		   ! interpolation end
	close(unit=10)
	RETURN
	END