C........................................................Dec.2012
C NEW!!!!!!!!!
C Extract map TEC, from daily IONEX file
      PROGRAM EXTMAPS1
C----------------------------------------------------------------
C Select NEW+++:Input 71 geographic latitudes: res1=87.5,85,,.0..-87.5N 
C at: NEW+++: 0,1,...,72 geographic longitudes [-180,-175,...,180] = IONEX step
C Produce maps fc & hc for 0, 1,..., 23hr UT.syr  
C
C*********TEST
	 integer ifcf2(71,0:72)
	CHARACTER*2 AYR,AMN,AUT,ADY
	CHARACTER*3 DDD
	DIMENSION GLATS(71),GLONS(0:72)
	 INTEGER*2 iyr,imn,nndy
	+,iut0
C**********TEST
      CHARACTER*128 INFILE,outfile

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

c--	DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
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
	start='START OF TEC MAP'
C
      WRITE(*,'(\A\)') ' ENTER name OF INPUT FILE='
      READ(*,'(A)') name
C
crem      WRITE(*,'(\A\)') ' ENTER YEAR OF INPUT FILE='
crem      READ(*,'(A)') AYEAR
	AYEAR='2013'  !ctemp
		ayr=ayear(3:4)
	read(ayr,*) ryr
	iyr=int(ryr)


crem      WRITE(*,'(\A\)') ' ENTER MN OF INPUT FILE='
crem      READ(*,'(A)') AMN
	amn='08'
	read(amn,*) xmn
	imn=int(xmn)

		WRITE(*,*) 'Enter ndy1 for input: '
 	read(*,987) nndy
  987	format(I2)
  988	format(A2)
	call blet2(nndy,ADY)

	lda=ndoy(iyr,imn,nndy)
	call blet3(lda,DDD)
C
		WRITE(*,*) 'Enter UT for input: '
 	read(*,988) AUT
C
	glat=-90.
	DO i=1,71
	glat=glat+2.5
	glats(i)=glat
	ENDDO
C
	glon=-195.
	do i=0,72
	glon=glon+5.0
	glons(i)=glon
	enddo
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

C
	IRUN=0 ! NORMAL COMMAND
	iut0=0 ! NORMAL COMMAND
C
c//	start='START OF'
	infile='nameDDD0.13i'  ! ionex type daily file
	infile(1:4)=name
	infile(5:7)=DDD
	infile(10:11)=ayr
	outfile='nameMMDDUT.13i'  !  map for given UT
	outfile(1:4)=name
	outfile(12:13)=ayr
	outfile(5:6)=amn
	outfile(7:8)=ady
	outfile(9:10)=aut

  118	format(A4)
cc	pause  ' '
C
C =========================================
c
	read(ayear,*) xyear
	IYYYY=int(xyear)
c
c outfile =================================
  80	continue
C++
	OPEN(111,FILE=INFILE,ACTION='READ')

   	do i=1,600					             !!
	READ (111,187,END=33,ERR=2) txt,txt1
  187	format(A60,A16)
	if (txt1.eq.start) goto 88
	enddo									 !!
  88	continue
	backspace(111)
C
   11	continue     ! day-to-day cycle >>>>>>>>>>>>>>>
C check availability of uhrg file:
   27 format(A60)

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

C Start of reading VTEC for UT ========================
  399		READ (111,187,END=33,ERR=2) txt,txt1
	if (txt1.ne.start) goto 399

  700 	read (111,89,end=9,err=85) ryear,rmn,rdy,rut
CADD++++++++++++++++++++++++++++++++++++++++++++++++
	if (rut(1:1).eq.' ') rut(1:1)='0'
	read(rut,*) xut
	iutk=int(xut)

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

   85	continue
      write(*,89) ryear,rmn,rdy,rut
	
	if (rut.ne.aut) goto 399 ! select map for goven UT >>>>>>>>>>>>>>
C
C Start input for given UT:++++++++++++++++++++
C
C =========================================
C
  701	jt=0
C
C 
  	ilat=0
D start cycle on glatitudes:
	glati=90.0
	nnlat=72
C
	DO 777 lat=1,71	   ! Start cycle on glati ++++++++++++++++++++++++++++++++
		ilat=ilat+1   ! ilat=1 for 87.5
	glati=glati-2.5
	ALATI=glati        ! for iriplas
	 
c   77	DO kl=1,72                 ! cycle on latitudes
   87	read (111,90,end=9,err=2) glat,txt
   90	format(2X,F6.1,A60)
  91   	j1=0
C
C Add check of wrong TEC.le.0<=itec_pre +++++++++++++
C
	do j=1,4        
	j1=(j-1)*16
   1	READ (111,180,END=9,ERR=2) (ixx(i),i=1,16)
  180	format(16(1X,I4))
	do k=1,16
	itxx(j1+k-1)=ixx(k)
	enddo
	enddo			  ! start selection of 4 longitudes
	READ (111,179,END=9,ERR=2) (ixx(i),i=1,9)
  179	format(9(1X,I4))
	do k=1,9
	itxx(63+k)=ixx(k)
	enddo
CC
	nnlat=nnlat-1  ! Keep results for GLAT=87.5(-87.5) at nnlat=71(1)
	do kk=0,72
	ifcf2(nnlat,kk)=itxx(kk)
	enddo
C Select values for Long=-180,-165,...0,15,30,..,165,180!!!!!!!!!!!!:
C
	ii=-1
	 jj=71
C====================================================
	write(*,181) iutk,ALATI
  777	continue   ! End cycle of reading all GLATs
CREM	rgec(iut)=rgec(iut)+GECUT/1.0E+32

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

		OPEN(12,FILE=OUTFILE)
	DO nnlat=1,71
		write(12,182) (ifcf2(nnlat,k),k=0,72)
	ENDDO
 182	format(73(1X,I4))							
	close(unit=12)
c//	if (iut.lt.23) then
c//	READ (111,187,END=33,ERR=2) txt,txt1
c//	goto 11
c//	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=111)

c//  101 idy=idy+1
cc??/	irun=irun+1
	irun=0
c	pause ' '
c//	if ((idy.le.idy2).and.(idy1.lt.idy2)) then
c//	goto 80
c//	else
		goto 35	   ! end of calculations
c//	endif
C
c	write (*,888) alat,alon,aday
c  888	format(1X,' alat=',A3,' alon=',A3,' day=',A3)

    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***********************************************************
