-
Notifications
You must be signed in to change notification settings - Fork 2
/
grvec.hoc
2405 lines (2271 loc) · 82.2 KB
/
grvec.hoc
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.672 2011/10/25 16:16:14 billl Exp $
//* Objects argtype: 0:double; 1:obj; 2:str; 3:double pointer
objref g[100],printlist,grv_,panobj,panobjl
strdef symb
symb = "O"
load_file("nqs.hoc") // declare vectors
gnum=-1
declare("show_panel",1)
obfunc file_with_dot(){} // stubs to declare later, otherwise external barfs
obfunc filname(){}
obfunc dirname(){}
func file_len(){}
proc tog (){if (numarg()==1) print $&1=1-$&1 else print gvmarkflag=1-gvmarkflag}
proc pvout2 () { } // stub for manipulating printlist
proc rv2 () { } // stub for manipulating the vectors before graphing
proc rv3 () { } // stub for manipulating the label
func setfilt2 () { return 0 } // stub for setting filter
func dir2mf2() {return 1} // stub for checking whether to include a trace
//* template 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, segs, num, ix, f, ty
strdef name,f
double loc[1]
proc init () {
segs=1 ty=4
if (argtype(5)==0) segs=$5 else if (argtype(5)==2) f=$s5
name=$s1 size=$2 num=$4
double loc[segs]
loc[0] = $3
ix=-1 // can be used as index if needed
}
endtemplate vfile_line
//* template vitem (vector item) is an internal vector used to store output from
// new vitem(var_name,vec_size,friendly_name)
// new vitem(var_name,vec_size,1) -- force tvec creation even if not cvode_local
// a simulation holds the name and the vector itself
tvflag_on=1
begintemplate vitem
external cvode,tvflag_on,isassigned
public tvec,vec,name,tvflag,pstep,o,code,resize
objref tvec,vec,o,this // o not set here but used for Acells
strdef tstr,name // variable name
proc init () {
name=$s1 tvflag=0 pstep=0 code=0
if (cvode.active()) { if (cvode.use_local_dt()) tvflag=1 else tvflag=-1 }
if (tvflag_on) tvflag=1
if (argtype(2)==0) vec=new Vector($2) else if (argtype(2)==1) vec=$o2
if (argtype(3)==0) { // very sloppy -- what if pstep=1??
if ($3==1) tvflag=1 else {tvflag=0 pstep=$3}
} else if (argtype(3)==1) {
tvec=$o3
tvflag=1 // don't create another one
}
if (argtype(4)==0) if ($4==1) tvflag=1 else {tvflag=0 pstep=$4}
if (tvflag==1 && !isassigned(tvec)) tvec=new Vector($2)
if (tvflag==-1) {
sprint(tstr,"if (!isassigned(tvec)) tvec=new Vector(%d)",$2) execute(tstr)
sprint(tstr,"%s.tvec=tvec",this) execute(tstr)
}
}
proc resize () {
vec.resize($1)
if (isassigned(tvec)) tvec.resize($1)
if (numarg()==2) { vec.resize($2) // typically sizeup and then resize to 0
if (isassigned(tvec)) tvec.resize($2) }
}
endtemplate vitem
//* main template: GRV
// the attributes of a particular set of graphs including line colors,
// world coordinates, etc
// glist is a list of all graphs created from this panel
// llist is a list of available names and associated vectors or locations
begintemplate GRV
public color,line,super,curcol,comment,vecpanel,mesg,tmplist,gxpan
public glist,oglist,llist,tvec,size,shift,vsz,vjmp,tloc,vloc,remote
public entries,segments,clear,keepgr
public read_vfile,rvaltdisp,read_file,grvec,remgrs,clear,record,read_pclamp
public cpplitem,chgplname,npl,new_pri,prlexp,numovecs,fchooser
public read_vdotfile,rpanel,panobjl,ddir,filter
public rlist,rvlist,attrpanl,wvpanl,remgrs,collapsegrs,viewplot,nvwall
public geall,lblall,relbl,grall,grsel,tposvec,fliptb,setrange,setgrransel,grransel
public chrange,rv,rv_readvec,rvec,rvl,read_rfile,gv
public grrtsize,ge,pvall,pvother,pvplist,pvclose,vf2fwf
public pvnext,pvout,prvec,pv,lpvec,nvplt,apbrowse,apkill
public newpl,find_secname,mkmenu,dir2pr,dir2mf,read_mf
public mkpanel,pbrgr,remprl,filename,onum,po,stub,go
public rvtr,vrdr,prdr,tmpobj,printlist,output_file,attr0,attrnum,s,vite
public glist,llist,tvec,ind,vec,vrtmp,tmpvec,tf1,tmpobj,apvb,printStep
public gvmarkflag,gveraseflag,fchooser_flag,byte_store,bst,szstr,regexp,tmpfile
public magga,mvga,ll,labelm,tstr
double size[4],vsz[2],wvloc[4],x[4]
objref glist, oglist, llist, tvec, ind, vec, vrtmp, tmpvec, tf1, tmpobj, apvb, ovb, printlist
objref vite,scob,printlist,szstr[4],g,this,tmplist,panobj,panobjl,Xo,Yo,tmpfile, gcomms
strdef comment,recstr,grvecstr,readtag,rvvec_name,grep,tstr,tstr2,ddir,filter
strdef temp_string_,temp_string2_,output_file,s,filename,mesg,regexp
external sfunc,osname,vfile_line,vitem,uname,nil,simname,gnum,XO,YO,graphList,isassigned
external isobj,isit,mso,msoptr,allocvecs,dealloc,tstop,method,cvode,show_panel,rv2,rv3,setfilt2
external cvode_active,cvode_local,datestr,runnum,i1,graphItem,GRV,strm,objnum,DBL,dir2mf2
external file_with_dot,count_substr,file_len,filname,dirname,dir,grv_,repl_mstr,pvout2,symb
// list iterator ltr
// usage 'for ltr(YO, tmplist) { print YO }'
iterator ltr () { local i
ii1=0
for i = 0,$o2.count-1 {
$o1 = $o2.object(i)
iterator_statement
ii1+=1
}
$o1=nil
}
proc init () { local flag,nopan
flag=1e9
if (numarg()==1) if (argtype(1)==0) flag=$1
if (numarg()==2) if (argtype(2)==0) flag=$2 else printf("2nd arg for GRV should be flag\n")
nopan=0 color=1 line=1 curcol=1 keepgr=tloc=-1 nvec=bvec=super=0 vjmp=50 entries=1 segments=1
fchooser_flag=0
vsz[0] = 300 vsz[1] = 200
glist = new List()
tmpfile = new File()
oglist = glist // save old glist for after superimpose
llist=new List() gcomms=new List() printlist=llist
tvec=new Vector(0) ind=tvec.c vec=tvec.c vrtmp=tvec.c tmpvec=tvec.c
rvvec_name = "vec"
ddir = "data/"
printStep=gvmarkflag=gveraseflag=mff=0
remote=0
entries=segments=shift=0
tloc=vloc=vjmp=x=y=luprd=0
wvloc[0]=50 wvloc[1]=50 wvloc[2]=800 wvloc[3]=150
onum=objnum(this)
for ii=0,3 { szstr[ii] = new String() }
if (sfunc.substr(osname,"inux")==1) grep="grep -a" else grep="grep"
readtag = "^//[:pbCM ]" // regexp used to identify header in mixed binary files
{ 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 = 0 // 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
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
attr0=0 // default is a panel for reading files
if (flag==0) { // make a sim-recording panel
if (numarg()>1) printf("GRV WARNING: creating simpan, ignoring filename\n")
attr0=1 attrnum=0
if (! isobj(panobjl,"List")) panobjl = new List()
attrnum=panobjl.append(this)-1
if (attrnum!=0) printf("GRV WARNING: attr0 with attrnum=%d!\n",attrnum)
if (show_panel) vecpanel()
sprint(tstr,"printlist=%s.printlist",this)
execute(tstr)
sprint(s,"GRV[%d]:%s (sim vecs)",objnum(this),simname)
return
}
panobjl=grv_.panobjl
attrnum=panobjl.append(this)-1
if (flag==-2) nopan=1
if (flag==-1) { fchooser() // ask user for filename
} else if (numarg()>=1) {
if (argtype(1)==2) read_vfile($s1)
}
if (!nopan) attrpanl()
}
//** newfile() calls fchooser
proc newfile () { localobj o
o = apvb
fchooser()
attrpanl()
}
//** bst() selects byte_store
func bst () {
if (numarg()>=1) byte_store=$1
if (numarg()>=2) tvec_bytesize=$2
return byte_store
}
//* attrpanl() gives attributes for a set of graphs
proc attrpanl () { local ii,jj
sfunc.tail(filename,"data.*/",grvecstr)
apvb=new VBox()
apvb.intercept(1)
xpanel(temp_string_)
xvarlabel(filename)
if (sfunc.len(mesg)>40) sfunc.left(mesg,40)
xvarlabel(mesg)
xvalue("Color(-1=multi)","color",1,"if (color==0) curcol=0",0,1)
xvalue("Line","line",1,"",0,1)
xpanel()
xpanel("",1)
xbutton("Superimpose: ","tog(&super) if (super==0) gnum=-1 sprint(mesg,\"super=%d\",super)")
xbutton("Where?","sprimp()")
xbutton("Restore","glist=oglist sprint(mesg,\"Restore graph list\")")
xpanel()
xpanel("",1)
xbutton("Limits","wvpanl()")
xbutton("Erase","geall()")
xbutton("Mark","togmark()")
if (attr0) xbutton("Panel","pbrgr(\"Graph\",\"gv\")") else {
xbutton("New file","newfile()") }
xpanel()
xpanel("",1)
xmenu("Graphs")
xbutton("Erase/redraw","gveraseflag=-(gveraseflag-1) if (gveraseflag==1) super=1 else super=0 sprint(mesg,\"Erase=%d\",gveraseflag)")
xbutton("Erase graphs","geall()")
xbutton("Remove graphs","remgrs()")
xbutton("Clean graph list","collapsegrs()")
xbutton("Erase axes","setrange(3)")
xbutton("Draw axes","setrange(0)")
xbutton("Label graphs","lblall()")
sprint(tstr,"execute(\"disptray(%d)\")",onum)
xbutton("Make tray",tstr)
xbutton("View = plot","for ltr(Xo,glist) Xo.exec_menu(\"View = plot\")")
xbutton("Crosshair","for ltr(Xo,glist) Xo.exec_menu(\"Crosshair\")")
xbutton("New view","for ltr(Xo,glist) Xo.exec_menu(\"NewView\")")
xbutton("Zoom","for ltr(Xo,glist) Xo.exec_menu(\"Zoom in/out\")")
xbutton("Delete Text","for ltr(Xo,glist) Xo.exec_menu(\"Delete\")")
xbutton("Move Text","for ltr(Xo,glist) Xo.exec_menu(\"Move Text\")")
xbutton("Change Text","for ltr(Xo,glist) Xo.exec_menu(\"Change Text\")")
xmenu()
// sprint(temp_string_,"remote",attrnum)
// sprint(temp_string2_,"grall(%d)",attrnum)
// xvalue("Graph all",temp_string_,0,temp_string2_)
if (attr0) redo_printlist() else xbutton("Show full panel","rpanel()")
xpanel()
apvb.intercept(0)
if (attr0) { sprint(s,"GRV[%d] %s SIM CONTROL",objnum(this),simname)
} else {
if (sfunc.len(filename)>0) filname(filename,grvecstr)
sprint(s,"GRV[%d] %s:%s",objnum(this),simname,grvecstr)
}
apvb.map(s)
}
//** sprimp() superimpose on another sim
proc sprimp () {
super=1
sprint(tstr,"SUPERIMPOSE %s ON?",s)
ovb=new VBox()
ovb.intercept(1)
xpanel(tstr)
xvalue("Superimpose on Graph[#]","gnum",1)
for ltr(Xo,panobjl) {
sprint(temp_string2_,"glist=%s.glist sprint(mesg,\"Using graph list from %s\") ovb.unmap() ovb=nil",Xo,Xo)
xbutton(Xo.s,temp_string2_)
}
xpanel()
ovb.intercept(0)
ovb.map(tstr)
ovb.dismiss_action("ovb.unmap ovb=nil")
}
//** fchooser() finds file and then create panel from it using rpanel
proc fchooser () {
if (fchooser_flag == 0) { // create panel first time only
if (setfilt2(filter)) { // do nothing
} else if (strm(filter,"\\*")) { // do nothing
} else sprint(filter,"*%s*",datestr)
tmpfile.chooser("","Read from a file",filter,"Open","Cancel",ddir)
}
fchooser_flag = 1
if (tmpfile.chooser()) {
// find out whether this is a vector file or not
tmpfile.getname(filename)
if (strm(filename,"\.mf")) read_mf() else read_vfile()
}
}
//** newpan() create a new panel and call fchooser from there
proc newpan () { tmpobj=new GRV(-1) }
//** read_vfile() 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()>=2) if (strcmp(filename,$s1)==0) return 2 // check if file is already active
if (attr0) {
if (!boolean_dialog("Look at file data instead of sim?","YES","NO")) {
printf("Read file cancelled\n")
return 0
}
} else { attr0=0 }
if (numarg()>=1) filename=$s1 else tmpfile.getname(filename)
if (strm(filename,"\.mf$")) return read_mf(filename)
sprint(s,"GRV[%d] %s: %s",objnum(this),simname,filename)
clear()
// grab hold of the different lines using grep
file_with_dot(filename,temp_string_) // put .filename into temp_string_
if (!tmpfile.ropen(temp_string_)) {
print "E1: Can't open ",temp_string_ // avoid grep error
return 0
} else flag = 1 // signifies that .file exists to use as key
while ((numr = tmpfile.gets(tstr)) != -1) { // throw out the leading '//'
// read the line
if (sfunc.head(tstr,"//[^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 (flag && entries > 1) { // a .file with MULTI segs
tmpfile.seek(-numr,1) // backup to beginning of line
read_vdotfile()
} else if (segments > 1) { // mult segs: different times for same var
tmpfile.seek(-numr,1) // backup to beginning of line
segments = read_vsegs() //**** NEEDS to be recovered from grvec.hoc442
} else { // read each line in for itself
if ( sscanf(tstr,"//b%1ld %g %s %ld %ld",&bvec,&nvec,tstr2,&sze,&loc)!=5) {
if (sscanf(tstr,"//b%1ld %s %ld %ld",&bvec,tstr2,&sze,&loc)!=4) {
printf("**** GRV read_vfile() parse ERR on %s in %s",tstr,filename)
} else if (printStep==-2) nvec=-2 else nvec=-1 // guess
}
if (nvec==2) {
printf("read_vfile forward compat. **** WARNING ****\n\t****consider edit of %s dot file to change 2 to -2\n",filename)
nvec=-2
}
if (strcmp(tstr2,"CVODE1.0 tvec")==0) {
tvec.resize(0)
printStep=-1
tloc = loc // where to find tvec later
} else {
tmpobj = new vfile_line(tstr2,sze,loc,nvec) // name size loc num
tmpobj.ty=bvec
llist.append(tmpobj)
tmpobj = nil
}
}
}
}
if (llist.count==0) {
printf("grvec.hoc::read_vfile ERR no vecs read from %s\n",filename)}
if (entries==1) entries = llist.count
if (! flag && segments>1) write_vsegs() // create key .file
if (! tmpfile.ropen(filename)) { print "E3: Can't open ",filename
return 0
}
if (printStep==-1) rtvec() // code for cvode_active()
mff=0
return 1
}
//** rtvec() reads tvec if it exists, returns -1 if it doesn't
func rtvec () {
if (tloc > -1) {
tmpfile.seek(tloc)
tvec.vread(tmpfile)
return 1
} else {
return 0
}
}
proc write_vsegs () { print "NEEDS to be ported from grvec.hoc442" }
//** read_vinfo()
proc read_vinfo () {
if (strm(tstr,"//printStep")) {
sfunc.tail(tstr," ",tstr) // just take end of string following space
sscanf(tstr,"%g",&printStep) // printstep==-1 means cvode
} else if (strm(tstr,"^//:")) { // a comment
sfunc.tail(tstr,"//: *",tstr)
sfunc.head(tstr,"\n",comment) // chop final newline
mesg=comment
} else if (strm(tstr,"^//CPU")) { // the machine type for byte storage
sfunc.tail(tstr," ",tstr)
if (! strm(tstr,uname)) {
printf("%s written from %s\n",filename,tstr)
}
} else if (strm(tstr,"^//MULTI")) { // multiple lines for each entry
sfunc.tail(tstr," ",tstr)
if (sscanf(tstr,"%d %d",&entries,&segments)==2) {
if (! multi_files) printf("**************** GRV read_vinfo ERRa\n")
} else segments=1
} else {
printf("Line:\t%s\n\tnot recognized in %s\n",tstr,filename)
}
}
//** read_vdotfile() read .file in abbreviated format (see write_vsegs)
proc read_vdotfile() { local loc,entries,segments,ii
entries=entries segments=segments
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
llist.append(tmpobj)
for ii=1,segments-1 { tmpobj.loc[ii] = tmpfile.scanvar() }
}
}
//** rpanel() creates a panel from information in llist
proc rpanel () { local ii
if (llist.count > 8) { rlist() return }
sprint(temp_string_,"%s ",simname)
xpanel(temp_string_)
xlabel(filename)
for ii=0,llist.count-1 {
sprint(temp_string2_,"rv(%d)",ii)
xbutton(llist.object(ii).name,temp_string2_)
}
xbutton("Attributes","attrpanl()")
sprint(temp_string_,"lpvec(filename,vrtmp,%g)",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 () {
sprint(tstr,"%d items on list: Enter regexp for subset or \"All\"",llist.count)
if (llist.count>50 || numarg()>=1) {
if (numarg()>=1) regexp=$s1 else if (!string_dialog(tstr,regexp)) return
if (! strm(regexp,"[Aa][Ll][Ll]")) {
if (! isobj(tmplist,"List")) tmplist = new List()
tmplist.remove_all
for ltr(Xo,llist) {
Xo.ix=ii1
if (strm(Xo.name,regexp)) tmplist.append(Xo)
}
tmplist.browser(filename,"name")
tmplist.accept_action("rv(tmplist.object(hoc_ac_).ix)")
printf("%d selected\n",tmplist.count)
return
}
}
llist.browser(filename,"name")
llist.accept_action("rv(hoc_ac_)")
}
//** rvlist(): like rpanel() but puts up a browser list instead of a panel
proc rvlist () { local flag,rdstr
rdstr = 1
flag = $1
if (numarg()==2) { recstr=$s2 rdstr=0 }
if (flag==0) {
llist.browser(filename,"name")
llist.accept_action("rvec(hoc_ac_)")
} else if (flag==1) { // proc(vec)
if (rdstr) string_dialog("Procedure name: proc, called as proc(vec)",recstr)
llist.browser(recstr,"name")
sprint(temp_string_,"rv_readvec(hoc_ac_,%s) execute1(\"%s(%s)\")",rvvec_name,recstr,rvvec_name)
llist.accept_action(temp_string_)
print ":",recstr,":",temp_string_,":",rvvec_name
} else if (flag==2) { // vec.command
if (rdstr) string_dialog("comm: print vec.comm",recstr)
llist.browser(recstr,"name")
sprint(temp_string_,"{rvec(hoc_ac_) print %s.%s}",rvvec_name,recstr)
llist.accept_action(temp_string_)
}
}
//* rv() reads line of vector file into IV graph via vector
// rv(llist_ind1[,llist_ind2])
// rvaltdisp(tvec,vec,name)
func rvaltdisp () { return 0 } // if returns 1 means there is an alternate display for rv
obfunc rv () { local inx,inx2 localobj o
// open the file and go to correct position
if (numarg() == 0) { print "rv(ind1,ind2) reads into vrtmp bzw vec" return this}
inx = $1
if (attr0) {return gv(inx)}
o=llist.object(inx)
if (numarg()>1) inx2 = $2 else inx2 = -1 // to graph one vec against another
rv_readvec(inx,vrtmp)
rv2(vrtmp,tvec)
// create a new plot if necessary and set color
if (vrtmp.size==0) { // assume this is a spike train in tvec
nvplt(ind,vrtmp)
ind.resize(tvec.size) ind.fill(0)
ind.mark(graphItem,tvec,symb,line,curcol)
} else if (inx2>-1) { // only make sense if they share the same tvec
rv_readvec(inx2,vec)
nvplt(vec,vrtmp)
if (numarg() >= 3) {
vec.mark(graphItem,vrtmp,$s3,line,curcol)
} else {
vec.mark(graphItem,vrtmp,symb,line,curcol)
}
} else if (o.num==-2) {
nvplt(vrtmp,tvec)
if (gvmarkflag) {
if (! rvaltdisp(tvec,vrtmp,llist.object(inx).name)) {
vrtmp.mark(graphItem,tvec,symb,line,curcol,4) }
} else vrtmp.line(graphItem,tvec,curcol,line)
} else if (o.num==-1) {
printf("rv() PROBLEM: CVODE global read not implemented\n")
} else {
if (o.num==0) {
printf("rv WARNING: taking printstep %g for %s\n",printStep,o.name)
o.num=printStep
}
nvplt(vrtmp,o.num)
if (gvmarkflag) {
vrtmp.mark(graphItem,o.num,symb,line,curcol,4)
} else vrtmp.line(graphItem,o.num,curcol,line)
}
// too much fussing with labels
if (sfunc.substr(filename,"batch")!=-1 || \
sfunc.substr(filename,"data")==-1) {
grvecstr = filename
} else sfunc.tail(filename,"data",grvecstr)
if (sfunc.len(llist.object(inx).name)>40) {
grvecstr=llist.object(inx).name } else {
sprint(grvecstr,"%s:%s",grvecstr,llist.object(inx).name) }
rv3(grvecstr)
if (super == 0 && labelm) { graphItem.label(0,0.9,grvecstr)
} else if (labelm) graphItem.label(0.0,0.95,grvecstr)
return graphItem
}
//* gv(vnum) graphs vector
obfunc gv () { local a,inx,lin localobj o,v1,vtmp
inx=-1
lin=line
a=allocvecs(vtmp)
if (numarg()==0) { inx = hoc_ac_ } else {
if (argtype(1)==0) inx = $1
if (argtype(1)==2) {
for ltr(Xo,printlist) if (strm(Xo.name,$s1)) inx=ii1
if (inx==-1) {print $s1," not found" return this}}
}
if (numarg()>=2) { color=curcol=$2 }
if (numarg()>=3) { lin=$3 }
o = printlist.object(inx)
vtmp.copy(o.vec)
rv2(o.vec) // alters vtmp
if (o.vec.size==0) { // assume that this is spk trace
if (o.tvec.size==0) { printf("\tNO SPIKES IN %s\n",printlist.object(inx).name)
} else {
nvplt(o.tvec)
ind.resize(o.tvec.size) ind.fill(1)
ind.mark(graphItem,o.tvec,symb,lin,curcol)
}
} else {
if (o.tvflag!=0) { // o.tvec should point to tvec if tvflag==-1
nvplt(o.vec,o.tvec)
if (gvmarkflag) { o.vec.mark(graphItem,o.tvec,symb,lin,curcol)
} else { o.vec.line(graphItem,o.tvec,curcol,lin) }
} else {
if (o.pstep==0) {
printf("gv WARNING: vitem.pstep not set with tvflag==0 (%s)\n",o)
o.pstep=printStep
}
nvplt(o.vec,o.pstep)
if (gvmarkflag) { o.vec.mark(graphItem,o.pstep,symb,lin,curcol)
} else { o.vec.line(graphItem,o.pstep,curcol,lin) }
}
if (labelm) {
grvecstr=printlist.object(inx).name
rv3(grvecstr) graphItem.label(0.,0.9,grvecstr)
}
}
o.vec.copy(vtmp) // in case has been changed by rv2()
dealloc(a)
return graphItem
}
// go(n) will goto location in the data file
obfunc go () { localobj o
if (argtype(1)==0) { inx=$1 o=llist.object(inx) } else o=$o1
tmpfile.seek(o.loc)
return o
}
// rv_readvec(index,vec)
// read vector #index from file into vector vec
func rv_readvec () { local inx,ii,n,bvec localobj o
if (argtype(1)==0) { inx=$1 o=llist.object(inx) } else o=$o1
n=o.num
if (mff) {tstr=filename filename=o.f}
tmpfile.getname(temp_string_) // may not be necessary?
if (strcmp(temp_string_,filename)!=0 || tmpfile.isopen()==0) { // don't reopen file if there
if (! tmpfile.ropen(filename)) {
print "ERROR rv() can't read ",filename
return 0
}
}
tmpfile.seek(o.loc)
bvec=o.ty
if (numarg()>=3) {
if (n!=-2) {
printf("ERROR rv() called with 2 vecs but only find 1 in %s %s %d\n",filename,o.name,inx)
return 0
}
if (bvec>5) {
$o2.fread(tmpfile,o.size,bvec-5) $o3.fread(tmpfile,o.size,bvec-5)
} else {
$o2.vread(tmpfile) $o3.vread(tmpfile)
}
} else if (n==-2) {
if (n==-2) {
if (bvec>5) {
tvec.fread(tmpfile,o.size,bvec-5) // no error check
} else if (!tvec.vread(tmpfile)) {
printf("rv_readvec tvec READ failure in %s %s %d\n",filename,o.name,inx) return 0 }
if (bvec>5) {
$o2.fread(tmpfile,o.size,bvec-5) // no error check
} else if (! $o2.vread(tmpfile)) {
printf("rv_readvec vec READ failure in %s %s %d\n",filename,o.name,inx) return 0 }
}
if (n==-2 && (tvec.size != $o2.size)) {
printf("rv_readvec size mismatch in %s %s %d\n",filename,o.name,inx)
return 0
}
} else $o2.vread(tmpfile) // fixed dt
if (segments>1) { // needs rewrite
tmpvec = new Vector($o2.size)
for ii=1,segments-1 {
tmpfile.seek(llist.object(inx).loc[ii])
tmpvec.vread(tmpfile)
$o2.copy(tmpvec,$o2.size)
}
tmpvec = nil
}
if (mff) filename=tstr // restore
return n
}
//** vf2fwf() take a file in vformat and prints out as multiple fwrites
proc vf2fwf () { local ii localobj f
f=new File()
f.wopen($s1)
for ii=0,entries-1 {
rv_readvec(ii,vrtmp)
vrtmp.fwrite(f)
printf("%d ",vrtmp.size)
}
f.close
printf("\n dt=%g\n",printStep)
}
//** rvec(num[,vec]) writes to vec, or contents of rvvec_name or
// to vector of same name if rvvec_name is empty
proc rvec () { local flag,on
flag=0
if (sfunc.len(rvvec_name)==0) flag=1
if (numarg()<1) on=hoc_ac_ else on=$1
if (numarg()>1) sprint(rvvec_name,"%s",$o2)
if (sfunc.len(rvvec_name)==0) rvvec_name=llist.object(on).name
printf("Copying %s to %s\n",llist.object(on).name,rvvec_name)
sprint(temp_string_,"%s.rv_readvec(%d,%s)",this,on,rvvec_name)
if (flag) rvvec_name="" // clear it again
if (! execute1(temp_string_)) print "ERROR: Declare target as a vector"
if (numarg()==4) $o4.copy(tvec)
}
//** rvl() reads line of vector file into IV graph via vector
// rvl(name,pos[,pos2,pos3,etc])
proc rvl () { local i
// open the file and go to correct position
tmpfile.getname(temp_string_)
if (strcmp(temp_string_,filename)!=0 || tmpfile.isopen()==0) {
tmpfile.ropen(filename) } // only open if necessary
if (tmpfile.isopen==0) { printf("ERROR: %s not found.\n",filename)
return }
if (numarg() == 3) {
tmpfile.seek($3)
tmpfile.gets(temp_string_) // throw away line
vrtmp.vread(tmpfile)
} else {
tmpvec = new Vector()
for i=3,numarg() {
tmpfile.seek($i)
tmpvec.vread(tmpfile)
vrtmp.copy(tmpvec,vrtmp.size)
}
}
tmpvec = nil
nvplt(vrtmp)
vrtmp.line(graphItem,printStep,curcol,line)
// graph it and label the graph
if (sfunc.substr(filename,"batch")!=-1) { grvecstr = filename
} else { sfunc.tail(filename,"data",grvecstr) }
sprint(grvecstr,"%s:%s",grvecstr,$s2)
if (super==0 && labelm) { graphItem.label(0,0.9,grvecstr)
} else if (labelm) graphItem.label(grvecstr)
}
//* utility programs (not all used or even all usable)
//** nvplt() put up new voltage plot
obfunc nvplt () { local xs,ys,flag,prstep
prstep=10
if (super == 0) flag=1 else {
if (gnum>-1) {
sprint(tstr,"{Graph[%d]}",gnum)
if (execute1(tstr,0)) { // Graph[gnum] exists
if (Graph[gnum].view_count>0) {
graphItem=Graph[gnum] flag=0
}
}
} else if (isobj(graphItem,"Graph")) if (graphItem.view_count() > 0) {
flag=0
} else { flag=1 } // else need new graph
}
if (flag) {
if (numarg()==2) if (argtype(2)==0) prstep=$2 else prstep=-1
if (size[1] != 0) { // xmax is set
newpl(size[0],size[1],size[2],size[3])
} else if (prstep<0) {
newpl(0,$o2.max,$o1.min,$o1.max)
} else {
newpl(0,$o1.size()*prstep,$o1.min,$o1.max)
}
} else if (gveraseflag) graphItem.erase_all
if (color == -1) {
curcol += 1
if (curcol == 0 || curcol>7) curcol = 1
} else curcol = color
graphItem.color(curcol)
g=graphItem
return g
}
//** grrtsize() use view=plot and then pad a little
proc grrtsize () { local h,w,frac
if (numarg()>=1) tmpobj=$o1 else tmpobj=graphItem
if (numarg()>=2) frac = $2 else frac=.05
tmpobj.exec_menu("View = plot")
tmpobj.size(&x)
w=frac*(x[1]-x[0]) h=frac*(x[3]-x[2])
x[0]-=2*w x[1]+=w x[2]-=4*h x[3]+=h // need extra padding on bottom
tmpobj.size(x[0],x[1],x[2],x[3])
}
//** newpl()
proc newpl () { local w,h
if (numarg()==5) newPlot($1,$2,$3,$4) // 5th arg is flag
if (numarg()==8) {wvloc[0]=$5 wvloc[1]=$6 wvloc[2]=$7 wvloc[3]=$8}
graphItem = new Graph(0)
g=graphItem
graphItem.xaxis() // view axis for x and y
graphItem.view($1,$3,$2-$1,$4-$3,wvloc[0],wvloc[1],wvloc[2],wvloc[3])
glist.append(graphItem)
}
//** find_secname(variable,result): put secname into result
proc find_secname () { localobj o
if ((sfunc.head($s1,"\.[_A-Za-z0-9]+$",$s2))==0) { // strip off stuff after terminal .
printf("grvec.hoc:find_secname ERR: no section found: %s\n",$s1) err() }
if ( strm($s1,"\.[_A-Za-z0-9]+[(][0-9.]+[)]$")) { // form eg v(0.5)
sfunc.head($s1,"\.[_A-Za-z0-9]+[(][0-9.]+[)]$",$s2)
} else {
o=isit($s2)
if (o.x) { // the stem is an obj
o.o.get_loc()
sectionname($s2)
pop_section()
} else {
printf("grvec.hoc:f_s ERR0: Can't find sec: %s\n",$s1) err()
}
}
}
//** vecpanel() main panel
proc vecpanel () {
if (! attr0) {printf("vecpanel (main panel) can only be run from attr0\n") return }
fchooser_flag = 0 // used to initialize the file chooser
sprint(temp_string_,"%s Vectors",simname)
xpanel(temp_string_)
xbutton("Graph from file","newpan()")
xbutton("Sim vectors","pbrgr(\"Graph\",\"gv\")")
xbutton("Sim attributes","attrpanl(0)")
xbutton("Save Sim","pvall()")
xbutton("Panels","apbrowse()")
redo_printlist()
xpanel()
}
//** lpvec(title,vector,printstep) dumps a single vector onto the printer using jgraph
proc lpvec () { local inx,ii
tmpfile.wopen("lptmp")
tmpfile.printf("newgraph\nnewcurve pts\n")
for ii = 0,$o2.size-1 {
tmpfile.printf("%g ",ii*$3)
$o2.printf(tmpfile,"%g",ii,ii)
}
tmpfile.printf("marktype none\nlinetype solid\ntitle : %s\n",$s1)
tmpfile.close()
system("jgraph -P lptmp > lptmp2")
system("lpt lptmp2")
}
//** remgrs() -- clears glist
proc remgrs () { local ii
for ltr(Xo,glist) Xo.unmap
if (keepgr!=-1) {
for (ii=glist.count-1;ii>0;ii-=1) glist.remove(ii) // leave #1
} else glist.remove_all
}
//** clear() -- clears llist
proc clear () {
entries=1 segments=1
comment = ""
llist.remove_all()
}
//** ll() same as external llist
proc ll () {
if (numarg()==1) {
if (attr0==1) { for ltr(XO,printlist) if (strm(XO.name,$s1)) print ii1,XO.name,XO.vec.size
} else for ltr(XO,llist) if (strm(XO.name,$s1)) print ii1,XO.name,XO.size
} else {
if (attr0==1) { for ltr(XO,printlist) print ii1,XO.name,XO.vec.size
} else for ltr(XO,llist) print ii1,XO.name,XO.size
}
}
//* read_pclamp(file,vscale,tscale): read physiol data file, similar to read_file()
proc read_pclamp () { local ii,cols,pt,length,pstep,tscale,vscale
if (! tmpfile.ropen($s1)) { printf("\tERROR: can't open file \"%s\"\n",$s1) }
if (numarg()>=2) vscale=$2 else vscale=1
if (numarg()>=3) tscale=$3 else tscale=1e3
printlist.remove_all()
method("implicit") printStep=0.1
tmpfile.gets(temp_string_)
length=1
while (! strm(temp_string_,"^\"Time")) {
length += 1
tmpfile.gets(temp_string_) // first word in line was not a number so next line
}
temp_string2_ = temp_string_ // column def line
cols = count_substr(temp_string_,"[(]") // destructive function
pt = tmpfile.tell()
length = file_len($s1) - length
vrtmp.scanf(tmpfile,length,1,cols) // tvec
pstep=vrtmp.x[1]-vrtmp.x[0]
pstep*=tscale // typically gives it in s statt ms
print "Reading ", cols, " columns; ", length, " lines; tstep=",pstep
for ii=2,cols { // pick up all of the columns
tmpfile.seek(pt)
vrtmp.scanf(tmpfile,length,ii,cols)
vrtmp.mul(vscale) // correct for a common scaling
npl("col",ii,vrtmp,pstep)
}
if (1) {
sprint(temp_string2_,"%s:%s",$s1,temp_string2_)
file_with_dot($s1,filename,"v") // put vfilename into name
print "Saving to ",filename
pvplist(filename,temp_string2_)
}
}
//* read_file(file,cols[,length]): read multicolumn file
// see also read_pclamp() above
func read_file () { local ii,cols,pt,length
if (numarg()==0) { print "\tread_file(\"file\",cols)"
print "\t(must set tstop and printStep.)"
return 0
}
printStep=10
if (cvode_status()!=0) print "WARNING: Turn off cvode."
if (numarg()==3) { length = $3 } else { length=tstop/printStep }
cols = $2
if (! tmpfile.ropen($s1)) { printf("\tERROR: can't open file \"%s\"\n",$s1) return 0}
// printlist.remove_all()
tmpfile.scanstr(temp_string_) pt = 0
// skip over a comment line; note that this will skip extra line if comment line is
// just one word long
while (sfunc.head(temp_string_,"[^-+0-9.e]",temp_string2_) != -1) {
tmpfile.gets(temp_string_) // first word in line was not a number so next line
pt = tmpfile.tell() // location at next line
tmpfile.scanstr(temp_string_) // get first word here
print temp_string2_
}
for ii=1,cols { // pick up all of the columns
tmpfile.seek(pt)
vrtmp.scanf(tmpfile,length,ii,cols)
npl("col",ii,vrtmp)
}
return 1
}
//* read_rfile(file): read multirow file
// use col2row to transpose columnar file first
proc read_rfile() { local num
if (numarg()==0) { print "\tread_rfile(\"file\")" return }
if (! tmpfile.ropen($s1)) { printf("\tERROR: can't open file \"%s\"\n",$s1) return}
printlist.remove_all()
while (tmpfile.scanstr(temp_string_) != -1) { // read lines
num = tmpfile.scanvar() // pick up number of items in col
vrtmp.scanf(tmpfile,num)
npl(temp_string_,vrtmp)
}
}
//* redo_printlist() menu allows removal or addition of inidividual items
proc redo_printlist () {
xmenu("Printlist")
xbutton("Save Sim","pvall()")
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("Archive to file:","pbrgr(\"Archive\",\"pv\")")
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
if (! isobj(printlist,"List")) printlist = new List()
flag = $1 rdstr = 1
if (numarg()==2) { recstr=$s2 rdstr=0 }
if (flag==0) {
if (! isobj(scob,"SymChooser")) scob = new SymChooser()
if (scob.run()) {
scob.text(temp_string_)
npl(temp_string_)
}
} else if (flag==1) { // remove item
printlist.browser("Double click on item to remove","name")
printlist.accept_action("printlist.remove(hoc_ac_)")
} else if (flag==2) { // .op
if (rdstr) string_dialog("Enter operation to be run on vec",recstr)
temp_string_ = "\"%s.%s = %g\\n\""
sprint(temp_string_,"printf(%s,printlist.object(hoc_ac_).name,\"%s\",x=printlist.object(hoc_ac_).vec.%s)",temp_string_,recstr,recstr)
printlist.browser(recstr,"name")
printlist.accept_action(temp_string_)
} else if (flag==3) { // put another set of things on list
if (! isobj(scob,"SymChooser")) scob = new SymChooser()
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(" npl(\"%s\")\n",printlist.object(ii).name)
}
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,"name")
sprint(temp_string_,"%s(printlist.object(hoc_ac_).vec,printlist.object(hoc_ac_).name,hoc_ac_)",recstr)
printlist.accept_action(temp_string_)
} else if (flag==7) { // XO is pointer to vec
printlist.browser("XO","name")
sprint(temp_string_,"{tmpobj=printlist.object(hoc_ac_) print hoc_ac_,tmpobj.name XO=tmpobj.vec YO=tmpobj.tvec}")
printlist.accept_action(temp_string_)
}
}
//** mkmenu(title,action,proc) makes a menu from printlist
proc mkmenu () { local ii
xmenu($s1)
for ii=0,printlist.count-1 {
sprint(temp_string_,"%s %s",$s2,printlist.object(ii).name)
sprint(temp_string2_,"%s(%d)",$s3,ii)
xbutton(temp_string_,temp_string2_)
}
sprint(temp_string_,"mkpanel(\"%s\",\"%s\",\"%s\")",$s1,$s2,$s3)
xbutton("Leave up",temp_string_)
xmenu()
}
//** 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_,"name")
sprint(temp_string2_,"%s()",$s2)
printlist.accept_action(temp_string2_)
}
}
//** mkpanel(title,action,proc) makes a panel from printlist
proc mkpanel () { local ii
sprint(temp_string_,"%s:%s",simname,$s1)
xpanel(temp_string_)
for ii=0,printlist.count-1 {
sprint(temp_string_,"%s %s",$s2,printlist.object(ii).name)
sprint(temp_string2_,"%s(%d)",$s3,ii)
xbutton(temp_string_,temp_string2_)
}