      subroutine subtecutmmsc(qs,AYR,AMN,ADY)
C .................................................Aug 2022
C iflag=1 when uqrg is available
C iflag=0 - missing UQRG
C Extract TEC UT maps from daily UPC GIM-TEC file
C
	CHARACTER*2 AYR,AMN,ADY,RMN,RDY,ADY0,AUT,AMM
	CHARACTER*3 DDD
	INTEGER itec(71,0:72)
C++	INTEGER*2 idy,iut
	CHARACTER*128 infile,outfile
	CHARACTER*16 start,txt1,startrms
	CHARACTER*60 txt
	CHARACTER*4 RYEAR
	CHARACTER*1 QS
	integer*4 ixx(16)
	dimension itxx(0:72)
C
        iflag=0              ! missing UQRG
	start='START OF TEC MAP'
	startrms='START OF RMS MAP'
	read(ady,*) zdy
	idy=int(zdy)
	read(ayr,*) zyr
	iyr=int(zyr)
	read(amn,*) zmn
	imn=int(zmn)
	lda=ndoy(iyr,imn,idy)
	call blet3(lda,DDD)
1001	ndyend=idy       ! for one day TEC maps
      IRUN=0 ! NORMAL COMMAND
	iut0=0 ! NORMAL COMMAND
	ady0=ady

	outfile='c:\web\graf\dtu\yr\mn\ut\tcmndyutmm.uyr'  ! ionex type map
      if (qs.eq.'q') then
	outfile(15:15)='u'
	else
	outfile(15:15)='a'
	endif
	outfile(17:18)=ayr
	outfile(20:21)=amn
	outfile(28:29)=amn
	outfile(30:31)=ady
	outfile(38:39)=ayr

C      infile='c:\web\graf\TECI\usrgDDD0.YRi'	!!!!!!!! usrg-file-hourly-15min
      infile='c:\web\graf\TECI\uqrgDDD0.YRi'	!!!!!!!! uqrg-file-hourly-15min or usrg
      if (qs.eq.'q') then
	 infile(19:21)='qrg'
	else
		 infile(19:21)='adg'	  ! NORMMMMMMMMMMMMMM
C	 infile(19:21)='sdg'		  !TEMPPPPPPPPPPPPPPP
	endif
C	 infile(19:19)=QS        ! uqrg or usrg
	infile(22:24)=DDD
	infile(27:28)=ayr		  ! 
	iruns=96
 
	iutend=iruns
	 OPEN(20,FILE=INFILE,ACTION='READ')
	ihr=0 
C+++++++++++++++++++++++++++++++++++++++++++++++++
C start cycle on hr-to-hr input:
   80	do i=1,1600					             !!
	READ (20,187,END=33,ERR=2) txt,txt1
  187	format(A60,A16)
      if (txt1.eq.startrms) goto 33 ! END reading TEC
	if (txt1.eq.start) goto 88
	enddo									 !!
  88	continue
C+	READ (20,187,END=33,ERR=2) txt,txt1
C+	backspace (20)
C Start of reading VTEC ========================
   	read (20,89,end=9,err=85) ryear,rmn,rdy,iut,imm
CADD++++++++++++++++++++++++++++++++++++++++++++++++
 	if (rdy(1:1).eq.' ') rdy(1:1)='0'
	if ((iut.lt.iut0).and.(rdy.eq.ady0)) goto 80  ! 
   89 format(2X,A4,4X,A2,4X,A2,2(4X,I2))
   85	continue
      rut=float(iut)
	call blet2(iut,AUT)	
	call blet2(imm,AMM)	

C
	outfile(32:33)=aut  ! true
	outfile(34:35)=amm  ! true

	if (rmn(1:1).eq.' ') rmn(1:1)='0'
 	if (rdy(1:1).eq.' ') rdy(1:1)='0'
	read (rdy,*) day
	idy=int(day)
C start cycle on glatitudes:
  	ilat=0
	glati=90.0
	nnlat=72
C
	DO 777 lat=1,71	   ! Start cycle on glati ++++++++++++++++++++++++++++++++
		ilat=ilat+1   ! ilat=1 for 87.5
	glati=glati-2.5
   87	read (20,90,end=9,err=2) glat,txt
   90	format(3X,F5.1,A60)
  91   	j1=0
C
C Add check of wrong TEC.le.0<=itec_pre +++++++++++++
C
	itec_pre=20	  ! assumed TEC_pre 
	do j=1,4        
	j1=(j-1)*16
   1	READ (20,180,END=9,ERR=2) (ixx(i),i=1,16)
  180	format(16(1X,I4))
	do k=1,16
	if ((ixx(k).le.0).or.(ixx(k).eq.9999)) then
	ixx(k)=itec_pre ! replace wrong TEC
	endif
	itxx(j1+k-1)=ixx(k)
	itec_pre=ixx(k)		! latest TEC_pre
	enddo
	enddo			  ! start selection of 4 longitudes
	READ (20,179,END=9,ERR=2) (ixx(i),i=1,9)
  179	format(9(1X,I4))
	do k=1,9
	if ((ixx(k).le.0).or.(ixx(k).eq.9999)) then
	ixx(k)=itec_pre ! replace wrong TEC
	endif
	itxx(63+k)=ixx(k)
	itec_pre=ixx(k)		! latest TEC_pre
	enddo

	nnlat=nnlat-1  ! Keep results for GLAT=87.5(-87.5) at nnlat=71(1)

C Select values for Long=-180,-165,...0,15,30,..,165,180!!!!!!!!!!!!:
C
	ii=-1
	 jj=71
C====================================================
	do il=-180,180,5     ! for long-cycle
	ii=ii+1					   ! ii=0 for glong=-180,...,ii=72 for glong=180
	ires=ii
	if (itxx(ii).lt.10) itxx(ii)=10 ! Replace TEC<1 by TEC=1 TECU (=0.1TECU)
	glong=float(il)
CC++		   
	itec(nnlat,ires)=itxx(ii)	! remember tec map
	enddo
  777	continue   ! End cycle of reading all GLATs
C Prepare output of results for nnlong=0,1,...,72
		OPEN(14,FILE=OUTFILE)
	iflag=1                        ! GIM-TEC UQRG available
		DO nnlat=1,71
crem	write(*,182) (itec(nnlat,k),k=0,72)
	write(14,182) (itec(nnlat,k),k=0,72) !OUT of TEC hourly maps
	ENDDO
 182	format(73(1X,I4))							
	close(unit=14)
    9	continue
  
C Continue to the next 15min-UT hr :
  32		irun=irun+1 
 	ady0=rdy
	read(20,187,END=33,ERR=2) txt,txt1 ! final line for pre_UT_15min
	if (irun.lt.iutend) goto 80 ! continue to the next UT_15min hr =>>>>
   33	close(unit=20)
	goto 35	   ! end of calculations
C
    2 CONTINUE
      if (irun.eq.0) then
       write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
 	pause ' '
	goto 35
      endif
C   33 if ((iidy.le.idy2).and.(idy1.lt.idy2)) goto 32
   35      write(*,*) infile,outfile
   	write(*,*) irun
	 nndy=nndy+1
crem	if (nndy.le.im(mn)) then
crem	if (nndy.le.ndyend) then
crem	goto 1001
crem	endif
C      pause ' ' 
      RETURN
       END
C -----------------------------------------------------------
