// 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



// init protocol, initializing and updating the model for each simulation run
proc init() {local p, k, savet, savesteps, savedt

	dt = setnsig(dt, nsigt)

	setparam()

	setmy()

	setsps()

	if (has_data) {
	
		updparampanel()
		updpelog()
	}
	
	finitialize(v_init)

	if (cvode.active()) {
		cvode.re_init()
	} else {
		fcurrent()
	}
	
	if (mode == 1) {
	
		savet = t
		savesteps = steps_per_ms
		savedt = dt
		steps_per_ms = 1e-9
		dt = 1/steps_per_ms
		for k = 0, 399 fadvance()
		steps_per_ms = savesteps
		dt = savedt
		t = savet
	}
	
	frecord_init()
}