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  at_time(nrn_threads, pstim[i].delay);
71  if (nt_t < pstim[i].delay - 1e-9 || nt_t > pstim[i].delay + pstim[i].duration - 1e-9) {
72  return 0.0;
73  }
74  return pstim[i].mag_seg;
75 }
76 
77 void fstimi(void) {
78  int i;
79  double cur;
80 
81  i = chkarg(1, 0., (double) (maxstim - 1));
82  if ((cur = stimulus(i)) != 0.) {
83  cur = pstim[i].mag;
84  }
85  hoc_retpushx(cur);
86 }
87 
88 void fstim(void) {
89  int i;
90 
91  if (nrn_nthread > 1) {
92  hoc_execerror("fstim does not allow threads", "");
93  }
94  i = chkarg(1, 0., 10000.);
95  if (ifarg(2)) {
96  if (i >= maxstim) {
97  hoc_execerror("index out of range", (char*) 0);
98  }
99  pstim[i].loc = chkarg(2, 0., 1.);
100  pstim[i].delay = chkarg(3, 0., 1e21);
101  pstim[i].duration = chkarg(4, 0., 1e21);
102  pstim[i].mag = *getarg(5);
103  pstim[i].sec = chk_access();
105  stim_record(i);
106  } else {
107  free_stim();
108  maxstim = i;
109  if (maxstim) {
110  pstim = (Stimulus*) emalloc((unsigned) (maxstim * sizeof(Stimulus)));
111  }
112  for (i = 0; i < maxstim; i++) {
113  pstim[i].loc = 0;
114  pstim[i].mag = 0.;
115  pstim[i].delay = 1e20;
116  pstim[i].duration = 0.;
117  pstim[i].sec = 0;
118  stim_record(i);
119  }
120  }
121  hoc_retpushx(0.);
122 }
123 
124 static void free_stim(void) {
125  int i;
126  if (maxstim) {
127  for (i = 0; i < maxstim; ++i) {
128  if (pstim[i].sec) {
130  }
131  }
132  free((char*) pstim);
133  maxstim = 0;
134  }
135 }
136 
137 static void stim_record(int i) /*fill in the section info*/
138 {
139  double area;
140  Section* sec;
141 
142  sec = pstim[i].sec;
143  if (sec) {
144  if (sec->prop) {
145  pstim[i].pnd = node_ptr(sec, pstim[i].loc, &area);
146  pstim[i].mag_seg = 1.e2 * pstim[i].mag / area;
147  } else {
149  pstim[i].sec = 0;
150  }
151  }
152 }
153 
154 void stim_prepare(void) {
155  int i;
156 
157  for (i = 0; i < maxstim; i++) {
158  stim_record(i);
159  }
160 }
161 
162 void activstim_rhs(void) {
163  int i;
164 
165  for (i = 0; i < maxstim; i++) {
166  if (pstim[i].sec) {
167  NODERHS(pstim[i].pnd) += stimulus(i);
168  }
169  }
170 }
Section * chk_access()
Definition: cabcode.cpp:449
const char * secname(Section *sec)
name of section (for use in error messages)
Definition: cabcode.cpp:1674
Node * node_ptr(Section *sec, double x, double *parea)
Definition: cabcode.cpp:1828
static double * duration
Definition: clamp.cpp:37
static Node * pnd
Definition: clamp.cpp:33
#define area
Definition: md1redef.h:12
#define sec
Definition: md1redef.h:20
#define i
Definition: md1redef.h:19
at_time
Definition: extargs.h:1
double chkarg(int, double low, double high)
Definition: code2.cpp:626
void print_stim()
Definition: fstim.cpp:49
static void stim_record(int)
Definition: fstim.cpp:137
struct Stimulus Stimulus
static void free_stim(void)
Definition: fstim.cpp:124
void activstim_rhs(void)
Definition: fstim.cpp:162
void fstimi(void)
Definition: fstim.cpp:77
void fstim(void)
Definition: fstim.cpp:88
void stim_prepare(void)
Definition: fstim.cpp:154
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:17
NrnThread * nrn_threads
Definition: multicore.cpp:56
int nrn_nthread
Definition: multicore.cpp:55
void hoc_execerror(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:39
static void * emalloc(size_t size)
Definition: mpispike.cpp:30
void section_ref(Section *)
Definition: solve.cpp:520
void section_unref(Section *)
Definition: solve.cpp:509
int ifarg(int)
Definition: code.cpp:1607
#define loc(x, y, z)
#define NODERHS(n)
Definition: section_fwd.hpp:55
Definition: section.h:105
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
int Printf(const char *fmt, Args... args)
Definition: logger.hpp:18