      program extfof2col
C...............................................................May. 2019
C Extract foF2 from RAL ascii files
      dimension IM(12)
	character*120 infile,outfilef,outfilem,outfileh,txt
	CHARACTER*2 AMN,AYR,ADY,AUT,BMN,BDY,BUT
	CHARACTER*4 AYEAR,BYEAR
	CHARACTER*5 af2(0:23),ah2(0:23),am3(0:23),bf2
	+,bm3
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/ 
C
c+	infile='d:\YEAR\ns_38501_YEAR_mn.txt'
c+	outfilef='d:\web\graf\YEAR\nsYRf.br'
c+	outfileh='d:\web\graf\YEAR\nsYRh.br'
c+	outfilem='d:\web\graf\YEAR\nsYRm.br'
	infile='d:\web\graf\YEAR\trYEAR.txt'
	outfilef='d:\web\graf\YEAR\trYRf.br'
	outfileh='d:\web\graf\YEAR\trYRh.br'
	outfilem='d:\web\graf\YEAR\trYRm.br'
   31 format(A120)
C
     	write(*,*) ' Enter YEAR:'
	read(*,*) IYEAR
 1		call blet4(iyear,AYEAR)
      iflag=0
 	ryear=float(iyear)
	AYR=AYEAR(3:4)
	read(ayr,*) ryr
	iyr=int(ryr)
		if(int(ryr/4.)*4.eq.iyr) THEN 
		 im(2)=29
	ndnyr=366
	                          ELSE
	IM(2)=28
	ndnyr=365
	ENDIF
	infile(13:16)=AYEAR
		infile(20:23)=AYEAR
		outfilef(13:16)=AYEAR
	outfileh(13:16)=AYEAR
	outfilem(13:16)=AYEAR
	outfilef(20:21)=AYR
	outfileh(20:21)=AYR
	outfilem(20:21)=AYR
	OPEN(11,file=outfilef,access='APPEND')
Crem	OPEN(12,file=outfileh)
Crem	OPEN(13,file=outfilem)
C
	OPEN(10,file=infile,action='READ')
	read(10,31) txt !1 extra line
	read(10,31) txt !1 extra line
	read(10,31) txt !1 extra line
C
      DO 104 imn=1,12
	ndr=IM(imn)
	call blet2(imn,AMN)
c-	infile(23:24)=AMN
C
	DO 105 idy=1,ndr	   !DAY
	call blet2(idy,ADY)
C
      do 46 iut=0,23		 !   UT
	call blet2(iut,AUT)
	af2(iut)=' 00  '
Crem	am3(iut)='000  '
	read(10,32,end=41) BYEAR,BMN,BDY,BUT,bf2
	IF ((BYEAR.eq.AYEAR).and.(BMN.eq.AMN).and.(BDY.eq.ADY).and.
	+(BUT.eq.AUT)) THEN
c	 if (bf2(1:1).eq.'/') bf2(1:3)=' 00'
c	if (bm3(1:1).eq.'/') bm3='0000 '
c	bm3(1:1)=' '
c	bm3(4:4)='0'
	af2(iut)=bf2
c	am3(iut)=bm3
c	ah2(iut)=' 00  '
	else
	backspace(10)
	ENDIF
   46	CONTINUE		   ! UT
	GOTO 43
   41	iflag=1
C
   43 CONTINUE
      if (imn.lt.8) goto 105
	  write(*,33) AYR,AMN,ADY,(af2(k),k=0,23)
	write(11,33) AYR,AMN,ADY,(af2(k),k=0,23)
Crem      write(*,33) AYR,AMN,ADY,(ah2(k),k=0,23)
Crem	write(12,33) AYR,AMN,ADY,(ah2(k),k=0,23)
Crem      write(*,34) AYR,AMN,ADY,(am3(k),k=0,23)
Crem	write(13,34) AYR,AMN,ADY,(am3(k),k=0,23)
  105	CONTINUE			! DAY
      if (iflag.eq.1) goto 44
104	CONTINUE			! mon
   44	close(unit=11)
      close(unit=10)
c	close(unit=12)
c	close(unit=13)
	iyear=iyear+1
	 if (iyear.lt.2013) goto 1
C
   32 format(A4,2A2,1X,A2,5X,A5)
   33 format(3A2,2X,24(A5))
   34 format(3A2,1X,24(A5))
   42	pause ' '
	STOP
	END