      program extaatot
C...........................................................Jan 2021
C   append aa total file aa18682020 with data for latest years
      INTEGER iaa(0:7)
	character*64 infaa,inftot
	character*4 AYEAR,BYEAR
	character*2	AYR,BMN,BDY,BUT
	infaa='d:/apkp/aa/aakpYEAR'
	inftot='d:/apkp/aa/aa18682020.txt'
C
   36	format(A4,3(1X,A2),1X,I2,2(1X,I3))
         OPEN(11,file=inftot,access='APPEND') ! outfile
C
       DO 50 iyear=2011,2020
		call blet4(iyear,AYEAR)
	AYR=AYEAR(3:4)
	read(ayr,*) ryr
	iyr=int(ryr)
		if(int(ryr/4.)*4.eq.iyr) THEN 
	ndnyr=366
	                          ELSE
	ndnyr=365
	ENDIF
C reading aa from annual file
	infaa(16:19)=AYEAR
	OPEN(10,file=infaa,action='READ')   ! infile
C
	do 49 lda=1,ndnyr
C
	do iut=0,7
	read(10,36,end=51) byear,bmn,bdy,but,kpi,iap,indaa
	iaa(iut)=indaa
	enddo
C
       ave=0.
	do k=0,7
	ave=ave+iaa(k)
	enddo
	ave=ave/8.
	write(*,35) byear,bmn,bdy,(iaa(k),k=0,7),ave
	write(11,35) byear,bmn,bdy,(iaa(k),k=0,7),ave
   49 continue
   51 close(unit=10)
C
   50 CONTINUE
      close(unit=11)
   35 format(A4,2A2,8(I3),F5.1)
	pause ' '
	STOP
	end
