-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindices.c
59 lines (51 loc) · 1.08 KB
/
indices.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Sat May 28 12:29:47 EEST 2011
Ver 0.1
Panagiotis Vavilis
#include "common.h"
/* Number of Individuals function */
int NumOfIndividuals ( station_t st, int nsp )
{
int i,sum=0;
for (i=0; i<nsp; i++) {
if ( st.spcs[i].size != 0 )
sum+=st.spcs[i].size;
}
return (sum);
}
/* Species Richness function */
int SpeciesRichness ( station_t st, int nsp )
{
int i,cnt=0;
for (i=0; i<nsp; i++) {
if ( st.spcs[i].size != 0 )
cnt++;
}
return (cnt);
}
/* Shannon Index function */
REAL ShannonIndex ( station_t st, int nsp )
{
int i;
REAL H,cf;
int N,S;
N = NumOfIndividuals(st, nsp);
S = SpeciesRichness(st, nsp);
if ( N == 0 )
return (0);
cf = (REAL)((S-1)/(2*N));
H=0;
for (i=0; i<nsp; i++) {
if ( st.spcs[i].size != 0 )
H = H + ((REAL)st.spcs[i].size/(REAL)N)*log((REAL)st.spcs[i].size/(REAL)N);
}
return (-H-cf);
}
/* Species Evenness function */
REAL SpeciesEvenness( station_t st, int nsp )
{
REAL H,Hmax;
H = ShannonIndex(st,nsp);
Hmax = log((REAL)SpeciesRichness(st,nsp));
return (H/Hmax);
}