      program datngdc
C.....................................................................Mar 2020
C extract data NGDC in .dat format
C
      character*110 infile,outfilef,outfileh,txt
      character*3 DDD
	character*2 AYR,AMN,ADY,st,BYR
	dimension ifc(0:23),ihc(0:23)
C
      infile='d:\web\graf\TR\TR170_2020-DDD.dat'
	AYR='20'
	iyr=20
	st='tr'
	write(*,*) ' Enter mn:'
	read(*,*) iMN
	call blet2(imn,AMN)
      write(*,*) ' Enter dy1,dy2:'
	read(*,*) idy1,idy2
	outfilef='d:\web\graf\2020\stYRf.br'
	outfilef(15:16)=AYR
      outfilef(18:19)=st
	outfilef(20:21)=AYR
	outfileh=outfilef
	outfileh(22:22)='h'
C
   30 format(A110)
c#          UT_Time      foF2      hmF2      foF1      hmF1      foE       zmE       foEs      fxI       TEC       
c#          Columns       4       5       6       7       8       9      10      11      12
c 2020 050 00:00:00       3.787   189.110     0.000     0.000     0.000     0.000     0.000     0.000     0.944
   31 format(3X,A2,1X,I3,2(1X,I2),9X,F6.3,3X,F7.3)
	OPEN(11,file=outfilef,access='APPEND')
	OPEN(12,file=outfileh,access='APPEND')
C
       DO 41 idy=idy1,idy2
	lda=ndoy(iyr,imn,idy)
	call blet2(idy,ADY)
	call blet3(lda,DDD)
	infile(27:29)=DDD
	OPEN(10,file=infile,action='READ')
	read(10,30,end=50) txt !extra line
	read(10,30,end=50) txt !extra line
c	read(10,30,end=50) txt !1st line
c	backspace(10)
	do k=0,23
	ifc(k)=0
	ihc(k)=0
	enddo
C
	DO 40 iut=0,23
   1	read(10,31,end=50) BYR,lda,MUT,MIN,fof2,hmf2
	if (mut.gt.iut) then
	backspace(10)
	goto 40
	endif
      if ((mut.eq.iut).and.(min.eq.0)) then
	ifc(iut)=nint(fof2*10.)
      ihc(iut)=nint(hmf2)
      endif
	read(10,30,end=50) txt !extra line
	read(10,30,end=50) txt !extra line
	goto 1
   40 CONTINUE
   50 close(unit=10)
      write(*,32) AYR,AMN,ADY,(ifc(k),k=0,23)
	write(11,32) AYR,AMN,ADY,(ifc(k),k=0,23)
	write(*,32) AYR,AMN,ADY,(ihc(k),k=0,23)
	write(12,32) AYR,AMN,ADY,(ihc(k),k=0,23)
   32 format(3A2,2X,24(I3,2X))
   41 CONTINUE
      close(unit=11)
      close(unit=12)
	pause ' '
	STOP
	END