Skip to content

Commit

Permalink
Updates for compatibility with SoA NEURON data. (#2)
Browse files Browse the repository at this point in the history
Also cope with Prop being a forward declaration.
  • Loading branch information
olupton committed Apr 30, 2023
1 parent 2e149ba commit c02aecc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.html
Expand Up @@ -27,4 +27,6 @@
---------
2022-05: Updated MOD files to contain valid C++ and be compatible
with the upcoming versions 8.2 and 9.0 of NEURON.
2023-04: Updated MOD files to be compatible with the new data
structures in the upcoming 9.0 version of NEURON.
</pre></html>
61 changes: 44 additions & 17 deletions intf_.mod
Expand Up @@ -27,6 +27,16 @@ VERBATIM
#include <limits.h> /* contains LONG_MAX */
#include "misc.h"

#ifdef NRN_MECHANISM_DATA_IS_SOA
#define get_dparam(prop) _nrn_mechanism_access_dparam(prop)
#define get_type(prop) _nrn_mechanism_get_type(prop)
#define id0ptr(prop) static_cast<id0*>(_nrn_mechanism_access_dparam(prop)[2].get<void*>())
#else
#define get_dparam(prop) prop->dparam
#define get_type(prop) prop->_type
#define id0ptr(prop) (*((id0**)&(prop->dparam[2])))
#endif

static int ctt(unsigned int, char**);
static int setdvi2(double*,double*,int,int);

Expand Down Expand Up @@ -110,7 +120,7 @@ static char iflags[100]="typ inh rec wre jtt inp vin inv jcn dea vbr dbx fla";
static char iflnum=13, iflneg=11, errflag; // turn on after generating an error message
static int vspn;
static double *isp, *vsp, *wsp, *jsp, *invlp;
static double *lop(Object *ob, unsigned int i); // accessed by all INTF
static void lop(Object *ob, unsigned int i); // accessed by all INTF
static double *jrid, *jrtv;
static void *jridv, *jrtvv;
static unsigned int jtpt,jtmax,jrmax;
Expand Down Expand Up @@ -353,8 +363,15 @@ ENDVERBATIM
if (_lflag==2) ip->flag=-1;
idty=(double)(FOFFSET+ip->id)+1e-2*(double)ip->type+1e-3*(double)ip->inhib+1e-4;
for (i=0;i<ip->dvt && !stoprun;i++) if (ip->sprob[i]) {
(*pnt_receive[ip->dvi[i]->_prop->_type])(ip->dvi[i], wts, idty);
_p=_pnt->_prop->param; _ppvar=_pnt->_prop->dparam; ip=IDP; // restore pointers each time
(*pnt_receive[get_type(ip->dvi[i]->_prop)])(ip->dvi[i], wts, idty);
// restore pointers each time
#ifdef NRN_MECHANISM_DATA_IS_SOA
neuron::legacy::set_globals_from_prop(_pnt->_prop, _ml_real, _ml, _iml);
#else
_p=_pnt->_prop->param;
#endif
_ppvar = get_dparam(_pnt->_prop);
ip=IDP;
}
return; // else see if destination has been reached
} else if (_lflag!=2 && (pathtytarg==(double)ip->type || pathidtarg==(double)ip->id)) {
Expand Down Expand Up @@ -857,14 +874,20 @@ PROCEDURE callback (fl) {
} else { // STDf=(1-STD)
wts[0]=(VTHC-VTH)/(Vblock-VTH); // just send [0,1] for STD
}
if (jp->sprob[i]) (*pnt_receive[jp->dvi[i]->_prop->_type])(jp->dvi[i], wts, idty);
_p=upnt->_prop->param; _ppvar=upnt->_prop->dparam; // restore pointers
if (jp->sprob[i]) (*pnt_receive[get_type(jp->dvi[i]->_prop)])(jp->dvi[i], wts, idty);
// restore pointers
#ifdef NRN_MECHANISM_DATA_IS_SOA
neuron::legacy::set_globals_from_prop(upnt->_prop, _ml_real, _ml, _iml);
#else
_p=upnt->_prop->param;
#endif
_ppvar = get_dparam(upnt->_prop);
i++;
if (i>=jp->dvt) return 0; // ran out
ddel=jp->del[i]-del0; // delays are relative to event; use difference in delays
}
// skip over pruned outputs and dead cells:
while (i<jp->dvt && (!jp->sprob[i] || (*(id0**)&(jp->dvi[i]->_prop->dparam[2]))->dead)) i++;
while (i<jp->dvt && (!jp->sprob[i] || id0ptr(jp->dvi[i]->_prop)->dead)) i++;
if (i<jp->dvt) {
ddel= jp->del[i] - del0;;
#if defined(t)
Expand Down Expand Up @@ -1025,7 +1048,7 @@ FUNCTION getdvi () {
idty=(double)(FOFFSET+ip->id)+1e-2*(double)ip->type+1e-3*(double)ip->inhib+1e-4;
prty=ip->type; sy=ip->inhib?GA:AM;
for (i=0,j=0;i<dvt;i++) {
qp=*((id0**) &((das[i]->_prop->dparam)[2])); // #define sop *_ppvar[2].pval
qp = id0ptr(das[i]->_prop); // #define sop *_ppvar[2].pval
if (getactive && (qp->dead || ip->sprob[i]==0)) continue;
if (flag==1.0) { x1[j]=(double)qp->type;
} else if (flag==2.0) { x1[qp->type]++;
Expand Down Expand Up @@ -1081,7 +1104,7 @@ VERBATIM
lop(ce,i);
dvt=qp->dvt; das=qp->dvi;
for (j=0;j<dvt;j++) {
if (ip==*((id0**) &((das[j]->_prop->dparam)[2]))) {
if (ip == id0ptr(das[j]->_prop)) {
if (prfl) {
if (flag!=2.0 && k>=sz) x=vector_newsize(voi,sz*=2);
if (flag==1.0) { x[k]=(double)qp->type;
Expand Down Expand Up @@ -1122,7 +1145,7 @@ FUNCTION adjlist () {
}
iSyns=0;
for(j=0;j<qp->dvt;j++){
rp=*((id0**) &((qp->dvi[j]->_prop->dparam)[2])); // #define sop *_ppvar[2].pval
rp = id0ptr(qp->dvi[j]->_prop); // #define sop *_ppvar[2].pval
if(skipinhib && rp->inhib) continue; // if skip inhib cells...
if(!rp->dead && qp->sprob[j]>0. && !pused[rp->id]){
pused[rp->id]=1;
Expand Down Expand Up @@ -1222,7 +1245,7 @@ FUNCTION svdvi () {
if(!qp->dvt)continue; //don't write empty pointers if no divergence
for(i=0;i<qp->dvt;i++){
pnnt=qp->dvi[i];
fwrite(&(*(id0**)&(pnnt->_prop->dparam[2]))->id,sizeof(unsigned int),1,fp); // id of output cell
fwrite(&(id0ptr(pnnt->_prop)->id), sizeof(unsigned int), 1, fp); // id of output cell
}
fwrite(qp->del,sizeof(double),qp->dvt,fp); // write divergence delays
fwrite(qp->sprob,sizeof(unsigned char),qp->dvt,fp); // write divergence firing probabilities
Expand Down Expand Up @@ -1396,7 +1419,7 @@ static int setdvi2 (double *y,double *d,int dvt,int flag) {
if (!(lb=ivoc_list_item(ce,(unsigned int)y[j]))) {
printf("INTF:callback %g exceeds %d for list ce\n",y[j],cesz); hxe(); }
pnnt=(Point_process *)lb->u.this_pointer;
if (ddvi==1 || !(pdead=(*(id0**)&(pnnt->_prop->dparam[2]))->dead)) {
if (ddvi==1 || !(pdead = id0ptr(pnnt->_prop)->dead)) {
da[i]=pnnt; db[i]=d[j]; i++;
}
}
Expand Down Expand Up @@ -1434,7 +1457,7 @@ PROCEDURE prune () {
for (j=0;j<ip->dvt;j++) if (dscr[j]<p) ip->sprob[j]=0; // prune with prob p
} else { // only prune synapses with postsynaptic type == potype
for (j=0;j<ip->dvt;j++){
ppost=*((id0**) &((ip->dvi[j]->_prop->dparam)[2])); // #define sop *_ppvar[2].pval
ppost = id0ptr(ip->dvi[j]->_prop); // #define sop *_ppvar[2].pval
if (ppost->type==potype && dscr[j]<p) ip->sprob[j]=0; // prune with prob p
}
}
Expand All @@ -1459,7 +1482,7 @@ PROCEDURE turnoff () {
lop(ce,(unsigned int)x[i]);
dvt=qp->dvt; das=qp->dvi;
for (j=0;j<dvt;j++) {
ip=*((id0**) &((das[j]->_prop->dparam)[2])); // sop is *_ppvar[2].pval
ip = id0ptr(das[j]->_prop); // sop is *_ppvar[2].pval
poid=(double)ip->id; // postsyn id
for (k=0;k<ny;k++) {
if (poid==y[k]) {
Expand Down Expand Up @@ -1969,15 +1992,19 @@ PROCEDURE initjttr () {
VERBATIM
//** lop(LIST,ITEM#) sets qp
// modeled on vector_arg_px(): picks up obj from list and resolves pointers
static double* lop (Object *ob, unsigned int i) {
static void lop(Object *ob, unsigned int i) {
Object *lb;
lb = ivoc_list_item(ob, i);
if (! lb) { printf("INTF:lop %d exceeds %d for list ce\n",i,cesz); hxe();}
pmt=ob2pntproc(lb);
qp=*((id0**) &((pmt->_prop->dparam)[2])); // #define sop *_ppvar[2].pval
qp = id0ptr(pmt->_prop); // #define sop *_ppvar[2].pval
// _hoc_setdata((void*)pmt); // make all the range vars accessible
_p=pmt->_prop->param; _ppvar=pmt->_prop->dparam;
return pmt->_prop->param;
#ifdef NRN_MECHANISM_DATA_IS_SOA
neuron::legacy::set_globals_from_prop(pmt->_prop, _ml_real, _ml, _iml);
#else
_p=pmt->_prop->param;
#endif
_ppvar = get_dparam(pmt->_prop);
}
// use stoppo() as a convenient conditional breakpoint in gdb (gdb watching is too slow)
Expand Down

0 comments on commit c02aecc

Please sign in to comment.