      program mapinter2
C..................................................................Oct.2015
C IONEX grids -87.5:2,5:87.5; -180:5:180;
C Add maps tc....jYR
C
C Interpolate maps t, f, h from 2h to 1h maps
C .................................................................Dec 2011
C
	dimension ires(0:72),XX(0:72),YY(0:72),ZZ(0:72),IM(12)
	CHARACTER*128 INFILE1,INFILE2,OUTFILE
	character*2 ayr,amn,ady,aut1,aut2,aut3
	+,amn_pre,ady_pre
c?	integer*2 iyr,imn,idy,ii1,ii2,ii3
	character*1 fht
	DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
C?	infile1='d:\web\dfc\yr\mn\fcmndyut.uyr'
	infile1='d:\web\graf\dtc\yr\mn\tcmndyut.jyr'
	WRITE(*,*) 'Enter AYR and AMN for input: '
	read(*,*) AYR,AMN
c//	pause ' '
C>	ayr='98'	 !temp
C>	amn='08'	 !temp
C
	read(ayr,*) yr
	iyr=int(yr)
	if(int(yr/4.)*4.eq.iyr) THEN 
	im(2)=29
	ndnr=366
	                          ELSE
	IM(2)=28
	ndnr=365
	ENDIF
	read(amn,*) rmn
	imn=int(rmn)


	write(*,23) ayr,amn
   23	format(1X,A2,1X,A2)
		WRITE(*,*) 'Enter ndy1, ndy2 for input: '
 	read(*,*) ndy1,ndy2
c-		fht='f'
c-	fht='h'
C?   24	WRITE(*,*) 'Enter <lettter> for input: '
C?	read(*,25) fht
	fht='t' !Temp
   25 format(A1)	 
	infile1(14:14)=fht
	infile1(15:15)='c'
C?	if (fht.eq.'e') infile1(9:10)='te'
C?	infile1(23:23)=fht
CNOT	infile1(27:27)=fht
	infile1(17:18)=ayr
	infile1(33:34)=ayr
  100	format(73(1X,F4.0))
  101	format(73(1X,I4))
C
C day-to-day cycle
      DO 70 idy=ndy1,ndy2
	call blet2(idy,ady)
	infile1(27:28)=ady
	infile2=infile1
	outfile=infile1
C ut-cycle Input for 01,03,...23 UT; output for 00,02,...,22 UT
	ii=0
	do iut=0,22,2
	if (iut.eq.0) then
C include prec.day
	ii1=23
	ii2=0
	ii3=1
	idy_pre=idy-1
	imn_pre=imn
	if (idy_pre.eq.0) then 
	imn_pre=imn-1
	idy_pre=im(imn_pre)
	endif
	call blet2(idy_pre,ADY_pre)
	call blet2(imn_pre,AMN_pre)
	infile1(20:21)=amn_pre
	 infile1(25:26)=amn_pre
      infile1(27:28)=ady_pre
                else
C  Only current day
	ii1=iut-1
	ii2=ii1+1
	ii3=ii2+1
	infile1(20:21)=amn
	infile1(25:26)=amn
	infile1(27:28)=ady
	       endif
	call blet2(ii1,aut1)
	call blet2(ii2,aut2)
	call blet2(ii3,aut3)
	infile1(29:30)=aut1
	infile2(20:21)=amn
	infile2(25:26)=amn
	infile2(29:30)=aut3
	infile2(27:28)=ady
	outfile=infile2
	outfile(29:30)=aut2
		OPEN(11,FILE=INFILE1)
		OPEN(12,FILE=OUTFILE)
		OPEN(13,FILE=INFILE2)
C
	do kk=1,71
	read(11,100,END=9,ERR=2) (xx(i),i=0,72)
	read(13,100,END=19,ERR=2) (yy(i),i=0,72)
	do k=0,72
	zz(k)=(xx(k)+yy(k))/2.
	ires(k)=nint(zz(k))
	enddo
		write(12,101) (ires(k),k=0,72)
crem	write(*,101) (ires(k),k=0,72)
	enddo			! end latis
C
    9	close(unit=11)
   19	close(unit=13)
      close(unit=12)

	enddo  ! end ut cycle
   70	continue ! end day-to-day cycle
	goto 33
    2	write(*,*) 'Error reading data file',infile1,infile2
   33	continue
	pause ' '
c>	if (fht.eq.'e') then
	goto 31
C>	             else
C>	goto 24
C>	endif
   31	stop
	end


