// nFit
// (c) Charles CH Cohen, 2014-present
// this software is released to the public under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 
// International license (CC BY-NC-ND 4.0, in English).
// for any questions, please email c.cohen@gmx.com



// ------------------------------Directories---------------------------------------
strdef root, lib, ses, out

root = getcwd()
sprint(lib, "%s%s", root, "lib/")
sprint(ses, "%s%s", root, "ses/")
sprint(out, "%s%s", root, "outdir/")
// --------------------------------------------------------------------------------


load_file("stdgui.hoc")
chdir(lib)
load_file("startlib.hoc")
loadfile(ses, "morph.hoc")
mode = getvarp(ses, "mode.dat")
setmaxform()
setmaxformvec()
has_data = getvarp(ses, "has_data.dat")
setfilestr(mode, has_data)
loaddll()

if (has_data) {

	getvec(ses, iampvecfilestr, iampvec)
	nrows = getmat(ses, vdatfilestr, vdatmat)
	tdatvec = new Vector()
	tdatvec.append(vdatmat.getcol(0))
	nsigt = getnsig(tdatvec)
	temprec = getvarp(ses, "temprec.dat")
	mintau0 = getvarp(ses, "mintau0.dat")
	getvec(ses, "BBvec.dat", BBvec)
	createpip(nrec = getstrlist(ses, "recloclist.dat", recloclist))
	conpip(recloclist)
	getvec(ses, "injlist.dat", injvec)
}

load_file("defsec.hoc")
bigsecl()
lilsecl()
load_file("setnseg.hoc")
setnseg(mintau0)
load_file("defparam.hoc")
load_file("setparam.hoc")
axontype = getaxontype(0)
setparam()
load_file("defsps.hoc")
defsps()
load_file("setsps.hoc")
setsps()
load_file("setmy.hoc")
setmy()
load_file("setstim.hoc")
seticlamp()
load_file("getparam.hoc")
load_file("writeses.hoc")
// --------------------------------------------------------------------------------



print "\nChange Axon Type"
	
if (axontype == 1) {

	print "\nCurrent axon type: ", axontype, "= no myelin"

} else if (axontype == 2) {

	print "\nCurrent axon type: ", axontype, "= single cable"

} else if (axontype == 3) {

	print "\nCurrent axon type: ", axontype, "= double cable without paranodes"

} else if (axontype == 4) {

	print "\nCurrent axon type: ", axontype, "= double cable with paranodes"

}

// Change axon type
strdef axonqstr
axonqstr = "\nPlease select one from the following axon types:\n1 = no myelin\n2 = single cable\n3 = double cable without paranodes\n4 = double cable with paranodes\n"
axontype = xred(axonqstr, axontype, 1, 4)

writebit(ses, "axontype.dat", axontype)
setparam()
if (mode == 0) {
	writevxplot(mode, getvarp(ses, "iamp-pas-def.dat"))
} else if (mode == 1) {
	writevxplot(mode, getvarp(ses, "iamp-act-def.dat"))
}

if (axontype == 1) {

	print "\nSuccessfully changed axon type to: no myelin"

} else if (axontype == 2) {

	print "\nSuccessfully changed axon type to: single cable"

} else if (axontype == 3) {

	print "\nSuccessfully changed axon type to: double cable without paranodes"

} else if (axontype == 4) {

	print "\nSuccessfully changed axon type to: double cable with paranodes"

}

print "\nPlease restart the model"