/*******************************************************************************
*$ Component_name:
*	XKep_Jseries
*$ Abstract:
*	This function evaluates a series in a planet's gravitational moments,
*	for internal use by Kepler Library routines.
*$ Keywords:
*	KEPLER, ORBITAL_MOTION
*	C, INTERNAL_ROUTINE
*$ Declarations:
*	double		XKep_Jseries( coefftJs, nJs, ratio2 )
*	double		coefftJs[], ratio2;
*	int		nJs;
*$ Inputs:
*	coefftJs[]	an array of gravitational moments, each scaled by the
*			numeric coefficient needed for the calculation.
*	nJs		number of elements in the array.
*	ratio2		(planetary radius/orbital radius)^2.
*$ Outputs:
*	none
*$ Returns:
*	sum of the desired series.
*$ Detailed_description:
*	This function evaluates the series of gravitational moments:
*		sum = (Rp/a)^2 coefft(2) J2 + 
*		    + (Rp/a)^4 coefft(4) J4 + 
*		    + (Rp/a)^6 coefft(6) J6 + ....
*	To speed the omega, kappa, and nu calculations, the coefficients on J
*	are calculated once within Kep_SetPlanet().  This function is intended
*	primarily for internal use by other Kepler Library functions,
*	specifically Kep_Omega(), Kep_Kappa(), Kep_Nu(), and Kep_Combo().
*$ External_references:
*	none
*$ Examples:
*	none
*$ Error_handling:
*	none
*$ Limitations:
*	none
*$ Author_and_institution:
*	Mark R. Showalter
*	NASA/Ames Research Center
*$ Version_and_date:
*	1991 June 18
*$ Change_history:
*	none
*******************************************************************************/
#include "kepler.h"

double	XKep_Jseries( coefftJs, nJs, ratio2 )
double	coefftJs[], ratio2;
int	nJs;
{
double	sum;
int	index;

	index = nJs - 1;
	if (index >= 0)  {
		sum = coefftJs[index];
		for( index--; index >= 0; index-- )
			sum = ratio2 * sum + coefftJs[index];
		sum = ratio2 * sum;
	}
	else
		sum = 0.;

	return sum;
}

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