	program extRAL
C......................................................Nov. 2017
C
c EXTRACT foF2 <dat(1)> FROM RAL DAILY-HOURLY FILE , 
C
	DIMENSION im(12)
	CHARACTER*128 infile,outfile
      	CHARACTER*60 TXT
 	CHARACTER*4 AYEAR,CYEAR,START
	CHARACTER*13 STAT
	CHARACTER*2 AYR,AMN,ADY,ST
	+,CMN,CDY
C     +,BMN,BDY,BUT,BMIN
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*5 DATF(0:32,0:23),CC
	DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
C-       write(*,*) 'Enter ST '
C-	read(*,22) ST
      	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
	CC='    C'
      TT(5:)='      '
	CYEAR=DD(1:4)
	CMN=DD(5:6)
	CDY=DD(7:8)
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
	START='Time'

C	st='ps'
C	stat='Port Stanley.'
C++	infile='d:\web\graf\YEAR\psYEARfRAL.txt'
C-	st='bp'
C-	stat='Bejing.'
C	st='dy'
C	stat='Dyess AFB.'
cMillstone Hill
c	st='eg'
c	stat='Eglin AFB.'
c	st='mh'
c	stat='Millstone Hill.'
c	st='mw'
c	stat='Mawson.'
c	st='pa'
c	stat='Pt Arguello.'
c	st='rm'
c	stat='Ramey.'
c	st='br'
c	stat='Brisbane.'
	st='cb'
	stat='Canberra.'
C	st='cr'
c	stat='Christchurch.'
c	st='dw'
c	stat='Darwin.'
c	st='ho'
c	stat='Hobart.'
c	st='mq'
c	stat='Macquarie Is.'
c	st='mu'
c	stat='Mundaring.'
c	st='py'
c	stat='Port Moresby.'
c	st='sq'
c	stat='Scott Base.'
c	st='tv'
c	stat='Townsville.'
c	st='va'
c	stat='Vanimo.'
c	st='os'
c	stat='Osan.'
c      st='sj'
c	stat='San Juan.'
c      st='tr'
c	stat='Tromso.'
c      st='le'
c	stat='Lerwick.'
c      st='ch'
c	stat='Chilton.'
	

C	infile='d:\web\graf\YEAR\stYEARfral.txt'
	infile='d:\web\graf\YEAR\stYEARf.txt'
C
C   START:
C
   1      write(*,*) 'Enter YEAR'
	read(*,*) AYEAR
CREM	AYEAR='2017'
        infile(13:16)=AYEAR
	infile(18:19)=st
	infile(20:23)=AYEAR
   19 format(A4)
	OPEN(33,FILE=INFILE,action='READ')
C
    6	AYR=AYEAR(3:4)
	read(ayr,*) ryr
	jyr=int(ryr)
C
	if(int(ryr/4.)*4.eq.jyr) THEN 
 	im(2)=29
	                          ELSE
	IM(2)=28
	ENDIF
C
       outfile='d:\web\dat1\YR\stYRMN.txt'
	outfile(13:14)=AYR
	outfile(16:17)=st
	outfile(18:19)=AYR
C	jmn1=1
	jmn1=1
C Monthly cycle
Crem        DO 140 jmn=jmn1,12
	jmn=jmn1-1
1140	 jmn=jmn+1
      if (jmn.gt.12) goto 44
C-	if ((jyr.eq.95).and.((jmn.gt.4).and.(jmn.lt.10))) goto 140 ! REM
       call blet2(jmn,AMN)
	read(33,*) txt ! title line
C
	outfile(20:21)=AMN
	OPEN(14,FILE=OUTFILE)
	write(14,17) stat
   17	format(A13)
		WRITE(*,18) cyear,cmn,cdy,TT
	WRITE(14,18) cyear,cmn,cdy,TT
  18	format('Date of issue: ',A4,'/',A2,'/',A2,' Time:',A4)
		write(14,201)
dd 	write(*,201) 
  201	format('YYMMDD|UT 0    1    2    3    4    5    6    7    8'
 	&'    9   10   11   12   13   14   15   16   17   18   19   20'
	&'   21   22   23'/'-------------------------------------------'
     &'-------------------------------------------------------------'
     &'------------------------')
C
	ndmn=im(jmn)
C
       do k=1,32
	DO i=0,23
	DATF(k,i)=' 00  '
	ENDDO
	 enddo
C
C Daily cycle
        DO 141 jdy=1,ndmn
C       DO 141 jdy=1,33
	call blet2(jdy,ADY)
 1141	continue
C
	do k=0,23
      datf(jdy,k)=CC
	enddo
C
C Calculate day-of-year:
C	lday=ndoy(jyr,jmn,jdy) ! function to define day-of-year
C	write(*,17) doy
C
c
  333 FORMAT(a60)
  331	FORMAT(I4,I2)

C Read data file:
C
	 	read(33,181,end=44) (datf(jdy,k),k=0,23) ! daily data	
C-	if (jdy.le.ndmn) then
	write(*,180) ayr,amn,ady,(datf(jdy,k),k=0,23)  ! last day-of-month
	write(14,180) ayr,amn,ady,(datf(jdy,k),k=0,23)
C	close(unit=14)
c-      endif
141	CONTINUE  ! day-to-day cycle
        read(33,*) txt  ! extra line
	read(33,*) txt  ! extra line
	if (ndmn.le.30) then
	read(33,*) txt  ! extra line
	endif
	if (ndmn.le.29) then
	read(33,*) txt  ! extra line
	endif
	if (ndmn.eq.28) then
	read(33,*) txt  ! extra line
	endif
C
  180	format(3A2,2X,24(A5))
  181	format(24(A5))
 140		close(unit=14)
      goto 1140
C
rem	pause ' '
	goto 1140
    3	 write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
    2  	write(*,*) infile
   44	       close(unit=33)
	pause ' '
C	goto 1
C
      STOP
	END
C ===============================================================

c=====================================================================================