      subroutine windex(xpar,xmed,delog,iw)
C
C   Procedure to calculate the ionospheric weather W index
C
C   Input: xpar = NeF2  - instantaneous value of the F2 layer peak electron density 
C      or  xpar = TECi  - instantaneous value of GPS-derived total electron content
C    		 xmed = NmF2  - quiet reference (median) value of the F2 layer peak electron density
C      or	 xmed = TEC m - quiet reference (median) value of total electron content
C
C   Output: ionospheric weather W index characterizing ionospheric and plasmaspheric activity:
C           W = 0, +1 or -1 (quiet state)
C           W = +2 or -2 (moderate disturbance)
C           W = +3 or -3 (moderate storm)
C           W = +4 or -4 (intense storm)
C
C   Includes logarithmic scale indices -4,-3,-2,-1,0,1,2,3,4
C   according to thresholds of 
C           log10(xpar/xmed)=-0.999,-0.301,-0.155,-0.045,0,0.045,0.155,0.301,0.999  
C
C   Ref.Gulyaeva, T.L.,, I. Stanislwska, and M. Tomasik. Ionospheric weather: Cloning missed 
C       foF2 observations for derivation of variability index. Annales Geophysicae, 26, N.2, 
C       315-321, 2008.
C       Gulyaeva, T.L.,and I. Stanislwska, Derivation of a planetary ionospheric storm index. 
C       Annales Geophysicae, 26, N.9, 2645-2648, 2008 .
C
      DIMENSION TR(7)
	real xpar,xmed
	INTEGER IIN(7)
   		data IIN/-3,-2,-1,0,1,2,3/           ! ID-index
	data TR/-.301,-.155,-.045,0.0
	+,.045,.155,.301/
C  Temp:
    	 if (delog.ne.0.) goto 5   ! temp if delog is entered
	      delog=alog10(XPAR)-alog10(XMED)
   5		if (delog.gt.tr(7)) then
		iw=4
	goto 2
		endif 
		if (delog.eq.0.) then
			iw=0
	goto 2
	endif
	      if(delog.le.tr(1)) then
	iw=-4                 ! W-index
	goto 2
	endif
	if (delog.ge.tr(7)) then
	iw=4				  ! W-index
 	goto 2
	endif
C
	do 1 n=1,7
	if (delog.lt.0.) then
	if ((delog.ge.tr(n)).and.(delog.lt.tr(n+1))) then
	iw=iin(n)              ! W-index
	endif
	      else
	if ((delog.gt.tr(n-1)).and.(delog.le.tr(n))) then
	iw=iin(n)              ! W-index
	endif

	endif
   1	continue
C
   2  continue
C
	RETURN
	END
C
C
C ===============================================================
