Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

JPLEphemeris Class Reference

#include <jpleph.h>

Collaboration diagram for JPLEphemeris:

Collaboration graph
List of all members.

Public Member Functions

unsigned int getDENumber () const
double getEndDate () const
Point3d getPlanetPosition (JPLEphemItem, double t) const
double getStartDate () const
 ~JPLEphemeris ()

Static Public Member Functions

static JPLEphemerisload (std::istream &)

Private Member Functions

 JPLEphemeris ()

Private Attributes

double au
JPLEphCoeffInfo coeffInfo [JPLEph_NItems]
double daysPerInterval
unsigned int DENum
double emrat
double endDate
JPLEphCoeffInfo librationCoeffInfo
std::vector< JPLEphRecordrecords
unsigned int recordSize
double startDate

Constructor & Destructor Documentation

JPLEphemeris::JPLEphemeris  )  [private]
 

Definition at line 71 of file jpleph.cpp.

Referenced by load().

00072 {
00073 }

JPLEphemeris::~JPLEphemeris  ) 
 

Definition at line 76 of file jpleph.cpp.

00077 {
00078 }


Member Function Documentation

unsigned int JPLEphemeris::getDENumber  )  const
 

Definition at line 81 of file jpleph.cpp.

References DENum.

Referenced by GetCustomOrbit().

00082 {
00083     return DENum;
00084 }

double JPLEphemeris::getEndDate  )  const
 

Definition at line 91 of file jpleph.cpp.

References endDate.

Referenced by CreateJPLEphOrbit(), and GetCustomOrbit().

00092 {
00093     return endDate;
00094 }

Point3d JPLEphemeris::getPlanetPosition JPLEphemItem  ,
double  t
const
 

Definition at line 96 of file jpleph.cpp.

References coeffInfo, JPLEphRecord::coeffs, daysPerInterval, endDate, MaxChebyshevCoeffs, JPLEphCoeffInfo::nCoeffs, JPLEphCoeffInfo::nGranules, JPLEphCoeffInfo::offset, records, startDate, and JPLEphRecord::t0.

00097 {
00098     // Clamp time to [ startDate, endDate ]
00099     if (t < startDate)
00100         t = startDate;
00101     else if (t > endDate)
00102         t = endDate;
00103     
00104     int recNo = (int) ((t - startDate) / daysPerInterval);
00105     // Make sure we don't go past the end of the array if t == endDate
00106     if (recNo >= records.size())
00107         recNo = records.size() - 1;
00108     const JPLEphRecord* rec = &records[recNo];
00109 
00110     assert(coeffInfo[planet].nGranules >= 1);
00111     assert(coeffInfo[planet].nGranules <= 32);
00112     assert(coeffInfo[planet].nCoeffs <= MaxChebyshevCoeffs);
00113 
00114     // u is the normalized time (in [-1, 1]) for interpolating
00115     // coeffs is a pointer to the Chebyshev coefficients
00116     double u = 0.0;
00117     double* coeffs = NULL;
00118     if (coeffInfo[planet].nGranules == -1)
00119     {
00120         coeffs = rec->coeffs + coeffInfo[planet].offset;
00121         u = 2.0 * (t - rec->t0) / daysPerInterval - 1.0;
00122     }
00123     else
00124     {
00125         double daysPerGranule = daysPerInterval / coeffInfo[planet].nGranules;
00126         int granule = (int) ((t - rec->t0) / daysPerGranule);
00127         double granuleStartDate = rec->t0 + 
00128             daysPerGranule * (double) granule;
00129         coeffs = rec->coeffs + coeffInfo[planet].offset +
00130             granule * coeffInfo[planet].nCoeffs * 3;
00131         u = 2.0 * (t - granuleStartDate) / daysPerGranule - 1.0;
00132     }
00133     
00134     double sum[3];
00135     double cc[MaxChebyshevCoeffs];
00136     unsigned int nCoeffs = coeffInfo[planet].nCoeffs;
00137     for (int i = 0; i < 3; i++)
00138     {
00139         cc[0] = 1.0;
00140         cc[1] = u;
00141         sum[i] = coeffs[i * nCoeffs] + coeffs[i * nCoeffs + 1] * u;
00142         for (unsigned int j = 2; j < nCoeffs; j++)
00143         {
00144             cc[j] = 2.0 * u * cc[j - 1] - cc[j - 2];
00145             sum[i] += coeffs[i * nCoeffs + j] * cc[j];
00146         }
00147     }
00148 
00149     return Point3d(sum[0], sum[1], sum[2]);
00150 }

double JPLEphemeris::getStartDate  )  const
 

Definition at line 86 of file jpleph.cpp.

References startDate.

Referenced by CreateJPLEphOrbit(), and GetCustomOrbit().

00087 {
00088     return startDate;
00089 }

JPLEphemeris * JPLEphemeris::load std::istream &   )  [static]
 

Definition at line 153 of file jpleph.cpp.

References au, coeffInfo, ConstantNameLength, daysPerInterval, DE200RecordSize, DE405RecordSize, DE406RecordSize, DENum, emrat, endDate, JPLEph_NItems, JPLEphemeris(), LabelSize, librationCoeffInfo, JPLEphCoeffInfo::nCoeffs, NConstants, JPLEphCoeffInfo::nGranules, JPLEphCoeffInfo::offset, readDouble(), readUint(), records, recordSize, and startDate.

