      program readwule0
C.........................................................Mar. 2022
C Count monthly WUm=0, WLm=0 WUn=0, WLn=0 WUs=0, WLs=0 
C
	DIMENSION IM(12),iwneg(12),iwpos(12),iwntot(12),iwptot(12)
	+,iwp24(0:23),iwn24(0:23),cpos(12),cneg(12)
	CHARACTER*2 AYR,AMN,ADY,BYR,BMN,BDY
	CHARACTER*64 infilep,infilen,outfilep,outfilen,txt
	CHARACTER*1 mns
C	CHARACTER*4 AYEAR
      DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
      infilep='d:\web\grif\datw\wuiYRm.txt'   !  WU
      infilen='d:\web\grif\datw\wliYRm.txt'   !  WU

	    outfilep='wupos0m.txt'  ! 
	    outfilen='wlneg0m.txt'  ! 
	OPEN(11,file=outfilep,access='APPEND')
	OPEN(12,file=outfilen,access='APPEND')
C
C
C cycle on m, n, s
       DO 123 mind=1,3
	if (mind.eq.1) mns='m' !global
      if (mind.eq.2) mns='n'	! north
	if (mind.eq.3) mns='s'	! south
	write(11,30) mns
      write(12,30) mns
   30	format(1X,A1)
	infilep(23:23)=mns
	infilen(23:23)=mns
	do k=1,12
	iwntot(k)=0
      iwptot(k)=0
	enddo
C
         totdays=0.0
C cycle on years
C
         DO 150 iyear=1994,2021
C	call blet4(iyear,AYEAR)
C	AYR=AYEAR(3,4)
	iyr=iyear-iyear/100*100
	call blet2(iyr,AYR)
	z1=iyr/4.0
      jz=int(z1)*4

      IF(jz.EQ.iyr) THEN
               IM(2)=29
	dnr=366.
        ELSE
                IM(2)=28
	  	dnr=365.
	       ENDIF
	do k=1,12
	iwneg(k)=0
      iwpos(k)=0
	enddo
         totdays=totdays+dnr
	if (iyear.eq.1994) totdays=totdays-14.
C
	infilep(21:22)=ayr
	infilen(21:22)=ayr
          OPEN(13,file=infilep,action='READ')
	OPEN(14,file=infilen,action='READ')
	read(13,*) txt
	read(14,*) txt
C
C cycle on mn
C
	DO 151 imn=1,12
       call blet2(imn,AMN)
	mndy=im(imn)
C
C cycle on day
   36 format(3A2,24(1X,I4))
C
        DO 152 idy=1,mndy
	call blet2(idy,ADY)
C
      read(13,36,end=51) BYR,BMN,BDY,(iwp24(k),k=0,23)
      read(14,36,end=52) BYR,BMN,BDY,(iwn24(k),k=0,23)
	if ((iyear.eq.1994).and.(imn.eq.1).and.(idy.lt.15)) then 
	goto 152
	endif
	do k=0,23
	if (iwp24(k).eq.0) iwpos(imn)=iwpos(imn)+1
	if (iwn24(k).eq.0) iwneg(imn)=iwneg(imn)+1
	enddo
  152	continue ! daily cycle
C
	if ((iyear.eq.1994).and.(imn.eq.1)) then 
	days=17.
	else
       days=float(mndy)
       endif
        cpos(imn)=iwpos(imn)/(days*24.)*100.  !%
        cneg(imn)=iwneg(imn)/(days*24.)*100.  !%
	iwptot(imn)=iwptot(imn)+iwpos(imn)
	iwntot(imn)=iwntot(imn)+iwneg(imn)
C
  151	continue ! monthly cycle
   51   close(unit=13)
   52	close(unit=14)
C Output:
	write(*,33) AYR,AMN,(cpos(k),k=1,12)
	write(11,33) AYR,AMN,(cpos(k),k=1,12)
	write(*,33) AYR,AMN,(cneg(k),k=1,12)
	write(12,33) AYR,AMN,(cneg(k),k=1,12)
C
  150 CONTINUE ! yearly cycle 
        totdayshr=totdays*24.
	write(*,35)	totdayshr
	write(11,35)	totdayshr
	write(12,35)	totdayshr
	write(*,34) (iwptot(k),k=1,12)
	write(11,34) (iwptot(k),k=1,12)
	write(*,34) (iwntot(k),k=1,12)
	write(12,34) (iwntot(k),k=1,12)
C
  123	CONTINUE       ! index type
    3	close(unit=11)
    2      close(unit=12)
   33 format(1X,2A2,12(1X,F8.4))
   34 format(1X,12(1X,I4))
   35 format(1X,F8.0)
	pause ' '
	STOP
	END