/*******************************************************************************
*$ Component_name:
*	Kep_Omega
*$ Abstract:
*	Calculates orbital mean motion as a function of distance from a planet.
*$ Keywords:
*	KEPLER, ORBITAL_MOTION
*	C, PUBLIC
*$ Declarations:
*	double		Kep_Omega( planet, a )
*	KEP_PLANET	*planet;	(typedef defined in "kepler.h")
*	double		a;
*$ Inputs:
*	planet		pointer to a KEP_PLANET structure, as returned by the
*			function Kep_SetPlanet().
*	a		mean orbital radius in km.
*$ Outputs:
*	none
*$ Returns:
*	orbital mean motion in radians/second.
*$ Detailed_description:
*	This function returns the orbital mean motion "omega" for a body at the
*	given mean distance from a planet center:
*		omega^2 = GM/a^3 (1. + 3/2 J2 (R/a)^2 - 15/8 J4 (R/a)^4 + ...)
*	Cf. Kep_Kappa(), Kep_Nu(), and Kep_Combo().
*$ External_references:
*	XKep_Jseries()
*$ Examples:
*	none
*$ Error_handling:
*	none
*$ Limitations:
*	Result should be exact for a small body on a circular orbit about an
*	oblate planet.  Perturbations from the sun and any other moons and rings
*	are not included.  A nonzero eccentricity or inclination would introduce
*	relative errors of order (e^2 J2 (R/a)^2) and (sin^2(i) J2 (R/a)^2).
*$ 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"

double		Kep_Omega( planet, a )
KEP_PLANET	*planet;
double		a;
{
double		a2, ratio2, omega2;

	if (a == 0.) return 0.;
	if (a <  0.) a = -a;

	a2 = a * a;
	ratio2 = planet->radius2 / a2;

	omega2 = planet->GM / (a*a2) * (1. +
		XKep_Jseries( planet->omegaJs, planet->nJs, ratio2 ));
	return sqrt(omega2);
}

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