#include "goal.h"

#include "hack.c"

void
goalRun(goal_p goal)
{
	goal->ode_solver = odeCreateSolver(goal->ps->num_particles * PHASESPACE_DIM,
		problem_right_side,false);
	if(!goal->ode_solver)
		return;
	if(!init_monitoring(goal))
	{
		odeDestroySolver(goal->ode_solver);
		return;
	}
	odeSetMonitor(goal->ode_solver,goal->ode_monitor,
		goal->ode_monitor_arg,(vec_t)1.0 / goal->saves_per_second,true);
	odeSetReal(goal->ode_solver,ODE_TIMEOUT,goal->solution_RK_timeout);
	odeSetReal(goal->ode_solver,ODE_MAXIMAL_STEP,goal->solution_maximal_step);
	hack_init(); /* FIXME */
	timerStart(goal->ps->rt_timer);
	odeIntegrate(goal->ode_solver,
		goal->ps->phase,
		goal->ps->cur_time,
		goal->solution_time_limit,
		goal->solution_RK_tolerance,
		goal->solution_maximal_step * 1e-3, /* estimation for step */
		goal->solution_maximal_step * 1e-10, /* minimal allowed step */
		ps);
	timerStop(goal->ps->rt_timer);
	hack_done(); /* FIXME */
	shutdown_monitoring(goal);
	odeDestroySolver(goal->ode_solver);
}