Referenced by GetCustomOrbit().

00154 {
00155     JPLEphemeris* eph = NULL;
00156 
00157     // Skip past three header labels
00158     in.ignore(LabelSize * 3);
00159     if (!in.good())
00160         return NULL;
00161 
00162     // Skip past the constant names
00163     in.ignore(NConstants * ConstantNameLength);
00164     if (!in.good())
00165         return NULL;
00166 
00167     eph = new JPLEphemeris();
00168     if (eph == NULL)
00169         return NULL;
00170 
00171     // Read the start time, end time, and time interval
00172     eph->startDate = readDouble(in);
00173     eph->endDate = readDouble(in);
00174     eph->daysPerInterval = readDouble(in);
00175     if (!in.good())
00176     {
00177         delete eph;
00178         return NULL;
00179     }
00180 
00181     // Number of constants with valid values; not useful for us
00182     (void) readUint(in);
00183 
00184     eph->au = readDouble(in);     // kilometers per astronomical unit
00185     eph->emrat = readDouble(in);  // ???
00186 
00187     // Read the coefficient information for each item in the ephemeris
00188     unsigned int i;
00189     for (i = 0; i < JPLEph_NItems; i++)
00190     {
00191         eph->coeffInfo[i].offset = readUint(in) - 3;
00192         eph->coeffInfo[i].nCoeffs = readUint(in);
00193         eph->coeffInfo[i].nGranules = readUint(in);
00194     }
00195     if (!in.good())
00196     {
00197         delete eph;
00198         return NULL;
00199     }
00200 
00201     eph->DENum = readUint(in);
00202 
00203     switch (eph->DENum)
00204     {
00205     case 200:
00206         eph->recordSize = DE200RecordSize;
00207         break;
00208     case 405:
00209         eph->recordSize = DE405RecordSize;
00210         break;
00211     case 406:
00212         eph->recordSize = DE406RecordSize;
00213         break;
00214     default:
00215         delete eph;
00216         return NULL;
00217     }
00218 
00219     eph->librationCoeffInfo.offset        = readUint(in);
00220     eph->librationCoeffInfo.nCoeffs       = readUint(in);
00221     eph->librationCoeffInfo.nGranules     = readUint(in);
00222     if (!in.good())
00223     {
00224         delete eph;
00225         return NULL;
00226     }
00227 
00228     // Skip past the rest of the record
00229     in.ignore(eph->recordSize * 8 - 2856);
00230     // The next record contains constant values (which we don't need)
00231     in.ignore(eph->recordSize * 8);
00232     if (!in.good())
00233     {
00234         delete eph;
00235         return NULL;
00236     }
00237 
00238     unsigned int nRecords = (unsigned int) ((eph->endDate - eph->startDate) / 
00239                                             eph->daysPerInterval);
00240     eph->records.resize(nRecords);
00241     for (i = 0; i < nRecords; i++)
00242     {
00243         eph->records[i].t0 = readDouble(in);
00244         eph->records[i].t1 = readDouble(in);
00245 
00246         // Allocate coefficient array for this record; the first two
00247         // 'coefficients' are actually the start and end time (t0 and t1)
00248         eph->records[i].coeffs = new double[eph->recordSize - 2];
00249         for (unsigned int j = 0; j < eph->recordSize - 2; j++)
00250             eph->records[i].coeffs[j] = readDouble(in);
00251 
00252         // Make sure that we read this record successfully
00253         if (!in.good())
00254         {
00255             delete eph;
00256             return NULL;
00257         }
00258     }
00259 
00260     return eph;
00261 }


Member Data Documentation

double JPLEphemeris::au [private]
 

Definition at line 82 of file jpleph.h.

Referenced by load().

JPLEphCoeffInfo JPLEphemeris::coeffInfo[JPLEph_NItems] [private]
 

Definition at line 75 of file jpleph.h.

Referenced by getPlanetPosition(), and load().

double JPLEphemeris::daysPerInterval [private]
 

Definition at line 80 of file jpleph.h.

Referenced by getPlanetPosition(), and load().

unsigned int JPLEphemeris::DENum [private]
 

Definition at line 85 of file jpleph.h.

Referenced by getDENumber(), and load().

double JPLEphemeris::emrat [private]
 

Definition at line 83 of file jpleph.h.

Referenced by load().

double JPLEphemeris::endDate [private]
 

Definition at line 79 of file jpleph.h.

Referenced by getEndDate(), getPlanetPosition(), and load().

JPLEphCoeffInfo JPLEphemeris::librationCoeffInfo [private]
 

Definition at line 76 of file jpleph.h.

Referenced by load().

std::vector<JPLEphRecord> JPLEphemeris::records [private]
 

Definition at line 88 of file jpleph.h.

Referenced by getPlanetPosition(), and load().

unsigned int JPLEphemeris::recordSize [private]
 

Definition at line 86 of file jpleph.h.

Referenced by load().

double JPLEphemeris::startDate [private]
 

Definition at line 78 of file jpleph.h.

Referenced by getPlanetPosition(), getStartDate(), and load().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:23 2006 for Celestia by  doxygen 1.4.1