Skip to content

Commit

Permalink
Set the voltage from _setdata. (#3066)
Browse files Browse the repository at this point in the history
* Move `_setdata` code in generated file.

We'll need access to `v` later. This pushes the definition of
`_setdata` further down the generated file; and prints a
declaration at the previous location. The declaration is needed
to register the function `_hoc_setdata`.

* Set the voltage from `_setdata`.

In non-VECTORIZED files, the voltage is a static double. When calling
`setdata` several other prop related global variables are set. However,
not the voltage. This commits fixes the bug and also sets `v` to the
voltage of the node associated with the prop provided.
  • Loading branch information
1uc authored Sep 3, 2024
1 parent 6704244 commit 9373eef
Showing 1 changed file with 39 additions and 28 deletions.
67 changes: 39 additions & 28 deletions src/nmodl/nocpout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,35 +428,10 @@ extern void nrn_promote(Prop*, int, int);\n\
defs_list,
"double get_loc_point_process(void*); return (get_loc_point_process(_vptr));\n}\n");
}
/* function to set up _p and _ppvar */
Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n");
Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n");
if (!point_process) {
Lappendstr(defs_list, "_extcall_prop = _prop;\n");
Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n");
}
if (!vectorize) {
Lappendstr(defs_list,
"neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n"
"_ppvar = _nrn_mechanism_access_dparam(_prop);\n");
}
Lappendstr(defs_list, "}\n");

if (point_process) {
Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n");
Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n");
} else {
Lappendstr(defs_list,
"static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n");
Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n");
Lappendstr(defs_list, buf);
}
Lappendstr(defs_list, " _setdata(_prop);\n");
if (point_process) {
Lappendstr(defs_list, "}\n");
} else {
Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n");
}
std::string hoc_setdata_arg = point_process ? "void*" : "";
Sprintf(buf, "static void _hoc_setdata(%s);\n", hoc_setdata_arg.c_str());
Lappendstr(defs_list, buf);

/* functions */
Lappendstr(defs_list, "/* connect user functions to hoc names */\n");
Expand Down Expand Up @@ -755,6 +730,42 @@ extern void nrn_promote(Prop*, int, int);\n\
}
}

/* function to set up _p and _ppvar */
Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n");
Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n");
if (!point_process) {
Lappendstr(defs_list, "_extcall_prop = _prop;\n");
Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n");
}
if (!vectorize) {
Lappendstr(defs_list,
"neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n"
"_ppvar = _nrn_mechanism_access_dparam(_prop);\n");
if (!artificial_cell) {
Lappendstr(defs_list,
"Node * _node = _nrn_mechanism_access_node(_prop);\n"
"v = _nrn_mechanism_access_voltage(_node);\n");
}
}
Lappendstr(defs_list, "}\n");

if (point_process) {
Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n");
Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n");
} else {
Lappendstr(defs_list,
"static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n");
Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n");
Lappendstr(defs_list, buf);
}
Lappendstr(defs_list, " _setdata(_prop);\n");
if (point_process) {
Lappendstr(defs_list, "}\n");
} else {
Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n");
}


/******** what normally goes into cabvars.h structures */

/*declaration of the range variables names to HOC */
Expand Down

0 comments on commit 9373eef

Please sign in to comment.