NEURON
fstim.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 /* /local/src/master/nrn/src/nrnoc/fstim.cpp,v 1.2 1997/08/15 13:04:11 hines Exp */
3 /* copy of synapse.cpp modified to simulate current stimulus pulses */
4 /* 4/9/2002 modified to conform to new treeset.cpp */
5 
6 /*
7 fstim(maxnum)
8  allocates space for maxnum synapses. Space for
9  previously existing synapses is released. All synapses initialized to
10  0 maximum conductance.
11 
12 fstim(i, loc, delay, duration, stim)
13  The ith current stimulus is injected at parameter `loc'
14  different current stimuli do not concatenate but can ride on top of
15  each other. delay refers to onset of stimulus relative to t=0
16  delay and duration are in msec.
17  stim in namps.
18 
19 fstimi(i)
20  returns stimulus current for ith stimulus at the value of the
21  global time t.
22 
23 */
24 
25 #include <stdlib.h>
26 #include "neuron.h"
27 #include "section.h"
28 #include "nrniv_mf.h"
29 
30 
31 typedef struct Stimulus {
32  double loc; /* parameter location (0--1) */
33  double delay; /* value of t in msec for onset */
34  double duration; /* turns off at t = delay + duration */
35  double mag; /* magnitude in namps */
36  double mag_seg; /* value added to rhs, depends on area of seg*/
37  Node* pnd; /* segment location */
40 
41 static int maxstim = 0; /* size of stimulus array */
42 static Stimulus* pstim; /* pointer to stimulus array */
43 static void free_stim(void);
44 
45 static void stim_record(int);
46 
47 #define nt_t nrn_threads->_t
48 
49 void print_stim() {
50  int i;
51 
52  if (maxstim == 0)
53  return;
54  /*SUPPRESS 440*/
55  Printf("fstim(%d)\n/* section fstim( #, loc, delay(ms), duration(ms), magnitude(namp)) */\n",
56  maxstim);
57  for (i = 0; i < maxstim; i++) {
58  Printf("%-15s fstim(%2d,%4g,%10g,%13g,%16g)\n",
59  secname(pstim[i].sec),
60  i,
61  pstim[i].loc,
62  pstim[i].delay,
63  pstim[i].duration,
64  pstim[i].mag);
65  }
66 }
67 
68 static double stimulus(int i) {
69 #if CVODE
70  at_time(nrn_threads, pstim[i].delay);
72 #endif
73  if (nt_t < pstim[i].delay - 1e-9 || nt_t > pstim[i].delay + pstim[i].duration - 1e-9) {
74  return 0.0;
75  }
76  return pstim[i].mag_seg;
77 }
78 
79 void fstimi(void) {
80  int i;
81  double cur;
82 
83  i = chkarg(1, 0., (double) (maxstim - 1));
84  if ((cur = stimulus(i)) != 0.) {
85  cur = pstim[i].mag;
86  }
88 }
89 
90 void fstim(void) {
91  int i;
92 
93  if (nrn_nthread > 1) {
94  hoc_execerror("fstim does not allow threads", "");
95  }
96  i = chkarg(1, 0., 10000.);
97  if (ifarg(2)) {
98  if (i >= maxstim) {
99  hoc_execerror("index out of range", (char*) 0);
100  }
101  pstim[i].loc = chkarg(2, 0., 1.);
102  pstim[i].delay = chkarg(3, 0., 1e21);
103  pstim[i].duration = chkarg(4, 0., 1e21);
104  pstim[i].mag = *getarg(5);
105  pstim[i].sec = chk_access();
107  stim_record(i);
108  } else {
109  free_stim();
110  maxstim = i;
111  if (maxstim) {
112  pstim = (Stimulus*) emalloc((unsigned) (maxstim * sizeof(Stimulus)));
113  }
114  for (i = 0; i < maxstim; i++) {
115  pstim[i].loc = 0;
116  pstim[i].mag = 0.;
117  pstim[i].delay = 1e20;
118  pstim[i].duration = 0.;
119  pstim[i].sec = 0;
120  stim_record(i);
121  }
122  }
123  hoc_retpushx(0.);
124 }
125 
126 static void free_stim(void) {
127  int i;
128  if (maxstim) {
129  for (i = 0; i < maxstim; ++i) {
130  if (pstim[i].sec) {
132  }
133  }
134  free((char*) pstim);
135  maxstim = 0;
136  }
137 }
138 
139 static void stim_record(int i) /*fill in the section info*/
140 {
141  double area;
142  Section* sec;
143 
144  sec = pstim[i].sec;
145  if (sec) {
146  if (sec->prop) {
147  pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area);
148  pstim[i].mag_seg = 1.e2 * pstim[i].mag / area;
149  } else {
151  pstim[i].sec = 0;
152  }
153  }
154 }
155 
156 void stim_prepare(void) {
157  int i;
158 
159  for (i = 0; i < maxstim; i++) {
160  stim_record(i);
161  }
162 }
163 
164 void activstim_rhs(void) {
165  int i;
166 
167  for (i = 0; i < maxstim; i++) {
168  if (pstim[i].sec) {
169  NODERHS(pstim[i].pnd) += stimulus(i);
170  }
171  }
172 }
const char * secname(Section *sec)
Definition: cabcode.cpp:1776
Node * node_ptr(Section *sec, double x, double *parea)
Definition: cabcode.cpp:1986
Section * chk_access(void)
Definition: cabcode.cpp:444
static double * duration
Definition: clamp.cpp:37
static Node * pnd
Definition: clamp.cpp:33
double chkarg(int, double low, double high)
Definition: code2.cpp:638
#define cur
Definition: eion.cpp:364
at_time
Definition: extargs.h:1
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
void print_stim()
Definition: fstim.cpp:49
static void stim_record(int)
Definition: fstim.cpp:139
struct Stimulus Stimulus
static void free_stim(void)
Definition: fstim.cpp:126
void activstim_rhs(void)
Definition: fstim.cpp:164
void fstimi(void)
Definition: fstim.cpp:79
void fstim(void)
Definition: fstim.cpp:90
void stim_prepare(void)
Definition: fstim.cpp:156
static int maxstim
Definition: fstim.cpp:41
static Stimulus * pstim
Definition: fstim.cpp:42
#define nt_t
Definition: fstim.cpp:47
static double stimulus(int i)
Definition: fstim.cpp:68
void hoc_retpushx(double x)
Definition: hocusr.cpp:154
#define getarg
Definition: hocdec.h:15
int ifarg(int)
Definition: code.cpp:1581
#define area
Definition: md1redef.h:5
#define sec
Definition: md1redef.h:13
#define i
Definition: md1redef.h:12
#define Printf
Definition: model.h:237
char * emalloc(unsigned n)
Definition: list.cpp:166
int nrn_nthread
Definition: multicore.cpp:46
NrnThread * nrn_threads
Definition: multicore.cpp:47
void section_ref(Section *)
Definition: solve.cpp:575
void section_unref(Section *)
Definition: solve.cpp:565
#define e
Definition: passive0.cpp:22
#define loc(x, y, z)
#define NODERHS(n)
Definition: section.h:105
Definition: section.h:133
double loc
Definition: fstim.cpp:32
double delay
Definition: fstim.cpp:33
double mag
Definition: fstim.cpp:35
double mag_seg
Definition: fstim.cpp:36
Section * sec
Definition: fstim.cpp:38
double duration
Definition: fstim.cpp:34
Node * pnd
Definition: fstim.cpp:37