File: watchrange.mod

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (134 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download | duplicates (3)
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
: for testing multiple WATCH statements activated as same time
: high, low, and mid regions watch a random uniform variable.
: The random variable ranges from 0 to 1 and changes at random times in
: the neighborhood of interval tick.

NEURON {
  THREADSAFE
  POINT_PROCESS Bounce
  RANGE r, result, n_high, n_low, n_mid, tick, x, t1
  BBCOREPOINTER ran
}

PARAMETER {
  tick = 0.25 (ms)
  LowThresh = 0.3
  HighThresh = 0.7
}

ASSIGNED {
  x (1)
  t1 (ms)
  r (1)
  n_high (1)
  n_mid (1)
  n_low (1)
  result (1)
  ran
}

DEFINE Low  1
DEFINE Mid  2
DEFINE High  3
DEFINE Clock 4

VERBATIM
#include "nrnran123.h"
ENDVERBATIM

INITIAL {
  VERBATIM
    if (_p_ran) {
      nrnran123_setseq((nrnran123_State*)_p_ran, 0, 0);
    }
  ENDVERBATIM
  n_high = 0
  n_mid = 0
  n_low = 0
  r = uniform()
  t1 = t
  x = 0
  net_send(0, Mid)
  net_send(0, Clock)
}

:AFTER SOLVE {
:  result = t1*100/1(ms) + x
:}

NET_RECEIVE(w) {
  t1 = t
  if (flag == Clock) {
    r = uniform()
    net_send(tick*(uniform() + .5), Clock)
  }
  if (flag == High) {
    x = High
    n_high = n_high + 1
    WATCH (r < LowThresh) Low
    WATCH (r < HighThresh ) Mid
  }else if (flag == Mid) {
    x = Mid
    n_mid = n_mid + 1
    WATCH (r < LowThresh) Low
    WATCH (r > HighThresh) High
  }else if (flag == Low) {
    x = Low
    n_low = n_low + 1
    WATCH (r > HighThresh) High
    WATCH (r > LowThresh) Mid
  }
}

FUNCTION uniform() {
  uniform = 0.5
VERBATIM
  if (_p_ran) {
    _luniform = nrnran123_dblpick((nrnran123_State*)_p_ran);
  }
ENDVERBATIM
}

PROCEDURE noiseFromRandom123() {
VERBATIM
#if !NRNBBCORE
 {
  nrnran123_State** pv = (nrnran123_State**)(&_p_ran);
  if (*pv) {
    nrnran123_deletestream(*pv);
    *pv = (nrnran123_State*)0;
  }
  if (ifarg(1)) {
    *pv = nrnran123_newstream3((uint32_t)*getarg(1), (uint32_t)*getarg(2), (uint32_t)*getarg(3));
  }
 }
#endif
ENDVERBATIM
}

VERBATIM
static void bbcore_write(double* z, int* d, int* zz, int* offset, _threadargsproto_) {
  if (d) {
    char which;  
    uint32_t* di = ((uint32_t*)d) + *offset;
    nrnran123_State** pv = (nrnran123_State**)(&_p_ran);
    nrnran123_getids3(*pv, di, di+1, di+2);
    nrnran123_getseq(*pv, di+3, &which);
    di[4] = (int)which;
  }                     
  *offset += 5;
}

static void bbcore_read(double* z, int* d, int* zz, int* offset, _threadargsproto_) {
  uint32_t* di = ((uint32_t*)d) + *offset;
  nrnran123_State** pv = (nrnran123_State**)(&_p_ran);
#if !NRNBBCORE
  if (*pv) {
    nrnran123_deletestream(*pv);
  }
#endif
  *pv = nrnran123_newstream3(di[0], di[1], di[2]);
  nrnran123_setseq(*pv, di[3], (char)di[4]);
  *offset += 5;
}
ENDVERBATIM