Functions

ephcom.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include "ephcom.h"
#include "gnulliver.h"

Go to the source code of this file.

Functions

static void ephcom_nxtgrp (char *group, const char *expected, FILE *infile)
static void ephcom_outdouble (FILE *outfp, double x)
static void ephcom_outint (FILE *outfp, unsigned u)
static void ephcom_doublestrc2f (char *buf)
static double ephcom_exact_time (double time)
static double ephcom_split (double time, double *itime)
static void ephcom_cheby (int maxcoeffs, double x, double span, double *y, int ncoords, int ncoeffs, double *pv)
static void ephcom_jd2cal (double tjd, int idate[6], int calendar_type)
void ephcom_readascii_header (FILE *infp, ephcom_Header *header)
int ephcom_readascii_block (FILE *infp, ephcom_Header *header, double *datablock)
void ephcom_readbinary_header (FILE *infp, ephcom_Header *header)
int ephcom_readbinary_block (FILE *infp, ephcom_Header *header, int blocknum, double *datablock)
void ephcom_writeascii_header (FILE *outfp, ephcom_Header *header)
void ephcom_writeascii_block (FILE *outfp, ephcom_Header *header, int blocknum, double *datablock)
void ephcom_writebinary_header (FILE *outfp, ephcom_Header *header)
void ephcom_writebinary_block (FILE *outfp, ephcom_Header *header, int blocknum, double *datablock)
void ephcom_parse_block (FILE *outfp, ephcom_Header *header, double *datablock)
double ephcom_indouble (FILE *infp)
int ephcom_inint (FILE *infp)
void ephcom_pleph (ephcom_Coords *coords, int ntarg, int ncntr, double *r)
int ephcom_get_coords (FILE *infp, ephcom_Header *header, ephcom_Coords *coords, double *datablock)
double ephcom_cal2jd (int idate[6], int calendar_type)

Detailed Description

Source code for the ephcom library.

Definition in file ephcom.c.


Function Documentation

double ephcom_cal2jd ( int  idate[6],
int  calendar_type 
)

Convert calendar date and time to JD. From pp. 604, 606 in the Explanatory Supplement to the Astronomical Almanac.

Parameters:
idate [IN ONLY] integer array of 6 values which contains the integer year, month, day, hour, minute, and second.
calendar_type [IN ONLY]Integer value which controls the kind of calendar used for the transformation: -1=Julian; 0=automatic; 1=Gregorian. If automatic, use Julian calendar for dates before 15 October 1582.
Returns:
double-precision Julian Day number corresponding to idate.

Definition at line 2038 of file ephcom.c.

static void ephcom_cheby ( int  maxcoeffs,
double  x,
double  span,
double *  y,
int  ncoords,
int  ncoeffs,
double *  pv 
) [inline, static]

Interpolate position and velocity (or nutation or libration angles and their time derivatives) at a time point (converted to Chebyshev coordinate in range [-1,1]) using JPL Chebyshev coefficients supplied for one solar system JPL "body" index, where the JPL "bodies" are identified as follows:

Index Identification
0 Mercury
1 Venus
2 Earth-Moon Barycenter
3 Mars
4 Jupiter
5 Saturn
6 Uranus
7 Neptune
8 Pluto
9 Moon (Geocentric)
10 Sun
11 Nutation angles
12 Lunar Libration angles
Parameters:
maxcoeffs [INPUT ONLY]Maximum number of Chebyshev components possible.
x [INPUT ONLY]Value of x over [-1,1] for Chebyshev interpolation.
span [INPUT ONLY]Span of subinterval in the time coordinate used for the time derivatives (velocity or radians per second for the angular coordinates).
y [INPUT ONLY]Pointer to an array of required Chebyshev coefficients for a particular JPL "body".
ncoords [INPUT ONLY]Total number of coordinates to interpolate for a particular JPL "body". This quantity is 3 except for nutation where it is two.
ncoeffs [INPUT ONLY]Number of Chebyshev coefficients per coordinate.
pv [OUTPUT ONLY]Pointer to an array to hold interpolated positions (or angles) in 1st half, interpolated velocity (or angle time derivatives) in 2nd half for a particular JPL "body".

Definition at line 1864 of file ephcom.c.

static void ephcom_doublestrc2f ( char *  buf  )  [static]

Function to convert a string with a double precision value written in C to a double precision value that fortran understands (i.e., with a "D" exponent character). Conversion happens in place.

