//	This is just like the Cylinder and Injector demo, except
//	that in this case, the cylinder is a Spiker.  So injecting
//	current causes it to produce a train of "action potentials".

// include the necessary header files
#include <stdio.h>			// for printf function
#include "Spiker.h"			// for cylindrical compartment
#include "Injector.h"		// for current injection

#ifdef macintosh
#include <console.h>
#endif

// define some global paramaters -- all in SI units

real RM = 0.33333;		// specific membrane resistance (ohm m^2)
real CM = 0.01;			// specific membrane capacitance (farad/m^2)
real RA = 0.3;			// specific axial resistance (ohms m)
real EREST = -0.07;		// resting membrane potential (volts)
real ELEAK = EREST + 0.0106;	// "leak" potential (volts)

real SOMA_L = 30E-6;	// cylinder length (m)
real SOMA_D = 30E-6;	// cylinder diameter (m)

real TMAX = 0.100;		// simulation time (sec)
real DT = 0.001;		// simulation time step (sec)

Cylinder *MakeDemoSoma( void )
{
	// create cylinder by radius and length
	Cylinder *soma = new Spiker(SOMA_D/2, SOMA_L);		// note Spiker!

	// copy membrane parameters from global variables
	soma->SetE( ELEAK );
	soma->SetRm( RM );
	soma->SetCm( CM );
	soma->SetRa( RA );
	
	soma->SetV( ELEAK );		// start at rest
	return soma;
}

main( int argc, char **argv  )
{
	// give Mac Symantec C++ users a chance to redirect input & output
	#ifdef macintosh
		
		ccommand( &argv );
	#endif
	
	// create the soma
	Cylinder *soma = MakeDemoSoma();
	
	// provide a current injection of 0.3 nA
	Injector inject( soma, 0.3E-9 );
	
	// run the simulation
	printf( "%4s\t%8s\n", "msec", "mV");
	for (real t=0; t<TMAX; t += DT) {
		printf( "%4.1f\t%8.4f\n", t*1000, soma->GetV()*1000 );
		gStepmaster.StepAll(DT);
	}
	
	return 1;
}