I see that the general handling of arrays
in DERIVATIVE blocks for cvode, cnexp, and derivimplicit is a lot more difficult than I envisioned and the fix could be a long time coming. In your case, if you don't
mind doing some manual repair to the generated c file it is possible to get it
working. First , avoid the loop index
as an arg to foobar. i.e
Code: Select all
DERIVATIVE states {
LOCAL x
FROM i = 0 TO 2 {
x = i
outVar'[i] = -foobar(x)
}
}
FUNCTION foobar(a) {
foobar = a
}
will emit the c code:
Code: Select all
/*CVODE*/
static int _ode_spec1 () {_reset=0;
{
double _lx ;
{int _li ;for ( _li = 0 ; _li <= 2 ; _li ++ ) {
_lx = ((double) _li ) ;
DoutVar [ _li ] = - foobar ( _lx ) ;
} }
}
return _reset;
}
static int _ode_matsol1() {
double _lx ;
{int _li ;for ( _li = 0 ; _li <= 2 ; _li ++ ) {
_lx = ((double) _li ) ;
DoutVar [ _li ] = DoutVar / (1. - dt*( 0.0 )) ;
}
/*END CVODE*/
static int states () {_reset=0;
{
double _lx ;
{int _li ;for ( _li = 0 ; _li <= 2 ; _li ++ ) {
_lx = ((double) _li ) ;
DoutVar [ _li outVar = outVar - dt*(- ( - foobar ( _lx ) ) ) ;
} }
}
return 0;
}
double foobar ( _la )
double _la ;
{
double _lfoobar;
_lfoobar = _la ;
return _lfoobar;
}
_ode_spec1 is ok as is.
_ode_matsol1 has two problems. First
the second occurrence of DoutVar is missing the [_li] suffix. Second, before the closing } of the function needs to
have three, total. i.e replace the closing
} with }}}. Actually, in the case you gave, the whole body is useless since the computation is DoutVar[_li] = DoutVar_li];
The main line in the states () function up to the -dt token is completely botched and the line should be
Code: Select all
outVar[_li] = outVar[_li] - dt*(.....
If you remove the
from your mod file statements you can see the proper form of the translated c code. The form will be different if one of the args to foobar is the dependent variable of the equation.
By the way, the c code is in the subdirectory (e.g. i686) created by nrnivmodl. You can change the c code
and rerun nrnivmodl and the translator will not overwrite it (unless the mod file
gets changed and has a date later than the c file.)