/*----------------------------------------------------------------------------

  DEMO OF SIMPLIFIED HODGKIN-HUXLEY MODELS OF CORTICAL NEURONS

  Models described in:

   Pospischil, M., Toledo-Rodriguez, M., Monier, C., Piwkowska, Z., 
   Bal, T., Fregnac, Y., Markram, H. and Destexhe, A.
   Minimal Hodgkin-Huxley type models for different classes of
   cortical and thalamic neurons.
   Biological Cybernetics 99: 427-441, 2008.

        Alain Destexhe, CNRS, 2009
	http://cns.iaf.cnrs-gif.fr

----------------------------------------------------------------------------*/

load_file("nrngui.hoc")

//----------------------------------------------------------------------------
//  define a panel to run the different demos
//----------------------------------------------------------------------------

proc make_demopanel() {
	xpanel("Simulations of cortical cells")
	xradiobutton("Regular-spiking pyramidal cell","restart(\"demo_PY_RS\")",1)
	xradiobutton("Bursting pyramidal cell","restart(\"demo_PY_IB\")")
	xradiobutton("Repetivive bursting pyramidal cell","restart(\"demo_PY_IBR\")")
	xradiobutton("LTS pyramidal cell","restart(\"demo_PY_LTS\")")
        xradiobutton("Fast-spiking interneuronl","restart(\"demo_IN_FS\")")
	xpanel(20,100)
}

proc restart() {local i

	ismenu = 0

	if (electrodes_present) {
		destroy_elec()
	}

	forall delete_section()

	for i=0, n_graph_lists-1 {
		graphList[i].remove_all()
	}
	flush_list.remove_all()
	fast_flush_list.remove_all()
	doNotify()
	for (i= PWManager[0].count-1; i >= pwmcnt; i -= 1) {
		PWManager[0].close(i)
		doNotify()
	}
	stoprun = 0
	cvode_active(0)

	ismenu=0
	
	sprint(tstr, "%s.hoc", $s1)
	load_file(1, tstr)
}


ismenu=0

load_file("nrngui.hoc")

strdef tstr
ncells=1
objref El[ncells]

electrodes_present=0	// after electrodes are created they must be
			// destroyed if simulation restarted

proc destroy_elec() {
	execute("objref stim, vc",El[0])
}

pwmcnt = PWManager[0].count  // the initial GUIs should not be dismissed

make_demopanel()

// starting with the first demo avoids an error of when the second
// demo is selected first

restart("demo_PY_RS")