Hi ,
How can we define and use a user defined function in nmodl within a verbatim block ?
User defined functions in VERBATIM
-
- Site Admin
- Posts: 6305
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: User defined functions in VERBATIM
VERBATIM blocks allow insertion of C source code, but are you sure you need to do that? NMODL allows you to define FUNCTIONs that contain general mathematical expressions.
Code: Select all
FUNCTION fname(arg (units)) {
fname = expression
}
Re: User defined functions in VERBATIM
Put the VERBATIM...END_VERBATIM within a FUNCTION and call outside the function with c syntax.
This allows the translator to generate the boilerplate interface between hoc and the FUNCTION.
From HOC, call the FUNCTION. eg
VERBATIM
static double bar(double arg) {
return arg*arg;
}
ENDVERBATIM
FUNCTION foo(arg) {
VERBATIM
_lfoo = bar(_larg)
ENDVERBATIM
}
See nrn/src/ivoc/oc2iv.h and nrn/src/nrniv/nrnoc2iv.h
for c functions you can use to get args besides doubles.
Also see nrn/src/nrnoc/pattern.mod for a fairly elaborate use of VERBATIM
in FUNCTIONS (and elsewhere).
Look at the translated c code to get an idea of how a naming convention is used
and the detailed c code that connects hoc and the c code.
Bill Lytton's models in ModelDB often have a mod file that supplies utility functions
using VERBATIM.
This allows the translator to generate the boilerplate interface between hoc and the FUNCTION.
From HOC, call the FUNCTION. eg
VERBATIM
static double bar(double arg) {
return arg*arg;
}
ENDVERBATIM
FUNCTION foo(arg) {
VERBATIM
_lfoo = bar(_larg)
ENDVERBATIM
}
See nrn/src/ivoc/oc2iv.h and nrn/src/nrniv/nrnoc2iv.h
for c functions you can use to get args besides doubles.
Also see nrn/src/nrnoc/pattern.mod for a fairly elaborate use of VERBATIM
in FUNCTIONS (and elsewhere).
Look at the translated c code to get an idea of how a naming convention is used
and the detailed c code that connects hoc and the c code.
Bill Lytton's models in ModelDB often have a mod file that supplies utility functions
using VERBATIM.
Re: User defined functions in VERBATIM
sorry I left out the ';' in
_lfoo = bar(_larg)
above. I did not execute this so there may be other syntax errors but the idea is sound.
_lfoo = bar(_larg)
above. I did not execute this so there may be other syntax errors but the idea is sound.
Re: User defined functions in VERBATIM
Thank you sir for showing me the approach. I'll work on it and in case of any problems will revert to you.