C........................................................Feb.2019
C Extract fixed TEC or Vs-index from JPLi 15-min files (1 x 1 deg)
C longs=-179.5:1:179.5
C lats -89.5:1:89.5
C input TEC; D:\UTEC\YEAR\MN\tiMNDDUTMM.jYR> IONEXi files
C       Vs : D:\web\drs\YR\MN\vlMNDDUTMM.jYR index file
C output <tvGLATGLONG.jYR>
C 
      PROGRAM decodjpli
C----------------------------------------------------------------
C
      integer itec(360),ivs(360)
C
	CHARACTER*2 AYR,AMN,ADY,AUT,AMM
	CHARACTER*4 AGLAT,AGLON
	CHARACTER*5 AGLONG
      CHARACTER*128 INFILET,INFILEV,OUTFILE
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
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+       WRITE(*,*) ' Enter glati: '
C+	read(*,*) glat
C+       WRITE(*,*) ' Enter glong: '
C+	read(*,*) glon
C Temp
C+       glat=55.1 !Obninsk mobn
C+	glon=36.6  !Obninsk mobn
C+       glat=39.9 !Ankara ankr
C+	glon=32.8  !Ankara ankr
C+       glat=35.1 !Nicosia nico
C+	glon=33.4  !Obninsk nico
C+       glat=35.7 !Koganei kgni
C+	glon=139.5  !Koganei kgni
C+       glat=-14.38 !Katherine kate
C+	glon=132.15  !Katherine kate
C+       glat=-20.98 !Karratha karr
C+	glon=117.1  !Karratha karr
C+       glat=69.66 !Tromso tro1
C+	glon=18.94  !Tromso tro1
       glat=32.8 !Haifa bshm
	glon=35.0  !Haifa bshm

	iglat=int(glat*10.)
	iglon=int(glon*10.)
C
	if (iglat.lt.0) then 
	mglat=-iglat
	call blet4(mglat,AGLAT)
	AGLAT(1:1)='-'
	else
	call blet4(iglat,AGLAT)
	AGLAT(1:1)='x'
	      endif
 	if (iglon.lt.0) then 
 	mglon=-iglon
	call blet4(mglon,AGLON)
	AGLONG(1:1)='-'
	AGLONG(2:5)=AGLON
	else
	call blet4(iglon,AGLON)
	AGLONG(1:1)='x'
	AGLONG(2:5)=AGLON
	      endif
C 
       WRITE(*,*) ' Enter YR: '
	read(*,*) AYR
       WRITE(*,*) ' Enter MN: '
	read(*,*) AMN
       WRITE(*,*) ' Enter iDY1,iDY2: '
	read(*,*) idy1,idy2
C
 	outfile='tvGLATGLONG.jYR'
	outfile(3:6)=AGLAT
	outfile(7:11)=AGLONG
	outfile(14:15)=AYR
C
   30 FORMAT(1X,2A2,2(1X,I2),2(1X,F6.1))
   31 FORMAT(360(1X,I4))
   32 FORMAT(1X,5A2,1X,F5.1,1X,I4)
C
	OPEN(10,file=outfile)
	WRITE(*,30) AYR,AMN,idy1,idy2,glat,glon
	WRITE(10,30) AYR,AMN,idy1,idy2,glat,glon

	infilet='D:\UTEC\20YR\MN\tiMNDDUTMM.jYR'
	infilev='D:\web\drs\YR\MN\vlMNDDUTMM.jYR'
	infilet(11:12)=AYR
	infilet(14:15)=AMN
	infilet(19:20)=AMN
	infilet(29:30)=AYR
	infilev(12:13)=AYR
	infilev(15:16)=AMN
	infilev(20:21)=AMN
	infilev(30:31)=AYR
C
C day-to-day cycle
       DO 40 idy=idy1,idy2
	CALL blet2(idy,ADY)
	infilet(21:22)=ADY
	infilev(22:23)=ADY
C
C UT cycle
       DO 41 iut=0,23
	call blet2(iut,AUT)
	infilet(23:24)=AUT
	infilev(24:25)=AUT
C
C Min cycle
       DO 42 imm=0,45,15
c      imm=0
	call blet2(imm,AMM)
	infilet(25:26)=AMM
	infilev(26:27)=AMM

	OPEN(11,file=infilet,action='READ')
	OPEN(12,file=infilev,action='READ')
C
      xlat=-90.5
	coglat=90.0-glat
	coglon=360.-glon
C lati cycle
	DO nlat=1,180
	xlat=xlat+1.0
	coxlat=90.0-xlat
	read(11,31,end=45) itec
	read(12,31,end=46) ivs
	if (abs(coxlat-coglat).lt.0.5) then	!++
C
      xlon=-180.5
	DO nlon=1,360
	xlon=xlon+1.0
	coxlon=360.-xlon
	if (abs(coxlon-coglon).le.0.5) then  ! +++
	restec=itec(nlon)/10.
	iresvs=ivs(nlon)
	write(*,32) AYR,AMN,ADY,AUT,AMM,restec,iresvs
	write(10,32) AYR,AMN,ADY,AUT,AMM,restec,iresvs
      exit
	endif					! +++
	ENDDO
C
      exit
	 endif !++
	ENDDO
   42 CONTINUE
   45	 close(unit=11)
   46		 close(unit=13)
   41 CONTINUE

   40 CONTINUE
	close(unit=10)
C
   35      write(*,*) infilet,infilev,outfile
      pause ' ' 
      STOP
       END

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