      program mapinter3a
C..................................................................Apr.2012
C IONEX grids -87.5:2,5:87.5; -180:5:180;
C Add maps ec....uYR
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,ady0,amn0,ayr0
	integer*2 iyr,imn,idy,ii1,ii2,ii3,idy0,iyr0,imn0
	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'
	WRITE(*,*) 'Check YEAR and month for input: '
	ayr='02'	 !temp
	amn='11'	 !temp
	iyr=02		 !temp
	imn=11		 !temp
	write(*,23) ayr,amn
   23	format(1X,A2,1X,A2)
c//	pause ' '
		WRITE(*,*) 'Enter ndy1, ndy2 for input: '
 	read(*,*) ndy1,ndy2
C+
	ryr=float(iyr)
		if(int(ryr/4.)*4.eq.iyr) THEN 
  	im(2)=29
	                          ELSE
	IM(2)=28
	ENDIF

	iyr0=iyr
	imn0=imn
	idy0=ndy1
C+
	if (ndy1.eq.1) then
	imn0=imn-1
      	if (imn0.eq.0) then
	iyr0=iyr-1
	if (iyr0.lt.0) iyr0=99
	imn0=12
	    endif
	idy0=im(imn0)
	                endif
C+
	call blet2(idy0,ady0)
	call blet2(imn0,amn0)
	call blet2(iyr0,ayr0)
c-		fht='f'
c-	fht='h'
   24	WRITE(*,*) 'Enter <lettter> for input: '
	read(*,25) fht
   25 format(A1)	 
crem       	fht='t'
	infile1(9:9)=fht
	infile1(10:10)='c'
	if (fht.eq.'e') infile1(9:10)='te'
	infile1(18:18)=fht
CNOT	infile1(27:27)=fht
	infile1(12:13)=ayr0
	infile1(15:16)=amn0
	infile1(20:21)=amn0
	infile1(28:29)=ayr0
	infile1(22:23)=ady0
	infile2=infile1
	infile2(12:13)=ayr
	infile2(15:16)=amn
	infile2(20:21)=amn
	infile2(28:29)=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)
	infile2(22:23)=ady
	outfile=infile2
C+
	if (idy.eq.1) goto 123
	 idy0=idy-1
	call blet2(idy0,ady0)
	infile1(22:23)=ady0
  123	continue
C ut-cycle
	ii=0
c//	do iut=0,23,2
c//	ii1=iut
c//	ii2=ii1+1
c//	ii3=ii2+1
      do 125 iut=0,22,2
 	ii1=iut-1
	ii2=ii1+1
	ii3=ii2+1
c//	if((ii1.lt.0).and.(idy.eq.1)) goto 125 ! avoid prec. month for idy=1,iut=0 
      if (ii1.lt.0) then
	 	ii1=23
c//	infile1(22:23)=ady0
	endif

	call blet2(ii1,aut1)
	call blet2(ii2,aut2)
	call blet2(ii3,aut3)
	infile1(24:25)=aut1
	outfile(24:25)=aut2
	infile2(24:25)=aut3
		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)
	infile1=infile2
  125	continue  ! end ut cycle
c//	enddo  ! end ut cycle
   70	continue ! end day-to-day cycle
	goto 33
    2	write(*,*) 'Error reading data file',infile1,infile2
	pause ' '
   33	continue
	if (fht.eq.'e') then
	goto 31
	             else
	goto 24
	endif
   31	stop
	end


