-
Notifications
You must be signed in to change notification settings - Fork 1
/
xgraph.g
1588 lines (1001 loc) · 27.4 KB
/
xgraph.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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//genesis
//
// $Id: xgraph.g 1.13.1.1.1.1.2.1.2.1.2.1.1.3 Thu, 04 Apr 2002 12:46:38 +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
//'
//////////////////////////////////////////////////////////////////////////////
// xgraph.g : xgraph functionality
int include_xgraph
if ( {include_xgraph} == 0 )
include_xgraph = 1
//v default color for plots
int iDefaultPlotColor = 38
//v bool for communication between XGraphPlotCompartment and others
int bXGraphPlotCompartmentResult = 0
//v normal path for xcell script
str cbXCell
///
/// SH: XGraphPlotColor
///
/// RE: color for current plot
///
/// DE: Give color for current plot
///
function XGraphPlotColor
//- get next color
int color = {getfield /xgraphs/graph cNextColor}
//- modulo 64 to get a legal value
color = {color} % 64
//- return result
return {color}
end
///
/// SH: XGraphNextColor
///
/// RE: color for current plot
///
/// DE: Give color for next plot
///
function XGraphNextColor
//- get next available color
int color = {getfield /xgraphs/graph cNextColor}
//- modulo 64 to get a legal value
color = {color + 19} % 64
//- increment the color count
setfield /xgraphs/graph cNextColor {color}
//- return result
return {color}
end
///
/// SH: XGraphPlotTitle
///
/// PA: comp..: compartment to be plotted
/// source: registered output source
/// value.: registered output value
/// flags.: registered output flags
///
/// RE: title for a plot
///
/// DE: Give title for a plot for given parameters
///
function XGraphPlotTitle(comp,source,value,flags)
str comp
str source
str value
int flags
//- get tail of compartment
str compTail = {getpath {comp} -tail}
//- default plot title is without index
str plotTitle = {compTail}
//- default index is none
str index = ""
//- find beginning of index
int iBegin = {findchar {compTail} "["}
//- if compartment has an index
if (iBegin != -1)
//- get index from registered compartement
index = {substring \
{compTail} \
{iBegin + 1} \
{{findchar {compTail} "]"} - 1}}
//- set title for plot
plotTitle = {substring {compTail} 0 {iBegin - 1}} \
@ "_" \
@ {index}
end
//- if output source is given
if (source != "")
//- if first char of output source is '/'
if ({substring {source} 0 0} == "/")
//- add output source minus '/' to plot title
plotTitle = {plotTitle} \
@ "_" \
@ {substring {source} 1}
//- else
else
//- add output source to plot title
plotTitle = {{plotTitle} @ "_" @ {source}}
end
end
// return plot title with added value
return {plotTitle} @ "_" @ {value}
//- return plot title
return {plotTitle}
end
///
/// SH: XGraphNextPlotMode
///
/// PA: mode..: next plotting mode
///
/// RE: 1 if mode is changed
/// 0 if mode is same
///
/// DE: Notify graph of switched output units
/// {mode} is one of (Gk,Ik,E,Vm,Ca,E).
/// Updates warning info widget in 'Add plot' window
///
function XGraphNextPlotMode(mode)
str mode
//v result of function
int bResult
//- if registered output value is different from given mode
if ({mode} != {getfield /xgraphs outputValue})
//- set field for warning info widget
setfield /xgraphs/addPlotForm/info4 \
title "Adding plots will remove all current plots"
//- set result : mode is changed
bResult = 1
//- else
else
//- erase field for warning info widget
setfield /xgraphs/addPlotForm/info4 \
title ""
//- set result : mode is same
bResult = 0
end
//- return result
return {bResult}
end
///
/// SH: XGraphPlotCompartment
///
/// PA: path..: path with solver
/// comp..: compartment to be plotted
/// color.: color for new plot
///
/// RE: 1 if successfull
/// 0 if failed
///
/// DE: Add a plot for the given compartment, reset the simulation
/// The registered xcell output parameters are considered for setting up
/// the message to the graph.
///
function XGraphPlotCompartment(path,comp,color)
str path
str comp
int color
//- set default result : success
int bResult = 1
//- get the registered xcell output
str xcOutput = {getfield /xcell output}
//- get the registered xcell output source
str xcOutputSource = {getfield /xcell outputSource}
//- get the registered xcell output value
str xcOutputValue = {getfield /xcell outputValue}
//- get the registered xcell output flags
int xcOutputFlags = {getfield /xcell outputFlags}
//- get the registered xcell output description
str xcOutputDescription = {getfield /xcell outputDescription}
//- get the registered xcell channel mode
str xcChannelMode = {getfield /xcell channelMode}
//- get xcell field for registering boundary element
str xcBoundElement = {getfield /xcell boundElement}
//- if registered output value is different from xcell output value
if ({xcOutputValue} != {getfield /xgraphs outputValue})
//- reset the graph
callfunc XGraphReset
end
//- register new output
setfield /xgraphs \
output {xcOutput}
//- register new output source
setfield /xgraphs \
outputSource {xcOutputSource}
//- register new output value
setfield /xgraphs \
outputValue {xcOutputValue}
//- register new output flags
setfield /xgraphs \
outputFlags {xcOutputFlags}
//- register new output description
setfield /xgraphs \
outputDescription {xcOutputDescription}
//- register new channel mode
setfield /xgraphs \
channelMode {xcChannelMode}
//- register new boundary element
setfield /xgraphs \
boundElement {xcBoundElement}
// reset parameters to compartmental voltage
//xcOutputSource = ""
//xcOutputValue = "Vm"
//xcOutputFlags = 1
//- get tail of compartment
str compTail = {getpath {comp} -tail}
//- get a plot title
str plotTitle = {XGraphPlotTitle \
{comp} \
{xcOutputSource} \
{xcOutputValue} \
{xcOutputFlags}}
//- if flags say compartmental output
if (xcOutputFlags == 1)
//- if the specified element exists
if ( {exists {comp} {xcOutputValue}} )
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is '(compartment)', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{comp} \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//echo {comp} {compTail} {index}
//echo {plotTitle}"_"{xcOutputValue}
//- else
else
//- give an informational message
echo "No plot for "{comp}", " \
"source is '(compartment)', " \
"value is '"{xcOutputValue}"'."
echo "The element or field does not exist."
//- set result
bResult = 0
end
//- else if flags say spiny Vm output
elif (xcOutputFlags == 4)
//- get the spine that gives messages to the element
str spine = {getmsg {comp} -outgoing -destination 7}
//- get tail of spine
str spineTail = {getpath {spine} -tail}
//- if we are handling a spine
if ( {strncmp {spineTail} "spine" 5} == 0 )
//- default index is zero
source = "head[0]"
//- if an index is available
if ( {strlen {spineTail}} != 5 )
//- get index of synapse
int synapseIndex \
= {substring \
{spineTail} \
6 \
{{strlen {spineTail}} - 1}}
//- make source string with index
source = "head[" @ {synapseIndex} @ "]"
end
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is '"{source}"', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{path}/{source} \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//- else inform the user
else
//- give an informational message
echo "No plot for "{comp}", " \
"source is '"{xcOutputSource}"', " \
"value is '"{xcOutputValue}"'."
echo "The element or field does not exist."
//- set result
bResult = 0
end
//- else if flags say excitatory channel output
elif (xcOutputFlags == 3)
//- get the spine that gives messages to the element
str spine = {getmsg {comp} -outgoing -destination 7}
//- get tail of spine
str spineTail = {getpath {spine} -tail}
//- get head of spine for use with solver's flat space
str spineHead = {getpath {spine} -head}
//- if we are handling a spine
if ( {strncmp {spineTail} "spine" 5} == 0 )
//- default index is zero
str source = "head[0]/par"
//- if an index is available
if ( {strlen {spineTail}} != 5 )
//- get index of synapse
int synapseIndex \
= {substring \
{spineTail} \
6 \
{{strlen {spineTail}} - 1}}
//- make source string with index
source = "head[" @ {synapseIndex} @ "]/par"
end
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is '"{spineHead}{source}"', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{spineHead}{source} \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//- else if we can find a climbing fiber input
elif ( {exists {comp}/climb} )
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is 'climb', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{comp}/climb \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//- else inform the user
else
//- give an informational message
echo "No plot for "{comp}", " \
"source is '"{xcOutputSource}"', " \
"value is '"{xcOutputValue}"'."
echo "The element or field does not exist."
//- set result
bResult = 0
end
//- else if flags say inhibitory channel output
elif (xcOutputFlags == 7)
//- if we can find a stellate cell
if ( {exists {comp}/stell} )
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is 'stell', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{comp}/stell \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//- else if we can find a stellate 1 cell
elif ( {exists {comp}/stell1} )
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is 'stell1', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{comp}/stell1 \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//- else if we can find a basket cell
elif ( {exists {comp}/basket} )
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is 'basket', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{comp}/basket \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//- else inform the user
else
//- give an informational message
echo "No plot for "{comp}", " \
"source is '"{xcOutputSource}"', " \
"value is '"{xcOutputValue}"'."
echo "The element or field does not exist."
//- set result
bResult = 0
end
//- else we have 'normal' compartmental output
else
//- if the specified element exists
if ( {exists {comp}/{xcOutputSource} {xcOutputValue}} )
//- give an informational message
echo "Adding plot for "{comp}", " \
"source is '"{xcOutputSource}"', " \
"value is '"{xcOutputValue}"'."
//- add message from solver to graph
addmsg {path}/solve /xgraphs/graph \
PLOT \
{findsolvefield \
{path}/solve \
{comp}/{xcOutputSource} \
{xcOutputValue}} \
*{plotTitle} \
*{color}
//echo {comp} {compTail} {index}
//echo {plotTitle}"_"{xcOutputValue}
//- else
else
//- give an informational message
echo "No plot for "{comp}", " \
"source is '"{xcOutputSource}"', " \
"value is '"{xcOutputValue}"'."
echo "The element or field does not exist."
//- set result
bResult = 0
end
end
//- if adding plot was successfull
if (bResult)
//- reset added plot (makes it visible)
call /xgraphs/graph/{plotTitle} RESET
end
//- set global result
bXGraphPlotCompartmentResult = {bResult}
//- return result
return {bResult}
end
///
/// SH: XGraphRemoveCompartment
///
/// PA: path..: path with solver
/// comp..: compartment to be removed from plot list
///
/// DE: Remove the plot for the given compartment
///
function XGraphRemoveCompartment(path,comp)
str path
str comp
//- get the registered xcell output source
str xcOutputSource = {getfield /xcell outputSource}
//- get the registered xcell output value
str xcOutputValue = {getfield /xcell outputValue}
//- get the registered xcell output flags
int xcOutputFlags = {getfield /xcell outputFlags}
//- get a plot title
str plotTitle = {XGraphPlotTitle \
{comp} \
{xcOutputSource} \
{xcOutputValue} \
{xcOutputFlags}}
//- if the plot exists
if ( {exists /xgraphs/graph/{plotTitle}} )
//- give diagnostics
echo "Removing plot "{plotTitle}
//- remove the plot
delete /xgraphs/graph/{plotTitle}
//- reset the graph
call /xgraphs/graph RESET
//- else
else
//- give diagnostics
echo "No plot named "{plotTitle}
end
end
///
/// SH: XGraphClear
///
/// PA: path..: parent element to clear all graphs for
///
/// DE: clear all graphs within the given element tree
///
function XGraphClear(path)
str path
//- give diagnostics
echo "Removing all plots"
//v old status of overlay
int overlayOld
//- loop over all plots in the given tree
str plot
foreach plot ( {el {path}/##[][TYPE=xplot]} )
//- delete the plot
delete {plot}
end
//- loop over all graphs in the given tree
str graph
foreach graph ( {el {path}/##[][TYPE=xgraph]} )
//- push the element
pushe {graph}
//- remember status of overlay field
overlayOld = {getfield . overlay}
//- unset overlay field
setfield . overlay 0
//echo RESET for {el .} with overlay {getfield . overlay}
//- reset the graph
call . RESET
//- reset overlay field to previous state
setfield . overlay {overlayOld}
//- pop previous current element
pope
end
//- remove all electrodes
callfunc XCellRemoveElectrodes
end
///
/// SH: XGraphResetAxes
///
/// DE: Reset the axes to registered values if any
///
/// NO: This functions is obsoleted because of normalized boundary
/// handling
///
function XGraphResetAxes
// call XGraphReset
//callfunc "XGraphReset"
//- get registered boundary element
str bound = {getfield /xgraphs boundElement}
//- set boundaries
callfunc XGraphSetBoundaries {bound}
end
///
/// SH: XGraphCancelScales
///
/// DE: Hide the set scales window
///
function XGraphCancelScales
//- hide the set scales window
xhide /xgraphs/setscales
end
///
/// SH: XGraphSetScales
///
/// DE: Set the scales as in the set scales window
///
function XGraphSetScales
//- set x min
setfield /xgraphs/graph \
xmin {getfield /xgraphs/setscales/xmin value}
//- set x max
setfield /xgraphs/graph \
xmax {getfield /xgraphs/setscales/xmax value}
//- set y min
setfield /xgraphs/graph \
ymin {getfield /xgraphs/setscales/ymin value}
//- set y max
setfield /xgraphs/graph \
ymax {getfield /xgraphs/setscales/ymax value}
//- hide the set scales window
xhide /xgraphs/setscales
end
///
/// SH: XGraphUpdateScales
///
/// DE: Update scales window with registered xgraph values
/// Values come from xmin, xmax, ymin and ymax fields from xgraph
///
function XGraphUpdateScales
//- set x min value
setfield /xgraphs/setscales/xmin \
value {getfield /xgraphs/graph xmin}
//- set x max value
setfield /xgraphs/setscales/xmax \
value {getfield /xgraphs/graph xmax}
//- set y min value
setfield /xgraphs/setscales/ymin \
value {getfield /xgraphs/graph ymin}
//- set y max value
setfield /xgraphs/setscales/ymax \
value {getfield /xgraphs/graph ymax}
end
///
/// SH: XGraphShowScales
///
/// DE: Popup set scales window
///
function XGraphShowScales
//- update values for scales window
XGraphUpdateScales
//- pop up the scales form
xshow /xgraphs/setscales
end
///
/// SH: XGraphHideAddPlot
///
/// DE: Hide the add plot window
/// Resets the xcell call back
///
function XGraphHideAddPlot
//- restore field for xcell script
setfield /xcell/draw/xcell1 \
script {cbXCell}
//- hide add plot window
xhide /xgraphs/addPlotForm
end
///
/// SH: XGraphSetAddPlot
///
/// PA: name..: name of compartment to add plot for
///
/// DE: Add plot for specified compartment name
/// The field and subelement to output are taken from xgraph output mode
/// If the function is successfull, the add plot window will hide.
///
function XGraphSetAddPlot(name)
str name
//- for empty given name
if ( {name} == "" )
//- just return
return
end
//- if name is relative