load_file("nrngui.hoc")
load_file("stdlib.hoc")

mosinit=1
objref b_
b_ = new VBox()
b_.intercept(1)
b_.save("")
xpanel("")
xbutton("Santhakumar et. al.", "parden_launch()")
xbutton("Traub et. al.", "traub_launch()")
xpanel()
b_.intercept(0)
b_.map("Figure 3 Launch model", 100, 200, 200, 200)

objref mesg_box_
strdef mesg_string_
mesg_string_ = "Select a model to load mod files and setup. This will take a few seconds."
mesg_box_ = new VBox()
mesg_box_.intercept(1)
mesg_box_.save("")
xpanel("")
xvarlabel(mesg_string_)
xpanel()
mesg_box_.intercept(0)
doNotify()

proc parden_launch() { localobj s
	s = new String()
	s.s = "Santhakumar et. al. model"
	if (mkdll_("pardentategyrus", "", s.s)) {
		load_file("init.hoc")
		setup_(s.s)
	}
}

proc traub_launch() { localobj s
	s = new String()
	s.s = "Traub et. al. model"
	if (mkdll_("nrntraub", "mod", s.s)) {
		load_file("init.hoc")
		setup_(s.s)
	}
}

func mkdll_() { localobj s, f
	b_.unmap()
	doNotify()
	mesg_($s3, ": building dynamically loadable library")
	s = new String()
	sprint(s.s, "sh mkdll.sh %s \"%s\" %d", $s1, $s2, unix_mac_pc())
	system(s.s, s.s)
	f = new File()
	if (f.ropen("mkdll.result")) {
		if (f.gets(s.s) > 1) {
			hoc_sf_.left(s.s, hoc_sf_.len(s.s) - 1)
			mesg_("Loading ", s.s)
			nrn_load_dll(s.s)
			chdir($s1)
			sprint(s.s, "Setting up %s in %s", $s3, $s1)
			mesg_(s.s, " (may take some time)")
			return 1
		}
	}
	mesg_($s3, ": dll build failed. Exit and handle manually")
	return 0
}

proc setup_() { localobj s
	s = new String()
	sprint(s.s, " setup time is %g sec", setuptime)
	mesg_($s1, s.s)
}

proc mesg_() {
	if (!mesg_box_.ismapped()) {
		mesg_box_.map("Progress Message", 100, 200, 600, 50)
		doNotify()
	}
	sprint(mesg_string_, "%s %s", $s1, $s2)
	doNotify()
}