      program extwcpiaeq
C..Produce 1h Wpo(pia) index..for 13 Hpo/Kp-stations........................July 2022
C JPL Wc indices 
C Wc interp from 4 W indices: at dlati=2.5o, dlong=5o around Kp station
C Wc = combined  with weights from 4 W-indices surrounding Kp station
C 
C 
C
      CHARACTER*64 outfile
	CHARACTER*2 AYR,AMN,ADY,AUT,aa(24),bb
	CHARACTER*4 AYEAR,AMEAN
	DIMENSION wp(13,0:23),glats(13),glons(13),IM(12),iwp(0:23)
	DATA im/31,28,31,30,31,30,31,31,30,31,30,31/
	DATA glats/-49.9, -45.0, 56.6, 51.9, 49.8, 47.9, 57.5, 52.1, 46.9
	+, 54.0, 47.2, 61.2, 59.4/
	DATA glons/172.4, 149.0, 17.4, 11.7,  9.1, 12.7,358.8,356.8,355.5
	+,284.5,282.6,246.7,224.7/
	DATA aa/'00','01','02','03','04','05','06','07','08','09','10'
	+,'11','12','13','14','15','16','17','18','19','20','21','22','23'/
C
C
	bb='UT'
	amean='mean'
	outfile='d:\web\graf\wpoyr.txt'	 ! daily 0:23 UT + daily Wpo index
C
198	format(4X,A2,24(3X,A2),3X,A5)
C
C Year cycle
       DO 150 iyear=1994,2022
	 call blet4(iyear,AYEAR)
	 AYR=Ayear(3:4)
	 outfile(16:17)=AYR          
       OPEN(12,file=outfile)
	write(*,198) bb,aa,amean
	write(12,198) bb,aa,amean

C
	ndy=0
C
C++ READ 1h Wp
		z1=iyear/4.0
      jz=int(z1)*4
      IF(jz.EQ.iyear) THEN
	ndnr=366
	im(2)=29
		  ELSE
                ndnr=365
	          im(2)=28
		       ENDIF
C
       imn2=12
	if (iyear.eq.2022) imn=06  !TEMPPPPPPPPPPPPPPPP
C
C Month cycle
	 DO 151 imn=1,imn2
	call blet2(imn,amn)
	ndmn=im(imn)
C
C
C daily cycle
       DO 152 idy=1,ndmn 
	call blet2(idy,ady)
C
	lda=ndoy(iyr,imn,idy)
C
C UT cycle
  43    DO 153 iut=0,23
	call blet2(iut,aut)
	DO k=1,13
	wp(k,iut)=0.
	ENDDO
C
C cycle on stations
C
       DO ista=1,13
C
      glat=glats(ista)
	glon=glons(ista)
	call subinterpw(glat,glon,ayr,amn,ady,aut,res)
	wp(ista,iut)=res
	ENDDO
  153 CONTINUE  ! End UT cycle
C
        wpday=0.
         DO kut=0,23
	 wpave=0.
        do kk=1,13
	wpave=wpave+wp(kk,kut)
	  enddo
	wph=wpave/24.
	iwp(kut)=nint(wph*100.)
	wpday=wpday+wph
	  ENDDO
	iwpday=nint(wpday*100.)
C Output
      write(*,32) ayr,amn,ady,(iwp(k),k=0,23),iwpday
      write(12,32) ayr,amn,ady,(iwp(k),k=0,23),iwpday
  152 CONTINUE  ! End Day cycle
C
  151 CONTINUE  ! End Mon cycle
   50		close(unit=12)
  150 continue  ! End Year cycle
   32 format(3(1X,A2),1X,24(1X,I5),2X,I5)
	pause ' '
	STOP
	END