load_file("nrngui.hoc")
load_file("../template/load_templates.hoc")

strdef accstr    // not confuse experimental variable bindings with neurophysiological variable bindings
objref econ                          // Create an experiment object
show_errs=1
debug_lev=1
econ=new ExperimentControl(show_errs,debug_lev)
econ.self_define(econ) 		// points the object at itself
econ.morphology_dir = "../morphology/n123"                             // Setup morphology directory
econ.generic_dir = "../experiment/"                                    // Setup directory with cell-setup file
econ.add_lib_dir("Terrence","../lib")                                  // Setup directory with library functions 

if (unix_mac_pc() ==1 ) {
	econ.data_dir       = "data"                       // Define directory to save produced data 
	sprint(econ.syscmd, "mkdir -p %s", econ.data_dir)  // make the data directory
	system(econ.syscmd)
}

// *******************************************************
// Setup cell
// *******************************************************

objref dendrv
dendrv = new Vector(0)

econ.xopen_geometry_dependent("cell_mul2")              // load the raw cell morphology
econ.xopen_geometry_dependent("cell-analysis_mul2")     // load user-defined semantics on morphology 
cell_analysis(econ)

printf("Opening cell setup\n")
econ.xopen_generic("cell-setup_mul2")                   // load the cell-setup file (define specific 
printf("Opened. Setting up cell\n")                // channels, membrane properties etc)
cell_setup(econ)

// *******************************************************
// Set simulation parameters
// *******************************************************

econ.defvar("Simulation Control", "tstop", "30", "Defines when the simulation stops.")
econ.defvar("Simulation Control", "dt", "0.025", "Timestep") // 0.1 originally
econ.defvar("Simulation Control", "steps_per_ms", "40", "How many points are plotted per ms")
setdt()


// *******************************************************
// Set maximum segment length 5um and nseg = odd multiple of 5
// *******************************************************

for i=0,118 {
apical_dendrite[i] {nseg=int((int(L/5)+5)/10)*10+5}
}

// *******************************************************
// Initialize experiment
// *******************************************************

nrnmainmenu()
access soma

v_init = -70

forall {insert cldifus}
forall {Ra = 100}

finitialize(v_init)
fcurrent()