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)

// Define spine position
dendr = 3
spinepos = 0.1

// Define spine geometry
neckW = 0.147
neckL = 0.667
headW = 0.519
headL = 0.519

econ.xopen_geometry_dependent("cell_+spine")    // load the raw cell morphology
econ.xopen_geometry_dependent("cell-analysis")     // load user-defined semantics on morphology 
cell_analysis(econ)

printf("Opening cell setup\n")
econ.xopen_generic("cell-setup_regular")                   // 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()