1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
: Vector stream of events
COMMENT
A VecStim is an artificial spiking cell that generates
events at times that are specified in a Vector.
HOC Example:
// assumes spt is a Vector whose elements are all > 0
// and are sorted in monotonically increasing order
objref vs
vs = new VecStim()
vs.play(spt)
// now launch a simulation, and vs will produce spike events
// at the times contained in spt
Python Example:
from neuron import h
spt = h.Vector(10).indgen(1, 0.2)
vs = h.VecStim()
vs.play(spt)
def pr():
print (h.t)
nc = h.NetCon(vs, None)
nc.record(pr)
cvode = h.CVode()
h.finitialize()
cvode.solve(20)
ENDCOMMENT
NEURON {
THREADSAFE
ARTIFICIAL_CELL VecStim
BBCOREPOINTER ptr
}
ASSIGNED {
index
etime (ms)
ptr
}
INITIAL {
index = 0
element()
if (index > 0) {
net_send(etime - t, 1)
}
}
NET_RECEIVE (w) {
if (flag == 1) {
net_event(t)
element()
if (index > 0) {
net_send(etime - t, 1)
}
}
}
DESTRUCTOR {
VERBATIM
#if !NRNBBCORE
void* vv = (void*)(_p_ptr);
if (vv) {
hoc_obj_unref(*vector_pobj(vv));
}
#endif
ENDVERBATIM
}
PROCEDURE element() {
VERBATIM
{ void* vv; int i, size; double* px;
i = (int)index;
if (i >= 0) {
vv = (void*)(_p_ptr);
if (vv) {
size = vector_capacity(vv);
px = vector_vec(vv);
if (i < size) {
etime = px[i];
index += 1.;
}else{
index = -1.;
}
}else{
index = -1.;
}
}
}
ENDVERBATIM
}
PROCEDURE play() {
VERBATIM
#if !NRNBBCORE
{
void** pv;
void* ptmp = NULL;
if (ifarg(1)) {
ptmp = vector_arg(1);
hoc_obj_ref(*vector_pobj(ptmp));
}
pv = (void**)(&_p_ptr);
if (*pv) {
hoc_obj_unref(*vector_pobj(*pv));
}
*pv = ptmp;
}
#endif
ENDVERBATIM
}
VERBATIM
static void bbcore_write(double* xarray, int* iarray, int* xoffset, int* ioffset, _threadargsproto_) {
int i, dsize, *ia;
double *xa, *dv;
dsize = 0;
if (_p_ptr) {
dsize = vector_capacity(_p_ptr);
}
if (iarray) {
void* vec = _p_ptr;
ia = iarray + *ioffset;
xa = xarray + *xoffset;
ia[0] = dsize;
if (dsize) {
dv = vector_vec(vec);
for (i = 0; i < dsize; ++i) {
xa[i] = dv[i];
}
}
}
*ioffset += 1;
*xoffset += dsize;
}
static void bbcore_read(double* xarray, int* iarray, int* xoffset, int* ioffset, _threadargsproto_) {
int dsize, i, *ia;
double *xa, *dv;
xa = xarray + *xoffset;
ia = iarray + *ioffset;
dsize = ia[0];
if (!_p_ptr) {
_p_ptr = vector_new1(dsize);
}
assert(dsize == vector_capacity(_p_ptr));
dv = vector_vec(_p_ptr);
for (i = 0; i < dsize; ++i) {
dv[i] = xa[i];
}
*xoffset += dsize;
*ioffset += 1;
}
ENDVERBATIM
|