      program extiripout
C..................................................................Sep. 2020
C
C extract Ne(h) and TEC(h) profiles from Iriplas.out file
C
	CHARACTER*88 infile,outfile,txt
	dimension xne(0:11,50),tec(11,50),tau(11),taub(11),taut(11)
	+,hmf(11),hc(11),xnm(11),techc(11) ! glats=-80,-60,-40,-20,-10,0,10,20,40,60,80
      infile='test2_1.out' ! Ne(h) TEC(h) profiles
	outfile='extiripout.txt'
		OPEN(10,FILE=INFILE,action='READ')
	OPEN(11,FILE=OUTFILE,access='APPEND')
C
Crem      rltime=0.0
      rltime=12.0
	 do i=1,7
      read(10,30) txt ! title line
	enddo
C
   30 format(A88)
   31 format(2(1X,I4),2(1X,F4.1),25X,2(1X,F5.1),18X,F6.1,1X,F5.2)
   32 format(1X,F8.0,24X,F6.2,3(1X,F6.2),1X,F6.1,13X,F6.1,1X,1PE11.4)
   33 format(1X,F6.0,2X,1PE11.4,39X,1PE11.4)
C lats cycle
      DO 40 ilat=11,1,-1
   45 read(10,30,end=49) txt ! title line
	read(10,31) iyear,imndy,rut,rlt,glat,glon,hmf(ilat),fof2 
	if (rlt.eq.rltime) then
	goto 44
	else
	do ii=1,55
	  read(10,30) txt ! extra  line
	enddo
	goto 45
	endif
   44   read(10,30) txt ! title line
	read(10,32) xnm(ilat),ecbot,ectop,ecpl,tectot,tau(ilat)
     +,hc(ilat),techc(ilat)
	 taub(ilat)=ecbot/xnm(ilat)*1.0E+07
	taut(ilat)=(ectop+ecpl)/xnm(ilat)*1.0E+07
	xnm(ilat)=xnm(ilat)/1.0E+05
	techc(ilat)=techc(ilat)/1.0E+16
      read(10,30) txt ! title line
C
C height cycle
      DO 41 ih=50,1,-1
	 read(10,33) h,xne(ilat,ih),tec(ilat,ih)
      tec(ilat,ih)=tec(ilat,ih)/1.0E+16
	xne(ilat,ih)=xne(ilat,ih)/1.0E+11
	xne(0,ih)=h
   41	continue
	      read(10,30) txt ! title line
      read(10,30) txt ! title line
C
   40	continue
   49 close(unit=10)
C
C output results
C
   35	format(A6,11(1X,F6.1))
   36	format(A6,11(1X,F6.2))
   37	format(11(1X,F7.4))
   38	format(1X,F6.0,11(1X,F7.4))
C hmF2
	write(*,35) 'hmf=[ ',(hmf(k),k=1,11)
	write(11,35) 'hmf=[ ',(hmf(k),k=1,11)
C Hc
	write(*,35) ' hc=[ ',(hc(k),k=1,11)
	write(11,35) ' hc=[ ',(hc(k),k=1,11)
C tau-bot
	write(*,35) 'taub=[',(taub(k),k=1,11)
	write(11,35) 'taub=[ ',(taub(k),k=1,11)
C tau-top
	write(*,35) 'taut=[',(taut(k),k=1,11)
	write(11,35) 'taut=[',(taut(k),k=1,11)
Ctau
	write(*,35) 'tau= [',(tau(k),k=1,11)
	write(11,35) 'tau= [',(tau(k),k=1,11)
C NmF2
	write(*,36) 'nmf=[ ',(xnm(k),k=1,11)
	write(11,36) 'nmf=[ ',(xnm(k),k=1,11)
C
       write(*,*) 'xne=['
	write(11,*) 'xne=['
       do ii=1,50
	write(*,38) (xne(k,ii),k=0,11)
	write(11,38) (xne(k,ii),k=0,11)
	enddo
       write(*,*) 'tec=['
	write(11,*) 'tec=['
       do ii=1,50
	write(*,37) (tec(k,ii),k=1,11)
	write(11,37) (tec(k,ii),k=1,11)
	enddo
C
      close(unit=11)
       pause ' '
	STOP
	END