-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.g
541 lines (327 loc) · 9.3 KB
/
config.g
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
//genesis
//
// $Id: config.g 1.7.1.2 Thu, 04 Apr 2002 11:55:56 +0200 hugo $
//
//////////////////////////////////////////////////////////////////////////////
//'
//' Purkinje tutorial
//'
//' (C) 1998-2002 BBF-UIA
//'
//' see our site at http://www.bbf.uia.ac.be/ for more information regarding
//' the Purkinje cell and genesis simulation software.
//'
//'
//' functional ideas ... Erik De Schutter, [email protected]
//' genesis coding ..... Hugo Cornelis, [email protected]
//'
//' general feedback ... Reinoud Maex, Erik De Schutter
//'
//////////////////////////////////////////////////////////////////////////////
// config.g : configuration file manipulation
int include_config
if ( {include_config} == 0 )
include_config = 1
///
/// SH: ConfigFilename
///
/// PA: cell..: cellfile that has been read with readcell command
/// path..: path to cell that has been read
///
/// RE: Filename for config file
///
/// DE: Construct a filename for a config file for the given cell and path
/// For the same combination of parameters this routine will allways
/// give the same result
///
function ConfigFilename(cell,path)
str cell
str path
//- return cell filename and cat '.config'
return {cell} @ ".config"
end
///
/// SH: ConfigHostType
///
/// PA: cell..: cellfile that has been read with readcell command
/// path..: path to cell that has been read
///
/// RE: string with the type of OS for current config file
/// if there is no valid config file, "nil" is returned.
///
/// DE: Return the type of OS the current config file was created on
///
function ConfigHostType(cell,path)
str cell
str path
//- create a filename for the config file
str filename = {ConfigFilename {cell} {path}}
//- create an empty config file if it does not exist
sh "touch "{filename}
//= read data from config file
str argline
str arg1
str arg2
//- open the config file
openfile {filename} r
//- read header line
argline = {readfile {filename} -line}
//- if the argument count is different from 1
if ( argline == "" || {CountArguments {argline}} != 1)
//- return nil
return "nil"
end
//- read line with type of OS
argline = {readfile {filename} -line}
//- obtain arguments
arg1 = {getarg {arglist {argline}} -arg 1}
arg2 = {getarg {arglist {argline}} -arg 2}
//- if the line does not contain OS information
if (arg1 != "hostType")
//- return nil
return "nil"
end
//- return the type of the OS
return {arg2}
end
///
/// SH: ConfigWrite
///
/// PA: cell..: cellfile that has been read with readcell command
/// path..: path to cell that has been read
///
/// DE: Make and write a configuration file.
///
function ConfigWrite(cell,path)
str cell
str path
//{
//1 first declare locals for all config settings
//2 determine the value for all config settings
//3 write all locals to config file
//}
//- create a filename for the config file
str filename = {ConfigFilename {cell} {path}}
//- give diagnostics
echo "Making "{filename}" configuration file for "{cell}
//{
//1 first declare locals for all config settings
//v type of host
str hostType
//v number of spines in the cell
int iSpines = 0
//v xcell wildcard
str xCellPath
//v number of elements in xcell
int xCellElements = 0
//2 determine the value for all config settings
//- determine type of host
//! since this does not work correctly on all systems,
//! it is commented out
//hostType = {getenv HOSTTYPE}
//! and replaced by a default
hostType = "default"
//- loop over all spines
str spine
foreach spine ( {el {path}/spine[]} )
//- increment count
iSpines = {iSpines + 1}
end
//- set xcell wildcard
xCellPath = {cellpath} @ "/soma[TYPE=compartment]," \
@ {cellpath} @ "/main[][TYPE=compartment]," \
@ {cellpath} @ "/b#[][TYPE=compartment]"
//- loop over the elements in the xcell
str xcomp
foreach xcomp ( {el {xCellPath}} )
//- increment count
xCellElements = {xCellElements + 1}
end
//3 write all locals to config file
//- open config file for output
openfile {filename} w
//- write the cell file as header
writefile {filename} "cellfile" {cell}
//- write the hostType
writefile {filename} "hostType" {hostType}
//- write the number of spines
writefile {filename} "iSpines" {iSpines}
//- write xcell wildcard
writefile {filename} "xCellPath" {xCellPath}
//- write number of elements in xcell
writefile {filename} "xCellElements" {xCellElements}
//- close config file
closefile {filename}
//}
end
///
/// SH: ConfigWriteUpdate
///
/// PA: cell..: cellfile that has been read with readcell command
/// path..: path to cell that has been read
///
/// DE: Update a config file if necessary
/// If the config file corresponds to the cell file, nothing is done.
///
function ConfigWriteUpdate(cell,path)
str cell
str path
//- create a filename for the config file
str filename = {ConfigFilename {cell} {path}}
//- default : we do not create a config file
int bCreate = 0
sh "touch "{filename}
//v read data from config file
str argline
str arg1
str arg2
//- open the config file
openfile {filename} r
//- read first line
argline = {readfile {filename} -line}
//echo config : count args = {CountArguments {argline}}
//- if the argument count is different from 1
if ( argline == "" || {CountArguments {argline}} != 1)
//- force a new config file
bCreate = 1
//- else check the contents
else
//- obtain arguments
arg1 = {getarg {arglist {argline}} -arg 1}
arg2 = {getarg {arglist {argline}} -arg 2}
//- close the config file
closefile {filename}
//- if this is not a valid config file
if (arg1 != "cellfile")
//- force a new config file
bCreate = 1
end
//- if the file does not match the cell
if (arg2 != cellfile)
//- force a new config file
bCreate = 1
end
end
//- if we should create a config file
if (bCreate)
//- make a new config file
ConfigWrite {cell} {path}
end
end
///
/// SH: ConfigRead
///
/// PA: cell..: cellfile that has been read with readcell command
/// path..: path to cell that has been read
///
/// RE: 0 for failure
/// 1 for success
///
/// DE: Read or make the configuration file.
/// If no configuration file is found, one will be made from the current
/// read cell in {cellpath}.
/// This function can produce a 'getarg' failure when the config file is
/// not valid.
///
function ConfigRead(cell,path)
str cell
str path
//- make sure the config file exists and is up to date
ConfigWriteUpdate {cell} {path}
//- create a filename for the config file
str filename = {ConfigFilename {cell} {path}}
//- give diagnostics
echo "Using configuration from "{filename}
//v line argument
str argline
//v two arguments
str arg1
str arg2
//{
//| Read in the configuration
//|
//1 first declare locals for all config settings
//2 read all locals from config file
//3 set the value for all config settings
//}
//{
//1 first declare locals for all config settings
//v type of OS
//! this is of no use anymore, it is always "default"
str hostType
//v number of spines
int iSpines
//v xcell wildcard
str xCellPath
//v number of elements in xcell
int xCellElements
//2 read all locals from config file
//- open the config file
openfile {filename} r
//- read first line
argline = {readfile {filename} -line}
//- obtain arguments
arg1 = {getarg {arglist {argline}} -arg 1}
arg2 = {getarg {arglist {argline}} -arg 2}
//- if this is not a valid config file
if (arg1 != "cellfile")
//- return a failure
return 0
end
//- if the file does not match the cell
if (arg2 != cellfile)
//- return a failure
return 0
end
//! from now on we assume a valid config file,
//! the tags identifying the data are ignored,
//! so the serial order is the only method for
//! identifying the information
//- read line with type of OS
argline = {readfile {filename} -line}
//- set type of OS
hostType = {getarg {arglist {argline}} -arg 2}
//- read line with number of spines
argline = {readfile {filename} -line}
//- set number of spines
iSpines = {getarg {arglist {argline}} -arg 2}
//- read line with xcell wildcard
argline = {readfile {filename} -line}
//- set xcell wildcard
xCellPath = {getarg {arglist {argline}} -arg 2}
//- read line with number of elements in xcell
argline = {readfile {filename} -line}
//- set number of elements in xcell
xCellElements = {getarg {arglist {argline}} -arg 2}
//3 set the value for all config settings
//- create a configuration element
create neutral /config
//- add a field for purkinje cell name
addfield /config \
cellfile -description "Cell read with readcell"
//- add a field for hostType
addfield /config \
hostType -description "Type of host"
//- add a field for the number of spines
addfield /config \
iSpines -description "Number of attached spines"
//- add a field for the xcell wildcard
addfield /config \
xCellPath -description "Elements displayed by xcell"
//- add a field for the number of elements in xcell
addfield /config \
xCellElements -description "Number of elements in xcell"
//- set the config values
setfield /config \
cellfile {cell} \
hostType {hostType} \
iSpines {iSpines} \
xCellPath {xCellPath} \
xCellElements {xCellElements}
//- close the config file
closefile {filename}
//}
//- return success with configuration
return 1
end
end