      subroutine mapionexmm(fht,ayear,amn,ady)
C.....................................................Sep 2024
C GIM maps in geogr. coords. 15min
C ady='00' for CCIR monthly median
C.....................................................
C produce diurnal results in formal UPC_IONEX format 
C          for given YEAR, MN, DY, UT=00,01,...,23, MIN = 00, 15, 30, 45
C
	CHARACTER*65 INFILE,OUTFILE
	CHARACTER*2 AYR,AMN,ADY,AUT,CMN,amap,AMM,CDY
	CHARACTER*4 AYEAR
	CHARACTER*1 fht ! foF2=f, hmF2 =h,TEC =t
	CHARACTER*20 start,enddesc,epoch
        CHARACTER*60 title1(16),tit1,tit2,tit3
	CHARACTER*20 title2(16),utend
	character*80 txt1(71),txt2(71),txt3(71),txt4(71)
	character*45 txt5(71)
	CHARACTER*3 tmon(12),rmon,doy
	dimension im(12)
C
	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     IRI-Plas            '
	+,'GIM V1.0            UPC                 11-Mar-2015 00:40   '
	+,' TEC IONOSPHERE MAPS                                        '
	+,'Global ionosphere maps for day 076, 2015 (17-03-2015)       '
	+,'produced with IRI-Plas model                                '
	+,'TEC*0.1 TECU; foF2*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
C      enddesc='END OF HEADER       '
      start='START OF TEC MAP    '
	enddesc='END OF HEADER       '
	epoch='EPOCH OF CURRENT MAP'
      utend='END OF TEC MAP      ' 
	iutend=23
	immend=45
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)
	 kdy=idy
	CDY=ADY
	if (kdy.eq.0) then 
	kdy=15
	CDY='15'
	endif
	lda=ndoy(iyr,imn,kdy)
	call blet3(lda,doy)
c
C_      infile='c:\web\graf\dtu\YR\MN\ut\tcMNDDUTMM.uYR'  !UPC
      infile='tcMN00UTMM.mYR'  !CCIR
C+++
        infile(1:1)=fht
	if (ADY.eq.'00') infile(2:2)='i'
	infile(13:14)=AYR
		infile(3:4)=AMN
		infile(5:6)=ADY
C_      outfile='c:\web\graf\dtu\YR\YRMNDYt_15m.txt'
      outfile='YRMNDYtc_15m.txt'
      outfile(7:7)=fht
	if (ADY.eq.'00') outfile(8:8)='i'
C+++
C	
	outfile(1:2)=AYR
	outfile(3:4)=AMN
	outfile(5:6)=ADY
C
	OPEN(10,file=outfile)
C
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 (fht.eq.'t') tit1(2:4)='TEC'
      	if (fht.eq.'f') tit1(1:4)='foF2'
      	if (fht.eq.'h') tit1(1:4)='hmF2'
      	endif
	if (nn.eq.4) then
	tit1(32:34)=doy
	tit1(37:40)=AYEAR
	tit1(43:44)=CDY
	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)=CDY
	endif
	write(*,202) tit1,title2(nn)
	write(10,202) tit1,title2(nn)
	ENDDO
  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)=CDY
C-	tit3(29:30)='00' ! min
	tit3(35:36)='00' ! sec
C
C cycle	UT
       imap=0
C
        DO 100 iut=0,iutend
	call blet2(iut,AUT)
	infile(7:8)=AUT
C
C		imap=iut+1
C
C cycle 15 min
C
       immfin=45
      if (iut.eq.iutend) immfin=immend
       DO	110 imm=0,immfin,15
	call blet2(imm,AMM)
	infile(9:10)=AMM
	imap=imap+1
 	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
	OPEN(11,file=infile,action='READ')
C =========================================
c
	do i=1,71
	i1=72-i
	READ (11,107,END=99,ERR=2) TXT1(i1),txt2(i1),txt3(i1),txt4(i1)
	+,txt5(i1) !map lines LATi(71)=(-87.5),...,LATI(1)=(+87.5)
	enddo
	glat=90.0
	do i=1,71
	glat=glat-2.5
C	write(*,1073) glat	  !Temp
	write(10,1073) glat
	write(10,1071) TXT1(i)
	write(10,1071) TXT2(i)
	write(10,1071) TXT3(i)
	write(10,1071) TXT4(i)
	write(10,1072) TXT5(i)
	enddo
  99	close(unit=11)
C
C Write 'END OF TEC MAP'
		write(*,202) tit2,utend
		write(10,202) tit2,utend
  110	continue   ! end min cycle
  100	continue   ! end ut cycle
        close(unit=10)
       GOTO 33
c==	endif
    2 CONTINUE
       write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
 	pause ' '
	goto 34
   33	continue
      write(*,*) infile,outfile
   34  RETURN
       END
