C........................................................May.2018
C........................................................
C Gulyaeva Tamara <gulyaeva@izmiran.ru>
C
C Extract 15-min maps TEC, from daily JPL-IONEX extended file
      PROGRAM EXTMAPTI
C----------------------------------------------------------------
C Select :Input 71 geographic latitudes: res1=87.5,85,,.0..-87.5N 
C at: 0,1,...,72 geographic longitudes [-180,-175,...,180] = IONEX step
C Produce maps fc (foF2),  hc (hmF2), tc (TEC) for 0, 1,..., 23hr UT.syr  
C
C*********TEST
	 integer ifcf2(180,0:359)
	CHARACTER*2 AYR,AMN,DY1,DY2
	CHARACTER*3 DOY
	DIMENSION GLATS(180),GLONS(0:359)
	 INTEGER*2 iyr,imn,idy,nndy,iut,ndyend
	+,iut0
C**********TEST
      CHARACTER*80 INFILE,outfile

	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*4 AYEAR,RYEAR
	CHARACTER*60 txt
	character*2 rmn,rdy,ady,ady0,RUT,rmm
	character*16 start,txt1
	integer*4 ixx(16)
	dimension itxx(0:359)

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(*,'(\A\)') ' ENTER YEAR OF INPUT FILE='
      READ(*,'(A)') AYEAR
C	AYEAR='2018' !temp
	write(*,*) ' Year=',AYEAR
		ayr=ayear(3:4)
      WRITE(*,'(\A\)') ' ENTER MN OF INPUT FILE='
      READ(*,'(A)') AMN
C	AMN='04' ! temp
	write(*,*) ' MN=',AMN

		WRITE(*,*) 'Enter ndy1, ndy2 for input: '
 	read(*,987) nndy,ndyend
  987	format(I2)
	call blet2(nndy,DY1)
	call blet2(ndyend,DY2)
	ady0=DY1
C
C
	glat=-90.5
	DO i=1,180
	glat=glat+1.0
	glats(i)=glat
	ENDDO
C
	glon=-180.5
	do i=0,359
	glon=glon+1.0
	glons(i)=glon
	enddo
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

C
	IRUN=0 ! NORMAL COMMAND
	iut0=0 ! NORMAL COMMAND
C
c
	start='START OF TEC MAP'
C
	infile='c:\web\dti\year\jpliDDD0.YRi'  ! ionex extended type daily file
	outfile='c:\web\dti\year\mn\timndyutmm.jyr'  ! one map file
	infile(12:15)=ayear
	infile(26:27)=ayr

	outfile(12:15)=ayear
	outfile(17:18)=amn
	outfile(22:23)=amn
	outfile(32:33)=ayr

  118	format(A4)
cc	pause  ' '
C
C =========================================
c
	read(ayear,*) xyear
	IYYYY=int(xyear)
	read(ayr,*) xyr
	iyr=int(xyr)
c
	read(amn,*) xmn
	imn=int(xmn)
CC
	write(*,199) dy1
  199	format(' day=',A2)

	read(dy1,*) xdy
	idy1=int(xdy)
	read(dy2,*) xdy2
	idy2=int(xdy2)

c outfiles =================================
	idy=idy1
  80	call blet2(idy,ADY)
	outfile(24:25)=ady
	 lda=ndoy(iyr,imn,idy)
	call blet3(lda,DOY)
	   infile(21:23)=doy
C++
	OPEN(11,FILE=INFILE,ACTION='READ')

   	do i=1,1200					             !!
	READ (11,187,END=33,ERR=2) txt,txt1
  187	format(A60,A16)
	if (txt1.eq.start) goto 88
	enddo									 !!
  88	continue

C
   11	continue     ! day-to-day cycle >>>>>>>>>>>>>>>
C
   27 format(A60)

C
c ***************************************************************
D start cycle on hr-to-hr input:

C Start of reading VTEC, for UT ========================
  700 	read (11,89,end=9,err=85) ryear,rmn,rdy,rut,rmm
CADD++++++++++++++++++++++++++++++++++++++++++++++++
	if (rut(1:1).eq.' ') rut(1:1)='0'
	read(rut,*) xut
	iut=int(xut)

	if (rmm(1:1).eq.' ') rmm(1:1)='0'
	read(rmm,*) xmm
	imm=int(xmm)

	outfile(26:27)=rut
	outfile(28:29)=rmm

   89 format(2X,A4,4X,A2,4X,A2,4X,A2,4X,A2)

   85	continue
      write(*,89) ryear,amn,rdy,rut,rmm
	

C
C Start input for given UT and MM:++++++++++++++++++++
C
C =========================================
C
	jt=0
C
C 
  	ilat=0
D start cycle on glatitudes:
	glati=90.5
	nnlat=181
C
	DO 777 lat=1,180	   ! Start cycle on glati ++++++++++++++++++++++++++++++++
		ilat=ilat+1   ! ilat=1 for 89.5
	glati=glati-1.0
	ALATI=glati        ! for iriplas
	 
c
   87	read (11,90,end=9,err=2) glat,txt
   90	format(2X,F6.1,A60)
  91   	j1=0
C
C
	do j=1,22        
	j1=(j-1)*16
   1	READ (11,180,END=9,ERR=2) (ixx(i),i=1,16)
  180	format(16(1X,I4))
	do k=1,16
crem	if (ixx(k).le.0) ixx(k)=20
	itxx(j1+k-1)=ixx(k)
	enddo
	enddo			  ! start selection of 4 longitudes
	READ (11,179,END=9,ERR=2) (ixx(i),i=1,8)
  179	format(8(1X,I4))
	do k=1,8
crem	if (ixx(k).le.0) ixx(k)=20
	itxx(351+k)=ixx(k)
	enddo
CC
	nnlat=nnlat-1  ! Keep results for GLAT=89.5(-89.5) at nnlat=180(1)
	do kk=0,359
	ifcf2(nnlat,kk)=itxx(kk)
	enddo
C Select values for Long=-180,-165,...0,15,30,..,165,180!!!!!!!!!!!!:
C
	ii=-1
	 jj=180
C====================================================
c//	write(*,181) iut,ALATI
  777	continue   ! End cycle of reading all GLATs

  181 format(2X,I2,2X,F5.1)
C
C ==================================================
C
C --------------- 
C Prepare output of results for nnlong=0,1,...,24

		OPEN(12,FILE=OUTFILE)
	DO nnlat=1,180
		write(12,182) (ifcf2(nnlat,k),k=0,359)
	ENDDO
 182	format(360(1X,I4))							
	close(unit=12)
 178	format(A60,A14)
	if (iut.lt.24) then
	READ (11,178,END=33,ERR=2) txt,txt1	  ! END OF TEC MAP
	READ (11,187,END=33,ERR=2) txt,txt1	  ! START OF TEC MAP
	if (txt1.eq.start) then
	goto 11
	else
	goto 33
	endif
	endif
	 
DD  775 continue   ! End calculation for given UT
C
    9	continue
C Continue to the next UT hr :
  32		irun=irun+1 
C

C 
   33	close(unit=11)

  101 idy=idy+1
	irun=0
c	pause ' '
	if ((idy.le.idy2).and.(idy1.lt.idy2)) then
	goto 80
	else
		goto 35	   ! end of calculations
	endif
C
    2 CONTINUE
      if (irun.eq.0) then
       write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
 	pause ' '
	goto 35
      endif

   35      write(*,*) infile,outfile
	write(*,*) irun
C temp
      pause ' ' 
      STOP
       END

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