SolarSystemEphemeris.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
49 //------------------------------------------------------------------------------------
50 #ifndef SOLAR_SYSTEM_EPHEMERIS_INCLUDE
51 #define SOLAR_SYSTEM_EPHEMERIS_INCLUDE
52 
53 //------------------------------------------------------------------------------------
54 // includes
55 // system
56 #include <fstream>
57 #include <iostream>
58 #include <map>
59 #include <string>
60 #include <vector>
61 // GNSSTk
62 #include "Exception.hpp"
63 #include "TimeConstants.hpp"
64 
65 namespace gnsstk
66 {
67 
68  //---------------------------------------------------------------------------------
97  {
98  public:
101  {
102  retOK = 0,
103  retEarly = -1,
104  retLate = -2,
105  retStrm = -3,
106  retEphN = -4
107  };
108 
110  enum Planet
111  {
112  // the following are relative to the solar system barycenter, except
113  // MOON
114  idNone = 0,
130  };
131 
137 
138  //------------------------------------------------------------------
139  // reading and writing ASCII (JPL) files
140 
151  void readASCIIheader(const std::string& filename);
152 
169  int readASCIIdata(std::vector<std::string>& filenames);
170 
181  int readASCIIdata(const std::string& filename);
182 
189  int writeASCIIheader(std::ostream& os);
190 
198  int writeASCIIdata(std::ostream& os);
199 
200  //------------------------------------------------------------------
201  // reading and writing binary files
202 
211  int writeBinaryFile(const std::string& filename);
212 
217  void clearStorage() { store.clear(); }
218 
229  int readBinaryFile(const std::string& filename);
230 
241  int initializeWithBinaryFile(const std::string& filename);
242 
243  //------------------------------------------------------------------
244  // utilizing the ephemeris
245 
279  void relativeInertialPositionVelocity(double MJD, Planet target,
280  Planet center, double PV[6],
281  bool kilometers = true);
282 
289  double AU()
290  {
291  if (EphemerisNumber == -1)
292  {
293  return -1.0;
294  }
295  return constants["AU"];
296  }
297 
303  int EphNumber() const { return EphemerisNumber; }
304 
310  double getConstant(const std::string& name)
311  {
312  if (EphemerisNumber == -1)
313  {
314  return -1.0;
315  }
316  if (constants.find(name) != constants.end())
317  {
318  return constants[name];
319  }
320  return 0.0;
321  }
322 
325  {
326  return getConstant(std::string("EMRAT"));
327  }
328 
331  {
332  double em = getConstant(std::string("EMRAT"));
333  double gms = getConstant(std::string("GMS"));
334  double gmb = getConstant(std::string("GMB"));
335  return (gms * ((1.0 + em) / em) / gmb);
336  }
337 
339  double startTimeMJD() const { return (startJD - MJD_TO_JD); }
340 
342  double endTimeMJD() const { return (endJD - MJD_TO_JD); }
343 
344  //------------------------------------------------------------------
345  // private functions
346 
347  private:
352  void writeBinary(std::ofstream& strm, const char *ptr, size_t size);
353 
358  void readBinary(char *ptr, size_t size);
359 
365  void readBinaryHeader(const std::string& filename);
366 
377  int readBinaryData(bool save);
378 
388  int readBinaryRecord(std::vector<double>& data_vector);
389 
403  int seekToJD(double JD);
404 
405  //------------------------------------------------------------------
406  // define here for use in next function
413  {
414  // the following are relative to the solar system barycenter, except
415  // MOON
416  NONE = -1,
427  SUN,
430  };
431 
447  void inertialPositionVelocity(double MJD, computeID which, double PV[6]);
448 
449  //------------------------------------------------------------------
450  // member data
451 
452  // input stream, for use by readBinary...()
453  std::ifstream istrm;
454 
455  // header information
456 
457  // protected so it can be used by class SolarSystem
465 
470  int Ncoeff;
471 
472  int Nconst;
473  std::string label[3];
474  double startJD;
475  double endJD;
476  double interval;
477  int c_offset[13];
478  int
480  c_ncoeff[13];
481  int c_nsets[13];
482 
512  std::map<std::string, double> constants;
513 
520  std::map<double, std::vector<double>> store;
521 
527  std::map<double, long> fileposMap;
528 
534  std::vector<double> coefficients;
535 
536  }; // end class SolarSystemEphemeris
537 
538 } // end namespace gnsstk
539 
540 #endif // SOLAR_SYSTEM_EPHEMERIS_INCLUDE
541 // nothing below this
gnsstk::SolarSystemEphemeris::endTimeMJD
double endTimeMJD() const
Return the MJD of end time of the data (system TDB)
Definition: SolarSystemEphemeris.hpp:342
TimeConstants.hpp
gnsstk::SolarSystemEphemeris::c_ncoeff
int c_ncoeff[13]
number of coefficients per component for each planet
Definition: SolarSystemEphemeris.hpp:480
gnsstk::SolarSystemEphemeris::coefficients
std::vector< double > coefficients
Definition: SolarSystemEphemeris.hpp:534
gnsstk::SolarSystemEphemeris::inertialPositionVelocity
void inertialPositionVelocity(double MJD, computeID which, double PV[6])
Definition: SolarSystemEphemeris.cpp:1563
gnsstk::SolarSystemEphemeris::label
std::string label[3]
lines under group 1010
Definition: SolarSystemEphemeris.hpp:473
gnsstk::SolarSystemEphemeris::readBinaryFile
int readBinaryFile(const std::string &filename)
Definition: SolarSystemEphemeris.cpp:844
gnsstk::SolarSystemEphemeris::initializeWithBinaryFile
int initializeWithBinaryFile(const std::string &filename)
Definition: SolarSystemEphemeris.cpp:874
gnsstk::SolarSystemEphemeris::SATURN
@ SATURN
5 Saturn
Definition: SolarSystemEphemeris.hpp:422
gnsstk::SolarSystemEphemeris::readBinaryRecord
int readBinaryRecord(std::vector< double > &data_vector)
Definition: SolarSystemEphemeris.cpp:1427
gnsstk::SolarSystemEphemeris::idPluto
@ idPluto
9 Pluto
Definition: SolarSystemEphemeris.hpp:123
gnsstk::SolarSystemEphemeris::readBinaryHeader
void readBinaryHeader(const std::string &filename)
Definition: SolarSystemEphemeris.cpp:1160
gnsstk::StringUtils::center
std::string & center(std::string &s, const std::string::size_type length, const char pad=' ')
Definition: StringUtils.hpp:1607
gnsstk::SolarSystemEphemeris::retLate
@ retLate
-2 out of range : input time is after last time in file
Definition: SolarSystemEphemeris.hpp:104
gnsstk::SolarSystemEphemeris::idSaturn
@ idSaturn
6 Saturn
Definition: SolarSystemEphemeris.hpp:120
gnsstk::SolarSystemEphemeris::istrm
std::ifstream istrm
input stream for binary files
Definition: SolarSystemEphemeris.hpp:453
gnsstk::SolarSystemEphemeris::idEarthMoonBarycenter
@ idEarthMoonBarycenter
13 Earth-moon barycenter
Definition: SolarSystemEphemeris.hpp:127
gnsstk::SolarSystemEphemeris::idSolarSystemBarycenter
@ idSolarSystemBarycenter
12 Solar system barycenter
Definition: SolarSystemEphemeris.hpp:126
gnsstk::SolarSystemEphemeris::idUranus
@ idUranus
7 Uranus
Definition: SolarSystemEphemeris.hpp:121
gnsstk::SolarSystemEphemeris::idVenus
@ idVenus
2 Venus
Definition: SolarSystemEphemeris.hpp:116
gnsstk::SolarSystemEphemeris::writeBinary
void writeBinary(std::ofstream &strm, const char *ptr, size_t size)
Definition: SolarSystemEphemeris.cpp:1101
gnsstk::SolarSystemEphemeris::computeID
computeID
Definition: SolarSystemEphemeris.hpp:412
gnsstk::SolarSystemEphemeris::interval
double interval
number of days covered by each block of coeff.s
Definition: SolarSystemEphemeris.hpp:476
gnsstk::SolarSystemEphemeris::ReturnValue
ReturnValue
Return values.
Definition: SolarSystemEphemeris.hpp:100
gnsstk::SolarSystemEphemeris::store
std::map< double, std::vector< double > > store
Definition: SolarSystemEphemeris.hpp:520
gnsstk::SolarSystemEphemeris::MARS
@ MARS
3 Mars
Definition: SolarSystemEphemeris.hpp:420
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::SolarSystemEphemeris::getConstant
double getConstant(const std::string &name)
Definition: SolarSystemEphemeris.hpp:310
gnsstk::SolarSystemEphemeris::EphemerisNumber
int EphemerisNumber
Definition: SolarSystemEphemeris.hpp:464
gnsstk::SolarSystemEphemeris::idMars
@ idMars
4 Mars
Definition: SolarSystemEphemeris.hpp:118
gnsstk::SolarSystemEphemeris::EphNumber
int EphNumber() const
Definition: SolarSystemEphemeris.hpp:303
gnsstk::MJD_TO_JD
const double MJD_TO_JD
Add this offset to convert Modified Julian Date to Julian Date.
Definition: TimeConstants.hpp:51
gnsstk::SolarSystemEphemeris::idNeptune
@ idNeptune
8 Neptune
Definition: SolarSystemEphemeris.hpp:122
gnsstk::SolarSystemEphemeris::SUN
@ SUN
10 Sun
Definition: SolarSystemEphemeris.hpp:427
gnsstk::SolarSystemEphemeris::fileposMap
std::map< double, long > fileposMap
Definition: SolarSystemEphemeris.hpp:527
gnsstk::SolarSystemEphemeris::writeASCIIdata
int writeASCIIdata(std::ostream &os)
Definition: SolarSystemEphemeris.cpp:625
gnsstk::SolarSystemEphemeris::retEphN
@ retEphN
-4 EphemerisNumber is not defined
Definition: SolarSystemEphemeris.hpp:106
gnsstk::SolarSystemEphemeris::readASCIIheader
void readASCIIheader(const std::string &filename)
Definition: SolarSystemEphemeris.cpp:86
gnsstk::SolarSystemEphemeris::Ncoeff
int Ncoeff
Definition: SolarSystemEphemeris.hpp:470
gnsstk::SolarSystemEphemeris::Planet
Planet
These are indexes used by the caller of inertialPositionVelocity().
Definition: SolarSystemEphemeris.hpp:110
gnsstk::SolarSystemEphemeris::URANUS
@ URANUS
6 Uranus
Definition: SolarSystemEphemeris.hpp:423
gnsstk::SolarSystemEphemeris::Nconst
int Nconst
number of constants in the header (see map constants)
Definition: SolarSystemEphemeris.hpp:472
gnsstk::SolarSystemEphemeris::retOK
@ retOK
0 ok
Definition: SolarSystemEphemeris.hpp:102
gnsstk::SolarSystemEphemeris::NUTATIONS
@ NUTATIONS
11 Nutations (psi, epsilon and their rates)
Definition: SolarSystemEphemeris.hpp:428
gnsstk::SolarSystemEphemeris::c_offset
int c_offset[13]
Definition: SolarSystemEphemeris.hpp:477
gnsstk::SolarSystemEphemeris::MOON
@ MOON
9 Moon (Geocentric coordinates)
Definition: SolarSystemEphemeris.hpp:426
gnsstk::SolarSystemEphemeris
Definition: SolarSystemEphemeris.hpp:96
gnsstk::SolarSystemEphemeris::idMoon
@ idMoon
10 Moon (Geocentric coordinates)
Definition: SolarSystemEphemeris.hpp:124
gnsstk::SolarSystemEphemeris::PLUTO
@ PLUTO
8 Pluto
Definition: SolarSystemEphemeris.hpp:425
gnsstk::SolarSystemEphemeris::c_nsets
int c_nsets[13]
number of sets of coefficients for each planet
Definition: SolarSystemEphemeris.hpp:481
gnsstk::SolarSystemEphemeris::writeBinaryFile
int writeBinaryFile(const std::string &filename)
Definition: SolarSystemEphemeris.cpp:689
gnsstk::SolarSystemEphemeris::idLibrations
@ idLibrations
15 Lunar Librations (3 euler angles)
Definition: SolarSystemEphemeris.hpp:129
gnsstk::SolarSystemEphemeris::retEarly
@ retEarly
-1 out of range : input time is before first time in file
Definition: SolarSystemEphemeris.hpp:103
gnsstk::SolarSystemEphemeris::VENUS
@ VENUS
1 Venus
Definition: SolarSystemEphemeris.hpp:418
gnsstk::SolarSystemEphemeris::ratioEarthToMoonMass
double ratioEarthToMoonMass()
Return the Earth-to-Moon mass ratio.
Definition: SolarSystemEphemeris.hpp:324
gnsstk::SolarSystemEphemeris::EMBARY
@ EMBARY
2 Earth-Moon barycenter
Definition: SolarSystemEphemeris.hpp:419
gnsstk::SolarSystemEphemeris::retStrm
@ retStrm
-3 stream is not open and good, or EOF found prematurely
Definition: SolarSystemEphemeris.hpp:105
gnsstk::SolarSystemEphemeris::relativeInertialPositionVelocity
void relativeInertialPositionVelocity(double MJD, Planet target, Planet center, double PV[6], bool kilometers=true)
Definition: SolarSystemEphemeris.cpp:916
gnsstk::SolarSystemEphemeris::JUPITER
@ JUPITER
4 Jupiter
Definition: SolarSystemEphemeris.hpp:421
gnsstk::SolarSystemEphemeris::startTimeMJD
double startTimeMJD() const
Return the MJD of start time of the data (system TDB)
Definition: SolarSystemEphemeris.hpp:339
gnsstk::SolarSystemEphemeris::idNone
@ idNone
0 place holder
Definition: SolarSystemEphemeris.hpp:114
gnsstk::SolarSystemEphemeris::NEPTUNE
@ NEPTUNE
7 Neptune
Definition: SolarSystemEphemeris.hpp:424
Exception.hpp
gnsstk::SolarSystemEphemeris::idSun
@ idSun
11 Sun
Definition: SolarSystemEphemeris.hpp:125
gnsstk::SolarSystemEphemeris::readBinary
void readBinary(char *ptr, size_t size)
Definition: SolarSystemEphemeris.cpp:1131
gnsstk::SolarSystemEphemeris::seekToJD
int seekToJD(double JD)
Definition: SolarSystemEphemeris.cpp:1489
gnsstk::SolarSystemEphemeris::writeASCIIheader
int writeASCIIheader(std::ostream &os)
Definition: SolarSystemEphemeris.cpp:499
gnsstk::SolarSystemEphemeris::MERCURY
@ MERCURY
0 Mercury
Definition: SolarSystemEphemeris.hpp:417
gnsstk::SolarSystemEphemeris::ratioSunToEarthMass
double ratioSunToEarthMass()
Return the Sun-to-Earth mass ratio.
Definition: SolarSystemEphemeris.hpp:330
gnsstk::MJD
Definition: MJD.hpp:54
gnsstk::SolarSystemEphemeris::NONE
@ NONE
-1 Place holder
Definition: SolarSystemEphemeris.hpp:416
gnsstk::SolarSystemEphemeris::clearStorage
void clearStorage()
Definition: SolarSystemEphemeris.hpp:217
gnsstk::SolarSystemEphemeris::SolarSystemEphemeris
SolarSystemEphemeris()
Definition: SolarSystemEphemeris.hpp:136
gnsstk::SolarSystemEphemeris::constants
std::map< std::string, double > constants
Definition: SolarSystemEphemeris.hpp:512
gnsstk::SolarSystemEphemeris::idJupiter
@ idJupiter
5 Jupiter
Definition: SolarSystemEphemeris.hpp:119
gnsstk::SolarSystemEphemeris::readASCIIdata
int readASCIIdata(std::vector< std::string > &filenames)
gnsstk::SolarSystemEphemeris::endJD
double endJD
JD of the end of the last record in the file.
Definition: SolarSystemEphemeris.hpp:475
gnsstk::SolarSystemEphemeris::LIBRATIONS
@ LIBRATIONS
12 Lunar Librations (3 euler angles)
Definition: SolarSystemEphemeris.hpp:429
gnsstk::SolarSystemEphemeris::readBinaryData
int readBinaryData(bool save)
Definition: SolarSystemEphemeris.cpp:1340
gnsstk::SolarSystemEphemeris::startJD
double startJD
JD of the start of the first record in the file.
Definition: SolarSystemEphemeris.hpp:474
gnsstk::SolarSystemEphemeris::AU
double AU()
Definition: SolarSystemEphemeris.hpp:289
gnsstk::SolarSystemEphemeris::idMercury
@ idMercury
1 Mercury
Definition: SolarSystemEphemeris.hpp:115
gnsstk::SolarSystemEphemeris::idEarth
@ idEarth
3 Earth
Definition: SolarSystemEphemeris.hpp:117
gnsstk::SolarSystemEphemeris::idNutations
@ idNutations
14 Nutations (psi, epsilon and rates)
Definition: SolarSystemEphemeris.hpp:128


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:41