	program extiriout
C....................................................Dec 2015
C Extract TECobs+TECoutCCIR+TECoutRzp+TECoutTECfit
C       	foF2obs+foF2outCCIR+foF2outRzp+foF2outTECfit
C       	hmF2obs+hmF2outCCIR+hmF2outRzp+hmF2outTECfit
C Outfile (LT)
C
C Infile1,infile2,outfile1: 
c
	DIMENSION hrlt(0:23),lt(0:23),rut(0:23)
	+,teci(4,0:23),fof2(4,0:23),hmf2(4,0:23)
	+,ifof2(0:23),ihmf2(0:23)
      CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*2 st,AYR,AMN,ADY,BYR,BMN,BDY
	CHARACTER*4 AYEAR,BYEAR
	CHARACTER*1 C,P,CI(0:23),CH(0:23)
	CHARACTER*80 infilest,infile1,infile2,infile3,infilef,infileh
	+,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='/'
	P='+'
C
	infilest='t1420st.inp' !TECobs
	infile1='t1420stc.out' !
	infile2='t1420st2.out' !
	infile3='t1420st.out' !
	infilef='st1412.txt'
	infileh='st1412h.txt'
	outfile='st1420iri.txt'  !
C	AYEAR='2014' !temp
C	AMN='12'	 !temp
C	ADY='20'	 !temp
C	AYEAR='2013' !temp
C	AMN='03'	 !temp
C	ADY='13'	 !temp
	AYEAR='2015' !temp
	AMN='03'	 !temp
C	ADY='17'	 !temp
	ADY='18'	 !temp
	read(ady,*) rdy
	ndy=int(rdy)
	AYR=AYEAR(3:4)
	infilest(2:3)=AYR
	infilest(4:5)=ADY
	infile1(2:3)=AYR
	infile1(4:5)=ADY
	infile2(2:3)=AYR
	infile2(4:5)=ADY
	infile3(2:3)=AYR
	infile3(4:5)=ADY
	infilef(3:4)=AYR
 	infilef(5:6)=AMN
	infileh(3:4)=AYR
 	infileh(5:6)=AMN
	outfile(3:4)=AYR
	outfile(5:6)=ADY

	write(*,*) ' Enter <st> name :'
	read(*,34) st
	infilest(6:7)=st
	infile1(6:7)=st
		infile2(6:7)=st
		infile3(6:7)=st
		infilef(1:2)=st
			infileh(1:2)=st
	outfile(1:2)=st
	OPEN(10,FILE=INFILEST,action='READ')
	OPEN(11,FILE=INFILE1,action='READ')
	OPEN(12,FILE=INFILE2,action='READ')
	OPEN(13,FILE=INFILE3,action='READ')
	OPEN(14,FILE=INFILEf,action='READ')
	OPEN(15,FILE=INFILEh,action='READ')

	OPEN(16,FILE=OUTFILE)
C
   34 format(A2)
   35	format(A80)
   36 format(73X,F6.2)
   37 format(3A2,2X,24(I3,A1,1X))
   38 format(3A2,2X,24(F3.0,2X))
C Read TECobs
C
C start read-write .inp file: =====================================
C		 TECobs:
	do iut=0,23	! 
  	read(10,36,end=48) teci(1,iut)
	write(*,36) teci(1,iut)
	enddo
   48	close(unit=10)
C
C          foF2obs  
	do i=1,4	! 
  	read(14,35,end=138) txt ! extra line
	enddo
	do idy=1,ndy
	read(14,37,end=138) byr,bmn,bdy,(ifof2(k),CI(k),k=0,23) 
	enddo
  	write(*,37) byr,bmn,bdy,(ifof2(k),CI(k),k=0,23) 
	do iut=0,23
	if (ci(iut).eq.'/') then
	fof2(1,iut)=-float(ifof2(iut))/10.
	else
	fof2(1,iut)=float(ifof2(iut))/10.
	endif
	enddo
  138	close(unit=14)
