C ===========================================================
	subroutine SUBTREAD(nn,yy)
C                                                             ! Nov. 2012   
C
C   EXTRACT TEC FROM IONEX1 format to array yy(glat,glon) relevant to IONEX format
c
C
C
c
      DIMENSION txx(3,0:179),yy(71,0:72),xxx(16)
	character*60 txt

  90	format(3X,F5.1,A60)
180	format(16(1X,F4.0))
179	format(4(1X,F4.0))

	do j=1,3
	do k=0,179
	txx(j,k)=0.
	enddo
	enddo
	alat=90.	! resuts alat
	glat1=92.
	trem=20.
	DO 20 ii=1,71 ! cycly on output lats
	alat=alat-2.5
   10	read(nn,90,err=2,end=9) glat,txt
	glat2=glat
C
	do j=1,11
	j1=(j-1)*16
    1	READ (nn,180,END=9,ERR=2) (xxx(i),i=1,16)
	do k=1,16
	if ((xxx(k).le.0.).or.(xxx(k).gt.9990.)) then
	if (txx(2,j1+k-1).gt.0.) then
	xxx(k)=txx(2,j1+k-1)	! replace wrong TEC
	                          else
	xxx(k)=trem ! replace wrong TEC
	endif
	                                       endif
	txx(2,j1+k-1)=xxx(k)
	trem=xxx(k)
	enddo
	enddo
	READ (nn,179,END=9,ERR=2) (xxx(i),i=1,4)
		do k=1,4
	if ((xxx(k).le.0.).or.(xxx(k).gt.9990.)) then
	if (txx(2,j1+k-1).gt.0.) then
	xxx(k)=txx(2,175+k)	! replace wrong TEC
	                          else
	xxx(k)=trem ! replace wrong TEC
	endif
	                                       endif
	txx(2,175+k)=xxx(k)
	trem=xxx(k)
	enddo
	if ((alat.le.glat1).and.(alat.gt.glat2)) then
	rat=(glat1-alat)/2.
      do k=0,179
	txx(3,k)=txx(1,k)+(txx(2,k)-txx(1,k))*rat
	txx(1,k)=txx(2,k)
	enddo
	glat1=glat2
C Interpolate in longi
crem	alon=-185.
      alon=-180.
	glon1=-180.
	jout=0
crem	DO jj=0,71 ! cycle on output longs
	DO jlon=0,179 ! cycle on intput longs
crem	alon=alon+5.
   27	glon2=glon1+2.
crem	jg1=jg1+1
	if ((alon.ge.glon1).and.(alon.lt.glon2)) then
	yy(ii,jout)=txx(3,jlon)+(txx(3,jlon+1)-txx(3,jlon))*(alon-glon1)/2.
	glon1=glon2
	alon=alon+5.
	jout=jout+1
	endif 
	 glon1=glon2
   	ENDDO
	yy(ii,72)=yy(ii,0)
	                        else
	glat1=glat2
	do k=0,179
	txx(1,k)=txx(2,k)
	enddo
	goto 10
	endif
   20	continue
	goto 22
C ============================================	
    9	write(*,*) ' end of file'
	pause ' '
	goto 22
    2	write(*,*) ' error in input file'
 	pause ' '
C
   22 continue
	return
	end
C
C ===============================================================