Parameters:
buf [IN AND OUT]Pointer to a character string holding the C double-precision value (in "E" exponential format with a trailing blank after the exponent to make room for the leading zero notation of the fortran value) on input and the fortran double-precision value in "D" exponential format for fortran (with leading zero before the decimal point) on output. If the resulting fortran exponent has a leading zero and more than two digits that leading zero is dropped while right justification is maintained by shifting the whole string to the right by one byte to overlay that leading zero by the exponent sign.

Definition at line 1343 of file ephcom.c.

static double ephcom_exact_time ( double  time  )  [static]

If Julian date is close to an integer + 0.5, return that exact "half" value. Use of this routine makes the code more robust for an early version of de422 (since corrected) which had numerical noise in its half days.

Parameters:
time [IN ONLY]Value of the Julian date which should be exactly half integral.
Returns:
exactly half integral Julian date closest to time if input time close to half-integral. If input time is not close to half-integral the routine returns the unmodified input time.

Definition at line 2093 of file ephcom.c.

int ephcom_get_coords ( FILE *  infp,
ephcom_Header header,
ephcom_Coords coords,
double *  datablock 
)

Interpolate positions and velocities of all stored JPL "bodies" at given time from a JPL binary ephemeris file. Transform the interpolated data to the following index scheme for JPL bodies where the index is one less than the index used for the arguments of ephcom_pleph():

