C.........................................................Nov 2024
C
C Produce global IONEX maps foF2,hmF2,TEC for given YR, MN, DY, UT=0,1,...,23, MIN = 00, 15, 30, 45
C
c	
	Program Test_Model3fht
C	use Mod_GTEC
C      use Mod_etime
c	use dflib
C	use ifport
	implicit none
Cnorm	  character(256):: filenameout = 'f:\web\gtc\YR\MN\gtMNDDUTMM.sYR'	!+TLG
	  character(256):: filenameout = 'c:\web\gtc\YR\MN\gtMNDDUTMM.sYR'	!+TLG
Cnorm     +,outfilef = 'f:\web\gfc\YR\MN\gfMNDDUTMM.sYR'	!+TLG
     +,outfilef = 'c:\web\gfc\YR\MN\gfMNDDUTMM.sYR'	!+TLG
Cnorm     +,outfileh = 'f:\web\ghc\YR\MN\ghMNDDUTMM.sYR'	!+TLG
     +,outfileh = 'c:\web\ghc\YR\MN\ghMNDDUTMM.sYR'	!+TLG
	character*2 AYR,AMN,ADY,AUT,AMM                                 !+TLG
	character*4 AYEAR                                           !+TLG
		logical chek_LT										!+TLG
	  integer daybeg, monthbeg, yearbeg						!+TLG
        real Hourbeg, Minbeg									!+TLG
        real Lati, longi										!+TLG
        integer nout,noutf,nouth										!+TLG
        data nout/3/									!+TLG
	 data noutf/4/									!+TLG
	 data nouth/5/									!+TLG
c     .. local scalars ..
	integer dayut, monthut, yearut
	integer iny_R,lat,lon,iut,imm	   !++TLG
C	+, ndayut
C	integer daylt, monthlt, yearlt
	        integer iny_R12,itec(0:72),k					   !+TLG
     +,if2(0:72),ih2(0:72)
c	
	real hour, UT
C	+, SLT
	real Ri, SSN_R12, R27 
	real TEC_SSN2, teclat(0:72),glat,glon						 !+TLG
	+,fof2_SSN2, f2lat(0:72), hmf2_SSN2, h2lat(0:72)				  !-TLG
c     .. function references ..
	real model_TEC,model_GMF2Rf3,model_GMF2Rh3
c
c     .. subroutine references ..
c     indices_iny_R12, rconvtime, nnday, indices
c
C 	elapsed_time = TIMEF( )
c
C      open(nout,file=filenameout)
C	write(nout,100)
c
C      open(ninp,file=filenameinp,status='old')
C      read(ninp,*)
C  1   continue
C      read(ninp,*,err=5) Daybeg,Monthbeg,Yearbeg,Hourbeg,Minbeg,
C     &                                       Lati,Longi,chek_LT 
C++
      Daybeg=15 
      Hourbeg=24
	Minbeg=0
	Lati=0.0
	Longi=0.0
	chek_LT=.False.
      call blet2(Daybeg,ADY)
C++

       write(*,*) ' Enter YEAR:'
	read(*,*) Yearbeg
       write(*,*) ' Enter MON:'
	read(*,*) Monthbeg
      call blet4(Yearbeg,AYEAR)
	AYR=AYEAR(3:4)
	filenameout(12:13)=AYR
      filenameout(22:23)=ADY
	filenameout(30:31)=AYR
C
C Cycle on Month
C
C-      DO 49 Monthbeg=1,12
C      DO 49 Monthbeg=7,12  !TEMPPPPPPPPPPPPPP 2019
C	Monthbeg=2            ! 2025.02
      call blet2(Monthbeg,AMN)
	filenameout(15:16)=AMN
      filenameout(20:21)=AMN
C
	    dayut = daybeg
	    monthut = monthbeg
	    yearut = yearbeg
C
C      if (longi<0.0) then
C         longi = 360.0 + longi
C      end if
c
C      if (longi<0.0) then
C         longi = 360.0 + longi
C      end if
c
 	call indices_iny_R12(INY_R12,INY_R)         !+TLG
      call indices(dayut,monthut,yearut,Ri,SSN_R12,R27
	+                         ,INY_R,'SSN2')				   !+TLG
C
C Cycle on UT
C
      DO 50 iut=0,23
	call blet2(iut,AUT)
	hour=float(iut)
	filenameout(24:25)=AUT
	write(*,*) ' UT=',AUT
