      program extavewmm
C........................................................Apr 2021
C extract daily average  WU, WL, WE 2000-2017
      DIMENSION wpos(0:96),wneg(0:96),wran(0:96),IM(12)
	CHARACTER*2 AYR,AMN,ADY
      CHARACTER*128 INFILEN,INFILEP,INFILER,OUTFILE,txt
            DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
c+      infilen='d:\web\graf\datw\wlnYYmm.txt'   !  Cnt(W-) 	 WL 00.15.30.45 min
C+      infilep='d:\web\graf\datw\wupYYmm.txt'   !  Cnt(W+) 	 WU	00.15.30.45 min
C+      infiler='d:\web\graf\datw\werYYmm.txt'   !  Cnt(Wrange) WE 00.15.30.45 min
C+      outfile='wuleavemm.txt'   !							 00.15.30.45 min
C+      infilen='d:\web\graf\datw\wlnYY.txt'   !  Cnt(W-) 	 WL	HOURLY
C+      infilep='d:\web\graf\datw\wupYY.txt'   !  Cnt(W+) 	 WU	HOURLY
C+      infiler='d:\web\graf\datw\werYY.txt'   !  Cnt(Wrange) WE	HOURLY
C+      outfile='wuleave.txt'   !					   ! HOURLY
      infilen='d:\web\graf\dats\wlnYYmms.txt'   !  Cnt(W-) 	 WL 00.15.30.45 min GTEC
      infilep='d:\web\graf\dats\wupYYmms.txt'   !  Cnt(W+) 	 WU	00.15.30.45 min GTEC
      infiler='d:\web\graf\dats\werYYmms.txt'   !  Cnt(Wrange) WE 00.15.30.45 min GTEC
      outfile='wuleavemms.txt'   !							 00.15.30.45 min   GTEC
C
      OPEN(10,file=outfile,access='APPEND')
C
   33 format(3A2,96(1X,F4.2),2X,F4.2)	  !00.15.30.45 min
C   33 format(3A2,24(1X,F4.2),2X,F4.2)	  !HOURLY
   34 format(1X,F8.3,1X,2A2,3(1X,F6.2))
      DO 500 iyr=0,17  ! 2000-2017
	call blet2(iyr,AYR)
      iyear=iyr+2000
      ryear=float(iyear)
C
	z1=iyear/4.0
      jz=int(z1)*4
      IF(jz.EQ.iyear) THEN
               IM(2)=29
	ndnr=366
        ELSE
                IM(2)=28
	  	ndnr=365
	       ENDIF
	del=1./ndnr
	infilep(21:22)=AYR
	infilen(21:22)=AYR
	infiler(21:22)=AYR
   	OPEN(11,file=infilep,action='READ')
	OPEN(12,file=infilen,action='READ')
	OPEN(13,file=infiler,action='READ')
	read(11,*) txt    ! title line
	read(12,*) txt    ! title line
	read(13,*) txt    ! title line
C
C      DO 100 lda=1,ndnr
        DO 100 imn=1,12
	mndy=im(imn)
	  DO 101 idy=1,mndy
	lda=ndoy(iyr,imn,idy)
	xyear=ryear+(lda-1)*del
	read(11,33,end=51)  AYR,AMN,ADY,(wpos(k),k=0,96) !00.15.30.45 min
	read(12,33,end=52)  AYR,AMN,ADY,(wneg(k),k=0,96) !00.15.30.45 min
	read(13,33,end=53)  AYR,AMN,ADY,(wran(k),k=0,96) !00.15.30.45 min
C+	read(11,33,end=51)  AYR,AMN,ADY,(wpos(k),k=0,24) !HOURLY
C+	read(12,33,end=52)  AYR,AMN,ADY,(wneg(k),k=0,24) !HOURLY
C+	read(13,33,end=53)  AYR,AMN,ADY,(wran(k),k=0,24) !HOURLY
	sump=0.
	sumn=0.
	sumr=0.
	do k=0,95							 !00.15.30.45 min
c+     do k=0,23							 !HOURLY
	sump=sump+wpos(k)
      sumn=sumn+wneg(k)
	sumr=sumr+wran(k)
	enddo
	avep=sump/96.						 !00.15.30.45 min
      aven=sumn/96.						 !00.15.30.45 min
	aver=sumr/96.						 !00.15.30.45 min
C+	avep=sump/24.						 !HOURLY
C+      aven=sumn/24.						 !HOURLY
C+	aver=sumr/24.						 !HOURLY
	write(*,34) xyear,amn,ady,avep,aven,aver
	write(10,34) xyear,amn,ady,avep,aven,aver
  101	CONTINUE
  100	CONTINUE
   51 close(unit=11)
   52 close(unit=12)
   53 close(unit=13)
  500	CONTINUE
      pause ' '
	STOP
	END