I would like to implement the Gamma function in NEURON (it is needed for the model I'm working on and may be useful for other).
A nice algorithm can be found in "Numerical Recipes in C" by Press et al.
After looking at http://senselab.med.yale.edu/senselab/m ... 7/rand.mod to see how to embed C code in NMODL I have written the mod file gamma.mod:
Code: Select all
COMMENT
Algorithms are taken from Press et al "Numerical Recipes in C"
ENDCOMMENT
VERBATIM
#include <stdio.h>
#include <math.h>
#define ITMAX 100
#define EPS 3.0e-7
#define FPMIN 1.0e-30
ENDVERBATIM
COMMENT
/****************************************
* Log. of the Gamma function *
****************************************/
ENDCOMMENT
FUNCTION lnGamma(xx) {
VERBATIM
double x, y, ser, tmp;
int j;
static double cof[6] = {76.18009172947146,-86.50532032941677,
24.01409824083091,-1.231739572450155,
0.1208650973866179e-2,-0.5395239384953e-5};
y = x = _lxx;
tmp = x + 5.5;
tmp -= (x+0.5)*log(tmp);
ser=1.000000000190015;
for (j=0;j<=5;j++) {
ser += cof[j]/++y;
}
_llnGamma = -tmp+log(2.5066282746310005*ser/x);
ENDVERBATIM
}
When I try to compile this mod file with nivmodl gIF4.mod I get:
Code: Select all
Translating gIF4.mod into gIF4.c
INCLUDEing gamma.mod
"/usr/local/nrn/share/nrn/libtool" --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -I"/usr/local/nrn/include/nrn" -I"/usr/local/nrn/i686/lib" -g -O2 -c -o gIF4.lo gIF4.c
mkdir .libs
gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/local/nrn/include/nrn -I/usr/local/nrn/i686/lib -g -O2 -c gIF4.c -fPIC -DPIC -o .libs/gIF4.o
gIF4.c:313: error: conflicting types for '_hoc_lnGamma'
gIF4.c:77: error: previous declaration of '_hoc_lnGamma' was here
make: *** [gIF4.lo] Error 1
line 77: static double _hoc_lnGamma();
line 313: static int _hoc_lnGamma() {...
Is there any mistake in my code confusing nrnivmodl? Otherwise, how to do?
Thanks in advance,
Mathieu.