      program aeapotest
C..........................................................Oct 2023
C Test AE(Apo) and AE(E,Apo) relations
C Input: 2018 ~ 5 3days data AEobs, Apo-obs, VBz-obs
C produce model AEmod1(Apo) and AEmod2(E,Apo)
C produce R**2 value between AEobs and AEmod1, AEobs and AEmod2
C
      DIMENSION aeob(72),apob(72),vsw(72),bz(72),eob(72)
     +,aemod1(72),aemod2(72)
C      CHARACTER*4 AYEAR
      CHARACTER*2 AMN,ADY
	CHARACTER*72 infilae,infilap,infilvb,outfile
C
       a=-916.8
	b=-0.02744
	c=874.0
	d=0.001715
	p00=219.1
	p10=34.88
	p01=4.955
C
       infilae='ae2018MNDD.txt'
       outfile='ae2018MNDD.res'
	iyear=2018
C??	del=1./365.
c
	write(*,*) ' Enter MN,DY,lda:'
	read(*,*) imn1,idy1,lda1
	imn0=imn1
	idy0=idy1-1
	lda0=lda1-1
	if (idy0.eq.0) then
	imn0=imn1-1
	idy0=31
	endif
      lda2=lda1+1
	imn2=imn1
	idy2=idy1+1
C
       call blet2(imn1,AMN)
       call blet2(idy1,ADY)
	infilae(7:8)=AMN
	infilae(9:10)=ADY
	infilap=infilae
	infilap(1:2)='ap'
	infilvb=infilae
	infilvb(1:2)='vb'
       outfile=infilae
	outfile(12:14)='res'
C
       OPEN(11,file=infilae,action='READ')
       OPEN(12,file=infilap,action='READ')
	OPEN(13,file=infilvb,action='READ')
	OPEN(10,file=outfile)
   30	format(1X,I4,1X,I3,3(1X,I2),1X,F6.0,1X,F5.0,1X,F8.2,2(1X,F7.1))
C
        DO kk=1,72
	read(11,*,end=51) k1yrmndd,rut,i76,aeob(kk),auob,alob,aoob
	read(12,*,end=52) k2yr,k2mn,k2dd,rut,rut1,rdd1,rdd2,hpo,iapo,k20
	apob(kk)=float(iapo)
      read(13,*,end=53) k3yr,lda,iut,btot,bz(kk),ptem,pden,vsw(kk)
      eob(kk)=-1.*bz(kk)*vsw(kk)/1000.
	aemod1(kk)=	a*exp(b*apob(kk))+c*exp(d*apob(kk))
      aemod2(kk)=p00+p10*eob(kk)+p01*apob(kk)
c
	write(*,30) iyear,lda,k2mn,k2dd,iut,aeob(kk),apob(kk),eob(kk)
	+,aemod1(kk),aemod2(kk)
	write(10,30) iyear,lda,k2mn,k2dd,iut,aeob(kk),apob(kk),eob(kk)
	+,aemod1(kk),aemod2(kk)
	ENDDO
   51 close(11)
   52 close(12)
   53 close(13)
      close(10)
	pause ' '
	STOP
	END
