-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgrvec.hoc
More file actions
1606 lines (1509 loc) · 57 KB
/
grvec.hoc
File metadata and controls
1606 lines (1509 loc) · 57 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
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
// $Id: grvec.hoc,v 1.218 2002/03/20 14:35:05 billl Exp $
// main panel is 'vecpanel()'
proc grvec () {}
load_file("declist.hoc","declist") // declare lists
load_file("decvec.hoc","decvec") // declare vectors
strdef grep // LINUX grep requires -a to handle a binary file
if (sfunc.substr(osname,"inux")==1) grep="grep -a" else grep="grep"
//* templates
//** attrpanl (attribute panel) template stores the information about
// the attributes of a particular set of graphs including line colors,
// world coordinates, ...
// glist is a list of all graphs created from this panel
// llist is a list of available names and associated vectors or locations
begintemplate panattr
public color,line,super,curcol,graph,filename,comment
public glist,llist,tvec,size,shift,vsz,vjmp,vloc,remote
public printStep,entries,segments,bytes
public clear
double color[1],line[1],super[1],curcol[1],printStep[1],remote[1]
double size[4],entries[1],segments[1],bytes[1],shift[1]
double vsz[2],vloc[1],vjmp[1]
objref glist,llist,tvec
strdef filename,comment
proc init() {
if (numarg()==1) filename = $s1
color=1 line=1 curcol=1 super=0 bytes=0 vjmp=50 entries=1 segments=1
vsz[0] = 300 vsz[1] = 200
glist = new List()
llist = new List()
tvec = new Vector(0)
}
proc remgrs () {
glist.remove_all
glist = nil
glist = new List()
}
proc clear() {
bytes=0 entries=1 segments=1
comment = ""
llist.remove_all()
}
endtemplate panattr
//** vfile_line (vector file line) template gives information about a line
// in a file that gives a vector: name, size and location
begintemplate vfile_line
public name, size, loc, num
strdef name
double size[1],loc[1],num[1],tvec[1]
proc init () {
name=$s1 size=$2 num=$4
double loc[num],tvec[num]
loc[0] = $3
}
endtemplate vfile_line
//** vitem (vector item) is an internal vector used to store output from
// new vitem(var_name,vec_size,friendly_name)
// a simulation holds the name and the vector itself
begintemplate vitem
external cvode_local
public tvec,vec,var
objref tvec,vec // vector
strdef var // variable name
proc init () {
var=$s1
if (cvode_local()==1) tvec=new Vector($2)
vec=new Vector($2)
// NB label is labile
if (numarg()==3) vec.label($s3) else vec.label("") // use label for friendly name
}
endtemplate vitem
//* object declarations
objref vite, scob, printlist, panobj, panobjl, szstr[4], tvec
panobj = new panattr(simname)
tvec = panobj.tvec // use as a pointer to the tvec being recorded
panobjl = new List()
printlist = new List()
panobjl.append(panobj) // global graphing attributes
panobj.llist = printlist
tmpfile = new File()
strdef filename, recstr, grvecstr, readtag
readtag = "^//[:pbCM ]" // regexp used to identify header in mixed binary files
for ii=0,3 { szstr[ii] = new String() }
{ szstr[0].s="Set xmin" szstr[1].s="Set xmax" szstr[2].s="Set ymin" szstr[3].s="Set ymax" }
multi_files = 1 // set 0 to show individual segments of multi-seg files
dec_runnum = 1 // whether to decrement runnum when saving a new file
byte_store = 4 // store as ascii (0), byte (1), int (2), float (3), double (4)
tvec_bytesize = 4 // always store tvecs with more precision
show_panel = 1 // whether or not to put a full panel up when a file is read
outvecint = 0 // dump vectors every outvecint time if not 0
outvect = 0 // time for next vec dump
labelm = 1 // set to 0 to turn off labeling
strdef rvvec_name
rvvec_name = "vec"
//* store cvode state in a double in form active.local
func cvode_status () { return cvode_active() + cvode_local()/10 }
cvode_state = cvode_status()
//** return true and update cvode_state if cvode state has changed
func cvode_change () {
if (cvode_state!=cvode_status()) {
cvode_state=cvode_status() return 1
} else { return 0 }
}
//** verbose form of cvode_change
func cvode_what () { local act,loc,newstat,newact,newloc
act=int(cvode_state) loc=(cvode_state-act)*10
newstat = cvode_status()
if (cvode_state!=newstat) {
newact=int(newstat) newloc=(newstat-newact)*10
printf("Updating active/local from %d/%d to %d/%d\n",act,loc,newact,newloc)
cvode_state=cvode_status() return 1
} else {
printf("cvode_state: active %d, local %d\n",act,loc)
return 0
}
}
if (xwindows) scob = new SymChooser()
//* vecpanel() main panel
proc vecpanel() {
fchooser_flag = 0 // used to initialize the file chooser
sprint(temp_string_,"%s Vectors",simname)
xpanel(temp_string_)
xbutton("Graph from file","fchooser(-1)")
xbutton("Graph vector","pbrgr(\"Graph\",\"gv\")")
xbutton("Archive to file:","pbrgr(\"Archive\",\"pv\")")
xbutton("Archive all to output_file","pvall()")
xstatebutton("Superimpose",&panobjl.object(0).super)
xbutton("Attributes","attrpanl(0)")
redo_printlist()
redo_attrlist()
xpanel()
}
//* pbrgr(browser name,action) is used to put up a browser
// note action given without '()'
proc pbrgr () {
if (printlist.count == 1) {
gv(0)
} else if (printlist.count <= 8) {
mkpanel("Vector",$s1,$s2)
} else {
sprint(temp_string_,"%s:%s",simname,$s1)
printlist.browser(temp_string_,"var")
sprint($s2,"%s()",$s2)
printlist.accept_action($s2)
}
}
//* record(list,what,vecptr) from items in $o1 object(ii).$s2 in vectors
// $o1 is the list arg $s2 is the thing to be recorded [eg soma.v(0.5)]
// optional $3 is the name of an object belonging to list items that will
// serve as a pointer to the recording vector
proc record () { local ii, dur, na3
for ltr(XO,$o1) {
sprint(recstr,"%s.%s",XO,$s2)
new_printlist_item(recstr)
if (numarg()==3) {
sprint(temp_string_,"%s.%s=printlist.object(printlist.count-1).vec",XO,$s3)
execute(temp_string_) // only way to get call by ref for object
}
}
}
//* record_spks(list[,what]) takes a list of netcons and puts in printlist objects for them
// assumes that the PP will be called pp
proc record_spks () { local ii,flag
for ltr(XO,$o1) {
flag=1
if (cvode.netconlist(XO, "", "").count>0) {
YO=cvode.netconlist(XO, "", "").object(0)
sprint(recstr,"%s%s",YO.precell,"_spks")
} else if (cvode.netconlist(XO.pp, "", "").count>0) {
YO=cvode.netconlist(XO.pp, "", "").object(0)
sprint(recstr,"%s%s",YO.pre,"_spks")
} else { printf("%s not connected.\n",XO) flag=0 }
if (flag) {
vite = new vitem(recstr,100)
// use_lv_ardt_ removed for nrn 5.3 compatibility TMM
// if (use_lvardt_) { YO.record(vite.tvec) vite.vec.resize(0) } else YO.record(vite.vec)
printlist.append(vite)
}
}
YO=nil
}
//* redo_printlist() menu allows removal or addition of inidividual items
proc redo_printlist() {
xmenu("Print list")
xbutton("Add var to printlist","redolist(0)")
xbutton("Clear printlist","printlist.remove_all()")
xbutton("Remove item from printlist","redolist(1)")
xbutton("Vector.op","redolist(2)")
xbutton("Proc(vector)","redolist(6)")
xbutton("Link XO->vec,YO->tvec","redolist(7)")
xbutton("Graph vector","redolist(4)")
xbutton("Save printlist","redolist(5)")
xbutton("Add all obj's of this type to printlist","redolist(3)")
xmenu()
}
//* redolist() set of functions for altering the printlist called by redo_printlist()
proc redolist () { local ii,flag
flag = $1 rdstr = 1
if (numarg()==2) { recstr=$s2 rdstr=0 }
if (flag==0) {
if (scob.run()) {
scob.text(temp_string_)
new_printlist_item(temp_string_)
}
} else if (flag==1) { // remove item
printlist.browser("Double click on item to remove","var")
printlist.accept_action("printlist.remove(hoc_ac_)")
} else if (flag==2) { // .op
if (rdstr) string_dialog("Enter operation to be run on vec",recstr)
// sprint(temp_string_,"print printlist.object(hoc_ac_).var,\"%s = \",printlist.object(hoc_ac_).vec.%s",recstr,recstr)
temp_string_ = "\"%s.%s = %g\\n\""
sprint(temp_string_,"printf(%s,printlist.object(hoc_ac_).var,\"%s\",printlist.object(hoc_ac_).vec.%s)",temp_string_,recstr,recstr)
printlist.browser(recstr,"var")
printlist.accept_action(temp_string_)
} else if (flag==3) { // put another set of things on list
if (rdstr) string_dialog("String to be used as suffix for all items on list",recstr)
scob.run()
scob.text(temp_string_)
tmplist = new List(temp_string_)
record(tmplist,recstr)
} else if (flag==4) { // show it
pbrgr("Graph","gv")
} else if (flag==5) {
fchooser_flag = 0
tmpfile.chooser("a","Add printlist to file")
if (tmpfile.chooser()==1) {
tmpfile.printf("\nproc make_printlist() { \n")
tmpfile.printf(" printlist.remove_all()\n")
for ii=0,printlist.count-1 {
tmpfile.printf(" new_printlist_item(\"%s\")\n",printlist.object(ii).var)
}
tmpfile.printf("}\nmake_printlist()\n")
tmpfile.close()
}
} else if (flag==6) { // proc(vec)
if (rdstr) string_dialog("Enter procedure name \"proc\",called as proc(vec,var,num)",recstr)
printlist.browser(recstr,"var")
sprint(temp_string_,"%s(printlist.object(hoc_ac_).vec,printlist.object(hoc_ac_).var,hoc_ac_)",recstr)
printlist.accept_action(temp_string_)
} else if (flag==7) { // XO is pointer to vec
printlist.browser("XO","var")
sprint(temp_string_,"{tmpobj=printlist.object(hoc_ac_) print hoc_ac_,tmpobj.var XO=tmpobj.vec YO=tmpobj.tvec}")
printlist.accept_action(temp_string_)
}
}
//** linkxo2vec([num]) link X0 to vector in printlist, optional arg can be pos or neg
proc linkxo2vec () { local num,cnt
cnt = printlist.count
if (numarg()==1) {if ($1>=0) num=$1 else num=cnt+$1} else num=cnt-1
if (num>cnt-1 || num<0) {
printf("%d!: Only %d items (0-%d) in list.\n",num,cnt,cnt-1) return
}
print num,":XO -> ",printlist.object(num).var
XO = printlist.object(num).vec
}
//** cpplitem([num]) copy X0 to new item in printlist, optional arg can be pos or neg
proc cpplitem () { local num,cnt
cnt = printlist.count
if (numarg()>0) {if ($1>=0) num=$1 else num=cnt+$1} else num=cnt-1
if (num>cnt-1 || num<0) {
printf("%d!: Only %d items (0-%d) in list.\n",num,cnt,cnt-1) return
}
if (numarg()>1) grvecstr=$s2 else sprint(grvecstr,"Copy_of_%s",printlist.object(num).var)
new_printlist_item(grvecstr,printlist.object(num).vec)
print printlist.count-1,":XO -> ",grvecstr
XO = printlist.object(printlist.count-1).vec
}
//** cpplitem([num]) copy X0 to new item in printlist, optional arg can be pos or neg
proc chgplname () { local num,cnt
cnt = printlist.count
if (numarg()>0) {if ($1>=0) num=$1 else num=cnt+$1} else num=cnt-1
if (num>cnt-1 || num<0) {
printf("%d!: Only %d items (0-%d) in list.\n",num,cnt,cnt-1) return
}
printlist.object(num).var=$s2
}
//* new_printlist_item(name) adds this item to the printlist
// new_printlist_item(name,vec) adds this vec to the printlist
// new_printlist_item(name,num,vec) adds this vec to the printlist under name_num0,name_num1,...
proc new_printlist_item () { local dur,pln
panobj = panobjl.object(0) tvec=panobj.tvec
if (outvecint == 0) dur = tstop else dur = outvecint
grvecstr = $s1
remove_spaces(grvecstr,temp_string2_) // splits on '/'
// eg new_printlist_item(name,ii,vec)
if (numarg()==3) { // allows formation of tags on the fly
sprint(temp_string_,"%s%s",grvecstr,":%d")
sprint(temp_string_,temp_string_,$2)
vite = new vitem(temp_string_,$o3.size,temp_string2_)
vite.vec.copy($o3)
printlist.append(vite)
return
}
if (numarg()==2) { // second arg is a vector to store
vite = new vitem(grvecstr,$o2.size,temp_string2_)
vite.vec.copy($o2)
printlist.append(vite)
return
}
// use_lvardt_ replaced by 0 in below 'if' for nrn 5.3 compatibility TMM
if (0) {
if (isobj(panobj.tvec,"Vector")) if (panobj.tvec.size!=0) { tvec.resize(0) tvec.play_remove() }
vite = new vitem(grvecstr,dur/printStep+10,temp_string2_)
panobj.printStep=-2
} else if (using_cvode_) {
vite = new vitem(grvecstr,dur/printStep+10,temp_string2_)
panobj.printStep=-1
if (panobj.tvec.size==0) {
tvec.resize(dur/printStep+10) panobj.tvec.record(&t) }
} else {
if (panobj.tvec.size!=0) { tvec.resize(0) tvec.play_remove()}
panobj.printStep=printStep
vite = new vitem(grvecstr,dur/printStep+10,temp_string2_)
}
printlist.append(vite)
pln = printlist.count-1 // current printlist number
if (numarg()==2) $o2=vite.vec // allow user to assign a pointer
vite = nil
// use_lvardt_ replaced by 0 in below 'if' for nrn 5.3 compatibility TMM
if (0) {
printlist.object(pln).vec.resize(dur/printStep+10)
printlist.object(pln).tvec.resize(dur/printStep+10)
sprint(temp_string_,\
"{cvode.record(&%s,printlist.object(%d).vec,printlist.object(%d).tvec)}",grvecstr,pln,pln)
} else if (using_cvode_) { // don't give an explicit printStep
printlist.object(pln).vec.resize(dur/printStep+10)
sprint(temp_string_,\
"{printlist.object(%d).vec.record(&%s)}",pln,grvecstr)
} else {
sprint(temp_string_,\
"printlist.object(%d).vec.record(&%s,%g)",pln,grvecstr,printStep)
}
execute(temp_string_)
}
//* prlexp(sz) expands all the vectors in printlist to size sz
proc prlexp () {
sz = $1
tvec.resize(sz)
for ltr(XO,printlist) { XO.vec.resize(sz) }
}
//* redo_attrlist() menu allows removal or addition of inidividual items
proc redo_attrlist() {
xmenu("Attribute panels")
xbutton("Read file","attrlist(0)")
xbutton("Remove","attrlist(1)")
xbutton("Show","attrlist(2)")
xbutton("Clear list","attrlist(3)")
xbutton("New","attrlist(4)")
xmenu()
}
//* attrlist() set of functions for altering panobjl (list of graph attributes)
proc attrlist() { local ii
if ($1==0) {
fchooser(-1)
} else if ($1==1) { // remove item
panobjl.browser("Double click on item to remove","filename")
panobjl.accept_action("panobjl.remove(hoc_ac_)")
} else if ($1==2) {
panobjl.browser("Double click on item",temp_string_,"numovecs()")
panobjl.accept_action("attrpanl(hoc_ac_)")
} else if ($1==3) { // clear but leave #0
for (ii=panobjl.count-1;ii>0;ii=ii-1) { panobjl.remove(ii) }
} else if ($1==4) { // create a new one without reading a file in
panobj = new panattr()
panobj.filename = "EMPTY"
panobjl.append(panobj)
panobj.remote = panobjl.count()-1
attrpanl(panobjl.count()-1)
} else if ($1==5) { // create one with given num and name
for ii=panobjl.count,$2 { // create more if needed
panobj = new panattr()
panobjl.append(panobj)
panobj.remote = ii
}
panobj = panobjl.object($2)
panobj.filename = $s3
panobj.comment = $s4
panobj.printStep = $5
}
}
// show the number of vectors as well as the name of the file
proc numovecs() { local num
if (hoc_ac_==0) num=printlist.count() else num=panobjl.object(hoc_ac_).llist.count()
sprint(temp_string_,"#%d %s: %d",hoc_ac_,panobjl.object(hoc_ac_).filename,num)
}
//* fchooser(attrnum) finds file and then create panel from it using rpanel
proc fchooser () { local attr0
attr0=$1
if (fchooser_flag == 0) { // create panel first time only
sprint(temp_string_,"v0*")
tmpfile.chooser("","Read from a file",temp_string_)
}
fchooser_flag = 1
if (tmpfile.chooser() == 1) {
// find out whether this is a vector file or not
tmpfile.getname(filename)
sfunc.tail(filename,"/data.*/",grvecstr) // just take the file name without the leading stuff
attrnum = read_vfile(attr0)
if (attrnum == 0) {print "ERROR in fchooser" return }// error
// a new one so should show something
if (attr0==-1) if (show_panel) rpanel(attrnum) else attrpanl(attrnum)
}
}
//* routines for reading in a vector file
//** read_vfile(attrnum) creates a panattr object from information in a file
// (uses grep to avoid loading big file)
// assumes file in tmpfile
func read_vfile () { local flag, ii, sz, loc, mult, sze, cloc, segs
if (numarg()==0) { print "read_vfile(attrnum,filename)" return 0 }
if (numarg()==2) filename = $s2
read_findattr($1) // set panobj and attrnum
// grab hold of the different lines using grep
file_with_dot(filename,temp_string_,temp_string2_) // put .filename into temp_string_
if (!tmpfile.ropen(temp_string_)) {
if (! tmpfile.ropen(filename)) { print "E1: Can't open ",filename
return 0 }
sprint(temp_string2_,"%s '%s' %s > %s",grep,readtag,filename,xtmp)
system(temp_string2_)
tmpfile.close()
if (! tmpfile.ropen(xtmp)) { print "E2: Can't open ",xtmp," (",filename,")"
return 0 }
flag = 0
} else flag = 1 // signifies that .file exists to use as key
while ((numr = tmpfile.scanstr(temp_string_)) != -1) { // throw out the leading '//'
// read the line
cloc = tmpfile.tell - numr // location of the beginning of this line
if (sfunc.head(temp_string_,"//[^b]",temp_string2_)==0) {
read_vinfo() // a line giving info about the file (eg comment)
} else { // NB: code in v60:516 to pickup byte_store value
if (panobj.bytes==0 && \
sfunc.head(temp_string_,"//b[1-9]",temp_string2_)==0) { panobj.bytes = 1 }
if (flag) { // a .file with locs has been written previously
tmpfile.seek(-numr,1) // backup to beginning of line
read_vdotfile()
} else if (panobj.segments > 1) { // mult segs: different times for same var
tmpfile.seek(-numr,1) // backup to beginning of line
panobj.segments = read_vsegs()
} else { // read each line in for itself
tmpfile.scanstr(temp_string_) // name of a var
sze = tmpfile.scanvar() // size of the vector or time it was dumped
loc = tmpfile.scanvar() // location of the vector
if (panobj.bytes) { tmpfile.seek(cloc) // go back and measure the line length
loc = loc + tmpfile.gets(temp_string2_) }
// create the item
if (! strcmp(temp_string_,"tvec")==0) {
tmpobj = new vfile_line(temp_string_,sze,loc,1)
panobjl.object(attrnum).llist.append(tmpobj)
tmpobj = nil
} else {
tvec = panobj.tvec
tvec.resize(0)
panobj.printStep = -loc // where to find tvec later
}
}
}
}
if (panobj.printStep==0) panobj.printStep = printStep
if (panobj.entries==1) panobj.entries = panobj.llist.count
if (! flag && panobj.segments>1) write_vsegs() // create key .file
if (! tmpfile.ropen(panobj.filename)) { print "E3: Can't open ",panobj.filename
return 0 }
return attrnum
}
//** read_findattr()
// see if want to use old attributes or start new ones
proc read_findattr () {
if ($1 > -1 && $1 < panobjl.count()) {
attrnum = $1
panobj = panobjl.object(attrnum)
panobj.clear()
panobj.filename = filename
} else { // create a new panel attribute object to hold color and line type
panobj = new panattr(filename)
panobjl.append(panobj)
panobj.remote = panobjl.index(panobj)
attrnum = panobjl.index(panobj)
}
}
//** read_vinfo()
// fill in panobj entries based on an information line in a vector file
proc read_vinfo () {
if (strcmp(temp_string_,"//printStep")==0) {
panobj.printStep = tmpfile.scanvar() // printstep==-1 means cvode
} else if (strcmp(temp_string_,"//:")==0) { // a comment
tmpfile.gets(temp_string_)
sfunc.head(temp_string_,"\n",panobj.comment) // chop final newline
} else if (strcmp(temp_string_,"//CPU")==0) { // the machine type for byte storage
tmpfile.scanstr(temp_string_)
if (strcmp(temp_string_,uname)!=0) {
printf("%s written from %s\n",filename,temp_string_)
}
} else if (strcmp(temp_string_,"//MULTI")==0) { // multiple lines for each entry
panobj.entries = tmpfile.scanvar()
if (multi_files) { panobj.segments = tmpfile.scanvar() }
} else {
printf("Line:\t%s\n\tnot recognized in %s\n",temp_string_,panobj.filename)
tmpfile.seek(-1,1)
tmpfile.gets(temp_string_) // clear this line out
}
}
//** read_vdotfile() read .file in abbreviated format (see write_vsegs)
proc read_vdotfile() { local loc,entries,segments
entries=panobj.entries segments=panobj.segments
panobj.bytes = 1
for i=1,entries { // read this abbreviated file version (much faster)
tmpfile.scanstr(temp_string_)
loc = tmpfile.scanvar()
tmpobj = new vfile_line(temp_string_,-1,loc,segments) // don't set size
panobj.llist.append(tmpobj)
for ii=1,segments-1 { tmpobj.loc[ii] = tmpfile.scanvar() }
}
}
//** read_vsegs() read a file that is segmented with diff vectors at diff times
// (see outvecs)
func read_vsegs () { local segments,entries,i,ii,jj,sze,loc,ret,cloc,clocend,llen
entries=panobj.entries segments=panobj.segments ret=1
for i=1,entries { // usually will be the number of cells recorded
cloc = tmpfile.tell() // starting location in the file
tmpfile.scanstr(temp_string_)
tmpfile.scanstr(temp_string_) // name of a var
sze = tmpfile.scanvar() // size of the vector or time it was dumped
loc = tmpfile.scanvar() + (tmpfile.tell() - cloc) // add line length
cloc = tmpfile.tell() // a location where a vec begins
tmpobj = new vfile_line(temp_string_,sze,loc,segments)
panobj.llist.append(tmpobj)
for ii=1,segments-1 { // go through all the different time segs
for jj=1,entries-1 { // go through all the cells
if ((ret = tmpfile.gets(temp_string_))==-1) { break } // EOF error
}
clocend = tmpfile.tell() // loc of end of this seg
tmpfile.scanstr(temp_string_) tmpfile.scanstr(temp_string_) // name of a var
if (strcmp(temp_string_,tmpobj.name)!=0) { // name should match
printf("ERROR: %d not %d segs found (%s)\n",ii,segments,tmpobj.name)
segments = ii
break
}
tmpfile.scanvar() // a time
tmpobj.loc[ii] = tmpfile.scanvar()+(tmpfile.tell()-clocend) // where the vector starts
clocend = tmpfile.tell()
}
tmpfile.seek(cloc) // go back for next entry
}
tmpfile.seek(clocend) // go to end of all this stuff
return segments
}
//** write_vsegs()
// write out names of all entries along with locations where the vecs start
proc write_vsegs () { local ii
file_with_dot(filename,temp_string_,temp_string2_) // put .filename into temp_string_
sprint(temp_string2_,"grep '^//[^bM]' %s > %s",xtmp,temp_string_)
system(temp_string2_) // copy the non-location lines into the new file
tmpfile.aopen(temp_string_)
tmpfile.printf("//MULTI %d %d\n",panobj.entries,panobj.segments) // redo in case differs
for ltr(XO,panobj.llist) {
tmpfile.printf("%s ",XO.name)
for ii=0,panobj.segments-1 { tmpfile.printf("%d ",XO.loc[ii]) }
tmpfile.printf("\n")
}
tmpfile.close()
}
//** make_vdot_files() go through a list of filenames to convert into .file format
proc make_vdot_files () { local ii,sav,cnt
cnt = panobjl.count()
for ltr(XO,$o1) {
filename = XO.s
print "Processing ",filename
read_vfile(cnt) // don't overwrite one that's being used
}
}
//* print out the CPU name
proc vfcpu () {
sprint(temp_string_,"%s '^//CPU' %s",grep,$s1)
system(temp_string_)
}
//* rpanel() creates a panel from information in llist
proc rpanel () { local ii
print $1
attrnum = $1
panobj = panobjl.object(attrnum)
if (panobj.llist.count > 8) { rlist($1) return }
sprint(temp_string_,"%s (#%d)",simname,attrnum)
xpanel(temp_string_)
xlabel(panobj.filename)
for ii=0,panobj.llist.count-1 {
sprint(temp_string2_,"rv(%d,%d)",attrnum,ii)
xbutton(panobj.llist.object(ii).name,temp_string2_)
}
sprint(temp_string_,"attrpanl(%d)",attrnum)
xbutton("Attributes",temp_string_)
sprint(temp_string_,"lpvec(filename,vrtmp,%g)",panobj.printStep)
xbutton("Print last vec",temp_string_)
xbutton("Erase","ge()")
xpanel()
}
//* rlist(): like rpanel() but puts up a browser list instead of a panel
proc rlist () {
panobjl.object($1).llist.browser(panobjl.object($1).filename,"name")
sprint(temp_string_,"rv(%d,hoc_ac_)",$1)
panobjl.object($1).llist.accept_action(temp_string_)
}
//* rvlist(): like rpanel() but puts up a browser list instead of a panel
proc rvlist () { local flag,attrnum,rdstr
rdstr = 1
flag = $1 attrnum = $2
if (numarg()==3) { recstr=$s3 rdstr=0 }
if (flag==0) {
panobjl.object(attrnum).llist.browser(panobjl.object(attrnum).filename,"name")
sprint(temp_string_,"rvec(%d,hoc_ac_)",attrnum)
panobjl.object(attrnum).llist.accept_action(temp_string_)
} else if (flag==1) { // proc(vec)
if (rdstr) string_dialog("Procedure name: proc, called as proc(vec)",recstr)
panobjl.object(attrnum).llist.browser(recstr,"name")
sprint(temp_string_,"{rvec(%d,hoc_ac_) %s(%s)}",attrnum,recstr,rvvec_name)
panobjl.object(attrnum).llist.accept_action(temp_string_)
print attrnum,":",recstr,":",temp_string_,":",rvvec_name
} else if (flag==2) { // vec.command
if (rdstr) string_dialog("comm: print vec.comm",recstr)
panobjl.object(attrnum).llist.browser(recstr,"name")
sprint(temp_string_,"{rvec(%d,hoc_ac_) print %s.%s}",attrnum,rvvec_name,recstr)
panobjl.object(attrnum).llist.accept_action(temp_string_)
}
}
proc disptray() { print "Must load boxes.hoc to get trays" }
//* attrpanl() gives attributes for a set of graphs
proc attrpanl () { local ii,jj
attrnum = $1 // use global for xbuttn
sfunc.tail(panobjl.object(attrnum).filename,"/data.*/",grvecstr)
sprint(temp_string_,"%s:%s (#%d)",simname,grvecstr,attrnum)
xpanel(temp_string_)
xvarlabel(panobjl.object(attrnum).filename)
xvarlabel(panobjl.object(attrnum).comment)
sprint(temp_string_,"panobjl.object(%d).color",attrnum)
xvalue("Color(-1=multi)",temp_string_,1)
sprint(temp_string_,"panobjl.object(%d).line",attrnum)
xvalue("Line",temp_string_,1)
xstatebutton("Superimpose",&panobjl.object(attrnum).super)
xbuttn("Graph limits","wvpanl(")
xmenu("Manipulate graphs")
xbuttn("Label graphs","lblall(")
xbuttn("Erase graphs","geall(")
xbuttn("Remove graphs","remgrs(")
sprint(temp_string2_,"disptray(%d)",attrnum)
xbutton("Make tray",temp_string2_)
sprint(temp_string2_,"setrange(%d,3)",attrnum)
xbutton("Erase axes",temp_string2_)
sprint(temp_string2_,"for ltr(XO,panobjl.object(%d).glist) XO.exec_menu(\"View = plot\")",attrnum)
xbutton("View = plot",temp_string2_)
sprint(temp_string2_,"for ltr(XO,panobjl.object(%d).glist) XO.exec_menu(\"Crosshair\")",attrnum)
xbutton("Crosshair",temp_string2_)
sprint(temp_string2_,"for ltr(XO,panobjl.object(%d).glist) XO.exec_menu(\"NewView\")",attrnum)
xbutton("New view",temp_string2_)
sprint(temp_string2_,"for ltr(XO,panobjl.object(%d).glist) XO.exec_menu(\"Delete\")",attrnum)
xbutton("Delete Text",temp_string2_)
sprint(temp_string2_,"for ltr(XO,panobjl.object(%d).glist) XO.exec_menu(\"Move Text\")",attrnum)
xbutton("Move Text",temp_string2_)
sprint(temp_string2_,"for ltr(XO,panobjl.object(%d).glist) XO.exec_menu(\"Change Text\")",attrnum)
xbutton("Change Text",temp_string2_)
xmenu()
sprint(temp_string_,"panobjl.object(%d).remote",attrnum)
sprint(temp_string2_,"grall(%d)",attrnum)
xvalue("Graph all",temp_string_,0,temp_string2_)
if (attrnum != 0) {
xmenu("Manipulate vectors")
xbutton("Vector name","string_dialog(\"Change Vector name\",rvvec_name)")
xbuttn("Write to vector","rvlist(0,")
xbuttn("Proc(vector)","rvlist(1,")
xbuttn("vector.command","rvlist(2,")
xmenu()
xbuttn("Show full panel","rpanel(")
xbuttn("Change file","fchooser(")
} else {
xbutton("Show full panel","pbrgr(\"Graph\",\"gv\")")
}
xpanel()
}
// allows inclusion of attrnum for each item
proc xbuttn () { sprint(temp_string2_,"%s%d)",$s2,attrnum) xbutton($s1,temp_string2_) }
//* set something for attrpanl to value
func attrset () { local attrnum, ii
if (numarg()==0) { printf("attrset(attrnum,\"thing\",val)\n")
} else if (numarg()==2) {
sprint(temp_string_,"tempvar = panobjl.object(%d).%s",$1,$s2)
execute(temp_string_)
return tempvar
} else {
sprint(temp_string_,"panobjl.object(%d).%s=%g",$1,$s2,$3)
execute(temp_string_)
return $3
}
}
proc wvpanl () { local attrnum, ii
attrnum = $1
sfunc.tail(panobjl.object(attrnum).filename,"/data.*/",grvecstr)
sprint(temp_string_,"%s:%s (#%d)",simname,grvecstr,attrnum)
xpanel(temp_string_)
sprint(temp_string_,"%d Vectors",panobjl.object(attrnum).llist.count)
xlabel(temp_string_)
for ii=0,3 {
sprint(temp_string_,"panobjl.object(%d).size[%d]",attrnum,ii)
sprint(temp_string2_,"chrange(%d,%d)",attrnum,ii)
xvalue(szstr[ii].s,temp_string_,0,temp_string2_)
}
sprint(temp_string_,"panobjl.object(%d).shift",attrnum)
sprint(temp_string2_,"chrange(%d,-2)",attrnum)
xvalue("Shift L/R",temp_string_,0,temp_string2_)
sprint(temp_string2_,"chrange(%d,%d)",attrnum,-1)
xbutton("Clear/Set to G0",temp_string2_)
xbutton("Clean graph list","collapsegrs()")
sprint(temp_string2_,"viewplot(%d)",attrnum)
xbutton("View=plot",temp_string2_)
xpanel()
}
//* remgrs() gets rid of all of the graphs (called from attrpanl)
proc remgrs () { local ii,cnt
if (isobj(graphItem,"Graph")) { graphItem.unmap graphItem = nil }
panobj = panobjl.object($1)
for ltr (XO,panobj.glist) XO.unmap()
panobj.glist.remove_all
}
//* collapsegrs () take off of glist graphs that have been closed on screen
proc collapsegrs () { local ii
if (numarg()==0) { panobj = panobjl.object(0)
} else { panobj = panobjl.object($1) }
for (ii=panobj.glist.count-1;ii>=0;ii-=1) {
if (panobj.glist.object(ii).view_count() == 0) {
panobj.glist.remove(ii)
}
}
}
//* viewplot() set the world for each graph correctly
proc viewplot () { local cnt,ii,flag,sz1,sz2,sz3,sz4
if (numarg()==2)flag=1 else flag=0
if (flag) { sz1=sz3=1e10 sz2=sz4=-1e10 }
panobj = panobjl.object($1)
for ltr(XO,panobj.glist) {
XO.size(&x[0])
if (flag) {
if (x[0]<sz1) sz1=x[0]
if (x[1]>sz2) sz2=x[1]
if (x[2]<sz3) sz3=x[2]
if (x[3]>sz4) sz4=x[3]
} else { XO.size(x[0],x[1],x[2],x[3]) }
}
if (flag) for ltr(XO,panobj.glist) XO.size(sz1,sz2,sz3,sz4)
}
//* nvwall() changes the size of the graphs
proc nvwall () { local cnt,ii,sz1,sz2,sz3,sz4,wd,ht
panobj = panobjl.object($1)
if (numarg()==3) { wd=$2 ht=$3 } else { wd=panobj.vsz[0] ht=panobj.vsz[1] }
cnt = panobj.glist.count()
for (ii=cnt-1;ii>=0;ii=ii-1) {
if (panobj.glist.object(ii).view_count()==0) {panobj.glist.remove(ii)
} else {
sz1 = panobj.glist.object(ii).size(1)
sz2 = panobj.glist.object(ii).size(2)
sz3 = panobj.glist.object(ii).size(3)
sz4 = panobj.glist.object(ii).size(4)
panobj.glist.object(ii).unmap()
panobj.vloc = panobj.vloc+panobj.vjmp
if (panobj.vloc > 700) { panobj.vloc = 0 }
panobj.glist.object(ii).view(sz1,sz3,sz2-sz1,sz4-sz3,0,panobj.vloc,wd,ht)
}
}
}
//* geall() erases all of the graphs
proc geall () { local cnt,ii
panobj = panobjl.object($1)
cnt = panobj.glist.count()
for ii=0,cnt-1 {
panobj.glist.object(ii).erase_all()
}
}
//* lblall(attrnum,label,#,xloc,yloc) put label on all of the graphs
// arg3 tells which single graph to put it on
proc lblall () { local cnt,ii,min,max,attrnum,lx,ly
if (numarg()==0) { printf("lblall(attrnum[,loc])\n") return }
attrnum = $1 panobj = panobjl.object(attrnum)
cnt = panobj.glist.count()
if (numarg()>2) { min=max=$3 } else { min=0 max=cnt-1 }
if (numarg()==5) { lx=$4 ly=$5 } else { lx=0.1 ly=0.8 }
if (numarg()>1) if (sfunc.len($s2)>0) { temp_string_ = $s2
} else if (attrnum==0) { temp_string_ = comment
} else sprint(temp_string_,"%s",panobjl.object(0).comment)
for ii=min,max {
panobj.glist.object(ii).color(panobj.color)
panobj.glist.object(ii).label(lx,ly,temp_string_)
// if (attrnum!=0&&ii<panobj.llist.count()) panobj.glist.object(ii).label(panobj.llist.object(ii).name)
}
}
//* relbl() put appropriate label on all of the graphs
proc relbl () { local cnt,ii,min,max,attrnum,lx,ly
if (numarg()==0) { printf("relbl(attrnum[,str])\n") return }
attrnum = $1 panobj = panobjl.object(attrnum)
cnt = panobj.glist.count()
if (numarg()==4) { lx=$3 ly=$4 } else { lx=0.1 ly=0.8 }
if (numarg()>1) panobj.glist.object(0).label($s2)
for ltr2(XO,YO,panobj.glist,panobj.llist) {
XO.color(0)
if (attrnum==0) XO.label(0.,.9,YO.var) else XO.label(0.,.9,YO.name)
XO.color(panobj.color)
XO.label(lx,ly,YO.vec.label)
}
}
//* grall() graphs all of the lines from the file
// use vector $o2 as indices for vectors (see tposvec)
proc grall () { local attrnum,cnt,ii,min,max,gr,skip,iskp,vind
if (numarg()==0) {printf("grall(attrnum[,min,max,remote,gr_offset,skipgr,iskp]): graph vectors.\n")
return }
attrnum=$1
panobj = panobjl.object(attrnum)
if (attrnum == 0) cnt = printlist.count() else cnt = panobj.llist.count()
// will reset max if is vector with numarg()==2
if (numarg()>2) { min=$2 max=$3 } else { min=0 max=cnt-1 }
// with 2 args, vector $o2 gives indices for vectors (see tposvec)
if (numarg()==2) { vind=1 min=0 max=$o2.size-1 } else vind=0
if (numarg()>3) { panobj.super=1 panobj.remote=$4 }
if (numarg()>4) gr=$5 else gr=0
if (numarg()>5) skip=$6 else skip=1
if (numarg()>6) iskp=$7 else iskp=1
if (iskp==0) iskp=1 if (skip==0) skip=1
if (panobj.super==1 && panobj.remote==attrnum && panobj.glist.count==0) {
remgrs(attrnum)
print "Creating plot"
skip=0
newPlot(0,tstop,-100,100) panobj.glist.append(graphItem)}
if (panobj.super==0 && panobj.glist.count==0) panobj.size[1]=0
for (ii=min;ii<=max;ii+=iskp) {
if (panobj.super == 1) {
if (gr >= panobjl.object(panobj.remote).glist.count()) break
graphItem = panobjl.object(panobj.remote).glist.object(gr)
gr=gr+skip
}
if (vind) rv($1,$o2.x[ii]) else rv($1,ii)
}
}
// tposvec(rows,cols): generate the indices for a transposed matrix of rows x cols
proc tposvec () { local rows,cols,i,j
rows=$2 cols=$3
$o1.resize($2*$3)
for (i=0;i<rows;i+=1) for (j=0;j<cols;j+=1) $o1.x[j*rows+i]=i*cols+j
}
// fliptb(rows,cols): generate the indices for a transposed matrix of rows x cols
proc fliptb () { local rows,cols,i,j,p
rows=$2 cols=$3
if ($o1.size != $2*$3) {print "Wrong size vector in fliptb()" return}
p = allocvecs(1) mso[p].resize(rows)
for (j=0;j<cols;j+=1) {
mso[p].copy($o1,j*rows,(j+1)*rows-1)
mso[p].reverse
$o1.copy(mso[p],j*rows)
}
}
//* setrange() sets the range
// setrange(attrnum,x0,x1,y0,y1)
proc setrange () {
if (numarg()==0) { print "setrange(attrnum,x0,x1,y0,y1)\n setrange(attrnum,3) erases axes"
return}
panobj = panobjl.object($1)
if (numarg()==1) { for ltr(XO,panobj.glist) { XO.size(0,tstop,-100,50) }
} else if (numarg()==2) { for ltr(XO,panobj.glist) XO.xaxis(3)
} else {
panobj.size[0]=$2
for ltr(XO,panobj.glist) XO.size($2,$3,$4,$5)
}
}
//* chrange() changes range for a set of graphs (called from attrpanl)
proc chrange () { local cnt, flag, ii, sz1, sz2, sz3, sz4
if (numarg()==2) { flag = $2 } else { flag = -1 }
panobj = panobjl.object($1)
cnt = panobj.glist.count()
for (ii=cnt-1;ii>=0;ii=ii-1) if (panobj.glist.object(ii).view_count() == 0) panobj.glist.remove(ii)
cnt = panobj.glist.count() // check again after removing any with no views
if (cnt==0) { for ii=0,3 panobj.size[ii]=0 return }
// flag -1 means set everything from the first graph
if (flag==-1) for ii=0,3 panobj.size[ii] = panobj.glist.object(0).size(ii+1)
if (flag==-2) for ii=0,1 panobj.size[ii] += panobj.shift // shift right or left
// for each of the graphs
for ltr(XO,panobj.glist) {
sz1=XO.size(1) sz2=XO.size(2) sz3=XO.size(3) sz4=XO.size(4)
if (flag==0) XO.size(panobj.size[0],sz2,sz3,sz4)
if (flag==1) XO.size(sz1,panobj.size[1],sz3,sz4)
if (flag==2) XO.size(sz1,sz2,panobj.size[2],sz4)
if (flag==3) XO.size(sz1,sz2,sz3,panobj.size[3])
if (flag==-1) XO.size(panobj.size[0],panobj.size[1],panobj.size[2],panobj.size[3])
if (flag==-2) XO.size(panobj.size[0],panobj.size[1],sz3,sz4)
}
for ii=0,3 if (panobj.size[ii]==0) panobj.size[ii]=panobj.glist.object(0).size(ii+1)
}
//* rtvec() reads tvec if it exists, returns -1 if it doesn't
// rtvec(attrnum)
func rtvec () { local attrnum,inx,inx2
attrnum = $1
panobj = panobjl.object(attrnum)
if (panobj.printStep < 0) {
tmpfile.seek(-panobj.printStep)
panobj.tvec.vread(tmpfile)
tvec = panobj.tvec
return 1
} else {
return 0
}
}
//* rv() reads line of vector file into IV graph via vector
// rv(attrnum,llist_ind1[,llist_ind2])
proc rv () { local attrnum,inx,inx2
// open the file and go to correct position
if (numarg() == 0) { print "rv(attrnum,ind1,ind2) reads into vrtmp bzw vec" return }
attrnum = $1
inx = $2
if (numarg() > 2) { inx2 = $3 } else { inx2 = -1 }
if (attrnum==0) { gv(inx) return }
rv_readvec(attrnum,inx,vrtmp) // will set panobj
// create a new plot if necessary and set color
nvplt(vrtmp)
if (vrtmp.size==0) { // assume this is a spike train in tvec
ind.resize(panobj.tvec.size) ind.fill(0)
ind.mark(graphItem,panobj.tvec,"O",panobj.line+4,panobj.curcol)
grrtsize()
} else if (inx2>-1) {
rv_readvec(attrnum,inx2,vec)
graphItem.size(0,vrtmp.max,0,vec.max)
if (numarg() > 3) {
vec.mark(graphItem,vrtmp,$s4,6,panobj.curcol)
} else {
vec.mark(graphItem,vrtmp,"O",6,panobj.curcol)
}
} else if (panobj.printStep<0) {
vrtmp.line(graphItem,panobj.tvec,panobj.curcol,panobj.line)
} else {
vrtmp.line(graphItem,panobj.printStep,panobj.curcol,panobj.line) }
// graph it and label the graph
if (sfunc.substr(panobj.filename,"batch")!=-1 || \
sfunc.substr(panobj.filename,"/data")==-1) {
grvecstr = panobj.filename
} else { sfunc.tail(panobj.filename,"/data",grvecstr) }
sprint(grvecstr,"%s:%s",grvecstr,panobj.llist.object(inx).name)
if (panobj.super == 0 && labelm) { graphItem.label(0,0.9,grvecstr)
} else if (labelm) graphItem.label(0.5,0.9,grvecstr)
}
// rv_readvec(attrnum,index,vec)
// read vector #index from file associated with attrnum into vector vec
proc rv_readvec () { local size,attrnum,inx,ii
attrnum = $1