-
Notifications
You must be signed in to change notification settings - Fork 4
/
bstick_net.hoc
10092 lines (9432 loc) · 355 KB
/
bstick_net.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
// Created 12/27/07 22:00:26 by /usr/site/scripts/loadfiles
//================================================================
// INSERTED bsticknet.hoc
//* =Id= bsticknet.hoc,v 1.36 2007/12/28 02:47:43 billl Exp
// COMMENT
// simulation to accompany "Just in time connectivity for large spiking networks"
// This is meant primarily as an illustration of both the coding framework and the general ideas
// in the paper; it would need some additional work to be a practical simulation:
// eg, this simulation will not currently run with variable time step (don't know why)
// This network was built out of the basic framework of net2spec.ho: a basic exercise result
// from the NEURON summer course.
// Although the cells are basically the same: templates B_BallStick and SE_NetStim, the overall
// structure of the network has been augmented (it was only 3 cells originally)
// There is now one NetStim and 124 BallSticks -- 100 excitatory called SU (for superficial cell)
// and 24 inhibitory call IN
// Useful globals include eg numc[SU],ix[SU],ixe[SU] for number,first index,last index of SU cells
// Parallel lists are used to facilitate intercommunication with NMODL and C code in jitcon.mod
// cells is list of cells
// ce is a list of associated JitCon's
// (each cell has its own JitCon to which it is connected via a NetCon)
// aml is list of lists of AMPA synapses
// gal is list of lists of GABAA synapses
// Global arrays are also used in common with jitcon.mod eg
// double pmat[CTYPi][CTYPi],wmat[CTYPi][CTYPi] // give connectivity density (pij) and weights
// // by cell type
// connec() is the main routine which makes the cell-cell connections using both NetCons --
// through calls to nc_append(); and via JitCons -- through calls to setdvi()
// Since presyn for all network NetCon connections are made from the JitCon, these NetCons can be
// effectively disconnected by setting the 'jcn' flag for all the JitCons
// (NB odd 'feature': jit is a single JitCon jit.flag("jcn",1) sets the jcn flag just for 'jit'
// jit.flag("jcn",1,1) sets flag for all JitCons in list ce)
// ENDCOMMENT
//================================================================
// INSERTED /usr/site/nrniv/local/hoc/setup.hoc
// =Id= setup.hoc,v 1.24 2006/11/08 00:51:51 billl Exp
// variables normally controlled by SIMCTRL
// load_file("setup.hoc")
load_file("stdgui.hoc")
show_panel=0
strdef simname, filename, output_file, datestr, uname, comment, section, osname
objref tmpfile,nil,graphItem,sfunc
sfunc = hoc_sf_ // from stdlib.hoc
proc chop () { sfunc.left($s1,sfunc.len($s1)-1) }
tmpfile = new File()
simname = "sim" // helpful if running multiple simulations simultaneously
runnum = 1 // updated at end of run
system("uname -m",uname) // keep track of type of machine for byte compatibility
chop(uname)
system("date +%y%b%d",datestr)
chop(datestr) // may prefer to downcase later
sprint(output_file,"data/%s.%02d",datestr,runnum) // assumes a subdir called data
if (unix_mac_pc()==1) osname = "Linux" else if (unix_mac_pc()==2) {
osname = "Mac" } else if (unix_mac_pc()==3) osname = "PC"
printStep = 0.25 // time interval for saving to vector
graph_flag=0
batch_flag=1
xwindows = 0 // can still save but not look without xwindows
// load_file("nrnoc.hoc")
// END /usr/site/nrniv/local/hoc/setup.hoc
//================================================================
//================================================================
// INSERTED /usr/site/nrniv/simctrl/hoc/nrnoc.hoc
// =Id= nrnoc.hoc,v 1.74 2007/11/20 07:51:52 billl Exp
proc nrnoc () {}
// Users should not edit nrnoc.hoc or default.hoc. Any local
// changes to these files should be made in local.hoc.
// key '*&*' is picked up by to indicate command for emacs
proc elisp () { printf("*&* %s\n",$s1) }
// if (not exists(simname)) { strdef simname, output_file, datestr, comment }
// Simctrl.hoc will automatically load stdgraph.hoc which automatically
// loads stdrun.hoc
strdef temp_string_, user_string_ // needed for simctrl
/* Global variable default values. NOTE that stdrun.hoc, stdgraph.hoc
and simctrl.hoc all contain variable definitions and thus default.hoc
should be loaded after these files */
//================================================================
// INSERTED /usr/site/nrniv/simctrl/hoc/default.hoc
// =Id= default.hoc,v 1.5 2003/07/08 16:16:52 billl Exp
/* This file contains various global defaults for hoc
** Users should not edit nrnoc.hoc or default.hoc. Any local
changes to these files should be made in local.hoc.
----------------------------------------------------------------*/
/*------------------------------------------------------------
Object defaults
------------------------------------------------------------*/
/*** Define a "nil" object ***/
objectvar nil
/*------------------------------------------------------------
String defaults
------------------------------------------------------------*/
/*** "Section" is used if errors are found in the initializiations ***/
strdef section
/*** Misc defines used by graphic routines ***/
temp_string_ = "t"
tempvar = 0
/*------------------------------------------------------------
Simulation defaults
------------------------------------------------------------*/
/* To be consistent w/the nmodl values */
FARADAY = 96520. /* Hoc default = 96484.56 */
PI = 3.14159 /* Hoc default = 3.1415927 */
/* 0=off, 1=on */
print_flag = 0 /* Write to output file */
graph_flag = 1 /* Plot output */
iv_flag = 1 /* Using Interviews plotting */
batch_flag = 0 /* Using batch_run() */
compress_flag = 0 /* Compress output file when saved */
stoprun = 0 /* 0=running, 1=stopped */
iv_loaded = 0 /* Load initial iv stuff on once */
init_seed = 830529
run_seed = 680612
t = 0 /* msec */
dt = .01 /* msec */
tstop = 100 /* msec */
printStep = 0.1 /* msec */
plotStep = 0.1 /* msec */
flushStep = 0.1 /* msec */
eventStep = 50 /* Number of nstep's before a doEvent */
secondorder = 0
celsius = 6.3 /* degC */
v_init = -70 /* (mV) */
global_ra = 200 /* (ohm-cm) specific axial resisitivity */
/*** Ion parameters ***/
ca_init = 50e-6 /* mM */
na_init = 10 /* mM */
k_init = 54.4 /* mM */
// END /usr/site/nrniv/simctrl/hoc/default.hoc
//================================================================
/* Allows arrays of strings */
objref hoc_obj_[2]
//================================================================
// INSERTED /usr/site/nrniv/simctrl/hoc/simctrl.hoc
// =Id= simctrl.hoc,v 1.14 2000/11/27 21:59:33 billl Exp
// Graphic routines for neuremacs simulation control
proc sim_panel () {
xpanel(simname)
xvarlabel(output_file)
xbutton("Init", "stdinit()")
xbutton("Init & Run", "run()")
xbutton("Stop", "stoprun=1")
xbutton("Continue till Tstop", "continueRun(tstop)")
xvalue("Continue till", "runStopAt", 1, "{continueRun(runStopAt) stoprun=1}", 1, 1)
xvalue("Continue for", "runStopIn", 1, "{continueRun(t + runStopIn) stoprun=1}", 1,1)
xbutton("Single Step", "steprun()")
xvalue("Tstop", "tstop", 1, "tstop_changed()", 0, 1)
graphmenu()
sim_menu_bar()
misc_menu_bar()
xpanel()
}
proc misc_menu_bar() {
xmenu("Miscellaneous")
xbutton("Label Graphs", "labelgrs()")
xbutton("Label With String", "labelwith()")
xbutton("Label Panel", "labelpanel()")
xbutton("Parameterized Function", "load_template(\"FunctionFitter\") makefitter()")
xmenu()
}
proc sim_menu_bar() {
xmenu("Simulation Control")
xbutton("File Vers", "elisp(\"sim-current-files\")")
xbutton("File Status...", "elisp(\"sim-rcs-status\")")
xbutton("Sim Status", "elisp(\"sim-portrait\")")
xbutton("Load Current Files", "elisp(\"sim-load-sim\")")
xbutton("Load Templates", "elisp(\"sim-load-templates\")")
xbutton("Load File...", "elisp(\"sim-load-file\")")
xbutton("Save Sim...", "elisp(\"sim-save-sim\")")
xbutton("Set File Vers...", "elisp(\"sim-set-file-ver\")")
xbutton("Read Current Vers From Index", "elisp(\"sim-read-index-file\")")
xbutton("Read Last Saved Vers", "elisp(\"sim-read-recent-versions\")")
xbutton("Output to sim buffer", "elisp(\"sim-direct-output\")")
xmenu()
}
proc labelpanel() {
xpanel(simname,1)
xvarlabel(output_file)
xpanel()
}
proc labels () {
labelwith($s1)
labelgrs()
}
proc labelgrs () { local i, j, cnt
for j=0,n_graph_lists-1 {
cnt = graphList[j].count() - 1
for i=0,cnt labelgr(graphList[j].object(i))
}
}
proc labelwith () { local i, j, cnt
temp_string_ = user_string_ // save the old one
if (numarg() == 1) { /* interactive mode */
user_string_ = $s1
} else {
string_dialog("write what?", user_string_)
}
for j=0,n_graph_lists-1 {
cnt = graphList[j].count() - 1
for i=0,cnt {
graphList[j].object(i).color(0)
graphList[j].object(i).label(0.5,0.9,temp_string_)
graphList[j].object(i).color(1)
graphList[j].object(i).label(0.5,0.9,user_string_)
}
}
}
proc labelgr () { local i
$o1.color(0) // white overwrite
for (i=0;i<10;i=i+1) { // erase every possible runnum for this date
sprint(temp_string_,"%s %d%d",datestr,i,i)
$o1.label(0.1,0.7,temp_string_) }
$o1.color(1) // back to basic black
sprint(temp_string_,"%s %02d",datestr,runnum)
$o1.label(0.1,0.7,temp_string_)
}
// END /usr/site/nrniv/simctrl/hoc/simctrl.hoc
//================================================================
proc run () {
running_ = 1
stdinit()
continueRun(tstop)
finish()
}
proc continueRun () { local rt, rtstart, ts
if (numarg()==1) ts=$1 else ts=t+1e3
realtime = 0 rt = screen_update_invl rtstart = startsw()
eventcount=0
eventslow=1
stoprun = 0
if (using_cvode_) {
if (cvode.use_local_dt || (cvode.current_method()%10) == 0) {
cvode.solve(ts)
flushPlot()
realtime = startsw() - rtstart
return
}
} else {
ts -= dt/2
}
while (t<ts && stoprun==0) {
step()
realtime = startsw() - rtstart
if (realtime >= rt) {
// if (!stdrun_quiet) fastflushPlot()
screen_update()
//really compute for at least screen_update_invl
realtime = startsw() - rtstart
rt = realtime + screen_update_invl
}
}
if (using_cvode_ && stoprun == 0) { // handle the "tstop" event
step() // so all recordings take place at tstop
}
flushPlot()
realtime = startsw() - rtstart
}
proc stdinit() {
cvode_simgraph()
realtime = 0
setdt()
init()
initPlot()
}
proc init () {
cvode_simgraph()
initMech()
initMisc1()
// Initialize state vars then calculate currents
// If user hand-set v in initMisc1() then v_init should be > 1000,
// else all compartments will be set to v_init
if (v_init < 1000) {
finitialize(v_init)
} else {
finitialize()
}
// Set ca pump and leak channel for steady state
setMemb()
initMisc2()
if (cvode_active()) cvode.re_init() else fcurrent()
frecord_init()
}
// Initialization of mechanism variables
// NOTE: if any changes are made to the NEURON block of any local mod
// file, the user must add the necessary inits to initMisc1()
proc initMech () {
forall {
if ((!ismembrane("pas")) && (!ismembrane("Passive"))) {
// Allow for either pas or Passive mod file usage
// errorMsg("passive not inserted")
}
if (ismembrane("na_ion")) {
nai = na_init
nai0_na_ion = na_init
}
if (ismembrane("k_ion")) {
ki = k_init
ki0_k_ion = k_init
}
if (ismembrane("ca_ion")) {
cai = ca_init
cai0_ca_ion = ca_init
}
}
}
//* setMemb complex -- multiple names for passive mech
//** declarations
iterator scase() { local i
for i = 1, numarg() { temp_string_ = $si iterator_statement }}
objref paslist,pasvars[3],XO
double pasvals[2],x[1]
paslist = new List()
for ii=0,2 pasvars[ii]= new String()
for scase("fastpas","pas","Pass","Passive") paslist.append(new String(temp_string_))
//** getval(),setval() -- return/set the hoc value of a string
func retval () { return getval($s1) }
func getval () {
sprint(temp_string2_,"x=%s",$s1)
execute(temp_string2_)
return x
}
proc setval () {
sprint(temp_string2_,"%s=%g",$s1,$2)
execute(temp_string2_)
}
//** findpas()
// assumes that we are starting in a live section since looks for pass mech there
qx_=0
proc findpas () {
for ii=0,paslist.count-1 {
XO=paslist.object(ii)
if (ismembrane(XO.s)) {
// print XO.s,"found"
pasvars[2].s=XO.s
sprint(pasvars[0].s,"g_%s(qx_)",XO.s)
for scase("e","erev","XXXX") { // look for the proper prefix
sprint(temp_string_,"%s_%s",temp_string_,XO.s)
if (name_declared(temp_string_)==1) break
}
if (name_declared(temp_string_)==0) { // not found
printf("SetMemb() in nrnoc.hoc: Can't find proper 'erev' prefix for %s\n",XO.s)
} else {
sprint(pasvars[1].s,"%s(qx_)",temp_string_)
}
}
}
}
proc setMemb () {
if (!secp()) return
findpas() // assume that passive name is the same in all sections
forall for (qx_,0) { // will eventually want 'for (x)' to handle all the segments
if (ismembrane(pasvars[2].s)) {
for ii=0,1 pasvals[ii]=getval(pasvars[ii].s)
setmemb2()
for ii=0,1 setval(pasvars[ii].s,pasvals[ii])
}
}
}
// secp() determine whether any sections exist
func secp () { local n
n=0
forall n+=1
if (n>0) return 1 else return 0
}
func setother () {return 0} // callback stub
proc setmemb2 () { local iSum, ii, epas, gpas
if (!secp()) return
gpas=pasvals[0] epas=pasvals[1]
// Setup steady state voltage using leak channel
iSum = 0.0
if (ismembrane("na_ion")) { iSum += ina(qx_) }
if (ismembrane("k_ion")) { iSum += ik(qx_) }
if (ismembrane("ca_ion")) { iSum += ica(qx_) }
iSum += setother()
if (iSum == 0) { // Passive cmp so set e_pas = v
epas = v
} else {
if (gpas > 0) { // Assume g set by user, calc e
epas = v + iSum/gpas
} else { // Assume e set by user, calc g
if (epas != v) {
gpas = iSum/(epas - v)
} else { gpas=0 }
}
if (gpas < 0) errorMsg("bad g", gpas)
if (epas < -100 || epas > 0) {
printf(".")
// printf("%s erev: %g %g %g\n",secname(),e_pas,ina,ik)
}
}
pasvals[0]=gpas pasvals[1]=epas
}
proc finish () {
/* Called following completion of continueRun() */
finishMisc()
if (graph_flag == 1) {
if (iv_flag == 1) {
flushPlot()
doEvents()
} else {
graphmode(-1)
plt(-1)
}
}
if (print_flag == 1) {
wopen("")
}
}
/*------------------------------------------------------------
User definable GRAPHICS and PRINTING routines
------------------------------------------------------------*/
proc outputData() {
// Default procedure - if outputData() doesn't exist in the run file
if (graph_flag == 1) {
if (iv_flag == 1) {
Plot()
rt = stopsw()
if (rt > realtime) {
realtime = rt
fastflushPlot()
doNotify()
if (realtime == 2 && eventcount > 50) {
eventslow = int(eventcount/50) + 1
}
eventcount = 0
}else{
eventcount = eventcount + 1
if ((eventcount%eventslow) == 0) {
doEvents()
}
}
} else {
graph(t)
}
}
if (print_flag == 1) {
if (t%printStep <= printStep) { printOut() }
}
}
proc printOut() {
/* Default procedure - if printOut() doesn't exist in the run file */
}
proc initGraph() {
/* Default procedure - if initGraph() doesn't exist in the run file */
graph()
}
proc initPrint() {
/* Default procedure - if initPrint() doesn't exist in the run file */
wopen(output_file)
}
/*------------------------------------------------------------
User definable BATCH RUN routines
------------------------------------------------------------*/
proc nextrun() {
// Called from finishmisc() following completion of batch in an autorun
wopen("")
runnum = runnum + 1
sprint(output_file,"data/b%s.%02d", datestr, runnum)
}
// commands for emacs
proc update_runnum() {
runnum = $1
sprint(output_file,"data/%s.%02d", datestr, runnum)
print "^&^ (progn (sim-index-revert)(setq sim-runnum ",runnum,"))" }
proc nrn_write_index() { printf("&INDEX& %s\n",$s1) }
proc nrn_update () { elisp("nrn-update") }
proc nrn_message () { printf("!&! %s\n",$s1) }
/*------------------------------------------------------------
User definable INITIALIZATION and FINISH routines
------------------------------------------------------------*/
// Default procedure - if initMisc1() doesn't exist in the run file
// Initializations performed prior to finitialize()
// This should contain point process inits and inits for any changes
// made to the NEURON block of any local mod file
proc initMisc1() { }
// Default procedure - if initMisc2() doesn't exist in the run file
// Initializations performed after finitialize()
proc initMisc2() { }
// Default procedure - if finishMisc() doesn't exist in the run file
proc finishMisc() { }
/*------------------------------------------------------------
Miscellaneous routines
------------------------------------------------------------*/
proc errorMsg() {
/* Print warning, assumes arg1 is string and arg2 if present is a
variable value */
sectionname(section)
if (numarg() == 0) {
printf("ERROR in errorMsg(): Needs at least 1 argument.\n")
} else if (numarg() == 1) {
printf("ERROR: %s in section %s.\n", $s1, section)
} else {
printf("ERROR: %s in section %s (var=%g).\n", $s1, section, $2)
}
}
proc clear() {
/* Clear non-interviews plot window */
plt(-3)
}
func mod() { local x, y
/* Mod function for non-integers */
x=$1
y=$2
return (x/y - int(x/y))
}
proc whatSection() { print secname() }
proc print_pp_location() { local x //arg1 must be a point process
x = $o1.get_loc()
sectionname(temp_string_)
printf("%s located at %s(%g)\n", $o1, temp_string_, x)
pop_section()
}
//* set method with method()
proc method () { local prc
if (numarg()==0) {
if (cvode_active() && cvode_local()) { printf("\tlocal atol=%g\n",cvode.atol)
} else if (cvode_active()) { printf("\tglobal atol=%g\n",cvode.atol)
} else if (secondorder==2) { printf("\tCrank-Nicholson dt=%g\n",dt)
} else if (secondorder==0) { printf("\timplicit dt=%g\n",dt)
} else { printf("\tMethod unrecognized\n") }
return
}
if (numarg()==2) prc = $2 else prc=0
finitialize()
if (strcmp($s1,"global")==0) {
cvode_active(1)
cvode.condition_order(2)
if (prc) cvode.atol(prc)
} else if (strcmp($s1,"local")==0) {
cvode_local(1)
cvode.condition_order(2)
if (prc) cvode.atol(prc)
} else if (strcmp($s1,"implicit")==0) {
secondorder=0
cvode_active(1)
cvode_active(0)
if (prc) dt=prc
} else if (strcmp($s1,"CN")==0) {
secondorder=2
cvode_active(1) // this turns off local
cvode_active(0)
if (prc) dt=prc
} else {
printf("Integration method %s not recognized\n",$s1)
}
}
//* Load local modifications to nrnoc.hoc and default.hoc
//================================================================
// INSERTED /usr/site/nrniv/simctrl/hoc/local.hoc
// $Header: /usr/site/nrniv/simctrl/hoc/RCS/local.hoc,v 1.15 2003/02/13 15:32:06 billl Exp $
//
// This file contains local modifications to nrnoc.hoc and default.hoc
//
// Users should not edit nrnoc.hoc or default.hoc. Any local
// changes to these files should be made in this file.
// ------------------------------------------------------------
//* MODIFICATIONS TO NRNOC.HOC
// The procedures declared here will overwrite any duplicate
// procedures in nrnoc.hoc.
// ------------------------------------------------------------
//*MODIFICATIONS TO DEFAULT.HOC
//
// Vars added here may not be handled properly within nrnoc.hoc
//------------------------------------------------------------
//** String defaults
//** Simulation defaults
long_dt = .001 // msec
objref sfunc,tmpfile
sfunc = hoc_sf_ // needed to use is_name()
tmpfile = new File() // check for existence before opening a user's local.hoc file
proc write_comment () {
tmpfile.aopen("index")
tmpfile.printf("%s\n",$s1)
tmpfile.close()
}
func asin () { return atan($1/sqrt(1-$1*$1)) }
func acos () { return atan(sqrt(1-$1*$1)/$1) }
objref mt[2]
mt = new MechanismType(0)
proc uninsert_all () { local ii
forall for ii=0,mt.count()-1 {
mt.select(ii)
mt.selected(temp_string_)
if (strcmp(temp_string_,"morphology")==0) continue
if (strcmp(temp_string_,"capacitance")==0) continue
if (strcmp(temp_string_,"extracellular")==0) continue
if (sfunc.substr(temp_string_,"_ion")!=-1) continue
mt.remove()
// print ii,temp_string_
}
}
condor_run = 0 // define for compatability
// END /usr/site/nrniv/simctrl/hoc/local.hoc
//================================================================
if (xwindows && graph_flag) { nrnmainmenu() } // pwman_place(50,50)
print "Init complete.\n"
// END /usr/site/nrniv/simctrl/hoc/nrnoc.hoc
//================================================================
//================================================================
// INSERTED init.hoc
// =Id= init.hoc,v 1.14 2007/12/27 14:47:29 billl Exp
install_vecst()
install_stats()
show_panel=0
//================================================================
// INSERTED /usr/site/nrniv/local/hoc/nqs.hoc
// =Id= nqs.hoc,v 1.584 2007/12/07 22:07:55 billl Exp
// primarily edited in nrniv/place
if (!name_declared("VECST_INSTALLED")) {
printf("NQS ERROR: Need vecst.mod nmodl package compiled in special.\n")
quit()
}
if (!VECST_INSTALLED) install_vecst()
if (! name_declared("datestr")) load_file("setup.hoc")
//================================================================
// INSERTED /usr/site/nrniv/local/hoc/decvec.hoc
// =Id= decvec.hoc,v 1.370 2007/12/26 19:00:41 billl Exp
proc decvec() {}
//* Declarations
objref ind, tvec, vec, vec0, vec1, tmpvec, vrtmp, veclist, veccollect, pwm
objref tmpobj, XO, YO, rdm, dir
strdef filename,dblform,tabform
dblform="%3.4g"
dir = new List()
tmpfile = new File()
if (! name_declared("datestr")) load_file("setup.hoc")
//================================================================
// INSERTED /usr/site/nrniv/local/hoc/declist.hoc
// =Id= declist.hoc,v 1.130 2007/12/19 16:26:15 billl Exp
//* Declarations
strdef mchnms
objref tmplist,tmplist2,tmpobj,aa,XO,YO
if (! name_declared("datestr")) load_file("setup.hoc")
tmplist = new List()
proc declist() {}
//* Templates
//** template String2
begintemplate String2
public s,t,x,append,prepend,exec,tinit
strdef s,t
proc init() {
if (numarg() == 1) { s=$s1 }
if (numarg() == 2) { s=$s1 t=$s2 }
if (numarg() == 3) { s=$s1 t=$s2 x=$3 }
}
proc append () { local i
if (argtype(1)==2) sprint(t,"%s%s",s,$s1)
for i=2,numarg() sprint(t,"%s%s",t,$si)
}
proc prepend () { local i
if (argtype(1)==2) sprint(t,"%s%s",$s1,s)
for i=2,numarg() sprint(t,"%s%s",$si,t)
}
proc exec () {
if (numarg()==1) sprint(t,"%s%s",$s1,s)
execute(t)
}
proc tinit() { t=$s1 }
endtemplate String2
//** template DBL
begintemplate DBL
public x
proc init () { if (numarg()==1) x=$1 else x=0 }
endtemplate DBL
//** template Union
// USAGE: XO=new Union(val) where val can be a number string or object
// XO=new Union(list,index) will pick up a string or object from list
// XO=new Union(vec,index) will pick up a number from vector
// XO=new Union(&dbl,index) will pick up a number from double array
// Union allows storage of a double, string or object
// It is useful as a localobj in an obfunc since it will permit returning anything
// It also makes it easy to pick up any kind of value out of a list, vector or array
if (!name_declared("isobj")) execute1("func isobj(){return 0}") // place holder
begintemplate Union
public ty,x,s,t,u,v,o
strdef s,t,u,v
objref o[10]
double x[10]
external sfunc,isobj
// 1arg -- store a num, string or obj
// 2arg -- pick up type out of list
proc init() { local ii,i,ox,xx,sx
ox=xx=sx=x=x[1]=0 ty=argtype(1) // 'type' of Union defined by 1st arg on creation
// special case of number in a vector or something in a list
if (argtype(1)==1 && argtype(2)==0 && argtype(3)==-1) {
ii=$2
printf("Union WARNING: taking single element out of a Vector or List\n")
if (argtype(1)==1) {
if (isobj($o1,"Vector")) {
if (ii<0 || ii>=$o1.size) {
printf("Union ERR: vec index (%d) out of bounds for %s\n",ii,$o1)
return }
ty=0 x=$o1.x[ii] o=$o1
} else if (isobj($o1,"List")) {
if (ii<0 || ii>=$o1.count) {
printf("Union ERR: list index (%d) out of bounds for %s\n",ii,$o1)
return }
if (isobj($o1.object(ii),"String")) { // will handle String2
ty=2 s=$o1.object(ii).s o=$o1.object(ii) x=ii
} else { ty=1 o=$o1.object(ii) x=ii }
}
} else if (argtype(1)==3) {
ty=0 x=$&1[ii] // could check - but no + bound checking possible
}
} else for i=1,numarg() {
ii=argtype(i)
if (ii==0) {
if (xx<10) {
x[xx]=$i xx+=1
} else printf("Only have 10 doubles available so can't store %g\n",$i)
} else if (ii==2) {
if (sx==0) s=$si else if (sx==1) t=$si else if (sx==2) u=$si else if (sx==3) v=$si else {
printf("Only have 4 strings available so can't store %s\n",$si) }
sx+=1
} else if (ii==1) {
if (ox<10) { o[ox]=$oi ox+=1
} else printf("Only have 10 objects available so can't store %s\n",$oi)
} else printf("Union ERR: argtype not recognized numarg %d %d\n",i,ii)
}
}
endtemplate Union
//* Iterators
//** list iterator ltr
// usage 'for ltr(tmplist) { print XO }' :: 1 arg, assumes XO as dummy
// usage 'for ltr(YO, tmplist) { print YO }' 2 arg, specify dummy
// usage 'for ltr(XO, tmplist, &x) { print XO,x }' :: x is counter (else use global i1)
// usage 'for ltr(XO, tmplist, 5) { print XO,x }' :: max; only print out 0-5
// usage 'for ltr(XO, tmplist, 5, 7) { print XO,x }' :: print 5-7
// usage 'for ltr(XO, tmplist, &x, 5) { print XO,x }' :: counter with max
// usage 'for ltr(XO, tmplist, &x, 5, 7) { print XO,x }' :: counter,min,max
iterator ltr () { local i,min,max,ifl
min=0 max=1e9 ifl=0 // iterator flag
if (numarg()==3) {
if (argtype(3)==3) {ifl=1 $&3=0}
if (argtype(3)==0) max=$3
} else if (numarg()==4) {
if (argtype(3)==0) i1=min=$3 else {ifl=1 $&3=0}
max=$4
} else if (numarg()==5) {
$&3=min=$4 max=$5 ifl=1
}
if (! ifl) i1=0
if (numarg()==1) {
for i = 0, $o1.count-1 {
XO = $o1.object(i)
iterator_statement
i1+=1
}
tmpobj=$o1
XO=nil
} else {
if (max==1e9) max=$o2.count()-1 else if (max<0) { min=$o2.count+max max=$o2.count-1
} else if (max>$o2.count-1) max=$o2.count-1
for i = min, max {
$o1 = $o2.object(i)
iterator_statement
if (ifl) { $&3+=1 } else { i1+=1 }
}
tmpobj=$o2
$o1 = nil
}
}
//** list iterator ltrb -- backwards list iterator
// usage 'for ltrb(tmplist) { print XO }' :: 1 arg, assumes XO as dummy
// usage 'for ltrb(YO, tmplist) { print YO }' 2 arg, specify dummy
// usage 'for ltrb(XO, tmplist, &x) { print XO,x }' :: 3 args, define counter (else i1 default)
// :: note that x, i1 must be defined
iterator ltrb () { local i
if (numarg()==1) {
i1=$o1.count-1
for (i=$o1.count()-1;i>=0;i-=1) {
XO = $o1.object(i)
iterator_statement
i1-=1
}
tmpobj=$o1 XO=nil
} else {
if (numarg()==3) $&3=$o2.count-1 else i1=$o2.count-1
for (i=$o2.count()-1;i>=0;i-=1) {
$o1 = $o2.object(i)
iterator_statement
if (numarg()==3) { $&3-=1 } else { i1-=1 }
}
tmpobj=$o2
$o1 = nil
}
}
//** list iterator ltr2
// usage 'for ltr2(XO, YO, list1, list2) { print XO,YO }'
iterator ltr2() { local i,cnt
if (numarg()==5) $&5=0 else i1=0
cnt=$o4.count
if ($o3.count != $o4.count) { print "ltr2 WARNING: lists have different lengths"
if ($o3.count<$o4.count) cnt=$o3.count }
for i = 0, cnt-1 {
$o1 = $o3.object(i)
$o2 = $o4.object(i)
iterator_statement
if (numarg()==5) { $&5+=1 } else { i1+=1 }
}
$o1=nil $o2=nil
}
//** list pairwise iterator ltrp
// usage 'for ltrp(XO, YO, list) { print XO,YO }' takes them pairwise
iterator ltrp() { local i
if (numarg()==4) {$&4=0} else {i1 = 0}
for (i=0;i<$o3.count()-1;i+=2) {
$o1 = $o3.object(i) $o2 = $o3.object(i+1)
iterator_statement
if (numarg()==4) { $&4+=1 } else { i1+=1 }
}
$o1=nil $o2=nil
}
//** list iterator sltr
// usage 'for sltr(XO, string) { print XO }'
iterator sltr() { local i
tmplist = new List($s2)
if (numarg()==3) {$&3=0} else {i1=0}
for i = 0, tmplist.count() - 1 {
$o1 = tmplist.object(i)
iterator_statement
if (numarg()==3) { $&3+=1 } else { i1+=1 }
}
$o1 = nil
}
//* Procedures
//** append(LIST,o1,o2,...) -- like revec() makes a list of objects
proc append () { local i,max
if (!isassigned($o1)) $o1=new List()
max=numarg()
if (argtype(max)==0) {max-=1 $o1.remove_all}
for i=2,max $o1.append($oi)
}
//** rcshead([flag])
// with flag does head from archive
func rcshead () { local x,flag localobj st
x=-1 flag=0
st=new String2()
if (numarg()==2) {
st=dirname($s1)
sprint(st.t,"%sRCS/%s,v",st.s,st.t)
flag=1
} else st.t=$s1
sprint(st.s,"head -1 %s",st.t)
system(st.s,st.s)
if (flag) sscanf(st.s,"head\t1.%d",&x) else sscanf(st.s,"%*[^,],v 1.%d",&x)
return x
}
//** getenv()
obfunc getenv () { localobj st
st=new String()
sprint(st.s,"echo $%s",$s1)
system(st.s,st.s)
sfunc.left(st.s,sfunc.len(st.s)-1)
if (numarg()==2) $s2=st.s
return st
}
//** rcsopen(file,vers[,flag]) -- version open, flag to do load_file
// rcsopen(file,vers,proc_name) -- just load the single proc or func from that vers
// rcsopen("nqsnet.hoc,43,network.hoc,17,params.hoc,842,run.hoc,241") will open several files
func rcsopen () { local a,vers,ii,x,ret localobj st,fn,v1,o,xo
st=new String2()
st.s=$s1 ret=1
// open network.hoc,params.hoc,run.hoc files for "#.#.#"
if (strm(st.s,"^[^,]+,[^,]+,[^,]+,[^,]+")) {
a=allocvecs(v1) o=new List()
split(st.s,o)
for (ii=1;ii<o.count;ii+=2) v1.append(str2num(o.o(ii).s))
if (o.count!=v1.size*2) { printf("rcsopen() discrepency: ") vlk(v1) llist(o) dealloc(a)
return 0 }
for ltr(xo,o,&x) if (x%2==0) { // every other
printf("Opening %s%d\n",xo.s,v1.x[x/2])
if (!rcsopen(xo.s,v1.x[x/2])) { dealloc(a) ret=0 }
}
dealloc(a)
return ret
}
if (numarg()>1) vers=$2 else vers=0
if (! vers) vers=rcshead(st.s,1) // vers=0 means get latest version
// do checkout
fn=filname(st.s)
sprint(st.t,"RCS/%s,v",st.s)
if (sfunc.len(fn.t)>0) {
sprint(st.t,"%sRCS/%s,v",fn.t,fn.s)