	program extrtec
C....................................................Dec 2015
C Extract TEC from IONOLAB file => to test5st.input
C
C Infile1,infile2,outfile1: 
c
      CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*6 teci(0:23),tec
	CHARACTER*2 st,AYR,AMN,ADY,AUT,AMI,BMN,BDY,BUT,BMI
	CHARACTER*1 but1
	CHARACTER*4 AYEAR,BYEAR
	CHARACTER*80 infile1,infile2,outfile,txt
C
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C

	infile1='tYRDYstc.inp' !
C	infile2='st141220.txt' !
	infile2='stYRMNDY.txt' !
C	outfile='test5st.inp'  !

C+	AYEAR='2014' !temp
	AYEAR='2015' !temp +

	AYR=AYEAR(3:4)
C+	AMN='12'
	AMN='03' !+
C+	ADY='20'
C+	ADY='17' !+
	ADY='18' !+
	AMI='00'
	read(amn,*) rmn
	imn=int(rmn)
	infile1(2:3)=AYR
	infile1(4:5)=ADY
	infile2(3:4)=AYR
	infile2(5:6)=AMN
	infile2(7:8)=ADY
	outfile=infile1
      outfile(8:)='.inp'
	write(*,*) ' Enter <st> name :'
	read(*,34) st
	infile1(6:7)=st
	infile2(1:2)=st
	outfile(6:7)=st
	OPEN(11,FILE=INFILE1,action='READ')
	OPEN(12,FILE=INFILE2,action='READ')
	OPEN(10,FILE=OUTFILE)
C
C Read IONOLAB TEC
	do i=1,2
	read(12,*) txt ! extra line
	enddo
   34 format(A2)
   36 format(A80)
	DO 40 iut=0,23
	call blet2(iut,AUT)
   41	read(12,36,end=42) txt
	if (imn.gt.10) then
      BYEAR=txt(7:10)
	BMN=txt(1:2)
	BDY=txt(4:5)
	else
	BYEAR=txt(6:9)
	BMN(1:1)='0'
	BMN(2:2)=txt(1:1)
	BDY=txt(3:4)
	endif
	nut=index(txt,':')
	if (iut.lt.10) then
	BUT1=txt(nut-1:nut-1)
	BUT(1:1)='0'
	BUT(2:2)=BUT1
	else
	BUT=txt(nut-2:nut-1)
	endif
c-	if ((BUT(1:1).eq.' ').or.(BUT(1:1).eq.'4')) BUT(1:1)='0'
	read(but,*) rut
	BMI=txt(nut+1:nut+2)
	read(bmi,*) rmi
	jbut=int(rut)
	jbmi=int(rmi)
	IF ((BYEAR.eq.AYEAR).and.(BMN.eq.AMN).and.(BDY.eq.ADY)
	+.and.(JBUT.eq.iUT).and.(JBMI.eq.0)) then
   	n=index(txt,'.')
	tec=txt(n-3:n+2)
	teci(iut)=tec
	goto 40
	               else
	goto 41
	                endif
   40	CONTINUE
   42	close(unit=12)
C
C start read-write .inp file: =====================================
C
	do 400 iut=0,23	! 
  401	read(11,36,end=38) txt
	write(*,36) txt
C	nt=index(txt,'.',BACK=.TRUE.)
C	txt(nt-2:nt+2)=teci(iut)
	tec=teci(iut)
	read(tec,*) rtec
	txt(74:80)=tec
C
  402	write(*,36) txt
	write(10,36) txt
  400	CONTINUE ! next year
   37 format(A75,1X,F6.2)	 ! 

   38	close(unit=10)
C
  139	close(unit=11)
C
C
C
C
C	
	goto 900
    2 CONTINUE
           write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
  900 pause ' '
      STOP
      END

