IERS.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: IERS.cpp 2972 2011-11-10 12:10:39Z yanweignss $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //
00016 //  The GPSTk is distributed in the hope that it will be useful,
00017 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU Lesser General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU Lesser General Public
00022 //  License along with GPSTk; if not, write to the Free Software Foundation,
00023 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //
00025 //  Wei Yan - Chinese Academy of Sciences . 2010
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       // PI
00038    const double IERS::PI = 4.0 * std::atan(1.0);
00039 
00040       // Arcseconds to radius convention 
00041    const double IERS::ARCSEC2RAD =  PI / 180.0 / 3600.0;
00042 
00043    PlanetEphemeris IERS::jplEphemeris;
00044 
00045       // Load the JPL ephemeris from a binary file
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       /* Compute planet position and velocity in J2000
00058        *  
00059        * @param TT         Time(Modified Julian Date in TT<TAI+32.184>) of interest 
00060        * @param entity     The planet to be computed
00061        * @param center     relative to whick the result apply
00062        * @return           The position and velocity of the planet in km and km/s
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          // change the unit to km/s from km/day
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; // km->m
00085          }
00086          else
00087          {
00088             rvJ2k.resize(6,0.0);
00089 
00090             // failed to compute
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 }  // End of namespace 'gpstk'

Generated on Tue May 22 03:30:58 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1