      subroutine mapionexfh(ayear,amn,ady,iutend,immend)
C.....................................................Oct 2024
C GIM maps in geograf, coords. 15min
C.....................................................May 2018
C produce diurnal results in formal UPC_IONEX format 
C          for given YR, MN, DY, UT=00,01,...,23 15-min
C
	CHARACTER*65 OUTFILE
	CHARACTER*2 AYR,AMN,ADY,AUT,CMN,amap,AMM,UTOUT,MMOUT
	CHARACTER*4 AYEAR
	CHARACTER*1 fhts,qs ! foF2: fhts=f, hmF2: fhts=h; qs=u (uadg fit), gs=c (uqrg fit) 
	CHARACTER*20 start,enddesc,epoch
        CHARACTER*60 title1(16),tit1,tit2,tit3
	CHARACTER*20 title2(16),utend
	CHARACTER*3 tmon(12),rmon,doy
	dimension im(12)
	INTEGER itec(71,0:72)
C
            COMMON /MTEC/itec
      COMMON /DAN/RZ,daynr,dnr,imap,irun,qs,iutfin,immfin 
C irun=1 TECobs; =2 TEC-CCIR; =3 foF2-CCIR; =4 hmF2-ccir; =5 foF2 instant; =6 hmF2 instant 
	DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
	DATA tmon/'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'
	+,'Sep','Oct','Nov','Dec'/
      DATA title1/
     + '     1.0            IONOSPHERE MAPS     GPS                 '
	+,'GIM V3.0            UPC - IonSAT        11-Mar-2015 00:40   '
	+,'GIM-foF2 INSTANT IONOSPHERE MAPS                            '
	+,'Global ionosphere maps for day 076, 2015 (17-03-2015)       '
	+,'produced from UPC GIM-TEC IONEX MAP                         '
	+,'foF2 in 0.1 MHz; hmF2, km. Hours, UT.                       '
	+,'  2015     3    18     0     0     0                        '
	+,'  2015     3    18    23    45     0                        '
	+,'  3600                                                      '
	+,'    96                                                      '
	+,'     2                                                      '
	+,'   450.0 450.0   0.0                                        '
	+,'    87.5 -87.5  -2.5                                        '
	+,'  -180.0 180.0   5.0                                        '
	+,'     0                                                      '
	+,'                                                            '/
      tit1=title1(16)
      tit2=tit1
      tit3=tit1
      DATA title2/
     + 'IONEX VERSION / TYPE','PGM / RUN BY / DATE '
	+,'COMMENT             ','COMMENT             '
	+,'COMMENT             ','COMMENT             '
	+,'EPOCH OF FIRST MAP  ','EPOCH OF LAST MAP   '
	+,'INTERVAL            ','# OF MAPS IN FILE   '
	+,'MAP DIMENSION       ','HGT1 / HGT2 / DHGT  '
	+,'LAT1 / LAT2 / DLAT  ','LON1 / LON2 / DLON  '
	+,'EXPONENT            ','END OF HEADER       '/
C
C
      if (irun.eq.5) fhts='f'  !GIM-foF2
	if (irun.eq.6) fhts='h'	 !GIM-hmF2
	if (irun.eq.7) fhts='t'	 !GIM-TEC
	if (irun.eq.8) fhts='w'	 !GIM-W index
C      enddesc='END OF HEADER       '
      start='START OF TEC MAP    '
	enddesc='END OF HEADER       '
	epoch='EPOCH OF CURRENT MAP'
      utend='END OF TEC MAP      ' 
C	btxt='-180.0 180.0   5.0 450.0'
C
      write(*,*) AYEAR
		ayr=ayear(3:4)
	read(ayr,*) ryr
	iyr=int(ryr)
	read(ayear,*) xyear
	IYYYY=int(xyear)
	read(ayr,*) ryr
	iyr=int(ryr)
	write(*,*) amn
	CMN=AMN
	if (CMN(1:1).eq.'0') CMN(1:1)=' '
	read(amn,*) xmn
	imn=int(xmn)
	rmon=tmon(imn)
C
		idayy=365
	      IM(2)=28
        if(iyr/4*4.eq.iyr) then
	  idayy=366
	   	 IM(2)=29
	  endif

	read(ady,*) xdy
	idy=int(xdy)
	lda=ndoy(iyr,imn,idy)
	call blet3(lda,doy)
c
      outfile='YRMNDYfx_15m.txt'
C+++
      if (qs.eq.'q') then
	outfile(8:8)='q'  ! ~uqrg
	else
	outfile(8:8)='a'   ! ~uadg 
	endif
C
C
	outfile(1:2)=AYR
	outfile(3:4)=AMN
	outfile(5:6)=ADY
	outfile(7:7)=fhts

	OPEN(10,file=outfile,access='APPEND')
C
      IF ((iutend.eq.0).and.(immend.eq.0)) THEN
C write title lines
C
	DO nn=1,16
	tit1=title1(nn)
	if (nn.eq.2) then
	tit1(41:42)=ADY
	tit1(44:46)=rmon
	tit1(48:51)=AYEAR
	endif
	if (nn.eq.3) then
	if (irun.eq.5) tit1(5:6)='fo'
      if (irun.eq.6) tit1(5:6)='hm'
                   endif	
C
	if (nn.eq.4) then
	tit1(32:34)=doy
	tit1(37:40)=AYEAR
	tit1(43:44)=ADY
	tit1(46:47)=AMN
	endif
	if ((nn.eq.7).or.(nn.eq.8)) then
	tit1(3:6)=AYEAR
	tit1(11:12)=CMN
	tit1(17:18)=ADY
	endif
	if (nn.eq.8) then
	call blet2(iutfin,UTOUT)
      call blet2(immfin,MMOUT)
	tit1(23:24)=UTOUT
      tit1(29:30)=MMOUT
	endif
	write(*,202) tit1,title2(nn)
	write(10,202) tit1,title2(nn)
	ENDDO
                ENDIF
  202 format(A60,A20)
  107 format(4(A80),A45)
 1071 format(A80)
 1072 format(A45)
 1073 format(3X,F5.1,'-180.0 180.0   5.0 450.0',28X
     +,'LAT/LON1/LON2/DLON/H')
C
      tit3(3:6)=AYEAR
	tit3(11:12)=AMN
	tit3(17:18)=ADY
	tit3(35:36)='00' ! sec
C
C
       iut=iutend
	call blet2(iut,AUT)
C
        imm=immend
	call blet2(imm,AMM)
 	call blet2(imap,amap)
	tit2(5:6)=AMAP
	write(*,202) tit2,start
	write(10,202) tit2,start
C
	tit3(23:24)=AUT
	tit3(29:30)=AMM ! min
	write(*,202) tit3,epoch
	write(10,202) tit3,epoch
C
 1074 format(16I5)
 1075 format(9I5)
C =========================================
	glat=90.0
	do 100 i=1,71
	glat=glat-2.5
C	write(*,1073) glat	  !Temp
	write(10,1073) glat
        DO kk=1,4
      	k1=(kk-1)*16
      	k2=k1+15
C      	write(*,1074) (itec(i,k),k=k1,k2)
      	write(10,1074) (itec(i,k),k=k1,k2)
        ENDDO
	    k3=k2+1
      	k4=k3+8
C      	write(*,1075) (itec(i,k),k=k3,k4)
      	write(10,1075) (itec(i,k),k=k3,k4)
  100	continue
C
C Write 'END OF TEC MAP'
		write(*,202) tit2,utend
		write(10,202) tit2,utend
        close(unit=10)
   33	continue
      write(*,*) outfile
   34  RETURN
       END
