proc readsyn() {localobj synfile
	synfile = new File()
	synfile.ropen($s1)
	

	$o2.G1_weight = synfile.scanvar()
	$o2.G1_eRev = synfile.scanvar()
	$o2.G1_opentc = synfile.scanvar()
	$o2.G1_closetc = synfile.scanvar()

	$o2.G2_weight = synfile.scanvar()
	$o2.G2_eRev = synfile.scanvar()
	$o2.G2_opentc = synfile.scanvar()
	$o2.G2_closetc = synfile.scanvar()

	$o2.G3_weight = synfile.scanvar()
	$o2.G3_eRev = synfile.scanvar()
	$o2.G3_opentc = synfile.scanvar()
	$o2.G3_closetc = synfile.scanvar()

	w1 = $o2.G1_weight 
	tc1 = $o2.G1_closetc 
	
	w2 = $o2.G2_weight 
	tc2 = $o2.G2_closetc 

	w3 = $o2.G3_weight 
	tc3 = $o2.G3_closetc 
	
}

/* 
Written by Bob Calin-Jageman

*/
load_file("nrngui.hoc")

// chdir("c:/sims/nfrost")
// chdir("mods")
// nrn_load_dll("nrnmech.dll")
// chdir("..")

load_file("celltypes/C2Type.hoc") 
load_file("celltypes/DSIType.hoc")
load_file("celltypes/VSIType.hoc")
load_file("celltypes/IFType.hoc")
load_file("celltypes/IFType.hoc")
load_file("celltypes/DRIType.hoc")

objref C2, DSI, VSI, DRI, VSINA, IF, synlist, outfile
strdef runcode, experiment, outfilename

experiment = "none"
runcode = "single"

outfile = new File()
outfile.aopen("bursts.txt")
strdef dstring

C2 = new C2Type()
DSI = new DSIType()
VSI = new VSIType()
IF = new IFType()
synlist = new List()
DRI = new DRIType()

objectvar DSI_DSIs, DSI_DSInc
DSI.soma {DSI_DSIs = new tholdsyn(0.5)}
access DSI.soma
DSI_DSInc = new NetCon(&v(0.5), DSI_DSIs, 0, 0, 1)
synlist.append(DSI_DSIs)

objectvar VSI_VSIs, VSI_VSInc
VSI.soma {VSI_VSIs = new tholdsyn(0.5)}
access VSI.soma
VSI_VSInc = new NetCon(&v(0.5), VSI_VSIs, 0, 0, 1)
synlist.append(VSI_VSIs)

readsyn("syndefs/DSI_DSI.txt", DSI_DSIs)
readsyn("syndefs/VSI_VSI.txt", VSI_VSIs)

access C2.soma
load_file("ses/cpg.ses")
tstop = 42000

objref cellpointer, spikeholder
cellpointer = VSI

objref mysyns
mysyns = new List("tholdsyn")

proc init() {local x



			finitialize(v_init)
			fcurrent()
			
			spikeholder = new Vector()
			lastsp1 = 0
			
			C2.soma.v = C2.ileak.vrest
			DSI.soma.v = DSI.ileak.vrest
			VSI.soma.v = VSI.ileak.vrest
			
		}

proc advance() {
	
	if (cellpointer.sthold.lastspike != lastsp1) {
		//print t
		spikeholder.append(t)
		lastsp1 = cellpointer.sthold.lastspike
	}

	fadvance()
	
}

proc cfplot() {local x, delay, firstsp, lastsp, y, offset localobj istim, outf
	access $o1.soma
	istim = new IClamp(0.5)
	offset = $2
	istim.del = offset
	istim.dur = 5000
	cellpointer = $o1
	outf = new File()
	outf.aopen("cfplot.txt")
	for (x=$3; x < $4; x = x + 0.5) {
		istim.amp = x
		init()
		run()
		delay = 0
		firstsp = 0
		lastsp = 0
		if (spikeholder.size() > 2) {
		for (y=1; y < spikeholder.size(); y = y + 1) {
			if ((spikeholder.x[y-1] > offset) && (spikeholder.x[y-1] < (offset+10000))) {
				lastsp = spikeholder.x[y] - spikeholder.x[y-1]
				if (firstsp == 0) {firstsp = lastsp }
				if (delay ==0) {delay = spikeholder.x[y-1] - 1000 }
			}
		}
		}	
		if (lastsp != 0) {	
		print $o1, x, delay, 1/(firstsp/1000), 1/(lastsp/1000)
		}
		if (lastsp != 0) {
		outf.printf("%s	%f	%f	%f	%f\n", $o1, x, delay, 1/(firstsp/1000), 1/(lastsp/1000))
		} else {
		outf.printf("%s	%f	%f	%f	%f\n", $o1, x, delay, firstsp, lastsp)
		}
	}
	istim.amp = 0
	outf.close()
}