NEURON
prcellstate.cpp
Go to the documentation of this file.
1 #include "../../nrnconf.h"
2 #include "section.h"
3 #include "membfunc.h"
4 #include "nrniv_mf.h"
5 #include "netcon.h"
6 #include "OS/table.h"
7 #include "OS/list.h"
8 #include "neuron.h"
9 
10 #define precision 15
11 
12 void nrn_prcellstate(int gid, const char* filesuffix);
13 
14 declarePtrList(NetConList, NetCon) // NetCons in same order as Point_process
15 implementPtrList(NetConList, NetCon) // and there may be several per pp.
16 declareTable(PV2I, void*, int)
17 implementTable(PV2I, void*, int)
18 static PV2I* pnt2index; // for deciding if NetCon is to be printed
19 static int pntindex; // running count of printed point processes.
20 
21 
22 static void pr_memb(int type, Memb_list* ml, int* cellnodes, NrnThread& nt, FILE* f) {
23  int header_printed = 0;
24  int size = nrn_prop_param_size_[type];
25  int psize = nrn_prop_dparam_size_[type];
26  int receives_events = pnt_receive[type] ? 1 : 0;
27  for (int i = 0; i < ml->nodecount; ++i) {
28  int inode = ml->nodeindices[i];
29  if (cellnodes[inode] >= 0) {
30  if (!header_printed) {
31  header_printed = 1;
32  fprintf(f, "type=%d %s size=%d\n", type, memb_func[type].sym->name, size);
33  }
34  if (receives_events) {
35  fprintf(f, "%d nri %d\n", cellnodes[inode], pntindex);
36  Point_process* pp = (Point_process*)ml->pdata[i][1]._pvoid;
37  pnt2index->insert(pp, pntindex);
38  ++pntindex;
39  }
40  for (int j=0; j < size; ++j) {
41  fprintf(f, " %d %d %.*g\n", cellnodes[inode], j, precision, ml->data[i][j]);
42  }
43  }
44  }
45 }
46 
47 static void pr_netcon(NrnThread& nt, FILE* f) {
48  if (pntindex == 0) { return; }
49  // pnt2index table has been filled
50 
51  // List of NetCon for each of the NET_RECEIVE point process instances
52  // ... all NetCon list in the hoc NetCon cTemplate
53  NetConList** nclist = new NetConList*[pntindex];
54  for (int i=0; i < pntindex; ++i) { nclist[i] = new NetConList(1); }
55  int nc_cnt = 0;
56  Symbol* ncsym = hoc_lookup("NetCon");
57  hoc_Item* q;
58  ITERATE (q, ncsym->u.ctemplate->olist) {
59  Object* obj = OBJ(q);
60  NetCon* nc = (NetCon*)obj->u.this_pointer;
61  Point_process* pp = nc->target_;
62  int index;
63  if (pnt2index->find(index, pp)) {
64  nclist[index]->append(nc);
65  ++nc_cnt;
66  }
67  }
68  fprintf(f, "netcons %d\n", nc_cnt);
69  fprintf(f, " pntindex srcgid active delay weights\n");
70  for (int i=0; i < pntindex; ++i) {
71  for (int j=0; j < nclist[i]->count(); ++j) {
72  NetCon* nc = nclist[i]->item(j);
73  int srcgid = -3;
74  srcgid = (nc->src_) ? nc->src_->gid_ : -3;
75  if (srcgid < 0 && nc->src_ && nc->src_->osrc_) {
76  const char* name = nc->src_->osrc_->ctemplate->sym->name;
77  fprintf(f, "%d %s %d %.*g", i, name, nc->active_?1:0, precision, nc->delay_);
78  }else if (srcgid < 0 && nc->src_ && nc->src_->ssrc_) {
79  fprintf(f, "%d %s %d %.*g", i, "v", nc->active_?1:0, precision, nc->delay_);
80  }else{
81  fprintf(f, "%d %d %d %.*g", i, srcgid, nc->active_?1:0, precision, nc->delay_);
82  }
83  int wcnt = pnt_receive_size[nc->target_->prop->type];
84  for (int k=0; k < wcnt; ++k) {
85  fprintf(f, " %.*g", precision, nc->weight_[k]);
86  }
87  fprintf(f, "\n");
88  }
89  }
90  // cleanup
91  for (int i=0; i < pntindex; ++i) { delete nclist[i]; }
92  delete [] nclist;
93 }
94 
95 static void pr_realcell(PreSyn& ps, NrnThread& nt, FILE* f) {
96  //for associating NetCons with Point_process identifiers
97  pnt2index = new PV2I(1000);
98 
99  pntindex = 0;
100 
101  // threshold variable is a voltage
102 printf("thvar=%p actual_v=%p end=%p\n", ps.thvar_, nt._actual_v,
103 nt._actual_v + nt.end);
104  int inode = -1;
105  if (ps.thvar_ < nt._actual_v || ps.thvar_ >= (nt._actual_v + nt.end)) {
106  if (ps.ssrc_) { /* not cache efficient, search the nodes in this section */
107 printf("%s\n", ps.ssrc_?secname(ps.ssrc_):"unknown");
108  for (int i=0; i < ps.ssrc_->nnode; ++i) {
109  Node* nd = ps.ssrc_->pnode[i];
110  if (ps.thvar_ == nd->_v) {
111  inode = nd->v_node_index;
112  break;
113  }
114  }
115  if (inode < 0) { /* check parent node */
116  Node* nd = ps.ssrc_->parentnode;
117  if (ps.thvar_ == nd->_v) {
118  inode = nd->v_node_index;
119  }
120  }
121  }
122  if (inode < 0) {
123  hoc_execerror("gid not associated with a voltage", 0);
124  }
125  }else{
126  inode = ps.thvar_ - nt._actual_v;
127  }
128 
129  // and the root node is ...
130  int rnode = inode;
131  while (rnode >= nt.ncell) {
132  rnode = nt._v_parent_index[rnode];
133  }
134 
135  // count the number of nodes in the cell
136  // do not assume all cell nodes except the root are contiguous
137  int* cellnodes = new int[nt.end];
138  for (int i=0; i < nt.end; ++i) { cellnodes[i] = -1; }
139  int cnt = 0;
140  cellnodes[rnode] = cnt++;
141  for (int i=nt.ncell; i < nt.end; ++i) {
142  if (cellnodes[nt._v_parent_index[i]] >= 0) {
143  cellnodes[i] = cnt++;
144  }
145  }
146  fprintf(f, "%d nodes %d is the threshold node\n", cnt, cellnodes[inode]-1);
147  fprintf(f, " threshold %.*g\n", precision, ps.threshold_);
148  fprintf(f, "inode parent area a b\n");
149  for (int i=0; i < nt.end; ++i) if (cellnodes[i] >= 0) {
150  Node* nd = nt._v_node[i]; //if not cach_efficient then _actual_area=NULL
151  fprintf(f, "%d %d %.*g %.*g %.*g\n",
152  cellnodes[i], i < nt.ncell ? -1 : cellnodes[nt._v_parent_index[i]],
154  }
155  fprintf(f, "inode v\n");
156  for (int i=0; i < nt.end; ++i) if (cellnodes[i] >= 0) {
157  Node* nd = nt._v_node[i]; //if not cach_efficient then _actual_v=NULL
158  fprintf(f, "%d %.*g\n",
159  cellnodes[i], precision, NODEV(nd));
160  }
161 
162  // each mechanism
163  for (NrnThreadMembList* tml = nt.tml; tml; tml = tml->next) {
164  pr_memb(tml->index, tml->ml, cellnodes, nt, f);
165  }
166 
167  // the NetCon info (uses pnt2index)
168  pr_netcon(nt, f);
169 
170  delete [] cellnodes;
171  delete pnt2index;
172 }
173 
174 void nrn_prcellstate(int gid, const char* suffix) {
175  PreSyn* ps = nrn_gid2outputpresyn(gid);
176  if (!ps) { return; }
177  // found it so create a <gid>_<suffix>.nrn file
178  char buf[200];
179  sprintf(buf, "%d_%s.nrndat", gid, suffix);
180  FILE* f = fopen(buf, "w");
181  assert(f);
182  NrnThread& nt = *ps->nt_;
183  fprintf(f, "gid = %d\n", gid);
184  fprintf(f, "t = %.*g\n", precision, nt._t);
185  fprintf(f, "celsius = %.*g\n", precision, celsius);
186  if (ps->thvar_) {
187  pr_realcell(*ps, nt, f);
188  }
189  fclose(f);
190 }
191 
192 
ReceiveFunc * pnt_receive
Definition: init.cpp:171
NetCon void static int PV2I * pnt2index
Definition: prcellstate.cpp:17
#define assert(ex)
Definition: hocassrt.h:26
short type
Definition: cabvars.h:10
short nnode
Definition: section.h:41
#define precision
Definition: prcellstate.cpp:10
struct Node * parentnode
Definition: section.h:50
Definition: netcon.h:232
#define NODEV(n)
Definition: section.h:114
struct NrnThreadMembList * next
Definition: multicore.h:34
if(status)
bool active_
Definition: netcon.h:110
#define ITERATE(itm, lst)
Definition: model.h:25
NrnThread * nt_
Definition: netcon.h:270
Symbol * hoc_lookup(const char *)
int * _v_parent_index
Definition: multicore.h:76
void * this_pointer
Definition: hocdec.h:231
Represent main neuron object computed by single thread.
Definition: multicore.h:58
Memb_func * memb_func
Definition: init.cpp:161
nd
Definition: treeset.cpp:893
Object * osrc_
Definition: netcon.h:265
Point_process * target_
Definition: netcon.h:106
Section * ssrc_
Definition: netcon.h:266
PreSyn * nrn_gid2outputpresyn(int gid)
Definition: netpar.cpp:1487
static philox4x32_key_t k
Definition: nrnran123.cpp:11
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
inode
Definition: multicore.cpp:985
double delay_
Definition: netcon.h:104
hoc_List * olist
Definition: hocdec.h:203
PreSyn * src_
Definition: netcon.h:105
#define implementTable(Table, Key, Value)
Definition: table.h:113
short type
Definition: section.h:215
static int pntindex
Definition: prcellstate.cpp:19
int ncell
Definition: multicore.h:64
#define implementPtrList(PtrList, T)
Node ** _v_node
Definition: multicore.h:77
double threshold_
Definition: netcon.h:262
Prop * prop
Definition: section.h:264
#define printf
Definition: mwprefix.h:26
void nrn_prcellstate(int gid, const char *filesuffix)
const char * secname(Section *sec)
Definition: cabcode.cpp:1787
static void pr_memb(int type, Memb_list *ml, int *cellnodes, NrnThread &nt, FILE *f)
Definition: prcellstate.cpp:22
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
static void pr_netcon(NrnThread &nt, FILE *f)
Definition: prcellstate.cpp:47
#define cnt
Definition: spt2queue.cpp:19
double * thvar_
Definition: netcon.h:264
NetCon declareTable(PV2I, void *, int) implementTable(PV2I
size_t j
fprintf(stderr, "Don't know the location of params at %p\, pp)
Definition: model.h:57
char * name
Definition: init.cpp:16
Definition: netcon.h:82
int * nrn_prop_param_size_
Definition: init.cpp:178
double * weight_
Definition: netcon.h:107
int gid_
Definition: netcon.h:277
double * _actual_a
Definition: multicore.h:72
int * nrn_prop_dparam_size_
Definition: init.cpp:179
int end
Definition: multicore.h:65
#define OBJ(q)
Definition: hoclist.h:67
double _t
Definition: multicore.h:59
int v_node_index
Definition: section.h:174
Definition: hocdec.h:226
HocStruct cTemplate * ctemplate
Definition: hocdec.h:151
#define i
Definition: md1redef.h:12
static void pr_realcell(PreSyn &ps, NrnThread &nt, FILE *f)
Definition: prcellstate.cpp:95
char buf[512]
Definition: init.cpp:13
declarePtrList(NetConList, NetCon) implementPtrList(NetConList
struct Node ** pnode
Definition: section.h:51
NrnThreadMembList * tml
Definition: multicore.h:62
short * pnt_receive_size
Definition: init.cpp:173
static char suffix[256]
Definition: nocpout.cpp:149
union Symbol::@18 u
union Object::@54 u
Definition: section.h:132
size_t q
FILE * fopen()
double celsius
Definition: init.cpp:123
double * _actual_b
Definition: multicore.h:73
double * _actual_v
Definition: multicore.h:74
short index
Definition: cabvars.h:11
#define NODEAREA(n)
Definition: section.h:115
double * _v
Definition: section.h:139