*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
* Brillouin's index by Sterling's approximation
* H = (1 / N) @ LOG(N! / PRODUCT(n[i]!))
* and n! = (2 @ pi @ n)^(1/2) @ (n/e)^n
*
*___Name___Type______In/Out___Description_______________________________
* N(S) Integer In Species populations
* S Integer In Number of species
*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
FUNCTION EINDEX (N, S)
IMPLICIT NONE
INTEGER N, S
REAL EINDEX
DIMENSION N(S)
* Local variables
INTEGER I, STRIM
REAL TOT, SNPHLN, LN2PI, f
PARAMETER (LN2PI = 1.8378771)
* Begin
EINDEX = -999.
STRIM = S
* Find SUM n[i] and SUM (n[i]+1/2) @ LOG(n[i])
TOT = 0.
SNPHLN = 0.
DO 10 i = 1, s
f = FLOAT(N(i))
IF (f < 0.5) THEN ! skip empty groups
STRIM = STRIM - 1
GO TO 10
END IF
TOT = TOT + f
SNPHLN = SNPHLN + (f + 0.5) * LOG(f)
10 CONTINUE
IF (STRIM .EQ. 0) RETURN ! return negative if no data
EINDEX = (1. / TOT) * ( (TOT+0.5) * LOG(TOT)
& - SNPHLN - (FLOAT(STRIM-1) / 2.) * LN2PI )
RETURN
END ! of EINDEX