      program readupc15min
C............................................................May 2021
C Read upc 15min file => diurnal file
C
	CHARACTER*2 AYR,AMN,ADY,AUT,amap,AMM
	CHARACTER*4 AYEAR
	CHARACTER*3 DOY
	CHARACTER*65 INFILE,OUTFILE
	CHARACTER*20 start,enddesc,epoch,startrms,utend
        CHARACTER*60 title1
	CHARACTER*20 title2
	character*80 txt1,txt2,txt3,txt4
	character*45 txt5
C
C start
C
      start='START OF TEC MAP    '
C+           start='START               '
	enddesc='END OF HEADER       '
	epoch='EPOCH OF CURRENT MAP'
      utend='END OF TEC MAP      ' 
	startrms='START OF RMS MAP    '
C
      WRITE(*,'(\A\)') ' ENTER AYEAR OF INPUT FILE='
      READ(*,'(A)') AYEAR
c/	AYEAR(1:2)='20'
c/	AYEAR(3:4)=ayr
	ayr=ayear(3:4)
	read(ayr,*) year
	iyr=int(year)
		idayy=365
        if(iyr/4*4.eq.iyr) then
	  idayy=366
	  endif
C
      WRITE(*,'(\A\)') ' ENTER AMONTH OF INPUT FILE='
      READ(*,'(A)') AMN
	read(amn,*) rmn
	imn=int(rmn)
c
      WRITE(*,'(\A\)') ' ENTER iDY ='
      READ(*,*) idy
 	call blet2(idy,ADY)

      WRITE(*,'(\A\)') ' ENTER iUT1 ='
      READ(*,*) iut1

      WRITE(*,'(\A\)') ' ENTER iMM1 ='
      READ(*,*) imm1
	imm=0
	do ii=0,75,25
	if (imm1.eq.imm) then
	imm2=ii
      exit
	endif
	imm=imm+15
	enddo
	      WRITE(*,'(\A\)') ' ENTER nn last map ='
      READ(*,*) nnmap

C
      lda=ndoy(iyr,imn,idy)
	call blet3(lda,DOY)
C
      infile='d:\web\graf\TECI\YEAR\usrgDDD0.UT.MM.YRi'  !UPC 15 min
CNORM	outfile='d:\web\graf\TECI\uqrgDDD0.YRi'  !UPC daily IONEX
	outfile='d:\web\graf\TECI\usrgDDD0.YRi'  !UPC daily IONEX
      infile(18:21)=AYEAR
      infile(27:29)=DOY
	infile(38:39)=AYR
	outfile(22:24)=DOY
	outfile(27:28)=AYR

	OPEN(10,file=outfile,access='APPEND')
C
C       nnmap=0
C cycle on iut
      DO 50 iut=0,23
	if (iut.lt.iut1) then
C	nnmap=nnmap+4
	goto 50
	endif 
 	call blet2(iut,AUT)
	infile(32:33)=AUT
C       
   30	FORMAT(A60,A20)
  107 format(4(A80),A45)
 1071 format(A80)
 1072 format(A45)
C 1073 format(3X,F5.1,'-180.0 180.0   5.0 450.0',28X
C     +,'LAT/LON1/LON2/DLON/H')
C cycle on 15 min
      DO 51 imm=0,75,25
	if ((iut.eq.iut1).and.(imm.lt.imm2)) goto 51
	nnmap=nnmap+1
	call blet2(nnmap,amap)
 	call blet2(imm,AMM)
	infile(35:36)=AMM
      OPEN(11,file=infile,action='READ')
	do i=1,24
    	read(11,*,end=61) title1,title2
      enddo
   1	read(11,30,end=61) title1,title2
	if (title2.eq.startrms) goto 61
C
	IF (title2.eq.start) THEN               !>>>>>>>>>>>>>>>>>>>
	title1(5:6)=amap
	write(*,30) title1,title2		   ! start of tec map
	write(10,30) title1,title2		   ! 
	read(11,30,end=61) title1,title2
	write(*,30) title1,title2		   !  EPOCH OF CURRENT MAP
	write(10,30) title1,title2		   ! 
C read-write TEC(lat)
	DO ilat=1,71
	read(11,30,end=61) title1,title2
	write(*,30) title1,title2		   !  LAT/LON1/LON2/DLON/H
	write(10,30) title1,title2		   !  LAT/LON1/LON2/DLON/H
	READ (11,1071,END=61,ERR=61) TXT1
	write(10,1071) TXT1
	READ (11,1071,END=61,ERR=61) txt2
		write(10,1071) TXT2
	READ (11,1071,END=61,ERR=61) txt3
		write(10,1071) TXT3
	READ (11,1071,END=61,ERR=61) txt4
		write(10,1071) TXT4
	READ (11,1072,END=61,ERR=61) txt5
		write(10,1072) TXT5
	enddo
C
	read(11,30,end=61) title1,title2
	title1(5:6)=amap
	write(*,30) title1,title2		   ! end of tec map
	write(10,30) title1,title2		   ! 
                                              ELSE  !>>>>>>>>>>>>>>>>
      goto 1
	                                       ENDIF !>>>>>>>>>>>>>>>>>>>>
   61 close(unit=11)
C
   51 CONTINUE  ! cycle on 15 min
C
   50 CONTINUE  ! cycle on UT
      CLOSE(unit=10)
	pause ' '
	STOP
	END