      program decodral
C
C......................................................................May 2019
C
C Decode RAL-WDC foF2 file to standard annual foF2 file
C
      DIMENSION IM(12),im3(0:23)
	CHARACTER*120 text,infile,outfile,title,infilef,outfilef
	CHARACTER*5 CODE,blank,blanks(24)
	CHARACTER*20 tityrmn,xxx
	CHARACTER*4 utime,AYEAR
	CHARACTER*2	AMN,ST,AYR,ADY,CYR,CMN,CDY,Cm(0:23)
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
       
 101	 write(*,*) 'Enter st name: '
	read(*,30) ST
	write(*,*) 'Enter stXXX CODE: '
 	read(*,34) CODE

C+	infile='d:\web\graf\1997\CL97.txt'
	infile='d:\web\graf\1994\st1994m.txt'
	outfile='d:\web\graf\1994\st94m.br'
	infile(18:19)=ST
	outfile(18:19)=ST
	infilef='d:\web\dat1\94\st94mn.txt'
      outfilef=outfile
	outfilef(22:22)='f'
C	CODE='CL424'
	UTIME='0000'
	BLANK='    C'
	do i=1,24
	BLANKS(i)=blank
	enddo
C
      AYR='94'
	infilef(13:14)=AYR
	infilef(16:17)=st
	infilef(18:19)=AYR
C foF2
	OPEN(13,file=outfilef)
	DO imn=1,12
C	AMN=blet2(imn)
      call blet2(imn,AMN)
	infilef(20:21)=AMN
	OPEN(12,file=infilef,action="READ")
      do i=1,4
	read(12,31,end=133) text
	enddo
	mndy=im(mn)
      do idy=1,mndy
	read(12,33,end=133) CYR,CMN,CDY,text
      write(*,33) CYR,CMN,CDY,text
	write(13,33) CYR,CMN,CDY,text
	enddo
  133	close(unit=12)
      ENDDO
	close(unit=13)
C
C M3000F2
        OPEN(10,file=infile,action="READ")
	OPEN(11,file=outfile)
  30	format(A2)
  34	format(A5)
  31	format(A120)
  33	format(3A2,2X,A120)
   32	format(24A5)
C?        imn=0
   1	READ(10,31,end=44) text
	n=index(text,code)
	if (n.eq.0) goto 1
	title=text
	READ(10,31,end=44) text  ! 2nd line
	tityrmn=text(1:20)
	AYEAR=tityrmn(1:4)
	AYR=AYEAR(3:4)

	AMN=tityrmn(7:8)
	if (AMN(1:1).eq.' ') AMN(1:1)='0'
	read(amn,*) rmn
	mn=int(rmn)

	title(101:120)=tityrmn
	write(*,31) title
C+	write(11,31) title
C
	do i=1,4
	read(10,*) xxx ! extra line
	enddo
C
C read ut HRS
C
  131 FORMAT(3A2,2X,A120)
  330 FORMAT(24(I3,A2))
  331 FORMAT(3A2,2X,24(I3,A2))
	mndy=im(mn)
C
   2	READ(10,31,end=44) text
	mt=index(text,utime)
	if (mt.gt.0) goto 2  ! exclude lines with UT
	backspace(10)
	DO idy=1,mndy
	call blet2(idy,ADY)
Ctxt	READ(10,31,end=44) text
	READ(10,330,end=44) (im3(k),Cm(k),k=0,23)
C+   	write(11,31) text
Ctxt      write(*,131) AYR,AMN,ADY,text
Ctxt	write(11,131) AYR,AMN,ADY,text
      write(*,331) AYR,AMN,ADY,(im3(k),Cm(k),k=0,23)
	write(11,331) AYR,AMN,ADY,(im3(k),Cm(k),k=0,23)
      enddo
C
	if (mndy.eq.31) goto 3
C
      if (mndy.eq.30) then
C+	write(11,32) blanks
	mndy=31
	goto 3
	             else
C Feb				  
C+	do k=1,3
C+	write(11,32) blanks
C+	enddo
	mndy=31
       endif
C
   3	if (mndy.eq.31) then
	READ(10,31,end=44) text ! med
C+   	write(11,31) text
	READ(10,31,end=44) text	! cnt
C+   	write(11,31) text
	do i=1,4
	read(10,31) xxx ! extra line
	enddo
	endif
C
       if (mn.lt.12) GOTO 1
   44	close(unit=10)
      close(unit=11)
	GOTO 101
	pause ' '
	STOP
	END