      subroutine subpianiaWm1(YEAR,AMN,ADY,xlat)
C
C.........................................................Nov. 2021
C Global WU, WL, WE from Wo maps in magn. coords.
C if xlat=0.0 output global results
C if xlat=60.0 output Arctic results for MLAT >=60 deg
C if xlat=-60.0 output Antarctic results for MLAT <=-60 deg
C
C.........................................................Dec. 2020
C Include weight e(glat)
C
C.........................................................Nov. 2020
C Weighted PIA -pos ion activity, NIA - neg ion activity
C extracted from global Wc(TEC) index derived from JPL GIM-TEC (IONEX)
C for ADY_pre and forecast for DD2
C
	DIMENSION weg(4),IM(12),iwneg(0:24),iwpos(0:24),iwran(0:24)
	CHARACTER*128 INFILE,OUTFILEN,OUTFILEP,OUTFILER  !global weighted Wfp,Wfn,Wfr = range index
C-	+,indate 
	CHARACTER*2 AYR,AUT,AMN,ADY,AUTOUT(0:23)
	CHARACTER*4 YEAR
	INTEGER ivsr(0:72) !  set of Wf indices for long=-10:5:180 at given lati
		DATA WEG/0.,0.6931,1.0986,1.3863/  ! =ln1, ln2, ln3, ln4
            DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
C-	indate='d:/web/graf/date'    !!! Tamara !!!!!!!	 
C-	open(10,file=indate)							 
C-	read(10,799) YEAR,AMN_cur,DD2,YEAR_pre,AMN_pre,ADY_pre,lda,lda_pre  !FORMAT NUMBER = 799
C-	WRITE(*,798) YEAR,AMN_cur,DD2,YEAR_pre,AMN_pre,ADY_pre,lda,lda_pre !FORMAT NUMBER = 798
C-	close(unit=10)
C-  798	format(' YEAR, AMN, DD2 = ',A4,2(1X,A2),1X,A4,2(1X,A2),2(1X,I3))
C-  799	format(A4,2(1X,A2),1X,A4,2(1X,A2),2(1X,I3))	
C
C
      AYR=YEAR(3:4)  ! for current day  	
        read(AMN,*) rmn
	imn=int(rmn)
        read(ADY,*) rdy
	  	idy=int(rdy)
C
C--      infile='d:\web\graf\dwc\YY\MM\ut\wcMMDDUT.jYY'   ! current mn
CPRE      infile='d:\web\dws\YY\MM\woMMDDUT.jYY'   ! current mn
      infile='f:\web\dws\YY\MM\woMMDDUT.jYY'   ! current mn -15d
C	outfilen='wfnYR.txt'   ! Cnt(Wf-) 
C	outfilep='wfpYR.txt'   ! Cnt(Wf+) 
C	outfiler='wfrYR.txt'
CPRE      outfilen='d:\web\grif\datw\wlnYYm.txt'   !  Cnt(W-) 	 WL
CPRE      outfilep='d:\web\grif\datw\wupYYm.txt'   !  Cnt(W+) 	 WU
CPRE      outfiler='d:\web\grif\datw\werYYm.txt'   !  Cnt(Wrange) WE
      outfilen='c:\web\grif\datw\wloYYm.txt'   !  Cnt(W-) 	 WL -15d mag
      outfilep='c:\web\grif\datw\wuoYYm.txt'   !  Cnt(W+) 	 WU	-15d mag
      outfiler='c:\web\grif\datw\weoYYm.txt'   !  Cnt(Wrange) WE	-15d mag
      if (xlat.lt.-59.) then
	outfilen(23:23)='s'
	outfilep(23:23)='s'
	outfiler(23:23)='s'
	endif
      if (xlat.gt.59.) then
	outfilen(23:23)='n'
	outfilep(23:23)='n'
	outfiler(23:23)='n'
	endif
	do iut=0,23
	call blet2(iut,aut)
	autout(iut)=aut
	enddo
   17 format(A2)
   31 FORMAT('YYMMDD',1X,24(2X,A2,1X),2X,'DAY')
   32 FORMAT(73(1X,I4))
C
  330	CONTINUE
C      WRITE(*,*)' ENTER YR OF INPUT FILE=	'
C	read(*,17) AYR
	read(AYR,*) ryr
	IYR=int(ryr)   ! current yr
	if (iyr.lt.90) then
	iyyyy=2000+iyr
	              else
	iyyyy=1900+iyr
	endif
	z1=iyyyy/4.0
      jz=int(z1)*4

      IF(jz.EQ.iyyyy) THEN
               IM(2)=29
	dnr=366.
        ELSE
                IM(2)=28
	  	dnr=365.
	       ENDIF
	infile(12:13)=ayr
	infile(28:29)=ayr
	outfilep(21:22)=ayr
	outfilen(21:22)=ayr
	outfiler(21:22)=ayr
