load_file("nrngui.hoc")

strdef file,command
double int1values[10]
double lgvalues[10]
double mcn1values[10]
double mcn1nvalues[3]

/***********************************************************/
pyloric=1000
tmax=0
max_time=10000

while(tmax < max_time){
	tmax = tmax + pyloric
}
dt=.05
secondorder=2
plot_it_too=1
xopen("constants.oc")
vertical_displacement=40
one_out_of_this_many=1/dt
coupling_method=FIXED
/*coupling_method=VDEP*/

xopen("mkcells.oc")
xopen("mkstim.oc")
xopen("mksyn.oc")
xopen("modify.oc")
xopen("init.oc")

proc myrun() {
if(plot_it_too){
	axis(0,tmax,5,-80,-20+1*vertical_displacement,10)
	axis()
	graph() 
	graph("INT1s.v","setcolor(RED)") 
	graph("LGs.v+vertical_displacement","setcolor(BLACK)")
	graph("MCN1n[MCN1_SEG-1].v+2*vertical_displacement","setcolor(BLUE)") 
}

t = 0
j = 0
/* sprint(file,"out.%d",pyloric) */
sprint(file,"out")
wopen(file)

initialize()

while (t < tmax) {

	if(j==one_out_of_this_many){  	

/*		fprint("%f %f %f %f %f %f %f %f %f\n",\
					t, MCN1n[MCN1_SEG-1].v,LGs.v,\
					INT1s.v,mcn1_lg.g*100000,MCN1a.v,\
					LGa.v,INT1a.v,LGn[0].v)
*/
		fprint("%.2f %.1f %.1f %.1f %.1f %.2f\n",\
					t,LGs.v,LGa.v,INT1s.v, MCN1a.v,mcn1_lg.g*100000)
		j=0
	}else{
		j=j+1}


	if(plot_it_too) {
		graph(t)
	}
	fadvance()
}
	if(plot_it_too) {
		graphmode(-1)
	}

	print_init()
wopen()
}

//run()

/***********************************************************/

// minimal modifications so that run is managed by stdrun.hoc
tstop = tmax

proc init() {
	max_time=tstop
	tmax = 0
	while(tmax < max_time){
		tmax = tmax + pyloric
	}
	// from mksyn.oc: needed if manually change tstop
	/*  AB -> INT1 */
	fsyn(tmax/pyloric)
	for(i=0;i<tmax/pyloric;i=i+1) {
		INT1n[PASSIVE_SEG-1] fsyn(i,0.5,pyloric*i,80,0.0018,-70)
	}
	initialize()
}

load_file("all.ses")