User defined functions in VERBATIM

NMODL and the Channel Builder.
Post Reply
auatai
Posts: 29
Joined: Mon Sep 14, 2009 6:33 am

User defined functions in VERBATIM

Post by auatai »

Hi ,

How can we define and use a user defined function in nmodl within a verbatim block ?
ted
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

Post by ted »

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
}
hines
Site Admin
Posts: 1692
Joined: Wed May 18, 2005 3:32 pm

Re: User defined functions in VERBATIM

Post by hines »

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.
hines
Site Admin
Posts: 1692
Joined: Wed May 18, 2005 3:32 pm

Re: User defined functions in VERBATIM

Post by hines »

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.
auatai
Posts: 29
Joined: Mon Sep 14, 2009 6:33 am

Re: User defined functions in VERBATIM

Post by auatai »

Thank you sir for showing me the approach. I'll work on it and in case of any problems will revert to you.
Post Reply