// 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
root = getcwd()

strdef lib, ses
strdef cwd
sprint(lib, "%s%s", root, "lib/")
sprint(ses, "%s%s", root, "ses/")
// --------------------------------------------------------------------------------



// -------------------------------Libraries----------------------------------------
load_file("stdgui.hoc")
chdir(lib)
load_file("startlib.hoc")
// --------------------------------------------------------------------------------


has_data = getvarp(ses, "has_data.dat")

strdef passesqstr_wdata, passesqstr_nodata
passesqstr_wdata = "\nReset passive session to default (with recording data)?  [y/n]"
passesqstr_nodata = "\nReset passive session to default (no recording data)?  [y/n]"

strdef actsesqstr_wdata, actsesqstr_nodata
actsesqstr_wdata = "\nReset active session to default (with recording data)?  [y/n]"
actsesqstr_nodata = "\nReset active session to default (no recording data)?  [y/n]"

if (has_data) {

	pasans = sred(passesqstr_wdata, "y", "ny")
	actans = sred(actsesqstr_wdata, "y", "ny")

} else {

	pasans = sred(passesqstr_nodata, "y", "ny")	
	actans = sred(actsesqstr_nodata, "y", "ny")
}

if (pasans) {

	if (has_data) {

		writebit(ses, "initbit-pas.dat", 0)
		print "\nPassive session reset to default (with recording data)"

	} else {

		writebit(ses, "initbit-pas-def.dat", 0)
		print "\nPassive session reset to default (no recording data)"
	}

} else {

	print "\nPassive session unchanged"
}

if (actans) {

	if (has_data) {

		writebit(ses, "initbit-act.dat", 0)
		print "Active session reset to default (with recording data)"

	} else {

		writebit(ses, "initbit-act-def.dat", 0)
		print "Active session reset to default (no recording data)"
	}	

} else {

	print "Active session unchanged"
}

print "\nPlease restart the model"