C          hmF2obs  
	do i=1,4	! 
  	read(15,35,end=238) txt ! extra line
	enddo
	do idy=1,ndy
	read(15,37,end=238) byr,bmn,bdy,(ihmf2(k),ch(k),k=0,23) 
	enddo
	write(*,37) byr,bmn,bdy,(ihmf2(k),ch(k),k=0,23) 
	do iut=0,23
	if (ch(iut).eq.'/') then
	hmf2(1,iut)=-float(ihmf2(iut))
	else
	hmf2(1,iut)=float(ihmf2(iut))
	endif
	enddo
  238	close(unit=15)
C       LT,foF2,hmF2, TEC CCIR
	do i=1,6	! 
  	read(11,35,end=338) txt ! extra line
	enddo
	do iut=0,23	! 
  	read(11,39,end=338) BYEAR,BMN,BDY,RUT(iut),HRLT(iut),hmf2(2,iut)
	+,fof2(2,iut),teci(2,iut)
	lt(iut)=nint(hrlt(iut))
	if (lt(iut).ge.24) lt(iut)=0
	if (lt(iut).eq.0) nstart=iut
	write(*,39) BYEAR,BMN,BDY,RUT(iut),HRLT(iut),hmf2(2,iut)
	+,fof2(2,iut),teci(2,iut)
	enddo
  338	close(unit=11)
   39 format(1X,A4,1X,2A2,2(1X,F4.1),56X,F5.1,1X,F5.2,54X,F6.2)
C       LT,foF2,hmF2, TEC for Rzproxy
	do i=1,8	! 
  	read(12,35,end=538) txt ! extra line
	enddo
	do iut=0,23	! 
  	read(12,39,end=538) BYEAR,BMN,BDY,RUT(iut),HRLT(iut),hmf2(3,iut)
	+,fof2(3,iut),teci(3,iut)
	write(*,39) BYEAR,BMN,BDY,RUT(iut),HRLT(iut),hmf2(3,iut)
	+,fof2(3,iut),teci(3,iut)
	enddo
  538	close(unit=12)
C       LT,foF2,hmF2, TEC for TEC-fit
	do i=1,7	! 
  	read(13,35,end=638) txt ! extra line
	enddo
	do iut=0,23	! 
  	read(13,39,end=638) BYEAR,BMN,BDY,RUT(iut),HRLT(iut),hmf2(4,iut)
	+,fof2(4,iut),teci(4,iut)
	write(*,39) BYEAR,BMN,BDY,RUT(iut),HRLT(iut),hmf2(4,iut)
	+,fof2(4,iut),teci(4,iut)
	enddo
  638	close(unit=13)
C Output results
	do ii=nstart,23
	write(*,40) lt(ii),hrlt(ii),rut(ii),(teci(k,ii),k=1,4)
	+,(fof2(k,ii),k=1,4),(hmf2(k,ii),k=1,4)
	write(16,40) lt(ii),hrlt(ii),rut(ii),(teci(k,ii),k=1,4)
	+,(fof2(k,ii),k=1,4),(hmf2(k,ii),k=1,4)
	enddo
	if (nstart.gt.0) then
	do ii=0,nstart-1
	write(*,40) lt(ii),hrlt(ii),rut(ii),(teci(k,ii),k=1,4)
	+,(fof2(k,ii),k=1,4),(hmf2(k,ii),k=1,4)
	write(16,40) lt(ii),hrlt(ii),rut(ii),(teci(k,ii),k=1,4)
	+,(fof2(k,ii),k=1,4),(hmf2(k,ii),k=1,4)
	enddo
	     endif
   40 format(1X,I2,2(1X,F4.1),4(1X,F6.2),4(1X,F6.2),4(1X,F6.1))
  400	CONTINUE ! 
 
C
  139	close(unit=16)
C	
	goto 900
    2 CONTINUE
           write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
  900 pause ' '
      STOP
      END

