-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimulationUtilities.hoc
More file actions
214 lines (180 loc) · 5.4 KB
/
Copy pathSimulationUtilities.hoc
File metadata and controls
214 lines (180 loc) · 5.4 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
proc SaveParams() { // local ims localobj LGMD, file, this
// SaveParams( file name )
// Saves global values and "forall psection()" to a text file
// this file could then be loaded to recreate the model state (need custom file loader to handle point processes)
hoc_stdout($s1)
PrintGlobals()
forall psection()
// need to modify psection() or write new proc to account for different diams for each segment
hoc_stdout()
if (verbosity > 1) printf("Saved global and section parameters to file ... \n")
}
proc PrintGlobals() { local i,j,k,size,ptf localobj gls, ms, fobj, strobj
// Prints the values of global parameters for membrane mechanisms
//
// PrintGlobals()
// PrintGlobals( File )
// PrintGlobals( List )
// PrintGlobals( strdef )
//
// if List is empty or not given, all mechanisms from MechanismType(0) with global values are printed
// if a strdef is given, all global values for the mechanism with the given name are printed
ptf=0
strobj = new String()
if (numarg() > 0) {
if (argtype(1) == 1) {
if (isclass($o1, "List")) {
gls = $o1
} else if (isclass($o1, "File")) {
ptf=1
fobj = $o1
gls = new List()
MechList(gls)
}
} else if (argtype(1)==2) {
gls = new List()
MakeStringList(gls,$s1)
} else if (argtype(1)==0) {
gls = new List()
MechList(gls)
}
} else {
gls = new List()
MechList(gls)
}
for j=0,gls.count()-1 {
ms = new MechanismStandard(gls.o(j).s, -1)
if (ms.count == 0) { continue }
for i=0, ms.count -1 {
size = ms.name(tmpstr, i)
if (size == 1) {
sprint(strtmp, "hoc_ac_ = %s", tmpstr)
execute(strtmp)
if (ptf==1) {
fobj.printf("%s = %g\n", tmpstr, hoc_ac_)
} else printf("%s = %g\n", tmpstr, hoc_ac_)
} else if (size < 20) {
for k=0, size-1 {
sprint(strtmp, "hoc_ac_ = %s[%d]", tmpstr, k)
execute(strtmp)
if (ptf==1) {
fobj.printf("%s[%d] = %g\n", tmpstr, k, hoc_ac_)
} else printf("%s[%d] = %g\n", tmpstr, k, hoc_ac_)
}
} else {
if (ptf==1) {
fobj.printf("%s[0 - %d]\n", tmpstr, size-1)
} else printf("%s[0 - %d]\n", tmpstr, size-1)
}
}
}
}
proc MVtextout() { local i
$o1.printf("%s\n", $o2.s)
if ($o2.children != nil) {
for i=0, $o2.children.count-1 {
MVtextout($o1, $o2.children.object(i))
}
}
}
proc SaveData() { local i,k, count, ti, tg localobj savdata, rec_matrix
//SaveData( filename, headerstr, Vm count, Im, G )
if (numarg()<3) {
if (verbosity > 0) printf("SaveData: not enough inputs. Not Saving \n")
return
} else if (verbosity > 1) printf("SaveData: saving data ... \n")
savdata = new File()
savdata.wopen($s1)
count = $3
if (verbosity > 2) printf("SaveData: opened file %s for writing ... \n", $s1)
ti=0
tg=0
k = count+1
if (numarg() > 3) ti = $4
if (numarg() > 4) tg = $5
if (ti) k+=1
if (tg) k+=gvec_G_.count()
if (verbosity > 2) printf("SaveData: saving voltage of %g sections plus %g additional vectors\n", count, k-count-1)
rec_matrix = new Matrix(tvec_G_.size(), k)
// rec_matrix.resize(tvec_G_.size(), count+ti)
rec_matrix.setcol(0,tvec_G_)
for (i=1; i<=count; i=i+1) {
rec_matrix.setcol(i,rvec_G_[i-1])
}
if (ti) {
rec_matrix.setcol(i,ivec_G_)
i+=1
}
if (tg) {
for k=0,gvec_G_.count()-1 {
rec_matrix.setcol(i,gvec_G_.o(k))
if (verbosity > 3) printf("SaveData: saving %s of length %g in column %g\n", gvec_G_.o(k).label, gvec_G_.o(k).size, i)
i+=1
}
}
savdata.printf($s2)
rec_matrix.fprint(savdata,"%-1.8g ")
savdata.printf( "time " )
// fix this bug. simsecs_G_ might not be used
// forsec simsecs_G_ savdata.printf( "%s ", secname() )
for k=0,count-1 {
savdata.printf( "%s ", rvec_G_[k].label() )
}
if (ti) savdata.printf( "Im " )
if (tg) {
for k=0,gvec_G_.count()-1 {
savdata.printf( "%s ", gvec_G_.o(k).label() )
}
}
savdata.printf( "\n" )
savdata.close()
}
proc SaveSections() { local i, opt
// SaveSections( flag, sections )
opt=0
if ( (object_id(simsecs_G_,1) == -1) && (numarg()==0) ) {
opt = 1
// seclist=1
}
if (numarg()>0) {
if (argtype(1)==0) {
opt = 1
seclist=$1
}
}
if ( numarg() > 1 ) opt = 2
if (object_id(simsecs_G_,1) == -1) simsecs_G_ = new SectionList()
if ( opt == 0 ) {
if (verbosity > 1) printf("SaveSections: simsecs_G_ unchanged\n")
return
} else if (opt == 1) {
simsecs_G_ = new SectionList()
if (seclist==1) {
MakeSecList(simsecs_G_,"soma[0]","Handle[25]","MainTrunk[0]","FieldC[15]","FieldB[15]","Tines[287]",\
"Tines[7]","Tines[621]","Tines[786]","Tines[1080]","Tines[895]")
} else if (seclist==2) {
MakeSecList(simsecs_G_,"Handle[40]","MainTrunk[0]","FieldC[25]","Tines[786]","Tines[0]")
} else if (seclist==3) {
MakeSecList( simsecs_G_, "MainTrunk[0]" )
} else if (seclist==4) {
MakeSecList(simsecs_G_,"MainTrunk[0]","Tines[287]","MainTrunk[40]",\
"Tines[7]","Tines[786]","Tines[1080]","Handle[20]")
} else if (seclist==5) {
if (AEC) {
MakeSecList(simsecs_G_,"soma[0]","Tine0[7]","Tine3[6]")//,"Tine5[5]")//,\
// "Tine8[8]","Tine17[4]")
} else MakeSecList(simsecs_G_,"soma[0]","Handle[20]","MainTrunk[0]","Tines[530]","Tines[17]","Tines[621]",\
"Tines[1101]","Tines[1200]","Tines[795]")
}
} else if (opt==2) {
if (argtype(2)==1) {
simsecs_G_ = $o2
} else if (argtype(2)==2) {
for i=2,numarg() {
forall ifsec $si simsecs_G_.append()
}
} else {
if (verbosity > 0) printf("SaveSections: Sections must be specified as string or SectionList\nsimsecs_G_ unchanged\n")
}
}
}