      program extrma5j
C................................................Sep. 2013
C Extract JPL TEC map for glat=-87.5.-85,...,85,87.5  (71 lines)
C                         glon=0, 5, 10, ..., 355, 360 (0:72 columns)
C 
C
C
C ...............................................Jan. 2013
C extract-interpolate from JPL-TEC or W-index map in IONEX format
C
	CHARACTER*2 AYR,AMN,ADY,AUT
	CHARACTER*1 fm
	CHARACTER*65 outfile,infile,txt
	INTEGER*2 jyr,jmn,jdy1,jdy2,jdy,jut
	DIMENSION im(12),itec(71,0:72)
	+,ixx(16)
	DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
  103	nn=1
  	fm='f'
C	nn=4		!
C	fm='w'
  102	format(73(1X,I4))
  101	format(73(1X,F5.1))
C
	write(*,*) 'enter AYR='
	read(*,*) AYR
	write(*,*) 'enter AMN='
	read(*,*) amn
C
 	read(ayr,*) ryr
	jyr=int(ryr)
	read(amn,*) rmn
	jmn=int(rmn)
	if(int(ryr/4.)*4.eq.jyr) THEN 
 	im(2)=29
	                          ELSE
	IM(2)=28
	ENDIF

	jdy1=1
	jdy2=im(jmn)
c/	jdy1=9	 !temp
c/	jdy2=9	 !temp
C
	infile='d:\web\dws\13\yymmddw.txt'
	infile(9:9)=fm
	infile(21:21)=fm
	infile(12:13)=AYR
	infile(15:16)=AYR
	infile(17:18)=AMN

C	outfile='d:\web\dtm\YR\MN\tmMNDYUT.jYR'
C 
C Start cycle on parameter
c-   31	nn=nn+1
c-	if (nn.gt.3) goto 23
C
C Day-to-day cycle
	do 120 jdy=jdy1,jdy2
	call blet2(jdy,ADY)
	infile(19:20)=ADY
	OPEN(11,file=infile)
C       
  181	format(A65)
	DO k=1,8
	read(11,181) txt  ! text lines
	enddo

C Cycle on UT
	do 115 jut=0,23
	read(11,181) txt  ! text YEAR, mn, dy, UT
	write(*,181) txt

	call blet2(jut,AUT)

	outfile='d:\web\dws\YR\MN\wcMNDYUT.jYR'
	outfile(9:9)=fm
	outfile(18:18)=fm
	outfile(12:13)=AYR
	outfile(28:29)=AYR
	outfile(15:16)=AMN
	outfile(20:21)=AMN
	outfile(22:23)=ADY
	outfile(24:25)=AUT
c	OPEN(13,file=outfile,access='APPEND')
	OPEN(12,file=outfile)

C
C All Mlats
  110	DO 100 ilat=71,1,-1
	read (11,90,end=9,err=2) glat,txt
   90	format(2X,F5.1,A60)

C??      	DO ilon=0,72 
C
	do j=1,4        
	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
	itec(ilat,j1+k-1)=ixx(k)
	enddo
	enddo			  ! start selection of 4 longitudes

	READ (11,179,END=9,ERR=2) (ixx(i),i=1,9)
  179	format(9(1X,I4))
	do k=1,9
	itec(ilat,63+k)=ixx(k)
	enddo
C
  100	continue ! End cycle on ilat

	do ilat=1,71
	write(*,102) (itec(ilat,k),k=0,72)
	write(12,102) (itec(ilat,k),k=0,72)
	enddo

C
	close(unit=12)
	read(11,181, end=9) txt  ! text end-of UT
	write(*,181) txt

  115	CONTINUE        ! End cycle on UT
    9	close(unit=11)

  120	CONTINUE        ! End day-to-day cycle
	GOTO 35
   2	write(*,*) 'Error reading input file: ',infile
   35	write(*,121) ayr,amn
  121	format(1X,A2,1X,A2)
   23	pause ' '
	stop
	end