// init.hoc
// Olfactory bulb network model: initialisation file
// Andrew Davison, The Babraham Institute, 2000.

if (!name_declared("thresh")) {
	thresh = 0 // just need to declare, see parameters*.hoc for real value
}

objref exptBox, ctrlBox
strdef filename
quitmodel = 0

exptBox = new VBox()
exptBox.intercept(1)
  xpanel("Experiments")
    xlabel("Choose an experiment:")
    xradiobutton("Response to olfactory nerve shock (Fig. 2)", "run_experiment(\"ddi_baseline\")")
    xradiobutton("Response to odour stimulus (Fig. 8)","run_experiment(\"odour_baseline\")")
  xpanel()
  xpanel("Controls",1)
    xbutton("Quit","quit()")
  xpanel()
exptBox.intercept(0)
exptBox.map("Olfactory bulb network model",0,80,-1,-1)

proc run_experiment() {
  exptBox.unmap()
  ctrlBox = new VBox()
  ctrlBox.intercept(1)
    xpanel("Progress")
    xlabel("The network is being created. This may take some time.")
    xpanel()
  ctrlBox.intercept(0)
  ctrlBox.map("Olfactory bulb network model",0,80,-1,-1)
  xopen("mathslib.hoc")			// mathematical procedures
if (pnm.myid == 0)  print "Reading channel tables"
  xopen("tabchannels.hoc")		// channel tables
if (pnm.myid == 0)  print "Reading mitral cell template"
  xopen("par_mitral.tem")		// mitral cell template
if (pnm.myid == 0)  print "Reading granule cell template"
  xopen("par_granule.tem")		// granule cell template
if (pnm.myid == 0)  print "Reading parameters"
  sprint(filename,"parameters_%s.hoc",$s1)
  xopen(filename)                       // model parameters
if (pnm.myid == 0)  print "Creating network"
  xopen("par_bulb.hoc")			// model set-up
if (pnm.myid == 0)  print "Reading input procedures"
  xopen("par_input.hoc")		// define procedures to set-up input
if (pnm.myid == 0)  print "Setting-up experiment"
  sprint(filename,"par_experiment_%s.hoc",$s1)
  xopen(filename)                       // which parameters to record
  ctrlBox.unmap()
  ctrlBox = new VBox()
  ctrlBox.intercept(1)
  xpanel("Instructions")
    xlabel("* To run the simulation, click on [Init & Run].")
    xlabel("* When the simulation is complete, click on [Save Results].")
    xlabel("* If you wish to run a different experiment, you will have")
    xlabel("   to quit NEURON and restart.")
  xpanel()
  xpanel("Controls",1)
    xbutton("Quit","quit()")
    xlabel(" ")
    xbutton("Save results","print_results()")
  xpanel()
  ctrlBox.intercept(0)
  ctrlBox.map("Olfactory bulb network model",0,80,-1,-1)
  
/*
  print "Initialisation complete"
  print ""
  print "To run the simulation, click on [Init & Run]."
  print "When the simulation is complete, click on [Save Results]."
  print "If you have gnuplot (http://www.gnuplot.info) installed"
  print "on your computer, you can produce a figure by running"
  print "gnuplot with the file ", $s1, ".gnu"
*/
}