C
C Cycle on MM
C
      DO 150 imm=0,45,15
	call blet2(imm,AMM)
	hour=float(iut)+imm/60.
	filenameout(26:27)=AMM
C
		    UT = hour                   ! TLG
      open(nout,file=filenameout)
C
       outfilef=filenameout
	outfilef(9:9)='f'
	outfilef(19:19)='f'
	      open(noutf,file=outfilef)
	outfileh=filenameout
	outfileh(9:9)='h'
	outfileh(19:19)='h'
	      open(nouth,file=outfileh)
c
C	hour = Hourbeg + Minbeg/60.0 
C	if (chek_LT) then 
C	   daylt = daybeg
C	   monthlt = monthbeg
C	   yearlt = yearbeg
C	   SLT = hour
C	   call rconvtime(1,daylt,monthlt,yearlt,longi,SLT,UT,
C     &                                dayut,monthut,yearut)
C	else    
C	    dayut = daybeg
C	    monthut = monthbeg
C	    yearut = yearbeg
C	    UT = hour
C	    call rconvtime(0,dayut,monthut,yearut,longi,SLT,UT,
C     &                                 daylt,monthlt,yearlt)
C      end if
c  
C      call nnday(dayut,monthut,yearut,ndayut)  
C      call indices(dayut,monthut,yearut,UT,Ri,SSN_R12,R27)
     
c          TEC_SSN2
C Cycle on Lats
      glat=-90.0
	DO 51 lat=1,71
      glat=glat+2.5
	lati=glat
C
	glon=-185.0
C cycle on Long
	do 52 lon=0,72
     	glon=glon+5.0
	longi=glon
      if (longi<0.0) then
         longi = 360.0 + longi
      end if
      TEC_SSN2 = model_TEC(dayut,monthut,UT,lati,longi,SSN_R12,R27,
     &                                                      'SSN2')
      teclat(lon)=TEC_SSN2
	itec(lon)=nint(TEC_SSN2*10.)
C
      fof2_SSN2 = model_GMF2Rf3(dayut,monthut,UT,lati,longi,SSN_R12,R27,
     &                                                      'SSN2')
      f2lat(lon)=foF2_SSN2
	if2(lon)=nint(foF2_SSN2*10.)
c
      hmF2_SSN2 = model_GMF2Rh3(dayut,monthut,UT,lati,longi,SSN_R12,R27,
     &                                                      'SSN2')
      h2lat(lon)=hmF2_SSN2
	ih2(lon)=nint(hmF2_SSN2)

   52 CONTINUE  ! end lon cycle
c          TEC_R27
C      TEC_R27 = model_TEC(dayut,monthut,UT,lati,longi,SSN_R12,R27,
C     &                                                      'R27')

C	write(nout,101) daylt,monthlt,yearlt,SLT,dayut,monthut,yearut,UT,
C     &                      lati,longi,Ri,SSN_R12,R27,TEC_SSN2,TEC_R27
C	       write(*,101) (itec(k),k=0,72) 
	       write(nout,101) (itec(k),k=0,72) 
C	       write(*,101) (if2(k),k=0,72) 
	       write(noutf,101) (if2(k),k=0,72) 
C	       write(*,101) (ih2(k),k=0,72) 
	       write(nouth,101) (ih2(k),k=0,72) 
   51 CONTINUE ! end lat cycle
      close(nout)
		close(noutf)
		close(nouth)
c
  150	CONTINUE ! end MIN cycle
C	
   50 CONTINUE ! end UT cycle
C      goto 1
       write(*,*) ' Year=',AYEAR,' MN=',AMN
   49 CONTINUE ! end MN cycle
c      	
  5   continue	
c
C	elapsed_time = TIMEF( )
C	call el_time()
C	write(nout,7210) elapsed_hour,elapsed_min,elapsed_sec
c
        pause ' '
	stop
 100  format(1x,'Day Month Year   LT   Day Month Year   UT',
C     &       6x,'lati  longi    R   SSN_R12   R27 TEC_SSN2 TEC_R27')  
     &       1x,I2,2X,'lati  longi   SSN_R12  TEC_SSN2')  
C 101  format(2x,2(2(i2.2,2x),1x,i4,f6.2,3x),5(f6.1,1x),2(f6.1,2x))
 101  format(73(1X,I4))
 102  format(2x,'Model TEC - ',a)
 105  format(2x,'TEC =',f6.1)
7210  format(/'Elapsed time =',i3.2,'h',1x,i2.2,'m',1x,f5.2,'sec' )
	end	
