00001 #pragma ident "$Id: IERS.cpp 2972 2011-11-10 12:10:39Z yanweignss $"
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "IERS.hpp"
00030 #include <string>
00031 #include <fstream>
00032 #include <cmath>
00033 #include "Logger.hpp"
00034
00035 namespace gpstk
00036 {
00037
00038 const double IERS::PI = 4.0 * std::atan(1.0);
00039
00040
00041 const double IERS::ARCSEC2RAD = PI / 180.0 / 3600.0;
00042
00043 PlanetEphemeris IERS::jplEphemeris;
00044
00045
00046 void IERS::loadBinaryEphemeris(const std::string ephFile)
00047 throw(Exception)
00048 {
00049 int rc = jplEphemeris.initializeWithBinaryFile(ephFile);
00050 if(rc!=0)
00051 {
00052 Exception e("Failed to load the JPL ephemeris '"+ephFile+"'.");
00053 GPSTK_THROW(e);
00054 }
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064 Vector<double> IERS::planetJ2kPosVel( const DayTime& TT,
00065 PlanetEphemeris::Planet entity,
00066 PlanetEphemeris::Planet center )
00067 throw(Exception)
00068 {
00069 Vector<double> rvJ2k(6,0.0);
00070
00071 try
00072 {
00073 double rvState[6] = {0.0};
00074 int rc = jplEphemeris.computeState(TT.JD(),entity, center, rvState);
00075
00076
00077 rvState[3] /= 86400.0;
00078 rvState[4] /= 86400.0;
00079 rvState[5] /= 86400.0;
00080
00081 if(rc == 0)
00082 {
00083 rvJ2k = rvState;
00084 return rvJ2k*1000.0;
00085 }
00086 else
00087 {
00088 rvJ2k.resize(6,0.0);
00089
00090
00091 InvalidRequest e("Failed to compute, error code: "
00092 +StringUtils::asString(rc)+" with meaning\n"
00093 +"-1 and -2 given time is out of the file \n"
00094 +"-3 and -4 input stream is not open or not valid,"
00095 +" or EOF was found prematurely");
00096
00097 GPSTK_THROW(e);
00098 }
00099 }
00100 catch(...)
00101 {
00102 Exception e("Failed to compute positon and velocity from JPL ephemeris.");
00103 GPSTK_THROW(e);
00104 }
00105
00106 return rvJ2k;
00107 }
00108
00109 Vector<double> IERS::sunJ2kPosition(const DayTime& TT)
00110 {
00111 Vector<double> pos(3,0.0);
00112 try
00113 {
00114 Vector<double> posvel = planetJ2kPosVel(TT,PlanetEphemeris::Sun);
00115 for(int i=0;i<3;i++) pos(i) = posvel(i);
00116 return pos;
00117 }
00118 catch(...)
00119 {
00120 return gpstk::sunJ2kPosition(TT);
00121 }
00122 }
00123
00124 Vector<double> IERS::moonJ2kPosition(const DayTime& TT)
00125 {
00126 Vector<double> pos(3,0.0);
00127 try
00128 {
00129 Vector<double> posvel = planetJ2kPosVel(TT,PlanetEphemeris::Moon);
00130 for(int i=0;i<3;i++) pos(i) = posvel(i);
00131 return pos;
00132 }
00133 catch(...)
00134 {
00135 return gpstk::moonJ2kPosition(TT);
00136 }
00137 }
00138
00139 Vector<double> IERS::sunECEFPosition(const DayTime& TT)
00140 {
00141 return J2kPosToECEF( GPST2UTC(TT), sunJ2kPosition(TT) );
00142 }
00143
00144 Vector<double> IERS::moonECEFPosition(const DayTime& TT)
00145 {
00146 return J2kPosToECEF( GPST2UTC(TT), moonJ2kPosition(TT) );
00147 }
00148
00149 }