      subroutine rsindex(xpar,xmed,xstd,rat,irs)
C......................................................................Feb. 2015
C
C Procedure to calculate Ionospheric Weather Storm S-index exceeding STD by +-10%
C
C
C   Input: xpar = NeF2  - instantaneous value of the F2 layer peak electron density 
C      or  xpar = foF2  - instantaneous value of the F2 layer critical frequency
C      or  xpar = hmF2  - instantaneous value of the F2 layer peak height 
C      or  xpar = TECi  - instantaneous value of GPS-derived total electron content
C      or  xpar = TECeff  - instantaneous value of GPS-derived spherical total electron content
C xmed = relevant quiet reference (-7 days median) value of any above parameter
C xstd - standard deviation of -15 days interval parameters from xmed for fixed location and time UT
C
C   Output: ionospheric weather S index characterizing ionospheric and plasmaspheric activity:
C           Rs = 0, +1 or -1 (quiet state)
C           Rs = +2 or -2 (moderate disturbance)
C           Rs = +3 or -3 (moderate storm)
C           Rs = +4 or -4 (intense storm)
C		  RAT - (xpar-xmed)/xstd
C
C   Includes Rs indices -4,-3,-2,-1,0,1,2,3,4
C
C Wx new derivation with dynamic thresholds
C                 S_4 = -4 ~ RAT <=-3.0
C                 S_3 = -3 ~-3.0<RAT =<-2.0
C                 S_2 = -2 ~ -2.0<RAT =<-1.0
C                 S_1 = -1 ~ -1.0<RAT <0.0
C                 S0 =  0 RAT=0
C                 S1 =  1 ~0.0<RAT <1.0
C                 S2 =  2 ~ 1.0<=RAT <2.0
C                 S3 =  3 ~  2.0<=RAT <3.0
C                 S4 =  4 ~ RAT >=3.0
C
C   Dynamic thresholds: 
C
      DIMENSION TR(7)
	INTEGER IIN(7)
	real xpar,xmed
	DATA TR/-3.0,-2.0,-1.0,0.0,1.0,2.0,3.0/
	DATA IIN/-3,-2,-1,0,1,2,3/
C 
	RAT=(xpar-xmed)/xstd
C
   5		if (RAT.eq.TR(4)) then
			irs=0
	goto 2
	endif
	      if(RAT.le.TR(1)) then
	irs=-4                 ! Rs-index
	goto 2
	endif
	if (RAT.ge.TR(7)) then
	irs=4				  ! Rs-index
 	goto 2
	endif
C
	do 1 n=1,7
	if (RAT.lt.0.) then
	if ((RAT.gt.tr(n)).and.(RAT.le.tr(n+1))) then
	irs=iin(n)              ! Rs-index
	goto 2
	endif
	      else
	if ((RAT.ge.tr(n-1)).and.(RAT.lt.tr(n))) then
	irs=iin(n)              ! Rs-index
	goto 2
	endif

	endif
   1	continue
C
   2  continue
C
	RETURN
	END
C
C
C ===============================================================
