      program calmed380
C..........................................................Dec 2021
C produce median from indices for 380 storms /= Jan, eqn, Jul.
C
      character*64 infile,infile0,infile1,infile2,infile3
	+,outfile
C-     +,outhss
	     character*1 gns,gns4(4)
	real dati(477,72),rmed(72),xi(72)
	integer med(72)
C	+,ires(72)
	DATA gns4/'f','m','n','s'/
		COMMON /BL1/dati,RMED
Ctot	infile0='hsswp3df.txt' !0
Ctot	infile1='hsswu3dx.txt' !1
Ctot	infile2='hsswl3dx.txt' !2
Ctot	infile3='hsswe3dx.txt' !3
Cjan	infile0='hsswp3dfjan.txt' !0
Cjan	infile1='hsswu3dxjan.txt' !1
Cjan	infile2='hsswl3dxjan.txt' !2
Cjan	infile3='hsswe3dxjan.txt' !3
Cjul	infile0='hsswp3dfjul.txt' !0
Cjul	infile1='hsswu3dxjul.txt' !1
Cjul	infile2='hsswl3dxjul.txt' !2
Cjul	infile3='hsswe3dxjul.txt' !3
	infile0='hsswp3dfeqn.txt' !0
	infile1='hsswu3dxeqn.txt' !1
	infile2='hsswl3dxeqn.txt' !2
	infile3='hsswe3dxeqn.txt' !3
C??        infile0='hsssw3d.txt'  ! HSS (replace 0 by median)
C-	outhss='hsssw3c.txt'
	outfile='calmed380.res'
	OPEN(10,file=outfile,access='APPEND')
C-	OPEN(15,file=outhss)
C
        igns=1
  17        select case(igns)
	case (1)
   1	infile=infile0
      gns=gns4(1)
   	OPEN(11,file=infile,action='READ')
	write(10,*) infile
	nn1=0
	DO ll=1,380	   !+++++++++
	read(11,*,end=41) xi
	nn1=nn1+1
	do k=1,72
	dati(ll,k)=xi(k)
	enddo
	ENDDO		  !+++++++++
   41	close(unit=11)
	call submed477(nn1,72)
     	write(*,30) (rmed(k),k=1,72)
	write(10,30) (rmed(k),k=1,72)
C--	close(10)
	goto 43
	case (2)
   2	infile=infile1
	goto 24
	case (3)
   3	infile=infile2
	goto 24
	case (4)
   4	infile=infile3
	goto 24
	case (5)
    5	 GOTO 222 ! stop
	end select
C
C
   24	DO 42 inp=1,3
      gns=gns4(inp+1)
	infile(8:8)=gns
C
   25	OPEN(11,file=infile,action='READ')
       write(10,*) infile
	nn1=0
	DO ll=1,477	   !+++++++++
	read(11,*,end=44) xi
	nn1=nn1+1
	do k=1,72
	if (igns.eq.3) then
	dati(ll,k)=-xi(k)
	                else
	dati(ll,k)=xi(k)
	endif
	enddo
	ENDDO		  !+++++++++
   44	close(unit=11)
	call submed477(nn1,72)
   30	format(72(1X,F5.1))
   31	format(72(1X,I4))
   32	format(1X,A1,I1,'=[',A16)
	write(*,32) gns,inp,infile
	write(10,32) gns,inp,infile
	do k=1,72
	if (igns.eq.3) then
	med(k)=-int(rmed(k))
	              else
	med(k)=int(rmed(k))
	endif
	enddo
	write(*,31)	(med(k),k=1,72)
	write(10,31) (med(k),k=1,72)
   42	CONTINUE
   43 CONTINUE
C-    DO nn=1,380
C-	DO k=1,72
C-	if (dati(nn,k).eq.0.) dati(nn,k)=rmed(k)
C-	ires(k)=nint(dati(nn,k))
C-	ENDDO
C-	write(*,31)	(ires(k),k=1,72)
C-	write(15,31) (ires(k),k=1,72)
C-	ENDDO
C-	close(unit=15)
      igns=igns+1
      if (igns.lt.5) GOTO 17
  222	close(unit=10)
       pause ' '
	STOP
	END