Index Identification
0 Mercury
1 Venus
2 Earth
3 Mars
4 Jupiter
5 Saturn
6 Uranus
7 Neptune
8 Pluto
9 Moon
10 Sun
11 Solar System Barycenter
12 Earth-Moon Barycenter
13 Nutation Angles
14 Libration Angles
15 Moon (Geocentric)
Parameters:
infp [IN ONLY]Pointer to a binary version of a JPL ephemeris FILE.
header [IN ONLY]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information that has already been read from that binary JPL ephemeris FILE.
coords [IN AND OUT]Pointer to a ephcom_Coords struct which contains on input coords->et2 (the split Julian date where the interpolation should occur) and also the control information coords->km (if nonzero, solar system body coordinates [but not nutation and libration angles which are always returned in radians] will be be returned in kilometers rather than astronomical units); coords->second (if nonzero, all solar system body and nutation and libration angle time derivatives will be returned in per second units rather than in per day units); coords->bary (if nonzero, all solar system body coordinates will be relative to the solar system barycenter, otherwise they will be relative to the solar system body indicated by the coords->center index; and coords->center (the index in the range from 0 to 12 which cooresponds to a particular solar system body indicated in the above table, and which only needs to be supplied if coords->bary is zero). Upon return this struct contains interpolated values of all coordinates and their time derivatives as calculated from the Chebyshev coefficients in datablock using the above body index scheme.
datablock [OUT ONLY]Pointer to an array that upon return will contain the block of Chebyshev coefficient data that has been read that has a Julian date range that contains the specified Julian date in coords where the interpolation occurred.
Returns:
0 on success and -1 on failure (due to specified Julian date in coords out of range or some i/o error).

Definition at line 1544 of file ephcom.c.

double ephcom_indouble ( FILE *  infp  ) 

Read a double-precision value from the given binary file with bytes swapped if necessary to match host endian order. On Intel 80x86 the bytes will get swapped, on Motorola or SPARC they won't.

Parameters:
infp [IN ONLY]Pointer to the binary input FILE.
Returns:
the (possibly) byte-swapped double-precision value that was read from the binary input FILE.

Definition at line 1292 of file ephcom.c.

int ephcom_inint ( FILE *  infp  ) 

Read an integer value from the given binary file with bytes swapped if necessary to match host endian order. On Intel 80x86 the bytes will get swapped, on Motorola or SPARC they won't.

Parameters:
infp [IN ONLY]Pointer to the binary input FILE.
Returns:
the (possibly) byte-swapped integer value that was read from the binary input FILE.

Definition at line 1317 of file ephcom.c.

static void ephcom_jd2cal ( double  tjd,
int  idate[6],
int  calendar_type 
) [static]

Convert Julian Day to calendar date and time. From pp. 604, 606 in the Explanatory Supplement to the Astronomical Almanac.

Parameters:
tjd [IN ONLY]Double-precision Julian Day number.
idate [OUT ONLY] integer array of 6 values which upon return will contain the integer year, month, day, hour, minute, and second corresponding to tjd.
calendar_type [IN ONLY]Integer value which controls the kind of calendar used for the transformation: -1=Julian; 0=automatic; 1=Gregorian. If automatic, use Julian calendar for dates before 15 October 1582.

Definition at line 1969 of file ephcom.c.

static void ephcom_nxtgrp ( char *  group,
const char *  expected,
FILE *  infile 
) [static]

Read the next two lines of the ascii form of a JPL ephemeris file. For the last of those check that it is exactly the same as the expected group header form, that is, 12 characters containing "GROUP nnnn" with the same nnnn as expected. If the group is not what is expected, then print an error message and exit.

Parameters:
group [OUT ONLY]Pointer to a group header that upon return will be filled by a 12-character null-terminated string that we read.
expected [IN ONLY]Pointer to a 12-character null-terminated string that we expect to read.
infile [IN ONLY]Pointer to the JPL ascii ephemeris FILE that we read.

Definition at line 1230 of file ephcom.c.

static void ephcom_outdouble ( FILE *  outfp,
double  x 
) [static]

Write a double-precision value to the given binary file with bytes swapped if necessary to match network order (Big Endian). On Intel 80x86 the bytes will get swapped, on Motorola or SPARC they won't.

Parameters:
outfp [IN ONLY]Pointer to the binary output FILE.
x [IN ONLY]Double-precision value that will be written to the binary FILE.

Definition at line 1256 of file ephcom.c.

static void ephcom_outint ( FILE *  outfp,
unsigned  u 
) [static]

Write a integer value to the given binary file with bytes swapped if necessary to match network order (Big Endian). On Intel 80x86 the bytes will get swapped, on Motorola or SPARC they won't.

Parameters:
outfp [IN ONLY]Pointer to the binary output FILE.
u [IN ONLY]Integer value that will be written to the binary FILE.

Definition at line 1275 of file ephcom.c.

void ephcom_parse_block ( FILE *  outfp,
ephcom_Header header,
double *  datablock 
)

Write out a block of JPL binary data in ascii form that is nicely formatted and therefore verbose.

Parameters:
outfp [IN ONLY]Pointer to the FILE which will be used to output the nicely formatted data.
header [IN ONLY]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information. Some of these data are used to control how to output the block of data in a nicely formatted way.
datablock [IN ONLY]Pointer to an array that contains the block of data that will be output in nicely formatted form.

Definition at line 1175 of file ephcom.c.

void ephcom_pleph ( ephcom_Coords coords,
int  ntarg,
int  ncntr,
double *  r 
)

This ephcom_pleph routine takes coordinates already calculated in a ephcom_Coords struct and returns selected results in an array depending on the ntarg and ncentr indices provided by the calling routine. These indices have the following interpretation (note the offset of one compared to the interpretation of the first index of pv in the ephcom_Coords struct.

Index Identification
1 Mercury
2 Venus
3 Earth
4 Mars
5 Jupiter
6 Saturn
7 Uranus
8 Neptune
9 Pluto
10 Moon
11 Sun
12 Solar System Barycenter
13 Earth-Moon Barycenter
14 Nutation Angles
15 Libration Angles
16 Moon (Geocentric)
Parameters:
coords [IN ONLY]Pointer to a ephcom_Coords struct which contains interpolated values of all coordinates and their time derivatives as calculated from Chebyshev coefficients supplied by a JPL ephemeris.
ntarg [IN ONLY]Index interpreted according to the above table which identifies the "target" data in coords.
ncntr [IN ONLY]Index interpreted according to the above table which identifies the "center" data in coords. If either ntarg or ncent is 14, the interpolated nutation angle data (two angles and two angle time derivatives) are returned in r. Otherwise, if either ntarg or ncent is 15, the interpolated libration angle data (three angles and three angle time derivatives) are returned in r. Otherwise, if either ntarg or ncent is 16, the moon geocentric position and velocity data (3 positions and 3 velocities) are returned in pv. Otherwise (the normal case) if 0 < ntarg < 14 and 0 < ncent < 14, the interpolated positions and velocities corresponding to the center index are subtracted from the interpolated positions and velocities corresponding to the target index and the resulting data (3 positions and 3 velocities) are returned in pv. Otherwise, ephcom_pleph() issues an error message and exits.
r [OUT ONLY]Pointer to an array which upon return will be filled with the requested interpolated results (4 values for nutation and 6 values for everything else).

Definition at line 1458 of file ephcom.c.

int ephcom_readascii_block ( FILE *  infp,
ephcom_Header header,
double *  datablock 
)

Read a block of data coefficients from a JPL ASCII ephemeris file.

Parameters:
infp [IN ONLY]Pointer to an ascii version of a JPL ephemeris FILE.
header [IN ONLY]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information that has already been read from the FILE.
datablock [OUT ONLY]Pointer to an array that upon successful return will be filled with datapoints == header->ncoeff data points.
Returns:
number of coefficients read or 0 at EOF or some other i/o error.

Definition at line 348 of file ephcom.c.

void ephcom_readascii_header ( FILE *  infp,
ephcom_Header header 
)

Read a JPL ephemeris ASCII header from the FILE pointed to by the infp argument and store all header data in the ephcom_Header struct pointed to by the header argument. If any errors are detected this routine writes a message to stderr and exits.

Parameters:
infp [IN ONLY]Pointer to an ascii version of a JPL ephemeris FILE.
header [OUT ONLY]Pointer to an ephcom_Header struct which upon return will contain all the JPL ephemeris header information that has been read from the FILE.

Definition at line 138 of file ephcom.c.

int ephcom_readbinary_block ( FILE *  infp,
ephcom_Header header,
int  blocknum,
double *  datablock 
)

Read a block of data coefficients from a JPL binary ephemeris file.

Parameters:
infp [IN ONLY]Pointer to a binary version of a JPL ephemeris FILE.
header [IN ONLY]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information that has already been read from the infp FILE.
blocknum [IN ONLY]Requested direct access block number with zero corresponding to the first data block after the two header blocks in the binary ephemeris.
datablock [OUT ONLY]Pointer to an array that upon successful return will be filled with datapoints == header->ncoeff data points.
Returns:
number of coefficients read or 0 at EOF or some other i/o error.

Definition at line 624 of file ephcom.c.

void ephcom_readbinary_header ( FILE *  infp,
ephcom_Header header 
)

Read a JPL ephemeris binary header from the FILE pointed to by the infp argument and store all header data in the ephcom_Header struct pointed to by the header argument. If any errors are detected this routine writes a message to stderr and exits.

Parameters:
infp [IN ONLY]Pointer to a binary version of a JPL ephemeris FILE.
header [OUT ONLY]Pointer to an ephcom_Header struct which upon return will contain all the JPL ephemeris header information that has been read from the FILE.

Definition at line 419 of file ephcom.c.

static double ephcom_split ( double  time,
double *  integral_time 
) [static]

Split time into an integer part and a positive remainder in the semi-open range [0., 1.).

Parameters:
time [IN ONLY]time value to be split.
integral_time [OUT ONLY]Pointer to a double value which upon return will contain the integral part of the split time.
Returns:
remainder of the split time in the semi-open range [0., 1.).

Definition at line 2112 of file ephcom.c.

void ephcom_writeascii_block ( FILE *  outfp,
ephcom_Header header,
int  blocknum,
double *  datablock 
)

Write JPL ephemeris coefficient block of data in ASCII format.

Parameters:
outfp [IN ONLY]Pointer to the FILE which will be used to output the formatted block of data.
header [IN ONLY]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information. Some of these data are included in the formatted block and some of these data are used to control how much is written in that formatted block.
blocknum [IN ONLY]Block number. This value + 1 will be used in the output formatted block of data.
datablock [IN ONLY]Pointer to an array that contains the block of data that will be output in formatted form.

Definition at line 884 of file ephcom.c.

void ephcom_writeascii_header ( FILE *  outfp,
ephcom_Header header 
)

Write JPL ephemeris header information in ASCII format.

Parameters:
outfp [IN ONLY]Pointer to the FILE which will be used to output the formatted header information.
header [IN and OUT]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information to be output to the FILE. However, some self-consistency adjustments of the header are made before such FILE output and those are returned to the calling routine as well.

Definition at line 666 of file ephcom.c.

void ephcom_writebinary_block ( FILE *  outfp,
ephcom_Header header,
int  blocknum,
double *  datablock 
)

Write JPL ephemeris coefficient block of data in binary form.

Parameters:
outfp [IN ONLY]Pointer to the FILE which will be used to output the binary block of data.
header [IN ONLY]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information. Some of these data are used to control where in the binary FILE the block of data is written and how large it is.
blocknum [IN ONLY]Block number. This value helps control where in the binary FILE the block of data is written.
datablock [IN ONLY]Pointer to an array that contains the block of data that will be output in binary form.

Definition at line 1125 of file ephcom.c.

void ephcom_writebinary_header ( FILE *  outfp,
ephcom_Header header 
)

Write JPL ephemeris header information in binary form.

Parameters:
outfp [IN ONLY]Pointer to the FILE which will be used to output the binary header information.
header [IN ONLY]Pointer to an ephcom_Header struct which contains the JPL ephemeris header information to be output in binary form.

Definition at line 944 of file ephcom.c.