/*******************************************************************************
*$ Component_name:
*	Kep_SetOrbit
*$ Abstract:
*	Function to define the orbit of a moon around a planet.
*$ Keywords:
*	KEPLER, ORBITAL_MOTION
*	C, PUBLIC
*$ Declarations:
*	void		Kep_SetOrbit( a, e, i, peri, node, meanLon, epoch,
*				planet, orbit )
*	double		a, e, i, peri, node, meanLon, epoch;
*	KEP_PLANET	*planet;	(typedef defined in "kepler.h")
*	KEP_ORBIT	*orbit;		(typedef defined in "kepler.h")
*$ Inputs:
*	a		semimajor axis (km).
*	e		eccentricity.
*	i		inclination (radians).
*	peri		longitude of pericenter (radians).  This is measured
*			from the reference longitude to the ascending node,
*			and thence along the ring plane.
*	node		longitude of ascending node (radians).
*	meanLon		mean longitude of the orbiting body at the given epoch
*			(radians).
*	epoch		time at which the orbital elements apply (sec).
*	*planet		planetary field structure, returned by Kep_SetPlanet().
*$ Outputs:
*	*orbit		orbit structure containing the desired information.
*$ Returns:
*	none
*$ Detailed_description:
*	This function is used to define a satellite orbit.  The resultant data
*	structure may then be passed into other modules of the Kepler Library
*	that make use of this information.  The structure returned contains many
*	pre-calculated parameters to speed up later calculations.
*$ External_references:
*	Kep_Omega(), Kep_Apse(), Kep_Node()
*$ Examples:
*	none
*$ Error_handling:
*	none
*$ Limitations:
*	Eccentricity must be less than unity.
*$ Author_and_institution:
*	Mark R. Showalter
*	NASA/Ames Research Center
*$ Version_and_date:
*	1991 June 18
*$ Change_history:
*	none
*******************************************************************************/
#include <math.h>
#include "kepler.h"

void		Kep_SetOrbit( a, e, i, peri, node, meanLon, epoch, planet,
			orbit )
double		a, e, i, peri, node, meanLon, epoch;
KEP_PLANET	*planet;
KEP_ORBIT	*orbit;
{
double		meanR, temp;

/*******************************************************************************
* Copy parameters into the orbit structure.
*******************************************************************************/

	orbit->a = a;
	orbit->e = e;
	orbit->i = i;
	orbit->peri = peri;
	orbit->node = node;
	orbit->meanLon = meanLon;
	orbit->epoch = epoch;

/*******************************************************************************
* Fill in derived parameters.
*******************************************************************************/

	orbit->eccRatio = sqrt((1.+e) / (1.-e));
	orbit->cosI = cos(i);
	orbit->sinI = sin(i);

	meanR = a;
	orbit->omega = Kep_Omega( planet, meanR );
	orbit->dPdT  = Kep_Apse(  planet, meanR );
	orbit->dNdT  = Kep_Node(  planet, meanR );

	temp = a * (orbit->omega - orbit->dPdT);
	orbit->a2kappa2 = temp * temp;

	orbit->dPNdT = orbit->dPdT - orbit->dNdT;

	return;
}

/******************************************************************************/
