functions in NMODL
Posted: Sat Apr 05, 2014 11:41 am
Hello, I want to make a function in NMODL that I can call from NMODL and hoc. I tried something, but it gives me an odd result when I call it from NMODL. I suspect I'm mixing up ints and doubles somehow, but I'm not sure what to do.
First I made an NMODL function that is callable from hoc:
Then I wrote some other NMODL code to install as a vector method (and also included a second definition of my function of interest for comparison):
Then in hoc, I compared the output of my function of interest called from hoc, to my function of interest and the comparison function called from NMODL:
Calling the function of interest from hoc is fine, and calling the comparison function from NMODL is fine, but calling the function of interest from NMODL gives a different result:
First I made an NMODL function that is callable from hoc:
Code: Select all
NEURON {
SUFFIX nothing
}
FUNCTION get_x_pos1(binSizeX) {
get_x_pos1 = binSizeX/2.0
}
Code: Select all
VERBATIM
# include <stdlib.h>
# include <stdio.h>
# include <math.h>
ENDVERBATIM
NEURON {
SUFFIX nothing
}
VERBATIM
extern double* vector_vec();
extern int vector_capacity();
extern void* vector_arg();
ENDVERBATIM
VERBATIM
static double get_x_pos2 (double binSizeX) {
double pos;
pos = binSizeX/2.0;
return pos;
}
static double testconn (void* vv) {
double finalconn, ny, *x, *y;
/* Get hoc vectors into c arrays */
finalconn = vector_instance_px(vv, &x); // x is an array corresponding
// to the placeholder vector
// of connections to make
ny = vector_arg_px(1, &y);
/* Parameters from the param array
y[0] binSizeX
*/
x [0] = get_x_pos1(y[0]);
x [1] = get_x_pos2(y[0]);
return finalconn;
}
ENDVERBATIM
PROCEDURE install_testconn () {
VERBATIM
install_vector_method("testconn", testconn);
ENDVERBATIM
}
Code: Select all
load_file("nrngui.hoc")
install_testconn()
binSizeX = 10.00
print "from hoc, use function of interest: ", get_x_pos1(binSizeX)
objref mypos, params
mypos = new Vector(2)
params = new Vector(1)
params.x[0] = binSizeX
mypos.testconn(params)
print "from NMODL, use function of interest: ", mypos.x[0], ", use comparison: ", mypos.x[1]
quit()
Not sure how to fix my "function of interest" definition so it works in NMODL? Note that "binSizeX" is an integer in this example but that may not be the case in my working code. Thanks!from hoc, use function of interest: 5
from NMODL, use function of interest: 1.0761011e+09 , use comparison: 5