      program extmed3h
C.......................................................Aug 2021
C Extract median for SSN2=0 periods (Kp<3; Kp >=3)
C
      character*128 infilwu,infilwl,infilwe,outfile
      dimension BB(180,0:7),xme(0:7)      
	integer ndat
	      character*1 cx
	character*2 AYR,AMN,BYR,BMN,BDY,AINP
C		COMMON /BL1/BB,XME
C
	infilwu='d:\Arts\Confer\SCOSTEP\INDIA\wuYRMN3.txt'
	infilwl='wlYRMN3.txt'
	infilwe='weYRMN3.txt'
	outfile='wulemed0_3.txt'
      OPEN(10, file=outfile,access='APPEND')
C
        write(*,*) ' Enter iyr:'
	read(*,*) iyr
	call blet2(iyr,AYR)
C
        write(*,*) ' Enter imn:'
	read(*,*) imn
      call blet2(imn,AMN)
C
        write(*,*) ' Enter cx (0 or 3):'
	read(*,*) cx
	infilwu(36:36)=cx
	if (cx.eq.'3') goto 22
C
	infilwu(32:33)=ayr
      infilwu(34:35)=amn
   22	continue
	infilwl=infilwu
      infilwe=infilwu
	infilwl(31:31)='l'
	infilwe(31:31)='e'
      OPEN(11,file=infilwu)
	OPEN(12,file=infilwl)
	OPEN(13,file=infilwe)
   30	FORMAT(1X,3A2,8(1X,F6.2))
C
       DO 23 jj=11,13
	Call blet2(jj,AINP)
	      ninp=jj
	do k=0,7
	xme(k)=0.
	enddo
      nn=0
      DO n=1,180
	read(ninp,30,end=24) BYR,BMN,BDY,(BB(n,k),k=0,7)
	do k=0,7
	if (BB(n,k).lt.0.) BB(n,k)=abs(BB(n,k))
	enddo
	nn=nn+1
	ENDDO
   24 close(unit=ninp)
      ndat=nn
      call submedian3h(ndat,BB,xme)
	if (jj.eq.12) then
	do k=0,7
	xme(k)=xme(k)*(-1.)
	enddo
	endif
C
        write(*,30) AYR,AMN,Ainp,(xme(k),k=0,7)
	write(10,30) AYR,AMN,Ainp,(xme(k),k=0,7)
   23	CONTINUE
      close(unit=10)
      pause ' '
	STOP
	END