-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstdutil.hoc
More file actions
279 lines (219 loc) · 6.13 KB
/
Copy pathstdutil.hoc
File metadata and controls
279 lines (219 loc) · 6.13 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// func isclass( objref, class name ) - checks if object is of a given type
// dependency: none (stdlib and stdrun always assumed to be loaded and not listed in dependency)
// proc MakeSecList( SectionList, section, ... ) - adds sections to SectionList from input strdef(s)
// dependency: isclass (local)
// obfunc chkSecList( sections ) - checks if input is SectionList. Makes one if not (NOTE: this is useless)
// dependency: none
// proc MakeStringList( List, section, ... ) - adds Strings from input strdef(s) to List
// dependency: none
// func SectionListCount( SectionList ) - returns number of sections in SectionList
// dependency: none
// proc findobj( out List, in List, parameter, value) - finds obj in List that have a given attribute
// dependency: none
objref StepEvents_, AdvanceEvents_
StepEvents_ = new List()
AdvanceEvents_ = new List()
proc init() {
finitialize(v_init)
doStepEvent()
}
proc step() {local i
if (using_cvode_) {
advance()
}else for i=1,nstep_steprun {
advance()
}
doStepEvent()
Plot()
}
proc doStepEvent() {local i,cnt
cnt = StepEvents_.count()-1
for i=0,cnt {
StepEvents_.o(i).update()
}
}
proc impedancemenu() {
xmenu("Impedance")
xbutton("Frequency", "load_file(\"impratio.hoc\") makeImpRatio()")
xbutton("Path", "load_file(\"impedanx.hoc\") makeImpx()")
xbutton("log(A) vs x", "load_file(\"logax.hoc\") makelogax()")
xbutton("Shape", "load_file(\"attshape.hoc\") makeImpShape()")
xmenu()
}
proc CleanStepEvent() {local i
for (i=StepEvents_.count()-1; i>=0; i=i-1) {
StepEvents_.remove(i)
}
}
func AddToStep() {local n
n = StepEvents_.append($o1)
return n
}
proc RemoveFromStep() {local n
n = StepEvents_.index($o1)
if (n>-1) StepEvents_.remove(n)
}
proc RemoveFromList() {local n
n = $o1.index($o2)
if (n>-1) $o1.remove(n)
}
func StringFind() {local x, n
// find the index of a string in a List of Strings
// StringFind(List of Strings, test string)
for n=0,count {
x = strcmp($o1.o(n).s, $s2)
if (x==0) return n
}
return -1
}
func SectionFind() {local x, n
// find the index of a section in a SectionList by name
// SectionFind(List of Strings, test string)
n=0
forsec $o1 {
x = strcmp( secname(), $s2)
if (x==0) {
return n
} else {
n+=1
}
}
return -1
}
func isclass() {localobj S
// isclass( object, class name)
// returns 1 if the object is of the specified class, returns 0 if not
S = new String()
classname($o1, S.s)
return strcmp(S.s, $s2) == 0
}
proc MakeSecList() { local i,count
//MakeSecList( SectionList, char list)
// create a new sectionlist from an input list of section names. uses greedy regexp ("" matches all)
count = numarg()
if (isclass( $o1,"NULLobject")) $o1 = new SectionList()
for i=2,count {
forall ifsec $si $o1.append()
}
//$o1.printnames()
}
func objrefcount() {local i
execute1("for i=0,1e3 $o1[i]",0)
return i
}
proc get_sec() {
// get the section name for the specified inserted mechanism
// get_sec(point process, strdef)
// get_sec(point process, string list)
if (argtype(2)==2) {
$o1.get_loc() $s2 = secname() pop_section()
} else if (argtype(2)==1) {
$o1.get_loc() $o2.append(new String( secname() )) pop_section()
}
}
proc get_sections() {local i
// get_sections(point process list, sectionlist)
// generates a sectionlist of the locations of a list of inserted mechanisms
if (object_id($o2,1) == -1) $o2 = new SectionList()
for i = 0,$o1.count-1 {
$o1.o(i).get_loc() $o2.append() pop_section()
}
}
obfunc get_subset() {local i, rm localobj sL, PPs, tL
// list = get_subset(point process list, section list, remove)
// returns the subset of objects in $o1 that are inserted in sections within $o2
// if remove, then remove the collected objects from $o1
PPs = new List()
get_sections( $o1, sL )
rm=0 // whether to remove object from original list after adding to new list
if (numarg()>2) rm = $3
if (argtype(2)==2) {
MakeSecList(tL,$s2)
} else if (argtype(2)==1) {
tL = $o2
}
i=0 // section number
forsec sL { // for each oject in $o1 (iterate by section)
ifsec tL { // if the section is also in test SectionList
PPs.append($o1.o(i)) // add object to new list
if (rm>0) {
$o1.remove(i)
i-=1 // deprecate section number. After removal of o(i), o(i) is next object
}
}
i+=1
}
return PPs
}
obfunc chkSecList() { localobj sl
// chkSecList( sections )
// returns objref of SectionList including all sections indicated by input arg. Empty input matches all
if (argtype(1)==2) {
sl = new SectionList()
forall ifsec $s1 sl.append()
if (verbosity > 2) printf("generated new SectionList from string: chkSecList\n")
if (verbosity > 3) sl.printnames()
} else if (argtype(1)==1) {
sl = $o1
} else {
sl = new SectionList()
forall sl.append()
}
return sl
}
proc MakeStringList() { local i,count
// MakeStringList( List, string1, string2, ...)
// makes a List of String obj
if (object_id($o1,1) == -1) $o1 = new List()
count = numarg()
if (verbosity > 2) printf("MakeStringList: adding %g strings\n", count-1 )
for i=2,count {
$o1.append(new String($si))
}
}
func SectionListCount() { local count
//count = SectionListCount( sectionlist )
// counts number of unique sections in list
count=0
if (argtype(1)==2) {
forsec $s1 { count+=1 }
} else if (argtype(1)==1) {
$o1.unique()
forsec $o1 { count+=1 }
}
return count
}
proc findobj() {local p0,p1,x,rng localobj outlist, inlist, ms, S, S1
// findobj(subset, full list, parameter, value)
// findobj(subset, full list, parameter, min value, max value)
//
// finds objects within List that has parameter equal to value or between min and max values
// returns a List with found objects
outlist = $o1
inlist = $o2
S = new String($s3)
p0 = $4
rng = 0
if (numarg()>4) {
p1 = $5
rng = 1
}
S1 = new String()
classname(inlist.o(0), S1.s)
ms = new MechanismStandard(S1.s)
for i=0,inlist.count()-1 {
if ( isclass(inlist.o(i), S1.s) ) {
ms.in(inlist.o(i))
} else {
classname(inlist.o(0), S1.s)
ms = new MechanismStandard(S1.s)
ms.in(inlist.o(i))
}
x = ms.get(S.s)
if (rng == 0) {
if (x == p0) outlist.append(inlist.o(i))
} else {
if (( x >= p0) && (x <= p1)) outlist.append(inlist.o(i))
}
}
}