C
	OPEN(11,file=outfilep,access='APPEND')
	OPEN(12,file=outfilen,access='APPEND')
	OPEN(13,file=outfiler,access='APPEND')

C
C month
C
	infile(15:16)=amn
	infile(20:21)=amn
	mndy=im(imn)
C
C  Day
C
	infile(22:23)=ady
C
	IF ((AMN.eq.'01').and.(ADY.eq.'01')) THEN
	write(*,31) (autout(k),k=0,23)
	write(11,31) (autout(k),k=0,23)
	write(12,31) (autout(k),k=0,23)
	write(13,31) (autout(k),k=0,23)
	ENDIF
C  UT cycle
C
      DO k=0,24
	iwneg(k)=0
	iwpos(k)=0
	iwran(k)=0
	ENDDO
	 wdyp=0.
	wdyn=0.
	wdyr=0.
	DO 53 iut=0,23
	call blet2(iut,AUT)
      infile(24:25)=aut
C
   	OPEN(10,file=infile,action='READ')
	sumn=0.		 ! count of Wf >=1
	sump=0.		 ! count of Wf <=-1
	icntp=0
	swegp=0.
      icntn=0
	swegn=0.
C
C/ cycle for lats:
       glat=-90.0	                  ! AD
	  do 54 ilat=1,71
	glat=glat+2.5				  ! AD
	elat=1.0+0.0001235*glat**2	  ! AD
	  read(10,32) (ivsr(k),k=0,72) 
C
	IF (xlat.eq.0.) goto 123
C 
     	IF (xlat.lt.-59.) THEN
		if(glat.le.-60.) then
      	goto 123
 	                       else
      	goto 54
	                       endif
     	                 ENDIF
C
      IF(xlat.gt.59.) THEN
	    if (glat.ge.60.) then
	    goto 123
	                  else
	    goto 54
	                    endif
	                 ENDIF
C
  123	DO 333 ilon=0,72
          if (ivsr(ilon).gt.1) then
        iad=ivsr(ilon)
c	sump=sump+weg(iad)*ivsr(ilon)
	sump=sump+elat*weg(iad)*ivsr(ilon)  ! AD
	icntp=icntp+1
	swegp=swegp+weg(iad)
	goto 333
	endif
          if (ivsr(ilon).lt.-1) then
        iad=-ivsr(ilon)
c	sumn=sumn+weg(iad)*ivsr(ilon)
	sumn=sumn+elat*weg(iad)*ivsr(ilon)   ! AD
	icntn=icntn+1
	swegn=swegn+weg(iad)
	goto 333
	endif
  333	CONTINUE
   54 CONTINUE
      xpos=0.
      if (icntp.gt.0.) then
C		xpos=sump/swegp		 ! /sum(weights)
		xpos=sump/icntp		 ! /cnt(Wf+)
	endif
      xneg=0.
      if (icntn.gt.0.) then
C			xneg=sumn/swegn	  ! /sum(weights)
			xneg=sumn/icntn	  ! /cnt(Wf-)
	endif
	xrange=xpos-xneg
	wdyp=wdyp+xpos
	wdyn=wdyn+xneg
      wdyr=wdyr+xrange
      iwneg(iut)=nint(xneg*100.)
	iwpos(iut)=nint(xpos*100.)
	iwran(iut)=nint(xrange*100.)
	close(unit=10)
   53	CONTINUE           ! end UT cycle
       iwpos(24)=nint(wdyp/24.*100.)
	iwneg(24)=nint(wdyn/24.*100.)
	iwran(24)=nint(wdyr/24.*100.)
C	write(*,33) AYR,AMN,ADY,(iwpos(k),k=0,24)
	write(11,33) AYR,AMN,ADY,(iwpos(k),k=0,24)
C	write(*,33) AYR,AMN,ADY,(iwneg(k),k=0,24)
	write(12,33) AYR,AMN,ADY,(iwneg(k),k=0,24)
C	write(*,33) AYR,AMN,ADY,(iwran(k),k=0,24)
	write(13,33) AYR,AMN,ADY,(iwran(k),k=0,24)
   33 format(3A2,24(1X,I4),2X,I4)
   52 CONTINUE  ! daily cycle
   51 CONTINUE  ! Monthly cycle
      close(unit=11)
	close(unit=12)
	close(unit=13)
C-      if (iyr.ne.20) GOTO 330
C      pause ' '
	RETURN
C	STOP
	END
