COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
Collaboration diagram for Coordinate conversion functions:

Namespaces

 Cosmos
 

Functions

int32_t loc_clear (locstruc *loc)
 Initialize locstruc. More...
 
int32_t loc_clear (locstruc &loc)
 
int32_t pos_clear (locstruc *loc)
 Initialize posstruc. More...
 
int32_t pos_clear (locstruc &loc)
 
int32_t att_clear (attstruc &att)
 Initialize attstruc. More...
 
int32_t pos_extra (locstruc *loc)
 Calculate Extra position information. More...
 
int32_t pos_extra (locstruc &loc)
 
int32_t pos_icrf (locstruc *loc)
 Set Barycentric position. More...
 
int32_t pos_icrf (locstruc &loc)
 
int32_t pos_eci (locstruc *loc)
 Set ECI position. More...
 
int32_t pos_eci (locstruc &loc)
 
int32_t pos_sci (locstruc *loc)
 Set SCI position. More...
 
int32_t pos_sci (locstruc &loc)
 
int32_t pos_geoc (locstruc *loc)
 Set Geocentric position. More...
 
int32_t pos_geoc (locstruc &loc)
 
int32_t pos_selc (locstruc *loc)
 Set Selenocentric position. More...
 
int32_t pos_selc (locstruc &loc)
 
int32_t pos_selg (locstruc *loc)
 Set Selenographic position. More...
 
int32_t pos_selg (locstruc &loc)
 
int32_t pos_geos (locstruc *loc)
 Set Geographic position. More...
 
int32_t pos_geos (locstruc &loc)
 
int32_t pos_geod (locstruc *loc)
 Set Geodetic position. More...
 
int32_t pos_geod (locstruc &loc)
 
int32_t pos_icrf2eci (locstruc *loc)
 Convert Barycentric to ECI. More...
 
int32_t pos_icrf2eci (locstruc &loc)
 
int32_t pos_eci2icrf (locstruc *loc)
 Convert ECI to Barycentric. More...
 
int32_t pos_eci2icrf (locstruc &loc)
 
int32_t pos_icrf2sci (locstruc *loc)
 Convert Barycentric to SCI. More...
 
int32_t pos_icrf2sci (locstruc &loc)
 
int32_t pos_sci2icrf (locstruc *loc)
 Convert SCI to Barycentric. More...
 
int32_t pos_sci2icrf (locstruc &loc)
 
int32_t pos_eci2geoc (locstruc *loc)
 Convert ECI to GEOC. More...
 
int32_t pos_eci2geoc (locstruc &loc)
 
int32_t pos_geoc2eci (locstruc *loc)
 Convert GEOC to ECI. More...
 
int32_t pos_geoc2eci (locstruc &loc)
 
int32_t pos_geoc2geos (locstruc *loc)
 Convert GEOC to GEOS. More...
 
int32_t pos_geoc2geos (locstruc &loc)
 
int32_t pos_geos2geoc (locstruc *loc)
 Convert GEOS to GEOC. More...
 
int32_t pos_geos2geoc (locstruc &loc)
 
int32_t geoc2geod (cartpos &geoc, geoidpos &geod)
 Convert GEOC to GEOD. More...
 
int32_t pos_geoc2geod (locstruc *loc)
 Update locstruc GEOC to GEOD. More...
 
int32_t pos_geoc2geod (locstruc &loc)
 
int32_t geod2geoc (geoidpos &geod, cartpos &geoc)
 Convert GEOD to GEOC. More...
 
int32_t pos_geod2geoc (locstruc *loc)
 Update GEOD to GEOC in locstruc. More...
 
int32_t pos_geod2geoc (locstruc &loc)
 
int32_t pos_sci2selc (locstruc *loc)
 Convert SCI to SELC. More...
 
int32_t pos_sci2selc (locstruc &loc)
 
int32_t pos_selc2sci (locstruc *loc)
 Convert SELC to SCI. More...
 
int32_t pos_selc2sci (locstruc &loc)
 
int32_t pos_selc2selg (locstruc *loc)
 Convert SELC to SELG. More...
 
int32_t pos_selc2selg (locstruc &loc)
 
int32_t pos_selg2selc (locstruc *loc)
 
int32_t pos_selg2selc (locstruc &loc)
 
double rearth (double lat)
 
int32_t att_extra (locstruc *loc)
 Calculate Extra attitude information. More...
 
int32_t att_extra (locstruc &loc)
 
int32_t att_icrf2geoc (locstruc *loc)
 
int32_t att_icrf2geoc (locstruc &loc)
 
int32_t att_geoc2icrf (locstruc *loc)
 
int32_t att_geoc2icrf (locstruc &loc)
 
int32_t att_geoc (locstruc *loc)
 
int32_t att_geoc (locstruc &loc)
 
int32_t att_icrf2selc (locstruc *loc)
 
int32_t att_icrf2selc (locstruc &loc)
 
int32_t att_selc2icrf (locstruc *loc)
 
int32_t att_selc2icrf (locstruc &loc)
 
int32_t att_selc (locstruc *loc)
 
int32_t att_selc (locstruc &loc)
 
int32_t att_icrf2lvlh (locstruc *loc)
 
int32_t att_icrf2lvlh (locstruc &loc)
 
int32_t att_icrf (locstruc *loc)
 
int32_t att_icrf (locstruc &loc)
 
int32_t att_planec2lvlh (locstruc *loc)
 Convert ITRS attitude to LVLH attitude. More...
 
int32_t att_planec2lvlh (locstruc &loc)
 
int32_t att_lvlh2planec (locstruc *loc)
 Convert LVLH attitude to ITRS attitude. More...
 
int32_t att_lvlh2planec (locstruc &loc)
 
int32_t att_lvlh2icrf (locstruc *loc)
 Convert LVLH attitude to ICRF attitude. More...
 
int32_t att_lvlh2icrf (locstruc &loc)
 
int32_t att_lvlh (locstruc *loc)
 
int32_t att_lvlh (locstruc &loc)
 
int32_t att_planec2topo (locstruc *loc)
 Planetocentric to Topo attitude. More...
 
int32_t att_planec2topo (locstruc &loc)
 
int32_t att_topo2planec (locstruc *loc)
 Topocentric to Planetocentric attitude. More...
 
int32_t att_topo2planec (locstruc &loc)
 
int32_t att_topo (locstruc *loc)
 
int32_t att_topo (locstruc &loc)
 
int32_t loc_update (locstruc *loc)
 Synchronize all frames in location structure. More...
 
int32_t loc_update (locstruc &loc)
 
int32_t teme2true (double ep0, rmatrix *rm)
 
int32_t true2teme (double ep0, rmatrix *rm)
 
int32_t true2pef (double utc, rmatrix *rm)
 
int32_t pef2true (double utc, rmatrix *rm)
 
int32_t pef2itrs (double utc, rmatrix *rm)
 
int32_t itrs2pef (double utc, rmatrix *rm)
 
int32_t mean2true (double ep0, rmatrix *pm)
 Rotate Mean of Epoch to True of Epoch. More...
 
int32_t true2mean (double ep0, rmatrix *pm)
 Rotate True of Epoch to Mean of Epoch. More...
 
int32_t mean2j2000 (double ep0, rmatrix *pm)
 Rotate Mean of Epoch to J2000. More...
 
int32_t itrs2gcrf (double utc, rmatrix *rnp, rmatrix *rm, rmatrix *drm, rmatrix *ddrm)
 ITRS to J2000 rotation matrix. More...
 
int32_t gcrf2itrs (double utc, rmatrix *rnp, rmatrix *rm, rmatrix *drm, rmatrix *ddrm)
 J2000 to ITRS rotation matrix. More...
 
int32_t j20002mean (double ep1, rmatrix *pm)
 
int32_t gcrf2j2000 (rmatrix *rm)
 
int32_t j20002gcrf (rmatrix *rm)
 
int32_t mean2mean (double ep0, double ep1, rmatrix *pm)
 
int32_t kep2eci (kepstruc &kep, cartpos &eci)
 
int32_t eci2kep (cartpos &eci, kepstruc &kep)
 
int32_t geoc2topo (gvector source, rvector targetgeoc, rvector &topo)
 Geocentric to Topocentric. More...
 
int32_t body2topo (Vector source, Vector target, Vector &topo)
 Body Centric to Topocentric. More...
 
int32_t topo2azel (rvector tpos, float &az, float &el)
 
int32_t topo2azel (Vector tpos, float &az, float &el)
 
int lines2eci (double utc, vector< tlestruc >lines, cartpos &eci)
 Return position from TLE set. More...
 
int sgp4 (double utc, tlestruc tle, cartpos &pos_teme)
 
int32_t eci2tle (double utc, cartpos eci, tlestruc &tle)
 TLE from ECI. More...
 
int tle2eci (double utc, tlestruc tle, cartpos &eci)
 
tlestruc get_line (uint16_t index, vector< tlestruc > lines)
 Get TLE from array of TLE's. More...
 
int32_t loadTLE (char *fname, tlestruc &tle)
 Load TLE from file. TODO!!! create new class for dealing with TLEs. More...
 
int32_t load_lines (string fname, vector< tlestruc > &lines)
 Load TLE from file. TODO!!! Rename Function to loadTle and create new class for dealing with TLEs. More...
 
int32_t load_lines_multi (string fname, vector< tlestruc > &lines)
 
int32_t load_stk (string filename, stkstruc &stkdata)
 Load STK elements. More...
 
int stk2eci (double utc, stkstruc &stk, cartpos &eci)
 ECI from STK data. More...
 
std::ostream & operator<< (std::ostream &out, const cartpos &a)
 
std::istream & operator>> (std::istream &in, cartpos &a)
 
std::ostream & operator<< (std::ostream &out, const cposstruc &a)
 
std::istream & operator>> (std::istream &in, cposstruc &a)
 
std::ostream & operator<< (std::ostream &out, const geoidpos &a)
 
std::istream & operator>> (std::istream &in, geoidpos &a)
 
std::ostream & operator<< (std::ostream &out, const spherpos &a)
 
std::istream & operator>> (std::istream &in, spherpos &a)
 
std::ostream & operator<< (std::ostream &out, const aattstruc &a)
 
std::istream & operator>> (std::istream &in, aattstruc &a)
 
std::ostream & operator<< (std::ostream &out, const quatatt &a)
 
std::istream & operator>> (std::istream &in, quatatt &a)
 
std::ostream & operator<< (std::ostream &out, const dcmatt &a)
 
std::istream & operator>> (std::istream &in, dcmatt &a)
 
std::ostream & operator<< (std::ostream &out, const qatt &a)
 
std::istream & operator>> (std::istream &in, qatt &a)
 
std::ostream & operator<< (std::ostream &out, const kepstruc &a)
 
std::istream & operator>> (std::istream &in, kepstruc &a)
 
std::ostream & operator<< (std::ostream &out, const bodypos &a)
 
std::istream & operator<< (std::istream &in, bodypos &a)
 
std::ostream & operator<< (std::ostream &out, const extrapos &a)
 
std::istream & operator>> (std::istream &in, extrapos &a)
 
std::ostream & operator<< (std::ostream &out, const extraatt &a)
 
std::istream & operator>> (std::istream &in, extraatt &a)
 
std::ostream & operator<< (std::ostream &out, const posstruc &a)
 
std::istream & operator>> (std::istream &in, posstruc &a)
 
std::ostream & operator<< (std::ostream &out, const attstruc &a)
 
std::istream & operator>> (std::istream &in, attstruc &a)
 
std::ostream & operator<< (std::ostream &out, const locstruc &a)
 
std::istream & operator>> (std::istream &in, locstruc &a)
 
int32_t pos_eci2selc (locstruc *loc)
 
int32_t pos_eci2sci (locstruc *loc)
 
int32_t pos_sci2eci (locstruc *loc)
 
int32_t pos_selc2eci (locstruc *loc)
 
int32_t pos_eci2selc (locstruc &loc)
 
int32_t pos_eci2sci (locstruc &loc)
 
int32_t pos_sci2eci (locstruc &loc)
 
int32_t pos_selc2eci (locstruc &loc)
 
double mjd2year (double mjd)
 Year from MJD. More...
 
double mjd2gmst (double mjd)
 
int32_t geos2geoc (spherpos *geos, cartpos *geoc)
 
int32_t geoc2geos (cartpos *geoc, spherpos *geos)
 
int32_t selg2selc (geoidpos *selg, cartpos *selc)
 
int32_t tle2sgp4 (tlestruc tle, sgp4struc &sgp4)
 
int32_t sgp42tle (sgp4struc sgp4, tlestruc &tle)
 
int tle_checksum (char *line)
 
int32_t eci2tlestring (cartpos eci, string &tle, std::string ref_tle, double bstar=0)
 

Detailed Description

Function Documentation

int32_t loc_clear ( locstruc loc)

Initialize locstruc.

Set entire structure to zero so that we can properly propagate changes.

Parameters
locPointer to locstruc that contains positions. attitudes.
59 {
60  int32_t iretn;
61  iretn = loc_clear(*loc);
62  return iretn;
63 }
int iretn
Definition: rw_test.cpp:37
int32_t loc_clear(locstruc *loc)
Initialize locstruc.
Definition: convertlib.cpp:58
int32_t loc_clear ( locstruc loc)
66 {
67  memset(static_cast<void *>(&loc), 0, sizeof(locstruc));
68  return 0;
69 }
Definition: convertdef.h:876
int32_t pos_clear ( locstruc loc)

Initialize posstruc.

Set entire structure to zero so that we can properly propagate changes.

Parameters
locPointer to locstruc that contains positions. attitudes.
78 {
79  int32_t iretn;
80  iretn = pos_clear(*loc);
81  return iretn;
82 }
int iretn
Definition: rw_test.cpp:37
int32_t pos_clear(locstruc *loc)
Initialize posstruc.
Definition: convertlib.cpp:77
int32_t pos_clear ( locstruc loc)
85 {
86  memset(static_cast<void *>(&loc.pos), 0, sizeof(posstruc));
87  att_clear(loc.att);
88  return 0;
89 }
Definition: convertdef.h:733
attstruc att
attstruc for this time.
Definition: convertdef.h:883
int32_t att_clear(attstruc &att)
Initialize attstruc.
Definition: convertlib.cpp:96
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
int32_t att_clear ( attstruc att)

Initialize attstruc.

Set entire structure to zero so that we can properly propagate changes.

Parameters
attPointer to attstruc that contains attitudes.
97 {
98  memset(static_cast<void *>(&att), 0, sizeof(attstruc));
99  return 0;
100 }
Definition: convertdef.h:823
int32_t pos_extra ( locstruc loc)

Calculate Extra position information.

Calculate things like sun position and insolation, and elements that are used in conversion, like libration and J2000 rotation matrices.

Parameters
loclocstruc with the current position and those to be updated.
108 {
109  return pos_extra(*loc);
110 }
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
int32_t pos_extra ( locstruc loc)
113 {
114  // Don't perform if time is invalid
115  if (!std::isfinite(loc.utc))
116  {
117  return CONVERT_ERROR_UTC;
118  }
119 
120  // These are all based on time, so they don't need to be repeated if time hasn't changed.
121  if (loc.pos.extra.utc == loc.utc)
122  {
123  return 0;
124  }
125 
126  double tt = utc2tt(loc.utc);
127  if (tt <= 0.)
128  {
129  return static_cast <int32_t>(tt);
130  }
131  loc.pos.extra.tt = tt;
132 
133  loc.pos.extra.utc = loc.utc;
134  loc.pos.extra.tdb = utc2tdb(loc.utc);
135  loc.pos.extra.ut = utc2ut1(loc.utc);
136 
137  gcrf2itrs(loc.utc,&loc.pos.extra.j2t,&loc.pos.extra.j2e,&loc.pos.extra.dj2e,&loc.pos.extra.ddj2e);
138  loc.pos.extra.t2j = rm_transpose(loc.pos.extra.j2t);
139  loc.pos.extra.e2j = rm_transpose(loc.pos.extra.j2e);
140  loc.pos.extra.de2j = rm_transpose(loc.pos.extra.dj2e);
142 
143  jpllib(loc.utc,&loc.pos.extra.s2t,&loc.pos.extra.ds2t);
144  loc.pos.extra.t2s = rm_transpose(loc.pos.extra.s2t);
145  loc.pos.extra.dt2s = rm_transpose(loc.pos.extra.ds2t);
146 
147  loc.pos.extra.j2s = rm_mmult(loc.pos.extra.t2s,loc.pos.extra.j2t);
148  loc.pos.extra.s2j = rm_transpose(loc.pos.extra.j2s);
149 
150 
153 
154  return 0;
155 }
double utc2tdb(double mjd)
Convert UTC to TDB.
Definition: timelib.cpp:826
int32_t jpllib(double utc, rmatrix *rm, rmatrix *drm)
Librations from JPL Ephemeris.
Definition: ephemlib.cpp:54
cartpos sun2earth
Definition: convertdef.h:605
rmatrix j2s
Definition: convertdef.h:598
#define JPL_SUN_BARY
Definition: convertdef.h:121
rmatrix dt2s
Definition: convertdef.h:604
rmatrix ddj2e
Definition: convertdef.h:592
rmatrix ds2t
Definition: convertdef.h:602
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
int32_t gcrf2itrs(double utc, rmatrix *rnp, rmatrix *rm, rmatrix *drm, rmatrix *ddrm)
J2000 to ITRS rotation matrix.
Definition: convertlib.cpp:2659
double tt
Terrestrial Time.
Definition: convertdef.h:584
double utc
Coordinated Universal Time.
Definition: convertdef.h:582
cartpos sun2moon
Definition: convertdef.h:606
rmatrix t2s
Definition: convertdef.h:603
#define JPL_MOON
Definition: convertdef.h:119
rmatrix s2j
Definition: convertdef.h:600
rmatrix de2j
Definition: convertdef.h:595
double tdb
Dynamical Barycentric Time.
Definition: convertdef.h:588
rmatrix dde2j
Definition: convertdef.h:596
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
rmatrix t2j
Definition: convertdef.h:599
#define JPL_EARTH
Definition: convertdef.h:112
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
rmatrix rm_transpose(rmatrix a)
rmatrix Transpose. Calculate the transpose of the supplied rmatrix.
Definition: matrix.cpp:172
rmatrix rm_mmult(rmatrix a, rmatrix b)
rmatrix Matrix Product
Definition: matrix.cpp:198
rmatrix dj2e
Definition: convertdef.h:591
int32_t jplpos(long from, long to, double utc, cartpos *pos)
Position from JPL Ephemeris.
Definition: ephemlib.cpp:128
rmatrix e2j
Transform from Geocentric to ICRF.
Definition: convertdef.h:594
double utc2ut1(double mjd)
Convert UTC to UT1.
Definition: timelib.cpp:792
rmatrix s2t
Definition: convertdef.h:601
double ut
UT0.
Definition: convertdef.h:586
rmatrix j2t
Definition: convertdef.h:597
rmatrix j2e
Transform from ICRF to Geocentric.
Definition: convertdef.h:590
double utc2tt(double mjd)
Convert UTC to TT.
Definition: timelib.cpp:884
int32_t pos_icrf ( locstruc loc)

Set Barycentric position.

Set the current time and position to whatever is in the Barycentric position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
163 {
164  return pos_icrf(*loc);
165 }
int32_t pos_icrf(locstruc *loc)
Set Barycentric position.
Definition: convertlib.cpp:162
int32_t pos_icrf ( locstruc loc)
168 {
169  int32_t iretn;
170  double distance, theta;
171  rvector sat2body;
172 
173  // Synchronize time
174  if (loc.pos.icrf.utc == 0.)
175  {
176  if (!std::isfinite(loc.utc))
177  {
178  return CONVERT_ERROR_UTC;
179  }
180  loc.pos.icrf.utc = loc.pos.utc = loc.utc;
181  }
182  else
183  {
184  if (!std::isfinite(loc.pos.icrf.utc))
185  {
186  return CONVERT_ERROR_UTC;
187  }
188  loc.utc = loc.pos.utc = loc.pos.icrf.utc;
189  }
190 
191  iretn = pos_extra(loc);
192  if (iretn < 0)
193  {
194  return iretn;
195  }
196 
197  // Determine closest planetary body
201 
202  // Set SUN specific stuff
203  distance = length_rv(loc.pos.icrf.s);
204  loc.pos.sunsize = static_cast <float>(RSUNM/distance);
205  loc.pos.sunradiance = static_cast <float>(3.839e26/(4.*DPI*distance*distance));
206 
207  // Check Earth:Sun separation
208  sat2body = rv_sub(loc.pos.icrf.s,loc.pos.extra.sun2earth.s);
209  loc.pos.earthsep = static_cast <float>(sep_rv(loc.pos.icrf.s,sat2body));
210  loc.pos.earthsep -= static_cast <float>(asin(REARTHM/length_rv(sat2body)));
211  if (loc.pos.earthsep < -loc.pos.sunsize)
212  loc.pos.sunradiance = 0.;
213  else
214  if (loc.pos.earthsep <= loc.pos.sunsize)
215  {
216  theta = DPI*(loc.pos.sunsize+loc.pos.earthsep)/loc.pos.sunsize;
217  loc.pos.sunradiance *= static_cast <float>((theta - sin(theta))/D2PI);
218  }
219 
220  // Set Moon specific stuff
221  sat2body = rv_sub(loc.pos.icrf.s,loc.pos.extra.sun2moon.s);
222 
223  // Check Earth:Moon separation
224  loc.pos.moonsep = static_cast <float>(sep_rv(loc.pos.icrf.s,sat2body));
225  loc.pos.moonsep -= static_cast <float>(asin(RMOONM/length_rv(sat2body)));
226  if (loc.pos.moonsep < -loc.pos.sunsize)
227  loc.pos.sunradiance = 0.;
228  else
229  if (loc.pos.moonsep <= loc.pos.sunsize)
230  {
231  theta = DPI*(loc.pos.sunsize+loc.pos.moonsep)/loc.pos.sunsize;
232  loc.pos.sunradiance *= static_cast <float>((theta - sin(theta))/D2PI);
233  }
234 
235  // Set related attitudes
236  loc.att.icrf.pass = loc.pos.icrf.pass;
237  loc.att.icrf.utc = loc.pos.icrf.utc;
238 
239  // Set adjoining positions
240  if (loc.pos.icrf.pass > loc.pos.eci.pass)
241  {
242  pos_icrf2eci(loc);
243  pos_eci(loc);
244  }
245  if (loc.pos.icrf.pass > loc.pos.sci.pass)
246  {
247  pos_icrf2sci(loc);
248  pos_sci(loc);
249  }
250  return 0;
251 }
cartpos sun2earth
Definition: convertdef.h:605
3 element generic row vector
Definition: vector.h:53
double utc
UTC of Position.
Definition: convertdef.h:161
double sep_rv(rvector v1, rvector v2)
Angular separation between row vectors.
Definition: vector.cpp:42
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int32_t pos_icrf2sci(locstruc *loc)
Convert Barycentric to SCI.
Definition: convertlib.cpp:730
int32_t pos_sci(locstruc *loc)
Set SCI position.
Definition: convertlib.cpp:312
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
int iretn
Definition: rw_test.cpp:37
float moonsep
Separation between sun/satellite and sun/limbofmoon vectors in radians.
Definition: convertdef.h:748
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
float earthsep
Separation between sun/satellite and sun/limbofearth vectors in radians.
Definition: convertdef.h:746
cartpos sun2moon
Definition: convertdef.h:606
float sunradiance
Watts per square meter per steradian.
Definition: convertdef.h:752
uint16_t closest
Definition: convertdef.h:607
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
attstruc att
attstruc for this time.
Definition: convertdef.h:883
double utc
Definition: convertdef.h:735
qatt icrf
Definition: convertdef.h:830
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
#define RMOONM
SI Radius of Moon.
Definition: convertdef.h:58
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
#define REARTHM
SI Radius of Earth.
Definition: convertdef.h:60
float sunsize
Radius of sun in radians.
Definition: convertdef.h:750
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
cartpos eci
Definition: convertdef.h:737
const double DPI
Double precision PI.
Definition: math/constants.h:14
cartpos icrf
Definition: convertdef.h:736
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
int32_t pos_icrf2eci(locstruc *loc)
Convert Barycentric to ECI.
Definition: convertlib.cpp:626
#define RSUNM
SI Radius of Sun.
Definition: convertdef.h:56
int32_t pos_eci ( locstruc loc)

Set ECI position.

Set the current time and position to whatever is in the Earth Centered Inertial position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
259 {
260  return pos_eci(*loc);
261 }
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
int32_t pos_eci ( locstruc loc)
264 {
265  int32_t iretn;
266  // Synchronize time
267  if (0. == loc.pos.eci.utc)
268  {
269  if (!std::isfinite(loc.utc))
270  {
271  return CONVERT_ERROR_UTC;
272  }
273  loc.pos.eci.utc = loc.pos.utc = loc.utc;
274  }
275  else
276  {
277  if (!std::isfinite(loc.pos.eci.utc))
278  {
279  return CONVERT_ERROR_UTC;
280  }
281  loc.utc = loc.pos.utc = loc.pos.eci.utc;
282  }
283 
284  iretn = pos_extra(loc);
285  if (iretn < 0)
286  {
287  return iretn;
288  }
289 
290  // Set adjoining positions
291  if (loc.pos.eci.pass > loc.pos.icrf.pass)
292  {
293  pos_eci2icrf(loc);
294  pos_icrf(loc);
295  }
296  if (loc.pos.eci.pass > loc.pos.geoc.pass)
297  {
298  pos_eci2geoc(loc);
299  pos_geoc(loc);
300  }
301 
302  // Set related attitude
303  loc.att.icrf.pass = loc.pos.eci.pass;
304  return 0;
305 }
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
attstruc att
attstruc for this time.
Definition: convertdef.h:883
double utc
Definition: convertdef.h:735
int32_t pos_eci2geoc(locstruc *loc)
Convert ECI to GEOC.
Definition: convertlib.cpp:836
qatt icrf
Definition: convertdef.h:830
int32_t pos_geoc(locstruc *loc)
Set Geocentric position.
Definition: convertlib.cpp:366
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
int32_t pos_icrf(locstruc *loc)
Set Barycentric position.
Definition: convertlib.cpp:162
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
cartpos eci
Definition: convertdef.h:737
cartpos icrf
Definition: convertdef.h:736
int32_t pos_eci2icrf(locstruc *loc)
Convert ECI to Barycentric.
Definition: convertlib.cpp:679
int32_t pos_sci ( locstruc loc)

Set SCI position.

Set the current time and position to whatever is in the Selene Centered Inertial position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
313 {
314  return pos_sci(*loc);
315 }
int32_t pos_sci(locstruc *loc)
Set SCI position.
Definition: convertlib.cpp:312
int32_t pos_sci ( locstruc loc)
318 {
319  int32_t iretn;
320  // Synchronize time
321  if (0. == loc.pos.sci.utc)
322  {
323  if (!std::isfinite(loc.utc))
324  {
325  return CONVERT_ERROR_UTC;
326  }
327  loc.pos.sci.utc = loc.pos.utc = loc.utc;
328  }
329  else
330  {
331  if (!std::isfinite(loc.pos.sci.utc))
332  {
333  return CONVERT_ERROR_UTC;
334  }
335  loc.utc = loc.pos.utc = loc.pos.sci.utc;
336  }
337 
338  iretn = pos_extra(loc);
339  if (iretn < 0)
340  {
341  return iretn;
342  }
343 
344  // Set adjoining positions
345  if (loc.pos.sci.pass > loc.pos.icrf.pass)
346  {
347  pos_sci2icrf(loc);
348  pos_icrf(loc);
349  }
350  if (loc.pos.sci.pass > loc.pos.selc.pass)
351  {
352  pos_sci2selc(loc);
353  pos_selc(loc);
354  }
355 
356  // Set related attitude
357  loc.att.icrf.pass = loc.pos.sci.pass;
358  return 0;
359 }
double utc
UTC of Position.
Definition: convertdef.h:161
cartpos selc
Definition: convertdef.h:740
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
int32_t pos_sci2icrf(locstruc *loc)
Convert SCI to Barycentric.
Definition: convertlib.cpp:784
attstruc att
attstruc for this time.
Definition: convertdef.h:883
double utc
Definition: convertdef.h:735
qatt icrf
Definition: convertdef.h:830
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
int32_t pos_icrf(locstruc *loc)
Set Barycentric position.
Definition: convertlib.cpp:162
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
int32_t pos_selc(locstruc *loc)
Set Selenocentric position.
Definition: convertlib.cpp:428
int32_t pos_sci2selc(locstruc *loc)
Convert SCI to SELC.
Definition: convertlib.cpp:1291
cartpos icrf
Definition: convertdef.h:736
int32_t pos_geoc ( locstruc loc)

Set Geocentric position.

Set the current time and position to whatever is in the Geocentric position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
367 {
368  return pos_geoc(*loc);
369 }
int32_t pos_geoc(locstruc *loc)
Set Geocentric position.
Definition: convertlib.cpp:366
int32_t pos_geoc ( locstruc loc)
372 {
373  int32_t iretn;
374  // Synchronize time
375  if (0. == loc.pos.geoc.utc)
376  {
377  if (!std::isfinite(loc.utc))
378  {
379  return CONVERT_ERROR_UTC;
380  }
381  loc.pos.geoc.utc = loc.pos.utc = loc.utc;
382  }
383  else
384  {
385  if (!std::isfinite(loc.pos.geoc.utc))
386  {
387  return CONVERT_ERROR_UTC;
388  }
389  loc.utc = loc.pos.utc = loc.pos.geoc.utc;
390  }
391 
392  iretn = pos_extra(loc);
393  if (iretn < 0)
394  {
395  return iretn;
396  }
397 
398  // Go to ECI if necessary
399  if (loc.pos.geoc.pass > loc.pos.eci.pass)
400  {
401  pos_geoc2eci(loc);
402  pos_eci(loc);
403  }
404  // Go to Geocentric Spherical if necessary
405  if (loc.pos.geoc.pass > loc.pos.geos.pass)
406  {
407  pos_geoc2geos(loc);
408  pos_geos(loc);
409  }
410  // Go to Geodetic if necessary
411  if (loc.pos.geoc.pass > loc.pos.geod.pass)
412  {
413  pos_geoc2geod(loc);
414  pos_geod(loc);
415  }
416 
417  // Set related attitude
418  loc.att.geoc.pass = loc.pos.geoc.pass;
419 
420  return 0;
421 }
qatt geoc
Definition: convertdef.h:828
spherpos geos
Definition: convertdef.h:743
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
int32_t pos_geos(locstruc *loc)
Set Geographic position.
Definition: convertlib.cpp:530
int32_t pos_geoc2eci(locstruc *loc)
Convert GEOC to ECI.
Definition: convertlib.cpp:913
attstruc att
attstruc for this time.
Definition: convertdef.h:883
double utc
Definition: convertdef.h:735
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
int32_t pos_geoc2geos(locstruc *loc)
Convert GEOC to GEOS.
Definition: convertlib.cpp:983
int32_t pos_geod(locstruc *loc)
Set Geodetic position.
Definition: convertlib.cpp:576
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
cartpos eci
Definition: convertdef.h:737
geoidpos geod
Definition: convertdef.h:741
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:324
int32_t pos_geoc2geod(locstruc *loc)
Update locstruc GEOC to GEOD.
Definition: convertlib.cpp:1167
int32_t pos_selc ( locstruc loc)

Set Selenocentric position.

Set the current time and position to whatever is in the Selenocentric position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
429 {
430  return pos_selc(*loc);
431 }
int32_t pos_selc(locstruc *loc)
Set Selenocentric position.
Definition: convertlib.cpp:428
int32_t pos_selc ( locstruc loc)
434 {
435  int32_t iretn;
436  // Synchronize time
437  if (0. == loc.pos.selc.utc)
438  {
439  if (!std::isfinite(loc.utc))
440  {
441  return CONVERT_ERROR_UTC;
442  }
443  loc.pos.selc.utc = loc.pos.utc = loc.utc;
444  }
445  else
446  {
447  if (!std::isfinite(loc.pos.selc.utc))
448  {
449  return CONVERT_ERROR_UTC;
450  }
451  loc.utc = loc.pos.utc = loc.pos.selc.utc;
452  }
453 
454  iretn = pos_extra(loc);
455  if (iretn < 0)
456  {
457  return iretn;
458  }
459 
460  // Go to SCI if necessary
461  if (loc.pos.selc.pass > loc.pos.sci.pass)
462  {
463  pos_selc2sci(loc);
464  pos_sci(loc);
465  }
466  // Go to Selenographic if necessary
467  if (loc.pos.selc.pass > loc.pos.selg.pass)
468  {
469  pos_selc2selg(loc);
470  pos_selg(loc);
471  }
472 
473  // Set related attitude
474  loc.att.selc.pass = loc.pos.selc.pass;
475 
476  return 0;
477 }
double utc
UTC of Position.
Definition: convertdef.h:161
cartpos selc
Definition: convertdef.h:740
int32_t pos_selc2sci(locstruc *loc)
Convert SELC to SCI.
Definition: convertlib.cpp:1366
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int32_t pos_sci(locstruc *loc)
Set SCI position.
Definition: convertlib.cpp:312
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
int32_t pos_selg(locstruc *loc)
Set Selenographic position.
Definition: convertlib.cpp:484
geoidpos selg
Definition: convertdef.h:742
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
double utc
Definition: convertdef.h:735
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
int32_t pos_selc2selg(locstruc *loc)
Convert SELC to SELG.
Definition: convertlib.cpp:1432
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
int32_t pos_selg ( locstruc loc)

Set Selenographic position.

Set the current time and position to whatever is in the Selenographic position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
485 {
486  return pos_selg(*loc);
487 }
int32_t pos_selg(locstruc *loc)
Set Selenographic position.
Definition: convertlib.cpp:484
int32_t pos_selg ( locstruc loc)
490 {
491  int32_t iretn;
492  // Synchroniz time
493  if (0. == loc.pos.selg.utc)
494  {
495  if (!std::isfinite(loc.utc))
496  {
497  return CONVERT_ERROR_UTC;
498  }
499  loc.pos.selg.utc = loc.pos.utc = loc.utc;
500  }
501  else
502  {
503  if (!std::isfinite(loc.pos.selg.utc))
504  {
505  return CONVERT_ERROR_UTC;
506  }
507  loc.utc = loc.pos.utc = loc.pos.selg.utc;
508  }
509 
510  iretn = pos_extra(loc);
511  if (iretn < 0)
512  {
513  return iretn;
514  }
515 
516  if (loc.pos.selg.pass > loc.pos.selc.pass)
517  {
518  pos_selg2selc(loc);
519  pos_selc(loc);
520  }
521 
522  return 0;
523 }
double utc
Definition: convertdef.h:261
cartpos selc
Definition: convertdef.h:740
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
geoidpos selg
Definition: convertdef.h:742
int32_t pos_selg2selc(locstruc *loc)
Definition: convertlib.cpp:1494
double utc
Definition: convertdef.h:735
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
int32_t pos_selc(locstruc *loc)
Set Selenocentric position.
Definition: convertlib.cpp:428
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
int32_t pos_geos ( locstruc loc)

Set Geographic position.

Set the current time and position to whatever is in the Geographic position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
531 {
532  return pos_geos(*loc);
533 }
int32_t pos_geos(locstruc *loc)
Set Geographic position.
Definition: convertlib.cpp:530
int32_t pos_geos ( locstruc loc)
536 {
537  int32_t iretn;
538  // Synchronize time
539  if (0. == loc.pos.geos.utc)
540  {
541  if (!std::isfinite(loc.utc))
542  {
543  return CONVERT_ERROR_UTC;
544  }
545  loc.pos.geos.utc = loc.pos.utc = loc.utc;
546  }
547  else
548  {
549  if (!std::isfinite(loc.pos.geos.utc))
550  {
551  return CONVERT_ERROR_UTC;
552  }
553  loc.utc = loc.pos.utc = loc.pos.geos.utc;
554  }
555 
556  iretn = pos_extra(loc);
557  if (iretn < 0)
558  {
559  return iretn;
560  }
561 
562  if (loc.pos.geos.pass > loc.pos.geoc.pass)
563  {
564  pos_geos2geoc(loc);
565  pos_geoc(loc);
566  }
567 
568  return 0;
569 }
spherpos geos
Definition: convertdef.h:743
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
double utc
Definition: convertdef.h:735
int32_t pos_geos2geoc(locstruc *loc)
Convert GEOS to GEOC.
Definition: convertlib.cpp:1047
int32_t pos_geoc(locstruc *loc)
Set Geocentric position.
Definition: convertlib.cpp:366
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
double utc
Definition: convertdef.h:316
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:324
int32_t pos_geod ( locstruc loc)

Set Geodetic position.

Set the current time and position to whatever is in the Geodetic position of the locstruc. Then propagate to all the other positions.

Parameters
loclocstruc with the current position and those to be updated.
577 {
578  return pos_geod(*loc);
579 }
int32_t pos_geod(locstruc *loc)
Set Geodetic position.
Definition: convertlib.cpp:576
int32_t pos_geod ( locstruc loc)
582 {
583  int32_t iretn;
584  // Synchronize time
585  if (0. == loc.pos.geod.utc)
586  {
587  if (!std::isfinite(loc.utc))
588  {
589  return CONVERT_ERROR_UTC;
590  }
591  loc.pos.geod.utc = loc.pos.utc = loc.utc;
592  }
593  else
594  {
595  if (!std::isfinite(loc.pos.geod.utc))
596  {
597  return CONVERT_ERROR_UTC;
598  }
599  loc.utc = loc.pos.utc = loc.pos.geod.utc;
600  }
601 
602  iretn = pos_extra(loc);
603  if (iretn < 0)
604  {
605  return iretn;
606  }
607 
608  if (loc.pos.geod.pass > loc.pos.geoc.pass)
609  {
610  pos_geod2geoc(loc);
611  pos_geoc(loc);
612  }
613  // Determine magnetic field in Topocentric system
614  geomag_front(loc.pos.geod.s, mjd2year(loc.utc), loc.pos.bearth);
615 
616  // Transform to ITRS
618  return 0;
619 }
rvector bearth
Earth magnetic vector in ITRS for this time and location.
Definition: convertdef.h:754
double utc
Definition: convertdef.h:261
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
const double DPI2
Double precision PI/2.
Definition: math/constants.h:18
quaternion q_change_around_y(double angle)
Rotation quaternion for Y axis.
Definition: vector.cpp:1435
double utc
Definition: convertdef.h:735
quaternion q_change_around_z(double angle)
Rotation quaternion for Z axis.
Definition: vector.cpp:1461
int32_t pos_geoc(locstruc *loc)
Set Geocentric position.
Definition: convertlib.cpp:366
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
double lon
Longitude in radians.
Definition: vector.h:227
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
int32_t pos_geod2geoc(locstruc *loc)
Update GEOD to GEOC in locstruc.
Definition: convertlib.cpp:1250
int32_t geomag_front(gvector pos, double time, rvector &comp)
Definition: geomag.cpp:99
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
geoidpos geod
Definition: convertdef.h:741
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
double mjd2year(double mjd)
Year from MJD.
Definition: timelib.cpp:997
int32_t pos_icrf2eci ( locstruc loc)

Convert Barycentric to ECI.

Propagate the position found in the Barycentric slot of the supplied locstruc to the Earth Centered Inertial slot, performing all relevant updates.

Parameters
locWorking locstruc
627 {
628  return pos_icrf2eci(*loc);
629 }
int32_t pos_icrf2eci(locstruc *loc)
Convert Barycentric to ECI.
Definition: convertlib.cpp:626
int32_t pos_icrf2eci ( locstruc loc)
632 {
633  int32_t iretn;
634  // Synchronize time
635  if (loc.pos.icrf.utc == 0.)
636  {
637  if (!std::isfinite(loc.utc))
638  {
639  return CONVERT_ERROR_UTC;
640  }
641  loc.pos.icrf.utc = loc.pos.utc = loc.utc;
642  }
643  else
644  {
645  if (!std::isfinite(loc.pos.icrf.utc))
646  {
647  return CONVERT_ERROR_UTC;
648  }
649  loc.utc = loc.pos.utc = loc.pos.icrf.utc;
650  }
651 
652  // Update extra information
653  iretn = pos_extra(loc);
654  if (iretn < 0)
655  {
656  return iretn;
657  }
658 
659  // Update time
660  loc.pos.eci.utc = loc.utc;
661 
662  // Update pass
663  loc.pos.eci.pass = loc.pos.icrf.pass;
664 
665  // Heliocentric to Geocentric Ecliptic
666  loc.pos.eci.s = loc.pos.eci.v = loc.pos.eci.a = rv_zero();
667 
668  loc.pos.eci.s = rv_sub(loc.pos.icrf.s,loc.pos.extra.sun2earth.s);
669  loc.pos.eci.v = rv_sub(loc.pos.icrf.v,loc.pos.extra.sun2earth.v);
670  loc.pos.eci.a = rv_sub(loc.pos.icrf.a,loc.pos.extra.sun2earth.a);
671  return 0;
672 }
cartpos sun2earth
Definition: convertdef.h:605
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector s
Location.
Definition: convertdef.h:163
double utc
Definition: convertdef.h:735
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
cartpos eci
Definition: convertdef.h:737
cartpos icrf
Definition: convertdef.h:736
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_eci2icrf ( locstruc loc)

Convert ECI to Barycentric.

Propagate the position found in the Earth Centered Inertial slot of the supplied locstruc to the Barycentric slot, performing all relevant updates.

Parameters
locWorking locstruc
680 {
681  return pos_eci2icrf(*loc);
682 }
int32_t pos_eci2icrf(locstruc *loc)
Convert ECI to Barycentric.
Definition: convertlib.cpp:679
int32_t pos_eci2icrf ( locstruc loc)
685 {
686  int32_t iretn;
687  // Synchronize time
688  if (0. == loc.pos.eci.utc)
689  {
690  if (!std::isfinite(loc.utc))
691  {
692  return CONVERT_ERROR_UTC;
693  }
694  loc.pos.eci.utc = loc.pos.utc = loc.utc;
695  }
696  else
697  {
698  if (!std::isfinite(loc.pos.eci.utc))
699  {
700  return CONVERT_ERROR_UTC;
701  }
702  loc.utc = loc.pos.utc = loc.pos.eci.utc;
703  }
704 
705  // Update extra information
706  iretn = pos_extra(loc);
707  if (iretn < 0)
708  {
709  return iretn;
710  }
711 
712  // Update pass
713  loc.pos.icrf.pass = loc.pos.eci.pass;
714 
715  // Update time
716  loc.pos.icrf.utc = loc.utc;
717 
718  // Geocentric Equatorial to Heliocentric
719  loc.pos.icrf.s = rv_add(loc.pos.eci.s,loc.pos.extra.sun2earth.s);
720  loc.pos.icrf.v = rv_add(loc.pos.eci.v,loc.pos.extra.sun2earth.v);
721  loc.pos.icrf.a = rv_add(loc.pos.eci.a,loc.pos.extra.sun2earth.a);
722  return 0;
723 }
cartpos sun2earth
Definition: convertdef.h:605
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector s
Location.
Definition: convertdef.h:163
double utc
Definition: convertdef.h:735
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
cartpos eci
Definition: convertdef.h:737
cartpos icrf
Definition: convertdef.h:736
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_icrf2sci ( locstruc loc)

Convert Barycentric to SCI.

Propagate the position found in the Barycentric slot of the supplied locstruc to the Selene Centered Inertial slot, performing all relevant updates.

Parameters
locWorking locstruc
731 {
732  return pos_icrf2sci(*loc);
733 }
int32_t pos_icrf2sci(locstruc *loc)
Convert Barycentric to SCI.
Definition: convertlib.cpp:730
int32_t pos_icrf2sci ( locstruc loc)
736 {
737  int32_t iretn;
738  // Synchronize time
739  if (loc.pos.icrf.utc == 0.)
740  {
741  if (!std::isfinite(loc.utc))
742  {
743  return CONVERT_ERROR_UTC;
744  }
745  loc.pos.icrf.utc = loc.pos.utc = loc.utc;
746  }
747  else
748  {
749  if (!std::isfinite(loc.pos.icrf.utc))
750  {
751  return CONVERT_ERROR_UTC;
752  }
753  loc.utc = loc.pos.utc = loc.pos.icrf.utc;
754  }
755 
756  // Update extra information
757  iretn = pos_extra(loc);
758  if (iretn < 0)
759  {
760  return iretn;
761  }
762 
763  // Update time
764  loc.pos.sci.utc = loc.utc;
765 
766  // Update pass
767  loc.pos.sci.pass = loc.pos.icrf.pass;
768 
769  // Heliocentric to Geocentric Ecliptic
770  loc.pos.sci.s = loc.pos.sci.v = loc.pos.sci.a = rv_zero();
771 
772  loc.pos.sci.s = rv_sub(loc.pos.icrf.s,loc.pos.extra.sun2moon.s);
773  loc.pos.sci.v = rv_sub(loc.pos.icrf.v,loc.pos.extra.sun2moon.v);
774  loc.pos.sci.a = rv_sub(loc.pos.icrf.a,loc.pos.extra.sun2moon.a);
775 
776  return 0;
777 }
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
cartpos sun2moon
Definition: convertdef.h:606
rvector s
Location.
Definition: convertdef.h:163
double utc
Definition: convertdef.h:735
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
cartpos icrf
Definition: convertdef.h:736
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_sci2icrf ( locstruc loc)

Convert SCI to Barycentric.

Propagate the position found in the Selene Centered Inertial slot of the supplied locstruc to the Barycentric slot, performing all relevant updates.

Parameters
locWorking locstruc
785 {
786  return pos_sci2icrf(*loc);
787 }
int32_t pos_sci2icrf(locstruc *loc)
Convert SCI to Barycentric.
Definition: convertlib.cpp:784
int32_t pos_sci2icrf ( locstruc loc)
790 {
791  int32_t iretn;
792  // Synchronize time
793  if (0. == loc.pos.sci.utc)
794  {
795  if (!std::isfinite(loc.utc))
796  {
797  return CONVERT_ERROR_UTC;
798  }
799  loc.pos.sci.utc = loc.pos.utc = loc.utc;
800  }
801  else
802  {
803  if (!std::isfinite(loc.pos.sci.utc))
804  {
805  return CONVERT_ERROR_UTC;
806  }
807  loc.utc = loc.pos.utc = loc.pos.sci.utc;
808  }
809 
810  // Update extra information
811  iretn = pos_extra(loc);
812  if (iretn < 0)
813  {
814  return iretn;
815  }
816 
817  // Update time
818  loc.pos.icrf.utc = loc.utc;
819 
820  // Update pass
821  loc.pos.icrf.pass = loc.pos.sci.pass;
822 
823  // Geocentric Equatorial to Heliocentric
824  loc.pos.icrf.s = rv_add(loc.pos.sci.s,loc.pos.extra.sun2moon.s);
825  loc.pos.icrf.v = rv_add(loc.pos.sci.v,loc.pos.extra.sun2moon.v);
826  loc.pos.icrf.a = rv_add(loc.pos.sci.a,loc.pos.extra.sun2moon.a);
827 
828  return 0;
829 }
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
cartpos sun2moon
Definition: convertdef.h:606
rvector s
Location.
Definition: convertdef.h:163
double utc
Definition: convertdef.h:735
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
cartpos icrf
Definition: convertdef.h:736
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_eci2geoc ( locstruc loc)

Convert ECI to GEOC.

Propagate the position found in the Earth Centered Inertial slot of the supplied locstruc to the Geocentric slot, performing all relevant updates.

Parameters
locWorking locstruc
837 {
838  return pos_eci2geoc(*loc);
839 }
int32_t pos_eci2geoc(locstruc *loc)
Convert ECI to GEOC.
Definition: convertlib.cpp:836
int32_t pos_eci2geoc ( locstruc loc)
842 {
843  int32_t iretn;
844  rvector v2;
845 
846  // Synchronize time
847  if (0. == loc.pos.eci.utc)
848  {
849  if (!std::isfinite(loc.utc))
850  {
851  return CONVERT_ERROR_UTC;
852  }
853  loc.pos.eci.utc = loc.pos.utc = loc.utc;
854  }
855  else
856  {
857  if (!std::isfinite(loc.pos.eci.utc))
858  {
859  return CONVERT_ERROR_UTC;
860  }
861  loc.utc = loc.pos.utc = loc.pos.eci.utc;
862  }
863 
864  // Update extra information
865  iretn = pos_extra(loc);
866  if (iretn < 0)
867  {
868  return iretn;
869  }
870 
871  // Update time
872  loc.pos.geoc.utc = loc.utc;
873 
874  // Update pass
875  loc.pos.geoc.pass = loc.att.icrf.pass = loc.pos.eci.pass;
876 
877  // Apply first order transform to all
878  loc.pos.geoc.s = rv_mmult(loc.pos.extra.j2e,loc.pos.eci.s);
879  loc.pos.geoc.v = rv_mmult(loc.pos.extra.j2e,loc.pos.eci.v);
880  loc.pos.geoc.a = rv_mmult(loc.pos.extra.j2e,loc.pos.eci.a);
881 
882  // Apply second order term due to first derivative of rotation matrix
883  v2 = rv_mmult(loc.pos.extra.dj2e,loc.pos.eci.s);
884  loc.pos.geoc.v = rv_add(loc.pos.geoc.v,v2);
885  v2 = rv_smult(2.,rv_mmult(loc.pos.extra.dj2e,loc.pos.eci.v));
886  loc.pos.geoc.a = rv_add(loc.pos.geoc.a,v2);
887  // Apply third order correction due to second derivative of rotation matrix
888  v2 = rv_mmult(loc.pos.extra.ddj2e,loc.pos.eci.s);
889  loc.pos.geoc.a = rv_add(loc.pos.geoc.a,v2);
890 
891  // Convert GEOC Position to GEOD
892  pos_geoc2geod(loc);
893 
894  // Convert GEOC Position to GEOS
895  pos_geoc2geos(loc);
896 
897  // Convert ICRF attitude to ITRF
898  att_icrf2geoc(loc);
899 
900  // Convert ITRF Attitude to Topo
901  att_planec2topo(loc);
902 
903  // Convert ITRF Attitude to LVLH
904  att_planec2lvlh(loc);
905  return 0;
906 }
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
3 element generic row vector
Definition: vector.h:53
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
rmatrix ddj2e
Definition: convertdef.h:592
int iretn
Definition: rw_test.cpp:37
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
rvector s
Location.
Definition: convertdef.h:163
attstruc att
attstruc for this time.
Definition: convertdef.h:883
double utc
Definition: convertdef.h:735
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
qatt icrf
Definition: convertdef.h:830
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
int32_t pos_geoc2geos(locstruc *loc)
Convert GEOC to GEOS.
Definition: convertlib.cpp:983
int32_t att_icrf2geoc(locstruc *loc)
Definition: convertlib.cpp:1591
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
cartpos eci
Definition: convertdef.h:737
rmatrix dj2e
Definition: convertdef.h:591
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
int32_t pos_geoc2geod(locstruc *loc)
Update locstruc GEOC to GEOD.
Definition: convertlib.cpp:1167
rmatrix j2e
Transform from ICRF to Geocentric.
Definition: convertdef.h:590
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_geoc2eci ( locstruc loc)

Convert GEOC to ECI.

Propagate the position found in the Geocentric slot of the supplied locstruc to the Earth Centered Inertial slot, performing all relevant updates.

Parameters
locWorking locstruc
914 {
915  return pos_geoc2eci(*loc);
916 }
int32_t pos_geoc2eci(locstruc *loc)
Convert GEOC to ECI.
Definition: convertlib.cpp:913
int32_t pos_geoc2eci ( locstruc loc)
919 {
920  int32_t iretn;
921  rvector ds;
922 
923  // Synchronize time
924  if (0. == loc.pos.geoc.utc)
925  {
926  if (!std::isfinite(loc.utc))
927  {
928  return CONVERT_ERROR_UTC;
929  }
930  loc.pos.geoc.utc = loc.pos.utc = loc.utc;
931  }
932  else
933  {
934  if (!std::isfinite(loc.pos.geoc.utc))
935  {
936  return CONVERT_ERROR_UTC;
937  }
938  loc.utc = loc.pos.utc = loc.pos.geoc.utc;
939  }
940 
941  // Update extra information
942  iretn = pos_extra(loc);
943  if (iretn < 0)
944  {
945  return iretn;
946  }
947 
948  // Update time
949  loc.pos.eci.utc = loc.utc;
950 
951  // Update pass
952  loc.pos.eci.pass = loc.att.geoc.pass = loc.pos.geoc.pass;
953 
954  // Apply first order transform to all
955  loc.pos.eci.s = rv_mmult(loc.pos.extra.e2j,loc.pos.geoc.s);
956  loc.pos.eci.v = rv_mmult(loc.pos.extra.e2j,loc.pos.geoc.v);
957  loc.pos.eci.a = rv_mmult(loc.pos.extra.e2j,loc.pos.geoc.a);
958 
959  // Apply second order correction due to first derivative of rotation matrix
960  ds = rv_mmult(loc.pos.extra.de2j,loc.pos.geoc.s);
961  loc.pos.eci.v = rv_add(loc.pos.eci.v,ds);
962  ds = rv_smult(2.,rv_mmult(loc.pos.extra.de2j,loc.pos.geoc.v));
963  loc.pos.eci.a = rv_add(loc.pos.eci.a,ds);
964  // Apply third order correction due to second derivative of rotation matrix
965  ds = rv_mmult(loc.pos.extra.dde2j,loc.pos.geoc.s);
966  loc.pos.eci.a = rv_add(loc.pos.eci.a,ds);
967 
968  // Convert ITRF Attitude to ICRF
969  att_geoc2icrf(loc);
970 
971  // Convert ITRF Attitude to LVLH
972  att_planec2lvlh(loc);
973 
974  // Convert ITRF Attitude to TOPO
975  att_planec2topo(loc);
976  return 0;
977 }
qatt geoc
Definition: convertdef.h:828
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
3 element generic row vector
Definition: vector.h:53
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
rvector s
Location.
Definition: convertdef.h:163
rmatrix de2j
Definition: convertdef.h:595
attstruc att
attstruc for this time.
Definition: convertdef.h:883
double utc
Definition: convertdef.h:735
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
int32_t att_geoc2icrf(locstruc *loc)
Definition: convertlib.cpp:1639
rmatrix dde2j
Definition: convertdef.h:596
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
cartpos eci
Definition: convertdef.h:737
rmatrix e2j
Transform from Geocentric to ICRF.
Definition: convertdef.h:594
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_geoc2geos ( locstruc loc)

Convert GEOC to GEOS.

Convert a Geocentric cartpos to a Geographic spherpos.

Parameters
loclocstruc containing position.
984 {
985  return pos_geoc2geos(*loc);
986 }
int32_t pos_geoc2geos(locstruc *loc)
Convert GEOC to GEOS.
Definition: convertlib.cpp:983
int32_t pos_geoc2geos ( locstruc loc)
989 {
990  double xvx, yvy, r2, r, minir, minir2;
991  double cp, cl, sl, sp;
992 
993  // Synchronize time
994  if (0. == loc.pos.geoc.utc)
995  {
996  if (!std::isfinite(loc.utc))
997  {
998  return CONVERT_ERROR_UTC;
999  }
1000  loc.pos.geoc.utc = loc.pos.utc = loc.utc;
1001  }
1002  else
1003  {
1004  if (!std::isfinite(loc.pos.geoc.utc))
1005  {
1006  return CONVERT_ERROR_UTC;
1007  }
1008  loc.utc = loc.pos.utc = loc.pos.geoc.utc;
1009  }
1010 
1011  // Update time
1012  loc.pos.geos.utc = loc.utc;
1013 
1014  // Update pass
1015  loc.pos.geos.pass = loc.pos.geoc.pass;
1016 
1017  // Convert Geocentric Cartesian to Spherical
1018  minir2 = loc.pos.geoc.s.col[0]*loc.pos.geoc.s.col[0]+loc.pos.geoc.s.col[1]*loc.pos.geoc.s.col[1];
1019  minir = sqrt(minir2);
1020  r2 = minir2+loc.pos.geoc.s.col[2]*loc.pos.geoc.s.col[2];
1021  loc.pos.geos.s.r = r = sqrt(r2);
1022  sp = loc.pos.geoc.s.col[2]/r;
1023  loc.pos.geos.s.phi = asin(sp);
1024  loc.pos.geos.s.lambda = atan2(loc.pos.geoc.s.col[1],loc.pos.geoc.s.col[0]);
1025 
1026  xvx = loc.pos.geoc.s.col[0]*loc.pos.geoc.v.col[0];
1027  yvy = loc.pos.geoc.s.col[1]*loc.pos.geoc.v.col[1];
1028  loc.pos.geos.v.r = (xvx+yvy+loc.pos.geoc.s.col[2]*loc.pos.geoc.v.col[2])/r;
1029  loc.pos.geos.v.phi = (-(xvx+yvy) * loc.pos.geoc.s.col[2] + minir2*loc.pos.geoc.v.col[2])/(r2*minir);
1030  //loc.pos.geos.v.lambda = -(loc.pos.geoc.s.col[0]*loc.pos.geoc.v.col[1]+loc.pos.geoc.s.col[1]*loc.pos.geoc.v.col[0])/minir2;
1031 
1032  cp = minir / r;
1033  cl = loc.pos.geoc.s.col[0] / minir;
1034  sl = loc.pos.geoc.s.col[1] / minir;
1035  if (fabs(loc.pos.geoc.s.col[1]) > fabs(loc.pos.geoc.s.col[0]))
1036  loc.pos.geos.v.lambda = (loc.pos.geoc.v.col[0] - cp * cl * loc.pos.geos.v.r + loc.pos.geoc.s.col[2] * cl * loc.pos.geos.v.phi) / (-loc.pos.geoc.s.col[1]);
1037  else
1038  loc.pos.geos.v.lambda = (loc.pos.geoc.v.col[1] - cp * sl * loc.pos.geos.v.r + loc.pos.geoc.s.col[2] * sl * loc.pos.geos.v.phi) / loc.pos.geoc.s.col[0];
1039 
1040  return 0;
1041 }
svector s
Position vector.
Definition: convertdef.h:318
double lambda
E/W in radians.
Definition: vector.h:172
spherpos geos
Definition: convertdef.h:743
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector s
Location.
Definition: convertdef.h:163
double phi
N/S in radians.
Definition: vector.h:170
double utc
Definition: convertdef.h:735
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
double col[3]
Definition: vector.h:55
svector v
Velocity vector.
Definition: convertdef.h:320
double utc
Definition: convertdef.h:316
double r
Radius in meters.
Definition: vector.h:174
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:324
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_geos2geoc ( locstruc loc)

Convert GEOS to GEOC.

Convert a Geographic spherpos to a Geocentric cartpos.

Parameters
loclocstruc containing position.
1048 {
1049  return pos_geos2geoc(*loc);
1050 }
int32_t pos_geos2geoc(locstruc *loc)
Convert GEOS to GEOC.
Definition: convertlib.cpp:1047
int32_t pos_geos2geoc ( locstruc loc)
1053 {
1054  double sp, cp, sl, cl, cpr;
1055 
1056  // Synchronize time
1057  if (0. == loc.pos.geos.utc)
1058  {
1059  if (!std::isfinite(loc.utc))
1060  {
1061  return CONVERT_ERROR_UTC;
1062  }
1063  loc.pos.geos.utc = loc.pos.utc = loc.utc;
1064  }
1065  else
1066  {
1067  if (!std::isfinite(loc.pos.geoc.utc))
1068  {
1069  return CONVERT_ERROR_UTC;
1070  }
1071  loc.utc = loc.pos.utc = loc.pos.geos.utc;
1072  }
1073 
1074  // Update time
1075  loc.pos.geoc.utc = loc.utc;
1076 
1077  // Update pass
1078  loc.pos.geoc.pass = loc.pos.geos.pass;
1079 
1080  sp = sin(loc.pos.geos.s.phi);
1081  cp = cos(loc.pos.geos.s.phi);
1082  sl = sin(loc.pos.geos.s.lambda);
1083  cl = cos(loc.pos.geos.s.lambda);
1084  cpr = cp * loc.pos.geos.s.r;
1085 
1086  loc.pos.geoc.s = loc.pos.geoc.v = loc.pos.geoc.a = rv_zero();
1087 
1088  loc.pos.geoc.s.col[0] = cpr * cl;
1089  loc.pos.geoc.s.col[1] = cpr * sl;
1090  loc.pos.geoc.s.col[2] = loc.pos.geos.s.r * sp;
1091 
1092  //loc.pos.geoc.v.col[0] = loc.pos.geos.v.r * cp * cl - loc.pos.geos.v.phi * loc.pos.geos.s.r * sp * cl - loc.pos.geos.v.lambda * cpr * sl;
1093  //loc.pos.geoc.v.col[1] = loc.pos.geos.v.r * cp * sl - loc.pos.geos.v.phi * loc.pos.geos.s.r * sp * sl + loc.pos.geos.v.lambda * cpr * cl;
1094  loc.pos.geoc.v.col[0] = loc.pos.geos.v.r * cp * cl - loc.pos.geos.v.lambda * cpr * sl - loc.pos.geos.v.phi * loc.pos.geos.s.r * sp * cl;
1095  loc.pos.geoc.v.col[1] = loc.pos.geos.v.r * cp * sl + loc.pos.geos.v.lambda * cpr * cl - loc.pos.geos.v.phi * loc.pos.geos.s.r * sp * sl;
1096  loc.pos.geoc.v.col[2] = loc.pos.geos.v.r * sp + loc.pos.geos.v.phi * cpr;
1097  return 0;
1098 }
svector s
Position vector.
Definition: convertdef.h:318
double lambda
E/W in radians.
Definition: vector.h:172
spherpos geos
Definition: convertdef.h:743
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector s
Location.
Definition: convertdef.h:163
double phi
N/S in radians.
Definition: vector.h:170
double utc
Definition: convertdef.h:735
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
double col[3]
Definition: vector.h:55
svector v
Velocity vector.
Definition: convertdef.h:320
double utc
Definition: convertdef.h:316
double r
Radius in meters.
Definition: vector.h:174
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:324
rvector v
Velocity.
Definition: convertdef.h:165
int32_t geoc2geod ( cartpos geoc,
geoidpos geod 
)

Convert GEOC to GEOD.

Convert a Geocentric cartpos to a Geodetic geoidpos.

Parameters
geocSource Geocentric position.
geodDestination Geodetic position.
1106 {
1107  double e2;
1108  double st;
1109  double ct, cn, sn;
1110  double c, rp, a1, a2, a3, b1, b2, c1, c2, c3, rbc;
1111  double p, phi, h, nh, rn;
1112 
1113  // calculate geodetic longitude = atan2(py/px)
1114  geod.s.lon = atan2(geoc.s.col[1], geoc.s.col[0]);
1115 
1116  // Calculate effects of oblate spheroid
1117  // TODO: Explain math
1118  // e2 (square of first eccentricity) = 1 - (1 - f)^2
1119  e2 = (1. - FRATIO2);
1120  p = sqrt(geoc.s.col[0]*geoc.s.col[0] + geoc.s.col[1]*geoc.s.col[1]);
1121  nh = sqrt(p*p + geoc.s.col[2]*geoc.s.col[2]) - REARTHM;
1122  phi = atan2(geoc.s.col[2],p);
1123  do
1124  {
1125  h = nh;
1126  st = sin(phi);
1127  // rn = radius of curvature in the vertical prime
1128  rn = REARTHM / sqrt(1.-e2*st*st);
1129  nh = p/cos(phi) - rn;
1130  phi = atan( (geoc.s.col[2]/p)/(1.-e2*rn/(rn+h) ) );
1131  } while (fabs(nh-h) > .01);
1132 
1133  geod.s.lat = phi;
1134  geod.s.h = h;
1135 
1136  // TODO: Explain math
1137  st = sin(geod.s.lat);
1138  ct = cos(geod.s.lat);
1139  sn = sin(geod.s.lon);
1140  cn = cos(geod.s.lon);
1141 
1142  c = 1./sqrt(ct * ct + FRATIO2 * st *st);
1143  rp = geod.s.h + REARTHM * FRATIO2 * c * c * c;
1144  a1 = ct * cn;
1145  b1 = -geoc.s.col[1];
1146  c1 = -st * cn * rp;
1147  a2 = ct * sn;
1148  b2 = geoc.s.col[0];
1149  c2 = -st * sn * rp;
1150  a3 = st;
1151  c3 = ct * rp;
1152  rbc = (b1*c2 - b2*c1)/c3;
1153  geod.v.h = (b2 * geoc.v.col[0] - b1 * geoc.v.col[1] + rbc * geoc.v.col[2])/(b2 * a1 - b1 * a2 + rbc*a3);
1154  geod.v.lat = (geoc.v.col[2] - a3 * geod.v.h) / c3;
1155  if (fabs(b1) > fabs(b2))
1156  geod.v.lon = (geoc.v.col[0] - a1 * geod.v.h - c1 * geod.v.lat) / b1;
1157  else
1158  geod.v.lon = (geoc.v.col[1] - a2 * geod.v.h - c2 * geod.v.lat) / b2;
1159 
1160  return 0;
1161 }
Definition: eci2kep_test.cpp:33
#define FRATIO2
Definition: convertdef.h:66
static double * p
Definition: gauss_jackson_test.cpp:42
rvector s
Location.
Definition: convertdef.h:163
double h
Height in meters.
Definition: vector.h:229
double lon
Longitude in radians.
Definition: vector.h:227
#define REARTHM
SI Radius of Earth.
Definition: convertdef.h:60
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
double col[3]
Definition: vector.h:55
gvector v
Velocity vector.
Definition: convertdef.h:265
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_geoc2geod ( locstruc loc)

Update locstruc GEOC to GEOD.

Convert a Geocentric cartpos to a Geodetic geoidpos in the provided locstruc.

Parameters
loclocstruc to be updated.
1168 {
1169  return pos_geoc2geod(*loc);
1170 }
int32_t pos_geoc2geod(locstruc *loc)
Update locstruc GEOC to GEOD.
Definition: convertlib.cpp:1167
int32_t pos_geoc2geod ( locstruc loc)
1173 {
1174  // Synchronize time
1175  if (0. == loc.pos.geoc.utc)
1176  {
1177  if (!std::isfinite(loc.utc))
1178  {
1179  return 0;
1180  }
1181  loc.pos.geoc.utc = loc.pos.utc = loc.utc;
1182  }
1183  else
1184  {
1185  if (!std::isfinite(loc.pos.geoc.utc))
1186  {
1187  return 0;
1188  }
1189  loc.utc = loc.pos.utc = loc.pos.geoc.utc;
1190  }
1191 
1192  // Update time
1193  loc.pos.geod.utc = loc.utc;
1194 
1195  // Update pass
1196  loc.pos.geod.pass = loc.pos.geoc.pass;
1197 
1198  // Update geodetic position
1199  geoc2geod(loc.pos.geoc, loc.pos.geod);
1200 
1201  // Determine magnetic field in Topocentric system
1202  geomag_front(loc.pos.geod.s, mjd2year(loc.utc), loc.pos.bearth);
1203 
1204  // Transform to ITRS
1206 
1207  return 0;
1208 }
rvector bearth
Earth magnetic vector in ITRS for this time and location.
Definition: convertdef.h:754
double utc
Definition: convertdef.h:261
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
const double DPI2
Double precision PI/2.
Definition: math/constants.h:18
quaternion q_change_around_y(double angle)
Rotation quaternion for Y axis.
Definition: vector.cpp:1435
double utc
Definition: convertdef.h:735
int32_t geoc2geod(cartpos &geoc, geoidpos &geod)
Convert GEOC to GEOD.
Definition: convertlib.cpp:1105
quaternion q_change_around_z(double angle)
Rotation quaternion for Z axis.
Definition: vector.cpp:1461
double lon
Longitude in radians.
Definition: vector.h:227
int32_t geomag_front(gvector pos, double time, rvector &comp)
Definition: geomag.cpp:99
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
geoidpos geod
Definition: convertdef.h:741
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
double mjd2year(double mjd)
Year from MJD.
Definition: timelib.cpp:997
int32_t geod2geoc ( geoidpos geod,
cartpos geoc 
)

Convert GEOD to GEOC.

Convert a Geodetic geoidpos to a Geocentric cartpos.

Parameters
geodSource Geodetic position.
geocDestination Geocentric position.
1216 {
1217  double lst, dlst, r, c, s, c2, rp;
1218  double cn, ct, sn, st;
1219 
1220  // Determine effects of oblate spheroid
1221  ct = cos(geod.s.lat);
1222  st = sin(geod.s.lat);
1223  c = 1./sqrt(ct * ct + FRATIO2 * st * st);
1224  c2 = c * c;
1225  s = FRATIO2 * c;
1226  r = (REARTHM * c + geod.s.h) * ct;
1227 
1228  geoc.s.col[2] = (REARTHM * s + geod.s.h) * st;
1229 
1230  lst = geod.s.lon;
1231  cn = cos(lst);
1232  sn = sin(lst);
1233  geoc.s.col[0] = r * cn;
1234  geoc.s.col[1] = r * sn;
1235 
1236  rp = geod.s.h + REARTHM * s * c2;
1237  geoc.v.col[2] = st * geod.v.h + rp * ct * geod.v.lat;
1238 
1239  dlst = geod.v.lon;
1240  geoc.v.col[0] = cn * ct * geod.v.h - geoc.s.col[1] * dlst - rp * cn * st * geod.v.lat;
1241  geoc.v.col[1] = sn * ct * geod.v.h + geoc.s.col[0] * dlst - rp * sn * st * geod.v.lat;
1242 
1243  return 0;
1244 }
#define FRATIO2
Definition: convertdef.h:66
rvector s
Location.
Definition: convertdef.h:163
double h
Height in meters.
Definition: vector.h:229
double lon
Longitude in radians.
Definition: vector.h:227
#define REARTHM
SI Radius of Earth.
Definition: convertdef.h:60
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
double col[3]
Definition: vector.h:55
gvector v
Velocity vector.
Definition: convertdef.h:265
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_geod2geoc ( locstruc loc)

Update GEOD to GEOC in locstruc.

Update the Geodetic geoidpos to a Geocentric cartpos in the provided locstruc.

Parameters
loclocstruc to be updated.
1251 {
1252  return pos_geod2geoc(*loc);
1253 }
int32_t pos_geod2geoc(locstruc *loc)
Update GEOD to GEOC in locstruc.
Definition: convertlib.cpp:1250
int32_t pos_geod2geoc ( locstruc loc)
1256 {
1257  // Synchronize time
1258  if (0. == loc.pos.geod.utc)
1259  {
1260  if (!std::isfinite(loc.utc))
1261  {
1262  return CONVERT_ERROR_UTC;
1263  }
1264  loc.pos.geod.utc = loc.pos.utc = loc.utc;
1265  }
1266  else
1267  {
1268  if (!std::isfinite(loc.pos.geod.utc))
1269  {
1270  return CONVERT_ERROR_UTC;
1271  }
1272  loc.utc = loc.pos.utc = loc.pos.geod.utc;
1273  }
1274 
1275  // Update time
1276  loc.pos.geoc.utc = loc.pos.geod.utc = loc.pos.utc = loc.utc;
1277 
1278  // Update pass
1279  loc.pos.geoc.pass = loc.pos.geod.pass;
1280 
1281  // Update the geocentric position
1282  geod2geoc(loc.pos.geod, loc.pos.geoc);
1283  return 0;
1284 }
double utc
Definition: convertdef.h:261
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int32_t geod2geoc(geoidpos &geod, cartpos &geoc)
Convert GEOD to GEOC.
Definition: convertlib.cpp:1215
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
double utc
Definition: convertdef.h:735
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
geoidpos geod
Definition: convertdef.h:741
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
int32_t pos_sci2selc ( locstruc loc)

Convert SCI to SELC.

Propagate the position found in the Selene Centered Inertial slot of the supplied locstruc to the Selenocentric slot, performing all relevant updates.

Parameters
locWorking locstruc
1292 {
1293  return pos_sci2selc(*loc);
1294 }
int32_t pos_sci2selc(locstruc *loc)
Convert SCI to SELC.
Definition: convertlib.cpp:1291
int32_t pos_sci2selc ( locstruc loc)
1297 {
1298  int32_t iretn;
1299  rvector v2;
1300  rmatrix m1;
1301 
1302  // Synchronize time
1303  if (0. == loc.pos.sci.utc)
1304  {
1305  if (!std::isfinite(loc.utc))
1306  {
1307  return CONVERT_ERROR_UTC;
1308  }
1309  loc.pos.sci.utc = loc.pos.utc = loc.utc;
1310  }
1311  else
1312  {
1313  if (!std::isfinite(loc.pos.sci.utc))
1314  {
1315  return CONVERT_ERROR_UTC;
1316  }
1317  loc.utc = loc.pos.utc = loc.pos.sci.utc;
1318  }
1319 
1320  // Update extra information
1321  iretn = pos_extra(loc);
1322  if (iretn < 0)
1323  {
1324  return iretn;
1325  }
1326 
1327  // Update time
1328  loc.pos.selc.utc = loc.utc;
1329 
1330  // Update pass
1331  loc.pos.selc.pass = loc.att.icrf.pass = loc.pos.sci.pass;
1332 
1333  // Apply first order transform to all: J2000 to ITRS, then Earth to Moon
1334  loc.pos.selc.s = rv_mmult(loc.pos.extra.j2s,loc.pos.sci.s);
1335  loc.pos.selc.v = rv_mmult(loc.pos.extra.j2s,loc.pos.sci.v);
1336  loc.pos.selc.a = rv_mmult(loc.pos.extra.j2s,loc.pos.sci.a);
1337 
1338  // Apply second order term due to first derivative of rotation matrix
1339  m1 = rm_mmult(loc.pos.extra.dt2s,loc.pos.extra.j2t);
1340  v2 = rv_mmult(m1,loc.pos.sci.s);
1341  loc.pos.selc.v = rv_add(loc.pos.selc.v,v2);
1342 
1343  v2 = rv_smult(2.,rv_mmult(m1,loc.pos.sci.v));
1344  loc.pos.selc.a = rv_add(loc.pos.selc.a,v2);
1345 
1346  // Convert SELC Position to SELG
1347  pos_selc2selg(loc);
1348 
1349  // Convert ICRF Attitude to SELC
1350  att_icrf2selc(loc);
1351 
1352  // Convert ITRF Attitude to Topo
1353  att_planec2topo(loc);
1354 
1355  // Convert ITRF Attitude to LVLH
1356  att_planec2lvlh(loc);
1357 
1358  return iretn;
1359 }
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
rmatrix j2s
Definition: convertdef.h:598
3 element generic row vector
Definition: vector.h:53
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
cartpos selc
Definition: convertdef.h:740
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
rmatrix dt2s
Definition: convertdef.h:604
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
int32_t att_icrf2selc(locstruc *loc)
Definition: convertlib.cpp:1710
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
rvector s
Location.
Definition: convertdef.h:163
attstruc att
attstruc for this time.
Definition: convertdef.h:883
3x3 element generic matrix
Definition: matrix.h:41
double utc
Definition: convertdef.h:735
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
qatt icrf
Definition: convertdef.h:830
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
int32_t pos_selc2selg(locstruc *loc)
Convert SELC to SELG.
Definition: convertlib.cpp:1432
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
rmatrix rm_mmult(rmatrix a, rmatrix b)
rmatrix Matrix Product
Definition: matrix.cpp:198
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rmatrix j2t
Definition: convertdef.h:597
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_selc2sci ( locstruc loc)

Convert SELC to SCI.

Propagate the position found in the Selenocentric slot of the supplied locstruc to the Selene Centered Inertial slot, performing all relevant updates.

Parameters
locWorking locstruc
1367 {
1368  return pos_selc2sci(*loc);
1369 }
int32_t pos_selc2sci(locstruc *loc)
Convert SELC to SCI.
Definition: convertlib.cpp:1366
int32_t pos_selc2sci ( locstruc loc)
1372 {
1373  int32_t iretn;
1374  rvector v2;
1375  rmatrix m1;
1376 
1377  // Synchroniz time
1378  if (0. == loc.pos.selc.utc)
1379  {
1380  if (!std::isfinite(loc.utc))
1381  {
1382  return CONVERT_ERROR_UTC;
1383  }
1384  loc.pos.selc.utc = loc.pos.utc = loc.utc;
1385  }
1386  else
1387  {
1388  if (!std::isfinite(loc.pos.selc.utc))
1389  {
1390  return CONVERT_ERROR_UTC;
1391  }
1392  loc.utc = loc.pos.utc = loc.pos.selc.utc;
1393  }
1394 
1395  // Update extra information
1396  iretn = pos_extra(loc);
1397  if (iretn < 0)
1398  {
1399  return iretn;
1400  }
1401 
1402  // Update time
1403  loc.pos.sci.utc = loc.utc;
1404 
1405  // Update pass
1406  loc.pos.sci.pass = loc.att.selc.pass = loc.pos.selc.pass;
1407 
1408  // Apply first order transform to all
1409  loc.pos.sci.s = rv_mmult(loc.pos.extra.s2j,loc.pos.selc.s);
1410  loc.pos.sci.v = rv_mmult(loc.pos.extra.s2j,loc.pos.selc.v);
1411  loc.pos.sci.a = rv_mmult(loc.pos.extra.s2j,loc.pos.selc.a);
1412 
1413  // Apply second order correction due to first derivative of rotation matrix
1414  m1 = rm_mmult(loc.pos.extra.t2j,loc.pos.extra.ds2t);
1415  v2 = rv_mmult(m1,loc.pos.selc.s);
1416  loc.pos.sci.v = rv_add(loc.pos.selc.v,v2);
1417 
1418  m1 = rm_smult(2.,m1);
1419  v2 = rv_mmult(m1,loc.pos.sci.v);
1420  loc.pos.sci.a = rv_add(loc.pos.selc.a,v2);
1421 
1422  // Convert SCI Attitude to ICRF
1423  att_selc2icrf(loc);
1424  return 0;
1425 }
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
3 element generic row vector
Definition: vector.h:53
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
cartpos selc
Definition: convertdef.h:740
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
rmatrix ds2t
Definition: convertdef.h:602
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rmatrix s2j
Definition: convertdef.h:600
rvector s
Location.
Definition: convertdef.h:163
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
3x3 element generic matrix
Definition: matrix.h:41
double utc
Definition: convertdef.h:735
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
rmatrix t2j
Definition: convertdef.h:599
int32_t att_selc2icrf(locstruc *loc)
Definition: convertlib.cpp:1760
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
rmatrix rm_smult(double a, rmatrix b)
Scalar rmatrix multiplication.
Definition: matrix.cpp:247
rmatrix rm_mmult(rmatrix a, rmatrix b)
rmatrix Matrix Product
Definition: matrix.cpp:198
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_selc2selg ( locstruc loc)

Convert SELC to SELG.

Propagate the position found in the Selenocentric slot of the supplied locstruc to the Selenographic slot, performing all relevant updates.

Parameters
locWorking locstruc
1433 {
1434  return pos_selc2selg(*loc);
1435 }
int32_t pos_selc2selg(locstruc *loc)
Convert SELC to SELG.
Definition: convertlib.cpp:1432
int32_t pos_selc2selg ( locstruc loc)
1438 {
1439  int32_t iretn;
1440  double xvx, yvy, r2, r, minir, minir2;
1441 
1442  // Synchroniz time
1443  if (0. == loc.pos.selc.utc)
1444  {
1445  if (!std::isfinite(loc.utc))
1446  {
1447  return CONVERT_ERROR_UTC;
1448  }
1449  loc.pos.selc.utc = loc.pos.utc = loc.utc;
1450  }
1451  else
1452  {
1453  if (!std::isfinite(loc.pos.selc.utc))
1454  {
1455  return CONVERT_ERROR_UTC;
1456  }
1457  loc.utc = loc.pos.utc = loc.pos.selc.utc;
1458  }
1459 
1460  // Update extra information
1461  iretn = pos_extra(loc);
1462  if (iretn < 0)
1463  {
1464  return iretn;
1465  }
1466 
1467  // Update time
1468  loc.pos.selg.utc = loc.utc;
1469 
1470  // Update pass
1471  loc.pos.selg.pass = loc.pos.selc.pass;
1472 
1473  // Convert Geocentric Cartesian to Spherical
1474  minir2 = loc.pos.selc.s.col[0]*loc.pos.selc.s.col[0]+loc.pos.selc.s.col[1]*loc.pos.selc.s.col[1];
1475  minir = fixprecision(sqrt(minir2),.1);
1476  r2 = minir2+loc.pos.selc.s.col[2]*loc.pos.selc.s.col[2];
1477  r = fixprecision(sqrt(r2),.1);
1478  loc.pos.selg.s.lat = asin(loc.pos.selc.s.col[2]/r);
1479  loc.pos.selg.s.lon = atan2(loc.pos.selc.s.col[1],loc.pos.selc.s.col[0]);
1480  loc.pos.selg.s.h = r - (RMOONM);
1481 
1482  xvx = loc.pos.selc.s.col[0]*loc.pos.selc.v.col[0];
1483  yvy = loc.pos.selc.s.col[1]*loc.pos.selc.v.col[1];
1484  loc.pos.selg.v.h = (xvx+yvy+loc.pos.selc.s.col[2]*loc.pos.selc.v.col[2])/r;
1485  loc.pos.selg.v.lat = (-(xvx+yvy) * loc.pos.selc.s.col[2] + minir2*loc.pos.selc.v.col[2])/(r2*minir);
1486  loc.pos.selg.v.lon = (loc.pos.selc.s.col[0]*loc.pos.selc.v.col[1]+loc.pos.selc.s.col[1]*loc.pos.selc.v.col[0])/minir2;
1487 
1488  // Indicate we have set SELG position
1489  loc.pos.selg.s.lat = fixprecision(loc.pos.selg.s.lat,.1/r);
1490  loc.pos.selg.s.lon = fixprecision(loc.pos.selg.s.lon,.1/r);
1491  return 0;
1492 }
double utc
Definition: convertdef.h:261
double utc
UTC of Position.
Definition: convertdef.h:161
cartpos selc
Definition: convertdef.h:740
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
geoidpos selg
Definition: convertdef.h:742
rvector s
Location.
Definition: convertdef.h:163
double utc
Definition: convertdef.h:735
double h
Height in meters.
Definition: vector.h:229
#define RMOONM
SI Radius of Moon.
Definition: convertdef.h:58
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
double lon
Longitude in radians.
Definition: vector.h:227
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
double col[3]
Definition: vector.h:55
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
gvector v
Velocity vector.
Definition: convertdef.h:265
double fixprecision(double number, double prec)
Limit precision.
Definition: mathlib.cpp:2191
rvector v
Velocity.
Definition: convertdef.h:165
int32_t pos_selg2selc ( locstruc loc)
1495 {
1496  return pos_selg2selc(*loc);
1497 }
int32_t pos_selg2selc(locstruc *loc)
Definition: convertlib.cpp:1494
int32_t pos_selg2selc ( locstruc loc)
1500 {
1501  int32_t iretn;
1502  double sp, cp, sl, cl, cpr, r;
1503 
1504  // Synchroniz time
1505  if (0. == loc.pos.selg.utc)
1506  {
1507  if (!std::isfinite(loc.utc))
1508  {
1509  return CONVERT_ERROR_UTC;
1510  }
1511  loc.pos.selg.utc = loc.pos.utc = loc.utc;
1512  }
1513  else
1514  {
1515  if (!std::isfinite(loc.pos.selg.utc))
1516  {
1517  return CONVERT_ERROR_UTC;
1518  }
1519  loc.utc = loc.pos.utc = loc.pos.selg.utc;
1520  }
1521 
1522  // Update extra information
1523  iretn = pos_extra(loc);
1524  if (iretn < 0)
1525  {
1526  return iretn;
1527  }
1528 
1529  // Update time
1530  loc.pos.selc.utc = loc.utc;
1531 
1532  // Update pass
1533  loc.pos.selc.pass = loc.pos.selg.pass;
1534 
1535  r = loc.pos.selg.s.h + RMOONM;
1536 
1537  sp = sin(loc.pos.selg.s.lat);
1538  cp = cos(loc.pos.selg.s.lat);
1539  sl = sin(loc.pos.selg.s.lon);
1540  cl = cos(loc.pos.selg.s.lon);
1541  cpr = cp * r;
1542 
1543  loc.pos.selc.s = loc.pos.selc.v = loc.pos.selc.a = rv_zero();
1544 
1545  loc.pos.selc.s.col[0] = cpr * cl;
1546  loc.pos.selc.s.col[1] = cpr * sl;
1547  loc.pos.selc.s.col[2] = r * sp;
1548 
1549  loc.pos.selc.v.col[0] = loc.pos.selg.v.h * cp * cl - loc.pos.selg.v.lat * r * sp * cl - loc.pos.selg.v.lon * cpr * sl;
1550  loc.pos.selc.v.col[1] = loc.pos.selg.v.h * cp * sl - loc.pos.selg.v.lat * r * sp * sl + loc.pos.selg.v.lon * cpr * cl;
1551  loc.pos.selc.v.col[2] = loc.pos.selg.v.h * sp + loc.pos.selg.v.lat * cpr;
1552 
1553  return 0;
1554 }
double utc
Definition: convertdef.h:261
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
cartpos selc
Definition: convertdef.h:740
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
geoidpos selg
Definition: convertdef.h:742
rvector s
Location.
Definition: convertdef.h:163
double utc
Definition: convertdef.h:735
double h
Height in meters.
Definition: vector.h:229
#define RMOONM
SI Radius of Moon.
Definition: convertdef.h:58
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
double lon
Longitude in radians.
Definition: vector.h:227
#define CONVERT_ERROR_UTC
Definition: cosmos-errno.h:254
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
double col[3]
Definition: vector.h:55
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
gvector v
Velocity vector.
Definition: convertdef.h:265
rvector v
Velocity.
Definition: convertdef.h:165
double rearth ( double  lat)
1557 {
1558  double st,ct;
1559  double c;
1560 
1561  st = sin(lat);
1562  ct = cos(lat);
1563  c = sqrt(((FRATIO2 * FRATIO2 * st * st) + (ct * ct))/((ct * ct) + (FRATIO2 * st * st)));
1564  return (REARTHM * c);
1565 }
#define FRATIO2
Definition: convertdef.h:66
#define REARTHM
SI Radius of Earth.
Definition: convertdef.h:60
int32_t att_extra ( locstruc loc)

Calculate Extra attitude information.

Calculate things like conversion matrix for ICRF to Body and Body to ICRF.

Parameters
loclocstruc with the current location and those to be updated.
1573 {
1574  att_extra(*loc);
1575 
1576  return 0;
1577 }
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
int32_t att_extra ( locstruc loc)
1580 {
1581  if (loc.att.extra.utc == loc.att.icrf.utc)
1582  return 0;
1583 
1584  loc.att.extra.b2j = rm_quaternion2dcm(loc.att.icrf.s);
1585  loc.att.extra.j2b = rm_transpose(loc.att.extra.b2j);
1586  loc.att.extra.utc = loc.att.icrf.utc;
1587 
1588  return 0;
1589 }
rmatrix rm_quaternion2dcm(quaternion q)
Quaternion to row matrix Direction Cosine Matrix.
Definition: mathlib.cpp:219
double utc
Definition: convertdef.h:477
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt icrf
Definition: convertdef.h:830
rmatrix j2b
Transform from ICRF to Body frame.
Definition: convertdef.h:694
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
rmatrix rm_transpose(rmatrix a)
rmatrix Transpose. Calculate the transpose of the supplied rmatrix.
Definition: matrix.cpp:172
extraatt extra
Definition: convertdef.h:831
rmatrix b2j
Transform from Body frame to ICRF.
Definition: convertdef.h:696
double utc
Coordinated Universal Time.
Definition: convertdef.h:692
int32_t att_icrf2geoc ( locstruc loc)
1592 {
1593  return att_icrf2geoc(*loc);
1594 }
int32_t att_icrf2geoc(locstruc *loc)
Definition: convertlib.cpp:1591
int32_t att_icrf2geoc ( locstruc loc)
1597 {
1598  int32_t iretn;
1599  rvector alpha;
1600  double radius;
1601 
1602  // Update extra
1603  iretn = pos_extra(loc);
1604  if (iretn < 0)
1605  {
1606  return iretn;
1607  }
1608  att_extra(loc);
1609 
1610  // Update time
1611  loc.att.geoc.utc = loc.att.icrf.utc = loc.utc;
1612 
1613  // Update pass
1614  loc.att.geoc.pass = loc.att.icrf.pass;
1615 
1616  // Use to rotate ECI into ITRS
1618  normalize_q(&loc.att.geoc.s);
1619  loc.att.geoc.v = rv_mmult(loc.pos.extra.j2e,loc.att.icrf.v);
1620  loc.att.geoc.a = rv_mmult(loc.pos.extra.j2e,loc.att.icrf.a);
1621 
1622  // Correct velocity for ECI angular velocity wrt ITRS, expressed in ITRS
1623  radius = length_rv(loc.pos.eci.s);
1624 
1625  alpha = rv_smult(1./(radius*radius),rv_cross(rv_mmult(loc.pos.extra.j2e,loc.pos.eci.s),rv_mmult(loc.pos.extra.dj2e,loc.pos.eci.s)));
1626  loc.att.geoc.v = rv_add(loc.att.geoc.v,alpha);
1627 
1628  alpha = rv_smult(2./(radius*radius),rv_cross(rv_mmult(loc.pos.extra.j2e,loc.pos.eci.s),rv_mmult(loc.pos.extra.dj2e,loc.pos.eci.v)));
1629  loc.att.geoc.a = rv_add(loc.att.geoc.a,alpha);
1630 
1631  // Convert ITRF attitude to Topocentric
1632  att_planec2topo(loc);
1633 
1634  // Convert ITRF attitude to LVLH
1635  att_planec2lvlh(loc);
1636  return 0;
1637 }
qatt geoc
Definition: convertdef.h:828
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
3 element generic row vector
Definition: vector.h:53
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
quaternion q_dcm2quaternion_rm(rmatrix m)
Row matrix DCM to Quaternion.
Definition: rotation.cpp:178
qatt icrf
Definition: convertdef.h:830
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
cartpos eci
Definition: convertdef.h:737
rmatrix dj2e
Definition: convertdef.h:591
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rmatrix j2e
Transform from ICRF to Geocentric.
Definition: convertdef.h:590
rvector v
Velocity.
Definition: convertdef.h:165
int32_t att_geoc2icrf ( locstruc loc)
1640 {
1641  att_geoc2icrf(*loc);
1642 
1643  return 0;
1644 }
int32_t att_geoc2icrf(locstruc *loc)
Definition: convertlib.cpp:1639
int32_t att_geoc2icrf ( locstruc loc)
1647 {
1648  // rmatrix fpm = {{{{0.}}}}, dpm = {{{{0.}}}};
1649  rvector alpha;
1650  double radius;
1651 
1652  // Propagate time
1653  loc.att.icrf.utc = loc.att.geoc.utc = loc.utc;
1654 
1655  // Update pass
1656  loc.att.icrf.pass = loc.att.geoc.pass;
1657 
1658  // Update extra
1659  att_extra(loc);
1660 
1661  // Perform first order rotation of ITRS frame into ECI frame
1663  normalize_q(&loc.att.icrf.s);
1664  loc.att.icrf.v = rv_mmult(loc.pos.extra.e2j,loc.att.geoc.v);
1665  loc.att.icrf.a = rv_mmult(loc.pos.extra.e2j,loc.att.geoc.a);
1666 
1667  // Correct for ITRS angular velocity wrt ECI, expressed in ECI
1668  radius = length_rv(loc.pos.geoc.s);
1669 
1670  alpha = rv_smult(1./(radius*radius),rv_cross(rv_mmult(loc.pos.extra.e2j,loc.pos.geoc.s),rv_mmult(loc.pos.extra.de2j,loc.pos.geoc.s)));
1671  loc.att.icrf.v = rv_add(loc.att.icrf.v,alpha);
1672 
1673  alpha = rv_smult(2./(radius*radius),rv_cross(rv_mmult(loc.pos.extra.e2j,loc.pos.geoc.s),rv_mmult(loc.pos.extra.de2j,loc.pos.geoc.v)));
1674  loc.att.icrf.a = rv_add(loc.att.icrf.a,alpha);
1675 
1676  // Extra attitude information
1677  att_extra(loc);
1678 
1679  return 0;
1680 }
qatt geoc
Definition: convertdef.h:828
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
3 element generic row vector
Definition: vector.h:53
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
rmatrix de2j
Definition: convertdef.h:595
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
quaternion q_dcm2quaternion_rm(rmatrix m)
Row matrix DCM to Quaternion.
Definition: rotation.cpp:178
qatt icrf
Definition: convertdef.h:830
extrapos extra
Definition: convertdef.h:744
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
rmatrix e2j
Transform from Geocentric to ICRF.
Definition: convertdef.h:594
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rvector v
Velocity.
Definition: convertdef.h:165
int32_t att_geoc ( locstruc loc)
1683 {
1684  att_geoc(*loc);
1685 
1686  return 0;
1687 }
int32_t att_geoc(locstruc *loc)
Definition: convertlib.cpp:1682
int32_t att_geoc ( locstruc loc)
1690 {
1691  if (loc.att.geoc.pass > loc.att.topo.pass)
1692  {
1693  att_planec2topo(loc);
1694  att_topo(loc);
1695  }
1696  if (loc.att.geoc.pass > loc.att.lvlh.pass)
1697  {
1698  att_planec2lvlh(loc);
1699  att_lvlh(loc);
1700  }
1701  if (loc.att.geoc.pass > loc.att.icrf.pass)
1702  {
1703  att_geoc2icrf(loc);
1704  att_icrf(loc);
1705  }
1706 
1707  return 0;
1708 }
qatt geoc
Definition: convertdef.h:828
int32_t att_icrf(locstruc *loc)
Definition: convertlib.cpp:1836
qatt lvlh
Definition: convertdef.h:827
attstruc att
attstruc for this time.
Definition: convertdef.h:883
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
qatt icrf
Definition: convertdef.h:830
int32_t att_geoc2icrf(locstruc *loc)
Definition: convertlib.cpp:1639
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
qatt topo
Definition: convertdef.h:826
int32_t att_topo(locstruc *loc)
Definition: convertlib.cpp:2252
int32_t att_lvlh(locstruc *loc)
Definition: convertlib.cpp:2064
int32_t att_icrf2selc ( locstruc loc)
1711 {
1712  return att_icrf2selc(*loc);
1713 }
int32_t att_icrf2selc(locstruc *loc)
Definition: convertlib.cpp:1710
int32_t att_icrf2selc ( locstruc loc)
1716 {
1717  int32_t iretn;
1718  rmatrix dpm;
1719  rvector alpha;
1720  double radius;
1721 
1722  // Propagate time
1723  loc.att.icrf.utc = loc.att.selc.utc = loc.utc;
1724 
1725  // Update pass
1726  loc.att.selc.pass = loc.att.icrf.pass;
1727 
1728  att_extra(loc);
1729  iretn = pos_extra(loc);
1730  if (iretn < 0)
1731  {
1732  return iretn;
1733  }
1734 
1735  // Use to rotate ICRF into SELC
1737  normalize_q(&loc.att.selc.s);
1738  loc.att.selc.v = rv_mmult(loc.pos.extra.j2s,loc.att.icrf.v);
1739  loc.att.selc.a = rv_mmult(loc.pos.extra.j2s,loc.att.icrf.a);
1740 
1741  // Correct velocity for ECI angular velocity wrt ITRS, expressed in ITRS
1742  radius = length_rv(loc.pos.eci.s);
1743 
1744  dpm = rm_zero();
1745 
1746  alpha = rv_smult(1./(radius*radius),rv_cross(rv_mmult(loc.pos.extra.j2s,loc.pos.eci.s),rv_mmult(dpm,loc.pos.eci.s)));
1747  loc.att.selc.v = rv_add(loc.att.selc.v,alpha);
1748 
1749  alpha = rv_smult(2./(radius*radius),rv_cross(rv_mmult(loc.pos.extra.j2s,loc.pos.eci.s),rv_mmult(dpm,loc.pos.eci.v)));
1750  loc.att.selc.a = rv_add(loc.att.selc.a,alpha);
1751 
1752  // Synchronize LVLH
1753  att_planec2lvlh(loc);
1754 
1755  // Synchronize Topo
1756  att_planec2topo(loc);
1757  return 0;
1758 }
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
rmatrix j2s
Definition: convertdef.h:598
3 element generic row vector
Definition: vector.h:53
rmatrix rm_zero()
Zero filled rmatrix.
Definition: matrix.cpp:125
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
int iretn
Definition: rw_test.cpp:37
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
3x3 element generic matrix
Definition: matrix.h:41
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
quaternion q_dcm2quaternion_rm(rmatrix m)
Row matrix DCM to Quaternion.
Definition: rotation.cpp:178
qatt icrf
Definition: convertdef.h:830
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
cartpos eci
Definition: convertdef.h:737
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rvector v
Velocity.
Definition: convertdef.h:165
int32_t att_selc2icrf ( locstruc loc)
1761 {
1762  att_selc2icrf(*loc);
1763 
1764  return 0;
1765 }
int32_t att_selc2icrf(locstruc *loc)
Definition: convertlib.cpp:1760
int32_t att_selc2icrf ( locstruc loc)
1768 {
1769  // rmatrix fpm = {{{{0.}}}};
1770 
1771  // Propagate time
1772  loc.att.icrf.utc = loc.att.selc.utc = loc.utc;
1773 
1774  // Update pass
1775  loc.att.icrf.pass = loc.att.selc.pass;
1776 
1777  att_extra(loc);
1778 
1779  // Calculate rotation matrix to J2000
1780  // fpm = loc.pos.extra.s2j;
1781 
1782  // Perform first order rotation of SELC frame into ICRF frame
1784  normalize_q(&loc.att.icrf.s);
1785  loc.att.icrf.v = rv_mmult(loc.pos.extra.s2j,loc.att.selc.v);
1786  loc.att.icrf.a = rv_mmult(loc.pos.extra.s2j,loc.att.selc.a);
1787 
1788  // Extra attitude information
1789  att_extra(loc);
1790 
1791  return 0;
1792 }
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
rmatrix s2j
Definition: convertdef.h:600
double utc
Definition: convertdef.h:477
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
quaternion q_dcm2quaternion_rm(rmatrix m)
Row matrix DCM to Quaternion.
Definition: rotation.cpp:178
qatt icrf
Definition: convertdef.h:830
extrapos extra
Definition: convertdef.h:744
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
int32_t att_selc ( locstruc loc)
1795 {
1796  att_selc(*loc);
1797 
1798  return 0;
1799 }
int32_t att_selc(locstruc *loc)
Definition: convertlib.cpp:1794
int32_t att_selc ( locstruc loc)
1802 {
1803  if (loc.att.selc.pass > loc.att.topo.pass)
1804  {
1805  att_planec2topo(loc);
1806  att_topo(loc);
1807  }
1808  if (loc.att.selc.pass > loc.att.lvlh.pass)
1809  {
1810  att_planec2lvlh(loc);
1811  att_lvlh(loc);
1812  }
1813  if (loc.att.selc.pass > loc.att.icrf.pass)
1814  {
1815  att_selc2icrf(loc);
1816  att_icrf(loc);
1817  }
1818 
1819  return 0;
1820 }
int32_t att_icrf(locstruc *loc)
Definition: convertlib.cpp:1836
qatt lvlh
Definition: convertdef.h:827
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
qatt icrf
Definition: convertdef.h:830
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
int32_t att_selc2icrf(locstruc *loc)
Definition: convertlib.cpp:1760
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
qatt topo
Definition: convertdef.h:826
int32_t att_topo(locstruc *loc)
Definition: convertlib.cpp:2252
int32_t att_lvlh(locstruc *loc)
Definition: convertlib.cpp:2064
int32_t att_icrf2lvlh ( locstruc loc)
1823 {
1824  att_icrf2lvlh(*loc);
1825  return 0;
1826 }
int32_t att_icrf2lvlh(locstruc *loc)
Definition: convertlib.cpp:1822
int32_t att_icrf2lvlh ( locstruc loc)
1829 {
1830  att_icrf2geoc(loc);
1831  att_icrf2selc(loc);
1832  att_planec2lvlh(loc);
1833  return 0;
1834 }
int32_t att_icrf2selc(locstruc *loc)
Definition: convertlib.cpp:1710
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
int32_t att_icrf2geoc(locstruc *loc)
Definition: convertlib.cpp:1591
int32_t att_icrf ( locstruc loc)
1837 {
1838  att_icrf(*loc);
1839  return 0;
1840 }
int32_t att_icrf(locstruc *loc)
Definition: convertlib.cpp:1836
int32_t att_icrf ( locstruc loc)
1843 {
1844  if (loc.att.icrf.pass > loc.att.geoc.pass)
1845  {
1846  att_icrf2geoc(loc);
1847  att_geoc(loc);
1848  }
1849 
1850  if (loc.att.icrf.pass > loc.att.selc.pass)
1851  {
1852  att_icrf2selc(loc);
1853  att_selc(loc);
1854  }
1855  return 0;
1856 }
int32_t att_selc(locstruc *loc)
Definition: convertlib.cpp:1794
qatt geoc
Definition: convertdef.h:828
int32_t att_icrf2selc(locstruc *loc)
Definition: convertlib.cpp:1710
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
qatt icrf
Definition: convertdef.h:830
int32_t att_geoc(locstruc *loc)
Definition: convertlib.cpp:1682
int32_t att_icrf2geoc(locstruc *loc)
Definition: convertlib.cpp:1591
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
int32_t att_planec2lvlh ( locstruc loc)

Convert ITRS attitude to LVLH attitude.

Calculate the rotation quaternion for taking a vector from LVLH to Body given the similar quaternion for ITRS

Parameters
locLocation structure to propagate the changes in
1864 {
1865  att_planec2lvlh(*loc);
1866  return 0;
1867 }
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
int32_t att_planec2lvlh ( locstruc loc)
1870 {
1871  quaternion qe_z = {{0.,0.,0.},1.}, qe_y = {{0.,0.,0.},1.}, fqe = {{0.,0.,0.},1.}, rqe = {{0.,0.,0.},1.};
1872  rvector lvlh_z = {0.,0.,1.}, lvlh_y = {0.,1.,0.}, geoc_z = {0.,0.,0.}, geoc_y = {0.,0.,0.}, alpha = {0.,0.,0.};
1873  qatt *patt;
1874  cartpos *ppos;
1875  double radius;
1876 
1877  switch (loc.pos.extra.closest)
1878  {
1879  case COSMOS_EARTH:
1880  default:
1881  patt = &loc.att.geoc;
1882  ppos = &loc.pos.geoc;
1883  break;
1884  case COSMOS_MOON:
1885  patt = &loc.att.selc;
1886  ppos = &loc.pos.selc;
1887  break;
1888  }
1889 
1890  radius = length_rv(ppos->s);
1891 
1892  // Update time
1893  loc.att.lvlh.utc = patt->utc = loc.utc;
1894 
1895  // Update pass
1896  loc.att.lvlh.pass = patt->pass;
1897 
1898  att_extra(loc);
1899 
1900  // LVLH Z is opposite of direction to satellite
1901  geoc_z = rv_smult(-1.,ppos->s);
1902  normalize_rv(geoc_z);
1903 
1904  // LVLH Y is Cross Product of LVLH Z and velocity vector
1905  geoc_y = rv_cross(geoc_z,ppos->v);
1906  normalize_rv(geoc_y);
1907 
1908  // Determine intrinsic rotation of ITRF Z into LVLH Z
1909  qe_z = q_conjugate(q_drotate_between_rv(geoc_z,lvlh_z));
1910 
1911  // Use to intrinsically rotate ITRF Y into intermediate Y
1912  // geoc_y = drotate(qe_z,geoc_y);
1913  geoc_y = irotate(qe_z,geoc_y);
1914 
1915  // Determine intrinsic rotation of this intermediate Y into LVLH Y
1916  qe_y = q_conjugate(q_drotate_between_rv(geoc_y,lvlh_y));
1917 
1918  // Combine to determine intrinsic rotation of ITRF into LVLH
1919  fqe = q_fmult(qe_z,qe_y);
1920  normalize_q(&fqe);
1921  rqe = q_conjugate(fqe);
1922 
1923  // Correct velocity for LVLH angular velocity wrt ITRS, expressed in ITRS
1924  alpha = rv_smult(1./(radius*radius),rv_cross(ppos->s,ppos->v));
1925  loc.att.lvlh.v = rv_sub(patt->v,alpha);
1926 
1927  // Transform ITRS into LVLH
1928  // loc.att.lvlh.s = q_fmult(patt->s,fqe);
1929  // loc.att.lvlh.v = irotate(fqe,loc.att.lvlh.v);
1930  // loc.att.lvlh.a = irotate(fqe,patt->a);
1931  loc.att.lvlh.s = q_fmult(rqe,patt->s);
1932  loc.att.lvlh.v = irotate(fqe,loc.att.lvlh.v);
1933  loc.att.lvlh.a = irotate(fqe,patt->a);
1934 
1935  return 0;
1936 }
qatt geoc
Definition: convertdef.h:828
Quaternion Attitude.
Definition: convertdef.h:475
3 element generic row vector
Definition: vector.h:53
cartpos selc
Definition: convertdef.h:740
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
Cartesian full position structure.
Definition: convertdef.h:158
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
quaternion q_conjugate(quaternion q)
Definition: vector.cpp:1010
void normalize_rv(rvector &v)
Normalize row order vector in place.
Definition: vector.cpp:222
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
qatt lvlh
Definition: convertdef.h:827
uint16_t closest
Definition: convertdef.h:607
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
quaternion q_drotate_between_rv(rvector from, rvector to)
Create rotation quaternion from 2 row vectors.
Definition: mathlib.cpp:81
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
extrapos extra
Definition: convertdef.h:744
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rvector v
Velocity.
Definition: convertdef.h:165
int32_t att_lvlh2planec ( locstruc loc)

Convert LVLH attitude to ITRS attitude.

Calculate the rotation quaternion for taking a vector from ITRS to Body given the similar quaternion for LVLH

Parameters
locLocation structure to propagate the changes in
1944 {
1945  att_lvlh2planec(*loc);
1946  return 0;
1947 }
int32_t att_lvlh2planec(locstruc *loc)
Convert LVLH attitude to ITRS attitude.
Definition: convertlib.cpp:1943
int32_t att_lvlh2planec ( locstruc loc)
1950 {
1951  quaternion qe_z = {{0.,0.,0.},1.}, qe_y = {{0.,0.,0.},1.}, fqe = {{0.,0.,0.},1.}, rqe = {{0.,0.,0.},1.};
1952  rvector lvlh_z = {0.,0.,1.}, lvlh_y = {0.,1.,0.}, geoc_z = {0.,0.,0.}, geoc_y = {0.,0.,0.}, alpha = {0.,0.,0.};
1953  qatt *patt;
1954  cartpos *ppos;
1955  double radius;
1956 
1957  switch (loc.pos.extra.closest)
1958  {
1959  case COSMOS_EARTH:
1960  default:
1961  patt = &loc.att.geoc;
1962  ppos = &loc.pos.geoc;
1963  break;
1964  case COSMOS_MOON:
1965  patt = &loc.att.selc;
1966  ppos = &loc.pos.selc;
1967  break;
1968  }
1969  radius = length_rv(ppos->s);
1970 
1971 
1972  // Update time
1973  loc.att.lvlh.utc = patt->utc = loc.utc;
1974 
1975  // Update pass
1976  ppos->pass = patt->pass = loc.att.lvlh.pass;
1977 
1978  att_extra(loc);
1979 
1980  // LVLH Z is opposite of earth to satellite vector
1981  geoc_z = rv_smult(-1.,ppos->s);
1982  normalize_rv(geoc_z);
1983 
1984  // LVLH Y is Cross Product of LVLH Z and velocity vector
1985  geoc_y = rv_cross(geoc_z,ppos->v);
1986  normalize_rv(geoc_y);
1987 
1988  // Determine rotation of ITRF Z into LVLH Z
1989  qe_z = q_conjugate(q_drotate_between_rv(geoc_z,lvlh_z));
1990  geoc_z = irotate(qe_z,geoc_z);
1991 
1992  // Use to rotate LVLH Y into intermediate LVLH Y
1993  // geoc_y = drotate(qe_z,geoc_y);
1994  geoc_y = irotate(qe_z,geoc_y);
1995 
1996  // Determine rotation of this LVLH Y into ITRF Y
1997  qe_y = q_conjugate(q_drotate_between_rv(geoc_y,lvlh_y));
1998 
1999  // Multiply to determine transformation of ITRF frame into LVLH frame
2000  fqe = q_fmult(qe_z,qe_y);
2001  normalize_q(&fqe);
2002  rqe = q_conjugate(fqe);
2003 
2004  // LVLH Z is opposite of earth to satellite vector
2005  geoc_z = rv_smult(-1.,ppos->s);
2006  normalize_rv(geoc_z);
2007 
2008  // LVLH Y is Cross Product of LVLH Z and velocity vector
2009  geoc_y = rv_cross(geoc_z,ppos->v);
2010  normalize_rv(geoc_y);
2011 
2012  // Rotate LVLH frame into ITRS frame
2013  // patt->s = q_fmult(rqe,loc.att.lvlh.s);
2014  // patt->v = irotate(fqe,loc.att.lvlh.v);
2015  // patt->a = irotate(fqe,loc.att.lvlh.a);
2016  patt->s = q_fmult(fqe,loc.att.lvlh.s);
2017  patt->v = irotate(rqe,loc.att.lvlh.v);
2018  patt->a = irotate(rqe,loc.att.lvlh.a);
2019 
2020  // Correct velocity for LVLH angular velocity wrt ITRS, expressed in ITRS
2021  alpha = rv_smult(1./(radius*radius),rv_cross(ppos->s,ppos->v));
2022  patt->v = rv_add(patt->v,alpha);
2023 
2024  // Synchronize Topo
2025  att_planec2topo(loc);
2026 
2027  return 0;
2028 }
qatt geoc
Definition: convertdef.h:828
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
Quaternion Attitude.
Definition: convertdef.h:475
3 element generic row vector
Definition: vector.h:53
cartpos selc
Definition: convertdef.h:740
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
Cartesian full position structure.
Definition: convertdef.h:158
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
quaternion q_conjugate(quaternion q)
Definition: vector.cpp:1010
void normalize_rv(rvector &v)
Normalize row order vector in place.
Definition: vector.cpp:222
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
qatt lvlh
Definition: convertdef.h:827
uint16_t closest
Definition: convertdef.h:607
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
quaternion q_drotate_between_rv(rvector from, rvector to)
Create rotation quaternion from 2 row vectors.
Definition: mathlib.cpp:81
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
extrapos extra
Definition: convertdef.h:744
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rvector v
Velocity.
Definition: convertdef.h:165
int32_t att_lvlh2icrf ( locstruc loc)

Convert LVLH attitude to ICRF attitude.

Calculate the rotation quaternion for taking a vector from ICRF to Body given the similar quaternion for LVLH

Parameters
locLocation structure to propagate the changes in
2036 {
2037  return att_lvlh2icrf(*loc);
2038 }
int32_t att_lvlh2icrf(locstruc *loc)
Convert LVLH attitude to ICRF attitude.
Definition: convertlib.cpp:2035
int32_t att_lvlh2icrf ( locstruc loc)
2041 {
2042  int32_t iretn;
2043  iretn = pos_extra(loc);
2044  if (iretn < 0)
2045  {
2046  return iretn;
2047  }
2048  att_extra(loc);
2049 
2050  att_lvlh2planec(loc);
2051  switch (loc.pos.extra.closest)
2052  {
2053  case COSMOS_EARTH:
2054  default:
2055  att_geoc2icrf(loc);
2056  break;
2057  case COSMOS_MOON:
2058  att_selc2icrf(loc);
2059  break;
2060  }
2061  return 0;
2062 }
int iretn
Definition: rw_test.cpp:37
uint16_t closest
Definition: convertdef.h:607
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
int32_t att_geoc2icrf(locstruc *loc)
Definition: convertlib.cpp:1639
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
int32_t att_selc2icrf(locstruc *loc)
Definition: convertlib.cpp:1760
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
int32_t att_lvlh2planec(locstruc *loc)
Convert LVLH attitude to ITRS attitude.
Definition: convertlib.cpp:1943
int32_t att_lvlh ( locstruc loc)
2065 {
2066  return att_lvlh(*loc);
2067 }
int32_t att_lvlh(locstruc *loc)
Definition: convertlib.cpp:2064
int32_t att_lvlh ( locstruc loc)
2070 {
2071  int32_t iretn;
2072  iretn = pos_extra(loc);
2073  if (iretn < 0)
2074  {
2075  return iretn;
2076  }
2077  att_extra(loc);
2078 
2079  switch (loc.pos.extra.closest)
2080  {
2081  case COSMOS_EARTH:
2082  default:
2083  if (loc.att.lvlh.pass > loc.att.geoc.pass)
2084  {
2085  att_lvlh2planec(loc);
2086  att_geoc(loc);
2087  }
2088  break;
2089  case COSMOS_MOON:
2090  if (loc.att.lvlh.pass > loc.att.selc.pass)
2091  {
2092  att_lvlh2planec(loc);
2093  att_selc(loc);
2094  }
2095  break;
2096  }
2097  return 0;
2098 }
int32_t att_selc(locstruc *loc)
Definition: convertlib.cpp:1794
qatt geoc
Definition: convertdef.h:828
int iretn
Definition: rw_test.cpp:37
qatt lvlh
Definition: convertdef.h:827
uint16_t closest
Definition: convertdef.h:607
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
int32_t att_geoc(locstruc *loc)
Definition: convertlib.cpp:1682
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
int32_t att_lvlh2planec(locstruc *loc)
Convert LVLH attitude to ITRS attitude.
Definition: convertlib.cpp:1943
int32_t att_planec2topo ( locstruc loc)

Planetocentric to Topo attitude.

Calculate the rotation quaternion for taking a vector between Topo and the closest planetocentric system and update whichever is older.

Parameters
locLocation structure to update
2106 {
2107  att_planec2topo(*loc);
2108  return 0;
2109 }
int32_t att_planec2topo(locstruc *loc)
Planetocentric to Topo attitude.
Definition: convertlib.cpp:2105
int32_t att_planec2topo ( locstruc loc)
2112 {
2113  quaternion t2g, t2g_z, t2g_x, g2t;
2114  rvector geoc_x, topo_x, alpha;
2115  qatt *patt;
2116  cartpos *ppos;
2117 
2118  switch (loc.pos.extra.closest)
2119  {
2120  case COSMOS_EARTH:
2121  default:
2122  patt = &loc.att.geoc;
2123  ppos = &loc.pos.geoc;
2124  break;
2125  case COSMOS_MOON:
2126  patt = &loc.att.selc;
2127  ppos = &loc.pos.selc;
2128  break;
2129  }
2130 
2131  // Update time
2132  loc.att.topo.utc = patt->utc = loc.utc;
2133 
2134  // Update pass
2135  loc.att.topo.pass = patt->pass;
2136 
2137  att_extra(loc);
2138 
2139  // Determine rotation of Topo unit Z into ITRS Z
2140  t2g_z = q_conjugate(q_drotate_between_rv(rv_unitz(),ppos->s));
2141 
2142  // Use to rotate Topo unit X into intermediate Topo X
2143  topo_x = irotate(t2g_z,rv_unitx());
2144 
2145  // Define ITRS unit x as x=-Topo.y and y=Topo.x
2146  geoc_x.col[0] = -ppos->s.col[1];
2147  geoc_x.col[1] = ppos->s.col[0];
2148 
2149  // Determine rotation of intermediate Topo X into ITRS unit X
2150  t2g_x = q_conjugate(q_drotate_between_rv(topo_x,geoc_x));
2151 
2152  // Multiply to determine rotation of Topo frame into ITRS frame
2153  t2g = q_fmult(t2g_z,t2g_x);
2154  normalize_q(&t2g);
2155  g2t = q_conjugate(t2g);
2156 
2157  // Correct velocity for Topo angular velocity wrt ITRS, expressed in ITRS
2158  alpha = rv_smult(-1./(length_rv(ppos->s)*length_rv(ppos->s)),rv_cross(ppos->s,ppos->v));
2159  loc.att.topo.v = rv_add(patt->v, alpha);
2160 
2161  // Rotate ITRS frame into Topo frame
2162  loc.att.topo.s = q_fmult(g2t, patt->s);
2163  loc.att.topo.v = irotate(t2g,loc.att.topo.v);
2164  loc.att.topo.a = irotate(t2g,patt->a);
2165 
2166  return 0;
2167 }
qatt geoc
Definition: convertdef.h:828
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
Quaternion Attitude.
Definition: convertdef.h:475
3 element generic row vector
Definition: vector.h:53
cartpos selc
Definition: convertdef.h:740
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
Cartesian full position structure.
Definition: convertdef.h:158
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
quaternion q_conjugate(quaternion q)
Definition: vector.cpp:1010
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
uint16_t closest
Definition: convertdef.h:607
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
quaternion q_drotate_between_rv(rvector from, rvector to)
Create rotation quaternion from 2 row vectors.
Definition: mathlib.cpp:81
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
extrapos extra
Definition: convertdef.h:744
rvector rv_unitz(double scale)
Scaled z row vector.
Definition: vector.cpp:140
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
qatt topo
Definition: convertdef.h:826
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
double col[3]
Definition: vector.h:55
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
rvector rv_unitx(double scale)
Scaled x row vector.
Definition: vector.cpp:118
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rvector v
Velocity.
Definition: convertdef.h:165
int32_t att_topo2planec ( locstruc loc)

Topocentric to Planetocentric attitude.

Calculate the rotation quaternion for taking a vector between Topo and the closest planetocentric system and update whichever is older.

Parameters
locLocation structure to update
2175 {
2176  att_topo2planec(*loc);
2177  return 0;
2178 }
int32_t att_topo2planec(locstruc *loc)
Topocentric to Planetocentric attitude.
Definition: convertlib.cpp:2174
int32_t att_topo2planec ( locstruc loc)
2181 {
2182  quaternion t2g, t2g_z, t2g_x, g2t;
2183  rvector geoc_x, topo_x, alpha;
2184  qatt *patt;
2185  cartpos *ppos;
2186 
2187  switch (loc.pos.extra.closest)
2188  {
2189  case COSMOS_EARTH:
2190  default:
2191  patt = &loc.att.geoc;
2192  ppos = &loc.pos.geoc;
2193  break;
2194  case COSMOS_MOON:
2195  patt = &loc.att.selc;
2196  ppos = &loc.pos.selc;
2197  break;
2198  }
2199 
2200  // Update time
2201  patt->utc = loc.att.topo.utc = loc.utc;
2202 
2203  // Update pass
2204  ppos->pass = patt->pass = loc.att.topo.pass;
2205 
2206  att_extra(loc);
2207 
2208  // Determine rotation of Topo unit Z into ITRS Z
2209  t2g_z = q_conjugate(q_drotate_between_rv(rv_unitz(),ppos->s));
2210 
2211  // Use to rotate Topo unit X into intermediate Topo X
2212  topo_x = irotate(t2g_z,rv_unitx());
2213 
2214  // Define ITRS unit x as x=-Topo.y and y=Topo.x
2215  geoc_x.col[0] = -ppos->s.col[1];
2216  geoc_x.col[1] = ppos->s.col[0];
2217 
2218  // Determine rotation of intermediate Topo X into ITRS unit X
2219  t2g_x = q_conjugate(q_drotate_between_rv(topo_x,geoc_x));
2220 
2221  // Multiply to determine rotation of Topo frame into ITRS frame
2222  t2g = q_fmult(t2g_z,t2g_x);
2223  normalize_q(&t2g);
2224  g2t = q_conjugate(t2g);
2225 
2226  // Rotate Topo frame into ITRS frame
2227  patt->s = q_fmult(loc.att.topo.s,t2g);
2228  patt->v = irotate(g2t,loc.att.topo.v);
2229  patt->a = irotate(g2t,loc.att.topo.a);
2230 
2231  // Correct velocity for Topo angular velocity wrt ITRS, expressed in ITRS
2232  alpha = rv_smult(-1./(length_rv(ppos->s)*length_rv(ppos->s)),rv_cross(ppos->s,ppos->v));
2233 
2234  // Correct for rotation of frame
2235  patt->v = rv_add(loc.att.topo.v,alpha);
2236 
2237  switch (loc.pos.extra.closest)
2238  {
2239  case COSMOS_EARTH:
2240  default:
2241  att_geoc2icrf(loc);
2242  break;
2243  case COSMOS_MOON:
2244  att_selc2icrf(loc);
2245  break;
2246  }
2247  att_planec2lvlh(loc);
2248 
2249  return 0;
2250 }
qatt geoc
Definition: convertdef.h:828
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
Quaternion Attitude.
Definition: convertdef.h:475
3 element generic row vector
Definition: vector.h:53
cartpos selc
Definition: convertdef.h:740
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
Cartesian full position structure.
Definition: convertdef.h:158
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
quaternion q_conjugate(quaternion q)
Definition: vector.cpp:1010
cartpos geoc
Definition: convertdef.h:739
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
uint16_t closest
Definition: convertdef.h:607
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
double utc
Definition: convertdef.h:477
rvector s
Location.
Definition: convertdef.h:163
quaternion q_drotate_between_rv(rvector from, rvector to)
Create rotation quaternion from 2 row vectors.
Definition: mathlib.cpp:81
void normalize_q(quaternion *q)
Definition: vector.cpp:961
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
int32_t att_planec2lvlh(locstruc *loc)
Convert ITRS attitude to LVLH attitude.
Definition: convertlib.cpp:1863
int32_t att_geoc2icrf(locstruc *loc)
Definition: convertlib.cpp:1639
extrapos extra
Definition: convertdef.h:744
rvector rv_unitz(double scale)
Scaled z row vector.
Definition: vector.cpp:140
int32_t att_selc2icrf(locstruc *loc)
Definition: convertlib.cpp:1760
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
qatt topo
Definition: convertdef.h:826
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
double col[3]
Definition: vector.h:55
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
rvector rv_unitx(double scale)
Scaled x row vector.
Definition: vector.cpp:118
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rvector v
Velocity.
Definition: convertdef.h:165
int32_t att_topo ( locstruc loc)
2253 {
2254  return att_topo(*loc);
2255 }
int32_t att_topo(locstruc *loc)
Definition: convertlib.cpp:2252
int32_t att_topo ( locstruc loc)
2258 {
2259  int32_t iretn;
2260  iretn = pos_extra(loc);
2261  if (iretn < 0)
2262  {
2263  return iretn;
2264  }
2265  att_extra(loc);
2266 
2267  switch (loc.pos.extra.closest)
2268  {
2269  case COSMOS_EARTH:
2270  default:
2271  if (loc.att.topo.pass > loc.att.geoc.pass)
2272  {
2273  att_topo2planec(loc);
2274  att_geoc(loc);
2275  }
2276  break;
2277  case COSMOS_MOON:
2278  if (loc.att.topo.pass > loc.att.selc.pass)
2279  {
2280  att_topo2planec(loc);
2281  att_selc(loc);
2282  }
2283  break;
2284  }
2285  return 0;
2286 }
int32_t att_selc(locstruc *loc)
Definition: convertlib.cpp:1794
qatt geoc
Definition: convertdef.h:828
int iretn
Definition: rw_test.cpp:37
uint16_t closest
Definition: convertdef.h:607
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
int32_t att_geoc(locstruc *loc)
Definition: convertlib.cpp:1682
int32_t pos_extra(locstruc *loc)
Calculate Extra position information.
Definition: convertlib.cpp:107
extrapos extra
Definition: convertdef.h:744
#define COSMOS_MOON
Definition: convertdef.h:144
#define COSMOS_EARTH
Definition: convertdef.h:137
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
qatt topo
Definition: convertdef.h:826
int32_t att_topo2planec(locstruc *loc)
Topocentric to Planetocentric attitude.
Definition: convertlib.cpp:2174
int32_t loc_update ( locstruc loc)

Synchronize all frames in location structure.

Work through provided location structure, first identifying the frame that is most up to date, then updating all other frames to match.

Parameters
loclocstruc to be synchronized
2295 {
2296  loc_update(*loc);
2297  return 0;
2298 }
int32_t loc_update(locstruc *loc)
Synchronize all frames in location structure.
Definition: convertlib.cpp:2294
int32_t loc_update ( locstruc loc)
2301 {
2302  uint32_t ppass=0, apass = 0;
2303  int32_t ptype=-1, atype = -1;
2304 
2305  if (loc.att.icrf.pass > apass)
2306  {
2307  apass = loc.att.icrf.pass;
2308  atype = JSON_TYPE_QATT_ICRF;
2309  }
2310  if (loc.att.geoc.pass > apass)
2311  {
2312  apass = loc.att.geoc.pass;
2313  atype = JSON_TYPE_QATT_GEOC;
2314  }
2315  if (loc.att.selc.pass > apass)
2316  {
2317  apass = loc.att.selc.pass;
2318  atype = JSON_TYPE_QATT_SELC;
2319  }
2320  if (loc.att.lvlh.pass > apass)
2321  {
2322  apass = loc.att.lvlh.pass;
2323  atype = JSON_TYPE_QATT_LVLH;
2324  }
2325  if (loc.att.topo.pass > apass)
2326  {
2327  apass = loc.att.topo.pass;
2328  atype = JSON_TYPE_QATT_TOPO;
2329  }
2330  if (loc.pos.icrf.pass > ppass)
2331  {
2332  ppass = loc.pos.icrf.pass;
2333  ptype = JSON_TYPE_POS_ICRF;
2334  }
2335  if (loc.pos.eci.pass > ppass)
2336  {
2337  ppass = loc.pos.eci.pass;
2338  ptype = JSON_TYPE_POS_ECI;
2339  }
2340  if (loc.pos.sci.pass > ppass)
2341  {
2342  ppass = loc.pos.sci.pass;
2343  ptype = JSON_TYPE_POS_SCI;
2344  }
2345  if (loc.pos.geoc.pass > ppass)
2346  {
2347  ppass = loc.pos.geoc.pass;
2348  ptype = JSON_TYPE_POS_GEOC;
2349  }
2350  if (loc.pos.selc.pass > ppass)
2351  {
2352  ppass = loc.pos.selc.pass;
2353  ptype = JSON_TYPE_POS_SELC;
2354  }
2355  if (loc.pos.geod.pass > ppass)
2356  {
2357  ppass = loc.pos.geod.pass;
2358  ptype = JSON_TYPE_POS_GEOD;
2359  }
2360  if (loc.pos.geos.pass > ppass)
2361  {
2362  ppass = loc.pos.geos.pass;
2363  ptype = JSON_TYPE_POS_GEOS;
2364  }
2365  if (loc.pos.selg.pass > ppass)
2366  {
2367  ppass = loc.pos.selg.pass;
2368  ptype = JSON_TYPE_POS_SELG;
2369  }
2370 
2371  switch (ptype)
2372  {
2373  case JSON_TYPE_POS_ICRF:
2374  pos_icrf(loc);
2375  break;
2376  case JSON_TYPE_POS_ECI:
2377  pos_eci(loc);
2378  break;
2379  case JSON_TYPE_POS_SCI:
2380  pos_sci(loc);
2381  break;
2382  case JSON_TYPE_POS_GEOC:
2383  pos_geoc(loc);
2384  break;
2385  case JSON_TYPE_POS_SELC:
2386  pos_selc(loc);
2387  break;
2388  case JSON_TYPE_POS_GEOD:
2389  pos_geod(loc);
2390  break;
2391  case JSON_TYPE_POS_GEOS:
2392  pos_geos(loc);
2393  break;
2394  case JSON_TYPE_POS_SELG:
2395  pos_selg(loc);
2396  break;
2397  }
2398 
2399  switch (atype)
2400  {
2401  case JSON_TYPE_QATT_ICRF:
2402  att_icrf(loc);
2403  break;
2404  case JSON_TYPE_QATT_GEOC:
2405  att_geoc(loc);
2406  break;
2407  case JSON_TYPE_QATT_SELC:
2408  att_selc(loc);
2409  break;
2410  case JSON_TYPE_QATT_LVLH:
2411  att_lvlh(loc);
2412  break;
2413  case JSON_TYPE_QATT_TOPO:
2414  att_topo(loc);
2415  break;
2416  }
2417 
2418  return 0;
2419 }
int32_t att_selc(locstruc *loc)
Definition: convertlib.cpp:1794
qatt geoc
Definition: convertdef.h:828
JSON Geocentric Attitude.
Definition: jsondef.h:264
spherpos geos
Definition: convertdef.h:743
cartpos selc
Definition: convertdef.h:740
JSON Earth Centered Inertial Position.
Definition: jsondef.h:247
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
int32_t pos_sci(locstruc *loc)
Set SCI position.
Definition: convertlib.cpp:312
cartpos geoc
Definition: convertdef.h:739
JSON Lunar Centered Inertial Attitude.
Definition: jsondef.h:266
int32_t att_icrf(locstruc *loc)
Definition: convertlib.cpp:1836
int32_t pos_selg(locstruc *loc)
Set Selenographic position.
Definition: convertlib.cpp:484
JSON Geocentric Spherical.
Definition: jsondef.h:257
JSON Geocentric Position.
Definition: jsondef.h:251
qatt lvlh
Definition: convertdef.h:827
int32_t pos_geos(locstruc *loc)
Set Geographic position.
Definition: convertlib.cpp:530
geoidpos selg
Definition: convertdef.h:742
JSON Lunar Centered Inertial Position.
Definition: jsondef.h:249
JSON Earth Centered Inertial Attitude.
Definition: jsondef.h:268
JSON LVLH Attitude.
Definition: jsondef.h:270
attstruc att
attstruc for this time.
Definition: convertdef.h:883
qatt selc
Definition: convertdef.h:829
qatt icrf
Definition: convertdef.h:830
JSON Geodetic Position.
Definition: jsondef.h:255
int32_t pos_geoc(locstruc *loc)
Set Geocentric position.
Definition: convertlib.cpp:366
int32_t att_geoc(locstruc *loc)
Definition: convertlib.cpp:1682
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
JSON Topocentric Attitude.
Definition: jsondef.h:262
int32_t pos_icrf(locstruc *loc)
Set Barycentric position.
Definition: convertlib.cpp:162
int32_t pos_geod(locstruc *loc)
Set Geodetic position.
Definition: convertlib.cpp:576
cartpos sci
Definition: convertdef.h:738
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
qatt topo
Definition: convertdef.h:826
int32_t pos_selc(locstruc *loc)
Set Selenocentric position.
Definition: convertlib.cpp:428
cartpos eci
Definition: convertdef.h:737
geoidpos geod
Definition: convertdef.h:741
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:324
cartpos icrf
Definition: convertdef.h:736
int32_t att_topo(locstruc *loc)
Definition: convertlib.cpp:2252
JSON Selenocentric Position.
Definition: jsondef.h:253
JSON Solar Barycentric Position.
Definition: jsondef.h:244
int32_t att_lvlh(locstruc *loc)
Definition: convertlib.cpp:2064
JSON Selenographic Position.
Definition: jsondef.h:259
int32_t teme2true ( double  ep0,
rmatrix rm 
)
2422 {
2423  // TEME to True of Date (Equation of Equinoxes)
2424  double eeq = utc2gast(ep0) - utc2gmst1982(ep0);
2425  *rm = rm_change_around_z(eeq);
2426  return 0;
2427 }
double utc2gast(double mjd)
UTC to GAST.
Definition: timelib.cpp:1048
rmatrix rm_change_around_z(double angle)
Rotation matrix for Z axis.
Definition: matrix.cpp:382
double utc2gmst1982(double mjd)
UTC (Modified Julian Day) to GMST.
Definition: timelib.cpp:1075
int32_t true2teme ( double  ep0,
rmatrix rm 
)
2430 {
2431  double eeq = utc2gast(ep0) - utc2gmst1982(ep0);
2432  *rm = rm_change_around_z(-eeq);
2433  return 0;
2434 }
double utc2gast(double mjd)
UTC to GAST.
Definition: timelib.cpp:1048
rmatrix rm_change_around_z(double angle)
Rotation matrix for Z axis.
Definition: matrix.cpp:382
double utc2gmst1982(double mjd)
UTC (Modified Julian Day) to GMST.
Definition: timelib.cpp:1075
int32_t true2pef ( double  utc,
rmatrix rm 
)
2437 {
2438  double gast = utc2gast(utc);
2439  *rm = rm_change_around_z(-gast);
2440  return 0;
2441 }
double utc2gast(double mjd)
UTC to GAST.
Definition: timelib.cpp:1048
rmatrix rm_change_around_z(double angle)
Rotation matrix for Z axis.
Definition: matrix.cpp:382
int32_t pef2true ( double  utc,
rmatrix rm 
)
2444 {
2445  double gast = utc2gast(utc);
2446  *rm = rm_change_around_z(gast);
2447  return 0;
2448 }
double utc2gast(double mjd)
UTC to GAST.
Definition: timelib.cpp:1048
rmatrix rm_change_around_z(double angle)
Rotation matrix for Z axis.
Definition: matrix.cpp:382
int32_t pef2itrs ( double  utc,
rmatrix rm 
)
2451 {
2452  double ttc = utc2jcentt(utc);
2453  cvector polm = polar_motion(utc);
2454  double pols = -47. * 4.848136811095359935899141e-12 * ttc;
2455 
2457  return 0;
2458 }
double y
Y value.
Definition: vector.h:114
double x
X value.
Definition: vector.h:112
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
cvector polar_motion(double mjd)
Polar motion.
Definition: timelib.cpp:1221
rmatrix rm_change_around_x(double angle)
Rotation matrix for X axis.
Definition: matrix.cpp:358
rmatrix rm_change_around_y(double angle)
Rotation matrix for Y axis.
Definition: matrix.cpp:368
rmatrix rm_mmult(rmatrix a, rmatrix b)
rmatrix Matrix Product
Definition: matrix.cpp:198
rmatrix rm_change_around_z(double angle)
Rotation matrix for Z axis.
Definition: matrix.cpp:382
3 element cartesian vector
Definition: vector.h:107
int32_t itrs2pef ( double  utc,
rmatrix rm 
)
2461 {
2462  static rmatrix orm;
2463  static double outc = 0.;
2464 
2465  if (utc == outc)
2466  {
2467  *rm = orm;
2468  return 0;
2469  }
2470 
2471  pef2itrs(utc, rm);
2472  *rm = rm_transpose(*rm);
2473 
2474  outc = utc;
2475  orm = *rm;
2476  return 0;
2477 }
3x3 element generic matrix
Definition: matrix.h:41
rmatrix rm_transpose(rmatrix a)
rmatrix Transpose. Calculate the transpose of the supplied rmatrix.
Definition: matrix.cpp:172
int32_t pef2itrs(double utc, rmatrix *rm)
Definition: convertlib.cpp:2450
int32_t mean2true ( double  ep0,
rmatrix pm 
)

Rotate Mean of Epoch to True of Epoch.

Calculate the rotation matrix for converting coordinates from a system based on the Mean orientation for that Epoch to one based on the True orientation. Adds effects of Nutation.

Parameters
ep0Epoch, in units of Modified Julian Day
pmRotation matrix
2487 {
2488  static rmatrix opm;
2489  static double oep0 = 0.;
2490 
2491  if (ep0 == oep0)
2492  {
2493  *pm = opm;
2494  return 0;
2495  }
2496 
2497  true2mean(ep0, pm);
2498  *pm = rm_transpose(*pm);
2499 
2500  oep0 = ep0;
2501  opm = *pm;
2502  return 0;
2503 }
int32_t true2mean(double ep0, rmatrix *pm)
Rotate True of Epoch to Mean of Epoch.
Definition: convertlib.cpp:2512
3x3 element generic matrix
Definition: matrix.h:41
rmatrix rm_transpose(rmatrix a)
rmatrix Transpose. Calculate the transpose of the supplied rmatrix.
Definition: matrix.cpp:172
int32_t true2mean ( double  ep0,
rmatrix pm 
)

Rotate True of Epoch to Mean of Epoch.

Calculate the rotation matrix for converting coordinates from a system based on the True orientation for that Epoch to one based on the Mean orientation. Removes effects of Nutation.

Parameters
ep0Epoch, in units of Modified Julian Day
pmRotation matrix
2513 {
2514  static rmatrix opm;
2515  static double oep0 = 0.;
2516  // double nuts[4], jt;
2517  double eps;
2518  double cdp, sdp, ce, se, cde, sde;
2519 
2520  if (ep0 == oep0)
2521  {
2522  *pm = opm;
2523  return 0;
2524  }
2525 
2526  rvector nuts = utc2nuts(ep0);
2527  eps = utc2epsilon(ep0);
2528  // jplnut(utc2tt(ep0),nuts);
2529  // jt = (ep0-51544.5)/36525.;
2530  // eps = DAS2R*(84381.448+jt*(-46.84024+jt*(-.00059+jt*.001813)));
2531 
2532  se = sin(eps);
2533  sdp = sin(nuts.col[0]);
2534  sde = sin(-eps+nuts.col[1]);
2535  ce = cos(eps);
2536  cdp = cos(nuts.col[0]);
2537  cde = cos(-eps+nuts.col[1]);
2538 
2539  pm->row[0].col[0] = cdp;
2540  pm->row[0].col[1] = sdp*ce;
2541  pm->row[0].col[2] = sdp*se;
2542 
2543  pm->row[1].col[0] = -sdp*cde;
2544  pm->row[1].col[1] = cde*cdp*ce-se*sde;
2545  pm->row[1].col[2] = cde*cdp*se+ce*sde;
2546 
2547  pm->row[2].col[0] = sdp*sde;
2548  pm->row[2].col[1] = -sde*cdp*ce-se*cde;
2549  pm->row[2].col[2] = -sde*cdp*se+cde*ce;
2550 
2551  oep0 = ep0;
2552  opm = *pm;
2553  return 0;
2554 }
3 element generic row vector
Definition: vector.h:53
3x3 element generic matrix
Definition: matrix.h:41
double utc2epsilon(double mjd)
Nutation Epsilon value.
Definition: timelib.cpp:573
double col[3]
Definition: vector.h:55
rvector utc2nuts(double mjd)
Nutation values.
Definition: timelib.cpp:508
rvector row[3]
Definition: matrix.h:43
int32_t mean2j2000 ( double  ep0,
rmatrix pm 
)

Rotate Mean of Epoch to J2000.

Calculate the rotation matrix for converting coordinates from a system based on the Mean of the indicated Epoch, to one based on J2000. Reflects the effects of precession.

Parameters
ep0Epoch, in units of Modified Julian Day
pmRotation matrix
2564 {
2565  // double t0, t, tas2r, w, zeta, z, theta;
2566  // double ca, sa, cb, sb, cg, sg;
2567  static rmatrix opm;
2568  static double oep0 = 0.;
2569 
2570  if (ep0 == oep0)
2571  {
2572  *pm = opm;
2573  return 0;
2574  }
2575 
2576  // double ttc = utc2jcentt(ep0);
2577 
2578  /* Euler angles */
2579  // Capitaine, et. al, A&A, 412, 567-586 (2003)
2580  // Expressions for IAU 2000 precession quantities
2581  // Equation 40
2582  // double zeta = (2.650545 + ttc*(2306.083227 + ttc*(0.2988499 + ttc*(0.01801828 + ttc*(-0.000005971 + ttc*(0.0000003173))))))*DAS2R;
2583  // double z = (-2.650545 + ttc*(2306.077181 + ttc*(1.0927348 + ttc*(0.01826837 + ttc*(-0.000028596 + ttc*(0.0000002904))))))*DAS2R;
2584  // double theta = ttc*(2004.191903 + ttc*(-0.4294934 + ttc*(-0.04182264 + ttc*(-0.000007089 + ttc*(-0.0000001274)))))*DAS2R;
2585  double zeta = utc2zeta(ep0);
2586  double theta = utc2theta(ep0);
2587  double z = utc2z(ep0);
2588 
2589  // *pm = rm_mmult(rm_change_around_z(zeta),rm_mmult(rm_change_around_y(-theta),rm_change_around_z(z)));
2591 
2592  // zeta = ttc*(2306.2181 + ttc*(0.30188 + ttc*(0.017998)))*DAS2R;
2593  // z = zeta + ttc*ttc*(0.79280 + ttc*(0.000205))*DAS2R;
2594  // theta = ttc*(2004.3109 + ttc*(-0.42665 + ttc*(-0.041833)))*DAS2R;
2595 
2596  // ca = cos(zeta);
2597  // sa = -sin(zeta);
2598  // cb = cos(theta);
2599  // sb = sin(theta);
2600  // cg = cos(z);
2601  // sg = -sin(z);
2602 
2603  // pm->row[0].col[0] = ca*cb*cg - sa*sg;
2604  // pm->row[0].col[1] = cg*sa*cb +ca*sg;
2605  // pm->row[0].col[2] = -sb*cg;
2606  // pm->row[1].col[0] = -ca*cb*sg - sa*cg;
2607  // pm->row[1].col[1] = -sa*cb*sg + ca*cg;
2608  // pm->row[1].col[2] = sg*sb;
2609  // pm->row[2].col[0] = ca*sb;
2610  // pm->row[2].col[1] = sa*sb;
2611  // pm->row[2].col[2] = cb;
2612  opm = *pm;
2613  return 0;
2614 }
double utc2theta(double utc)
Precession theta value.
Definition: timelib.cpp:737
double utc2z(double utc)
Precession z value.
Definition: timelib.cpp:720
3x3 element generic matrix
Definition: matrix.h:41
rmatrix rm_change_around_y(double angle)
Rotation matrix for Y axis.
Definition: matrix.cpp:368
double utc2zeta(double utc)
Precession zeta value.
Definition: timelib.cpp:703
rmatrix rm_mmult(rmatrix a, rmatrix b)
rmatrix Matrix Product
Definition: matrix.cpp:198
rmatrix rm_change_around_z(double angle)
Rotation matrix for Z axis.
Definition: matrix.cpp:382
__inline_double zeta(double zz, double zl)
Definition: nrlmsise-00.cpp:379
int32_t itrs2gcrf ( double  utc,
rmatrix rnp,
rmatrix rm,
rmatrix drm,
rmatrix ddrm 
)

ITRS to J2000 rotation matrix.

Rotation matrix for transformation from an ITRS coordinate system of date to the J2000 system. Includes all effects of Precession, Nutation, Sidereal Time and Polar Motion.

Parameters
utcEpoch to change from, UTC in MJD
rnpPointer to ITRF rotation matrix.
rmpointer to rotation matrix
drmpointer to rotation matrix derivative
ddrmpointer to rotation matrix 2nd derivative
2626 {
2627  static rmatrix orm, odrm, oddrm, ornp;
2628  static double outc = 0.;
2629 
2630  if (utc == outc)
2631  {
2632  *rnp = ornp;
2633  *rm = orm;
2634  *drm = odrm;
2635  *ddrm = oddrm;
2636  }
2637  else
2638  {
2639  gcrf2itrs(utc,rnp,rm,drm,ddrm);
2640  ornp = *rnp = rm_transpose(*rnp);
2641  orm = *rm = rm_transpose(*rm);
2642  odrm = *drm = rm_transpose(*drm);
2643  oddrm = *drm = rm_transpose(*ddrm);
2644  outc = utc;
2645  }
2646  return 0;
2647 }
int32_t gcrf2itrs(double utc, rmatrix *rnp, rmatrix *rm, rmatrix *drm, rmatrix *ddrm)
J2000 to ITRS rotation matrix.
Definition: convertlib.cpp:2659
3x3 element generic matrix
Definition: matrix.h:41
rmatrix rm_transpose(rmatrix a)
rmatrix Transpose. Calculate the transpose of the supplied rmatrix.
Definition: matrix.cpp:172
int32_t gcrf2itrs ( double  utc,
rmatrix rnp,
rmatrix rm,
rmatrix drm,
rmatrix ddrm 
)

J2000 to ITRS rotation matrix.

Rotation matrix for transformation from a J2000 coordinate system to the International Terrestrial Reference System of date. Includes all effects of Precession, Nutation, Sidereal Time and Polar Motion.

Parameters
utcEpoch to change to, UTC in MJD
rnpPointer to ITRF rotation matrix.
rmpointer to rotation matrix
drmpointer to rotation matrix derivative
ddrmpointer to rotation matrix second derivative
2660 {
2661  double ut1;
2662  rmatrix nrm[3], ndrm, nddrm;
2663  rmatrix pm, nm, sm, pw;
2664  static rmatrix bm = {{1.,-0.000273e-8,9.740996e-8},{0.000273e-8,1.,1.324146e-8},{-9.740996e-8,-1.324146e-8,1.}};
2665  static rmatrix orm, odrm, oddrm, ornp;
2666  static double outc = 0.;
2667  static double realsec = 0.;
2668  int i;
2669 
2670  if (!std::isfinite(utc))
2671  {
2672  return 0;
2673  }
2674 
2675  if (utc == outc)
2676  {
2677  *rm = orm;
2678  *drm = odrm;
2679  *ddrm = oddrm;
2680  *rnp = ornp;
2681  return 0;
2682  }
2683 
2684  // Set size of actual second if first time in
2685  if (realsec == 0.)
2686  {
2687  ut1 = utc + 1./86400.;
2688  realsec = ut1 - utc;
2689  }
2690 
2691  // Do it 3 times to get rate change
2692  outc = utc;
2693  utc -= realsec;
2694  // Calculate bias offset for GCRF to J2000
2695  gcrf2j2000(&bm);
2696  for (i=0; i<3; i++)
2697  {
2698  // Calculate Precession Matrix (pm)
2699  // ttc = utc2jcentt(utc);
2700 
2701  /* Euler angles */
2702  // zeta = (2.650545 + ttc*(2306.083227 + ttc*(0.2988499 + ttc*(0.01801828 + ttc*(-0.000005971)))))*DAS2R;
2703  // z = (-2.650545 + ttc*(2306.077181 + ttc*(1.0927348 + ttc*(0.01826837 + ttc*(-0.000028596)))))*DAS2R;
2704  // theta = ttc*(2004.191903 + ttc*(-0.4294934 + ttc*(-0.04182264 + ttc*(-0.000007089 + ttc*(-0.0000001274)))))*DAS2R;
2705  // pm = rm_mmult(rm_change_around_z(zeta),rm_mmult(rm_change_around_y(-theta),rm_change_around_z(z)));
2706 
2707  j20002mean(utc, &pm);
2708 
2709  // Calculate Nutation Matrix (nm)
2710  // nuts = utc2nuts(utc);
2711  // dpsi = nuts.col[0];
2712  // deps = nuts.col[1];
2713  // eps = utc2epsilon(utc);
2714 
2715  // se = sin(eps);
2716  // sdp = sin(dpsi);
2717  // sde = sin(-eps+deps);
2718  // ce = cos(eps);
2719  // cdp = cos(dpsi);
2720  // cde = cos(-eps+deps);
2721 
2722  // nm = rm_zero();
2723  // nm.row[0].col[0] = cdp;
2724  // nm.row[1].col[0] = sdp*ce;
2725  // nm.row[2].col[0] = sdp*se;
2726 
2727  // nm.row[0].col[1] = -sdp*cde;
2728  // nm.row[1].col[1] = cde*cdp*ce-se*sde;
2729  // nm.row[2].col[1] = cde*cdp*se+ce*sde;
2730 
2731  // nm.row[0].col[2] = sdp*sde;
2732  // nm.row[1].col[2] = -sde*cdp*ce-se*cde;
2733  // nm.row[2].col[2] = -sde*cdp*se+cde*ce;
2734  mean2true(utc, &nm);
2735 
2736  // Calculate Earth Rotation (Sidereal Time) Matrix (sm)
2737  // gast = utc2gast(utc);
2738  // sm = rm_change_around_z(-gast);
2739  true2pef(utc, &sm);
2740 
2741  // dsm = rm_zero();
2742  // dsm.row[1].col[0] = cos(gast);
2743  // dsm.row[0].col[1] = -dsm.row[1].col[0];
2744  // dsm.row[0].col[0] = dsm.row[1].col[1] = -sin(gast);
2745  // dsm = rm_smult(-.000072921158553,dsm);
2746 
2747  // Calculate Polar Motion (Wander) Matrix (pw)
2748  // polm = polar_motion(utc);
2749  // pols = -47. * 4.848136811095359935899141e-12 * ttc;
2750 
2751  // pw = rm_mmult(rm_change_around_z(-pols),rm_mmult(rm_change_around_y(polm.x),rm_change_around_x(polm.y)));
2752  pef2itrs(utc, &pw);
2753 
2754  // Start with ICRS to J2000 Matrix (bm)
2755  // Final Matrix = pw * sm * nm * pm * bm
2756  nrm[i] = rm_mmult(nm,rm_mmult(pm,bm));
2757  if (i==1)
2758  *rnp = nrm[i];
2759 
2760  nrm[i] = rm_mmult(sm,nrm[i]);
2761  nrm[i] = rm_mmult(pw,nrm[i]);
2762  utc += realsec;
2763  }
2764 
2765  nddrm = rm_sub(rm_sub(nrm[2],nrm[1]),rm_sub(nrm[1],nrm[0]));
2766  ndrm = rm_smult(.5,rm_sub(nrm[2],nrm[0]));
2767  orm = *rm = (rm_quaternion2dcm(q_dcm2quaternion_rm(nrm[1])));
2768  odrm = *drm = ndrm;
2769  oddrm = *ddrm = nddrm;
2770  ornp = *rnp;
2771  return 0;
2772 }
int32_t true2pef(double utc, rmatrix *rm)
Definition: convertlib.cpp:2436
rmatrix rm_quaternion2dcm(quaternion q)
Quaternion to row matrix Direction Cosine Matrix.
Definition: mathlib.cpp:219
int i
Definition: rw_test.cpp:37
int32_t gcrf2j2000(rmatrix *rm)
Definition: convertlib.cpp:2823
int32_t j20002mean(double ep1, rmatrix *pm)
Definition: convertlib.cpp:2779
3x3 element generic matrix
Definition: matrix.h:41
quaternion q_dcm2quaternion_rm(rmatrix m)
Row matrix DCM to Quaternion.
Definition: rotation.cpp:178
int32_t mean2true(double ep0, rmatrix *pm)
Rotate Mean of Epoch to True of Epoch.
Definition: convertlib.cpp:2486
rmatrix rm_sub(rmatrix a, rmatrix b)
rmatrix subtraction. Subtract two rmatrix values.
Definition: matrix.cpp:294
rmatrix rm_smult(double a, rmatrix b)
Scalar rmatrix multiplication.
Definition: matrix.cpp:247
rmatrix rm_mmult(rmatrix a, rmatrix b)
rmatrix Matrix Product
Definition: matrix.cpp:198
int32_t pef2itrs(double utc, rmatrix *rm)
Definition: convertlib.cpp:2450
int32_t j20002mean ( double  ep1,
rmatrix pm 
)

Rotation matrix for transformation from a J2000 coordinate system to one based on the Mean of the Epoch.

Parameters
ep1Epoch to change to, UTC in MJD
pmpointer to rotation matrix
2780 {
2781  double t, tas2r, w, zeta, z, theta;
2782  double ca, sa, cb, sb, cg, sg;
2783  static rmatrix opm;
2784  static double oep1 = 0.;
2785 
2786  if (ep1 == oep1)
2787  {
2788  *pm = opm;
2789  return 0;
2790  }
2791 
2792  /* Interval over which precession required (JC) */
2793  t = (ep1 - 51544.5) / 36525.;
2794 
2795  /* Euler angles */
2796  tas2r = t * DAS2R;
2797  w = 2306.2181;
2798  zeta = (w + ( ( 0.30188) + 0.017998 * t ) * t ) * tas2r;
2799  z = (w + ( ( 1.09468) + 0.018203 * t ) * t ) * tas2r;
2800  theta = ((2004.3109)+ ((-0.42665) - 0.041833 * t) * t) * tas2r;
2801 
2802  ca = cos(zeta);
2803  sa = -sin(zeta);
2804  cb = cos(theta);
2805  sb = sin(theta);
2806  cg = cos(z);
2807  sg = -sin(z);
2808 
2809  pm->row[0].col[0] = ca*cb*cg - sa*sg;
2810  pm->row[0].col[1] = cg*sa*cb +ca*sg;
2811  pm->row[0].col[2] = -sb*cg;
2812  pm->row[1].col[0] = -ca*cb*sg - sa*cg;
2813  pm->row[1].col[1] = -sa*cb*sg + ca*cg;
2814  pm->row[1].col[2] = sg*sb;
2815  pm->row[2].col[0] = ca*sb;
2816  pm->row[2].col[1] = sa*sb;
2817  pm->row[2].col[2] = cb;
2818  opm = *pm;
2819  oep1 = ep1;
2820  return 0;
2821 }
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
3x3 element generic matrix
Definition: matrix.h:41
double col[3]
Definition: vector.h:55
rvector row[3]
Definition: matrix.h:43
__inline_double zeta(double zz, double zl)
Definition: nrlmsise-00.cpp:379
int32_t gcrf2j2000 ( rmatrix rm)
2824 {
2825  // Vallado, Seago, Seidelmann: Implementation Issues Surrounding the New IAU Reference System for Astrodynamics
2826  static rmatrix bm = {{0.99999999999999,-0.0000000707827974,0.0000000805621715},{0.0000000707827948,0.9999999999999969,0.0000000330604145},{-0.0000000805621738,-0.0000000330604088,0.9999999999999962}};
2827  *rm = bm;
2828  return 0;
2829 }
3x3 element generic matrix
Definition: matrix.h:41
int32_t j20002gcrf ( rmatrix rm)
2832 {
2833  static rmatrix bm = {{0.99999999999999,-0.0000000707827974,0.0000000805621715},{0.0000000707827948,0.9999999999999969,0.0000000330604145},{-0.0000000805621738,-0.0000000330604088,0.9999999999999962}};
2834  *rm = rm_transpose(bm);
2835  return 0;
2836 }
3x3 element generic matrix
Definition: matrix.h:41
rmatrix rm_transpose(rmatrix a)
rmatrix Transpose. Calculate the transpose of the supplied rmatrix.
Definition: matrix.cpp:172
int32_t mean2mean ( double  ep0,
double  ep1,
rmatrix pm 
)
2839 {
2840  double t0, t, tas2r, w, zeta, z, theta;
2841  double ca, sa, cb, sb, cg, sg;
2842 
2843  /* Interval between basic epoch J2000.0 and beginning epoch (JC) */
2844  //t0 = ( ep0 - 2000.0 ) / 100.0;
2845  t0 = (ep0 - 51544.5) / 36525.;
2846 
2847  /* Interval over which precession required (JC) */
2848  //t = ( ep1 - ep0 ) / 100.0;
2849  t = (ep1 - ep0) / 36525.;
2850 
2851  /* Euler angles */
2852  tas2r = t * DAS2R;
2853  w = 2306.2181 + ( ( 1.39656 - ( 0.000139 * t0 ) ) * t0 );
2854  zeta = (w + ( ( 0.30188 - 0.000344 * t0 ) + 0.017998 * t ) * t ) * tas2r;
2855  z = (w + ( ( 1.09468 + 0.000066 * t0 ) + 0.018203 * t ) * t ) * tas2r;
2856  theta = ((2004.3109 + (-0.85330 - 0.000217 * t0) * t0)+ ((-0.42665 - 0.000217 * t0) - 0.041833 * t) * t) * tas2r;
2857 
2858  ca = cos(zeta);
2859  sa = -sin(zeta);
2860  cb = cos(theta);
2861  sb = sin(theta);
2862  cg = cos(z);
2863  sg = -sin(z);
2864 
2865  pm->row[0].col[0] = ca*cb*cg - sa*sg;
2866  pm->row[0].col[1] = cg*sa*cb +ca*sg;
2867  pm->row[0].col[2] = -sb*cg;
2868  pm->row[1].col[0] = -ca*cb*sg - sa*cg;
2869  pm->row[1].col[1] = -sa*cb*sg + ca*cg;
2870  pm->row[1].col[2] = sg*sb;
2871  pm->row[2].col[0] = ca*sb;
2872  pm->row[2].col[1] = sa*sb;
2873  pm->row[2].col[2] = cb;
2874 
2875  return 0;
2876 }
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double col[3]
Definition: vector.h:55
rvector row[3]
Definition: matrix.h:43
__inline_double zeta(double zz, double zl)
Definition: nrlmsise-00.cpp:379
int32_t kep2eci ( kepstruc kep,
cartpos eci 
)
2879 {
2880  rvector qpos, qvel;
2881  double s1, s2, s3, c1, c2, c3;
2882  double xx, xy, xz, yx, yy, yz, zx, zy, zz;
2883  double sea, cea, sqe;
2884 
2885  sea = sin(kep.ea);
2886  cea = cos(kep.ea);
2887  sqe = sqrt(1. - kep.e * kep.e);
2888 
2889  qpos.col[0] = kep.a * (cea - kep.e);
2890  qpos.col[1] = kep.a * sqe * sea;
2891  qpos.col[2] = 0.;
2892 
2893  // find mean motion and period
2894  kep.mm = sqrt(GM/pow(kep.a,3.));
2895  kep.period = 2. * DPI / kep.mm;
2896  qvel.col[0] = -kep.mm * kep.a * sea / (1. - kep.e*cea);
2897  qvel.col[1] = kep.mm * kep.a * sqe * cea / (1. - kep.e*cea);
2898  qvel.col[2] = 0.;
2899 
2900  s1 = sin(kep.raan);
2901  c1 = cos(kep.raan);
2902  s2 = sin(kep.i);
2903  c2 = cos(kep.i);
2904  s3 = sin(kep.ap);
2905  c3 = cos(kep.ap);
2906 
2907  xx = c1*c3 - s1*c2*s3;
2908  xy = -c1*s3 - s1*c2*c3;
2909  xz = s1*s2;
2910 
2911  yx = s1*c3 + c1*c2*s3;
2912  yy = -s1*s3 + c1*c2*c3;
2913  yz = -c1*s2;
2914 
2915  zx = s2*s3;
2916  zy = s2*c3;
2917  zz = c2;
2918 
2919  eci.s = eci.v = eci.a = rv_zero();
2920 
2921  eci.s.col[0] = qpos.col[0] * xx + qpos.col[1] * xy + qpos.col[2] * xz;
2922  eci.s.col[1] = qpos.col[0] * yx + qpos.col[1] * yy + qpos.col[2] * yz;
2923  eci.s.col[2] = qpos.col[0] * zx + qpos.col[1] * zy + qpos.col[2] * zz;
2924 
2925  eci.v.col[0] = qvel.col[0] * xx + qvel.col[1] * xy + qvel.col[2] * xz;
2926  eci.v.col[1] = qvel.col[0] * yx + qvel.col[1] * yy + qvel.col[2] * yz;
2927  eci.v.col[2] = qvel.col[0] * zx + qvel.col[1] * zy + qvel.col[2] * zz;
2928 
2929  eci.utc = kep.utc;
2930 
2931  return 0;
2932 }
double mm
Mean Motion.
Definition: convertdef.h:561
double utc
UTC time of state vector in MJD.
Definition: convertdef.h:532
3 element generic row vector
Definition: vector.h:53
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
double e
Eccentricity.
Definition: convertdef.h:540
#define GM
SI Mass * Gravitational Constant for Earth.
Definition: convertdef.h:79
rvector s
Location.
Definition: convertdef.h:163
double period
Orbital Period in seconds.
Definition: convertdef.h:536
double raan
Right Ascension of the Ascending Node in radians.
Definition: convertdef.h:549
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
double ap
Argument of Perigee.
Definition: convertdef.h:551
double col[3]
Definition: vector.h:55
double i
Orbital Inclination in radians.
Definition: convertdef.h:547
double a
Semi-Major Axis in meters.
Definition: convertdef.h:538
const double DPI
Double precision PI.
Definition: math/constants.h:14
double ea
Eccentric Anomoly.
Definition: convertdef.h:559
rvector v
Velocity.
Definition: convertdef.h:165
int32_t eci2kep ( cartpos eci,
kepstruc kep 
)
2935 {
2936  double magr, magv, magn, sme, rdotv, temp;
2937  double c1, hk, magh;
2938  rvector nbar, ebar, rsun, hsat;
2939  cartpos earthpos;
2940 
2941  kep.utc = eci.utc;
2942 
2943  magr = length_rv(eci.s);
2944  if (magr < D_SMALL)
2945  magr = D_SMALL;
2946  magv = length_rv(eci.v);
2947  if (magv < D_SMALL)
2948  magv = D_SMALL;
2949  kep.h = rv_cross(eci.s,eci.v);
2950  if (magr == D_SMALL && magv == D_SMALL)
2951  kep.fa = acos(1./D_SMALL);
2952  else
2953  kep.fa = acos(length_rv(kep.h)/(magr*magv));
2954  kep.eta = magv*magv/2. - GM/magr;
2955  magh = length_rv(kep.h);
2956  jplpos(JPL_EARTH,JPL_SUN_BARY,utc2tt(eci.utc),&earthpos);
2957  rsun = earthpos.s;
2958  normalize_rv(rsun);
2959  hsat = kep.h;
2960  normalize_rv(hsat);
2961  kep.beta = asin(dot_rv(rsun,hsat));
2962 
2963  if (magh > O_SMALL)
2964  {
2965  // ------------ find a e and semi-latus rectum ----------
2966  nbar.col[0] = -kep.h.col[1];
2967  nbar.col[1] = kep.h.col[0];
2968  nbar.col[2] = 0.0;
2969  magn = length_rv(nbar);
2970  c1 = magv * magv - GM / magr;
2971  rdotv = dot_rv(eci.s,eci.v);
2972  ebar.col[0] = (c1 * eci.s.col[0] - rdotv * eci.v.col[0]) / GM;
2973  ebar.col[1] = (c1 * eci.s.col[1] - rdotv * eci.v.col[1]) / GM;
2974  ebar.col[2] = (c1 * eci.s.col[2] - rdotv * eci.v.col[2]) / GM;
2975  kep.e = length_rv(ebar);
2976 
2977  sme = (magv * magv * 0.5) - (GM / magr);
2978  if (fabs(sme) > O_SMALL)
2979  kep.a = -GM / (2. * sme);
2980  else
2981  kep.a = O_INFINITE;
2982  // p = magh * magh / GM;
2983 
2984  // find mean motion and period
2985  kep.mm = sqrt(GM/pow(kep.a,3.));
2986  kep.period = 2. * DPI / kep.mm;
2987 
2988  // ----------------- find inclination -------------------
2989  hk = kep.h.col[2] / magh;
2990  kep.i = acos(hk);
2991 
2992  // ---------- find longitude of ascending node ------------
2993  if (magn > O_SMALL)
2994  {
2995  temp = nbar.col[0] / magn;
2996  if (fabs(temp) > 1.)
2997  temp = temp<1.?-1.:(temp>1.?1.:0.);
2998  kep.raan = acos(temp);
2999  if (nbar.col[1] < 0.)
3000  kep.raan = D2PI - kep.raan;
3001  }
3002  else
3003  kep.raan = O_UNDEFINED;
3004 
3005  // Find eccentric and mean anomaly
3006  kep.ea = atan2(rdotv/sqrt(kep.a*GM),1.-magr/kep.a);
3007  kep.ma = kep.ea - kep.e*sin(kep.ea);
3008 
3009  // Find argument of latitude
3010  kep.alat = atan2(eci.s.col[2],(eci.s.col[1]*kep.h.col[0]-eci.s.col[0]*kep.h.col[1])/magh);
3011 
3012  // Find true anomaly
3013  kep.ta = atan2(sqrt(1-kep.e*kep.e)*sin(kep.ea),cos(kep.ea)-kep.e);
3014 
3015  // Find argument of perigee
3016  kep.ap = kep.alat - kep.ta;
3017  }
3018  else
3019  {
3020  kep.a = kep.e = kep.i = kep.raan = O_UNDEFINED;
3021  kep.ap = kep.alat = kep.ma = kep.ta = kep.ea = kep.mm = O_UNDEFINED;
3022  }
3023 
3024  return 0;
3025 }
double ta
True Anomoly.
Definition: convertdef.h:557
double mm
Mean Motion.
Definition: convertdef.h:561
double utc
UTC time of state vector in MJD.
Definition: convertdef.h:532
3 element generic row vector
Definition: vector.h:53
double utc
UTC of Position.
Definition: convertdef.h:161
double e
Eccentricity.
Definition: convertdef.h:540
#define JPL_SUN_BARY
Definition: convertdef.h:121
Cartesian full position structure.
Definition: convertdef.h:158
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
double ma
Mean Anomoly.
Definition: convertdef.h:555
const double O_SMALL
Definition: math/constants.h:39
void normalize_rv(rvector &v)
Normalize row order vector in place.
Definition: vector.cpp:222
rvector h
Angular Momentum vector.
Definition: convertdef.h:542
double eta
Definition: convertdef.h:545
#define GM
SI Mass * Gravitational Constant for Earth.
Definition: convertdef.h:79
const double O_UNDEFINED
Definition: math/constants.h:37
rvector s
Location.
Definition: convertdef.h:163
double period
Orbital Period in seconds.
Definition: convertdef.h:536
double dot_rv(rvector a, rvector b)
Dot product of two row vectors.
Definition: vector.cpp:379
double fa
Definition: convertdef.h:562
const double O_INFINITE
Definition: math/constants.h:38
double raan
Right Ascension of the Ascending Node in radians.
Definition: convertdef.h:549
#define JPL_EARTH
Definition: convertdef.h:112
const double D_SMALL
Definition: math/constants.h:40
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double ap
Argument of Perigee.
Definition: convertdef.h:551
double col[3]
Definition: vector.h:55
double i
Orbital Inclination in radians.
Definition: convertdef.h:547
double beta
Solar Beta Angle in radians.
Definition: convertdef.h:544
double a
Semi-Major Axis in meters.
Definition: convertdef.h:538
int32_t jplpos(long from, long to, double utc, cartpos *pos)
Position from JPL Ephemeris.
Definition: ephemlib.cpp:128
const double DPI
Double precision PI.
Definition: math/constants.h:14
double ea
Eccentric Anomoly.
Definition: convertdef.h:559
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
rvector v
Velocity.
Definition: convertdef.h:165
double utc2tt(double mjd)
Convert UTC to TT.
Definition: timelib.cpp:884
double alat
Argument of Latitude.
Definition: convertdef.h:553
int32_t geoc2topo ( gvector  source,
rvector  targetgeoc,
rvector topo 
)

Geocentric to Topocentric.

Calculate the Topocentric position of a Target with respect to a Source.

Parameters
sourceGeodetic location of Source.
targetgeocGeocentric location of Target.
topoResulting Topocentric position.
3034 {
3035  rmatrix g2t;
3036  double clat, clon, slat, slon;
3037  double lst, r, c, s;
3038  double cs, ct, ss, st;
3039  rvector sourcegeoc;
3040 
3041  clon = cos(source.lon);
3042  slon = sin(source.lon);
3043  clat = cos(source.lat);
3044  slat = sin(source.lat);
3045 
3046  g2t.row[0].col[0] = -slon;
3047  g2t.row[0].col[1] = clon;
3048  g2t.row[0].col[2] = 0.;
3049  g2t.row[1].col[0] = -slat*clon;
3050  g2t.row[1].col[1] = -slat*slon;
3051  g2t.row[1].col[2] = clat;
3052  g2t.row[2].col[0] = clat*clon;
3053  g2t.row[2].col[1] = clat*slon;
3054  g2t.row[2].col[2] = slat;
3055 
3056  ct = cos(source.lat);
3057  st = sin(source.lat);
3058  c = 1./sqrt(ct * ct + FRATIO2 * st * st);
3059  s = FRATIO2 * c;
3060  r = (REARTHM * c + source.h) * ct;
3061  sourcegeoc.col[2] = (REARTHM * s + source.h) * st;
3062 
3063  lst = source.lon;
3064  cs = cos(lst);
3065  ss = sin(lst);
3066  sourcegeoc.col[0] = r * cs;
3067  sourcegeoc.col[1] = r * ss;
3068 
3069  topo = rv_mmult(g2t,rv_sub(targetgeoc,sourcegeoc));
3070 
3071  return 0;
3072 }
#define FRATIO2
Definition: convertdef.h:66
3 element generic row vector
Definition: vector.h:53
3x3 element generic matrix
Definition: matrix.h:41
double h
Height in meters.
Definition: vector.h:229
double lon
Longitude in radians.
Definition: vector.h:227
#define REARTHM
SI Radius of Earth.
Definition: convertdef.h:60
double lat
Latitude in radians.
Definition: vector.h:225
double col[3]
Definition: vector.h:55
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector row[3]
Definition: matrix.h:43
int32_t body2topo ( Vector  source,
Vector  target,
Vector topo 
)

Body Centric to Topocentric.

Calculate the Topocentric position of a Target with respect to a Source.

Parameters
sourceBody centered location of Source.
targetBody centered location of Target.
topoResulting Topocentric position.
3081 {
3082  Matrix b2t;
3083  double clat, clon, slat, slon;
3084 
3085  double llon = sqrt(source[0] * source[0] + source[1] * source[1]);
3086  if (llon > 0.)
3087  {
3088  clon = source[0] / llon;
3089  slon = source[1] / llon;
3090  }
3091  else
3092  {
3093  clon = 1.;
3094  slon = 0.;
3095  }
3096 
3097  double llat = sqrt(llon * llon + source[2] * source[2]);
3098  if (llat > 0.)
3099  {
3100  clat = llon / llat;
3101  slat = source[2] / llat;
3102  }
3103  else
3104  {
3105  clat = 1.;
3106  slat = 0.;
3107  }
3108 
3109  b2t[0][0] = -slon;
3110  b2t[0][1] = clon;
3111  b2t[0][2] = 0.;
3112  b2t[1][0] = -slat*clon;
3113  b2t[1][1] = -slat*slon;
3114  b2t[1][2] = clat;
3115  b2t[2][0] = clat*clon;
3116  b2t[2][1] = clat*slon;
3117  b2t[2][2] = slat;
3118 
3119  topo = b2t * (target - source);
3120 
3121  return 0;
3122 }
static string source
Definition: ax25_recv.cpp:42
Definition: matrix.h:255
int32_t topo2azel ( rvector  tpos,
float &  az,
float &  el 
)

Topocentric to Azimuth and Eleveation Calculate the Azimuth and Elevation of a position based on its Topocentric position

Parameters
tposTopocentric position
azCalculated azimuth in radians
elCalculated elevation in radians
3130 {
3131  az = static_cast <float>(atan2(tpos.col[0], tpos.col[1]));
3132  el = static_cast <float>(atan2(tpos.col[2], sqrt(tpos.col[0] * tpos.col[0] + tpos.col[1] * tpos.col[1])));
3133  return 0;
3134 }
double col[3]
Definition: vector.h:55
int32_t topo2azel ( Vector  tpos,
float &  az,
float &  el 
)

Topocentric to Azimuth and Eleveation Calculate the Azimuth and Elevation of a position based on its Topocentric position

Parameters
tposTopocentric position
azCalculated azimuth in radians
elCalculated elevation in radians
3142 {
3143  az = static_cast <float>(atan2(tpos[0], tpos[1]));
3144  el = static_cast <float>(atan2(tpos[2], sqrt(tpos[0] * tpos[0] + tpos[1] * tpos[1])));
3145  return 0;
3146 }
int lines2eci ( double  utc,
vector< tlestruc lines,
cartpos eci 
)

Return position from TLE set.

Find the TLE closest to, but not exceeding the provided utc, then return the position in ECI coordinates.

Parameters
utcCoordinated Universal Time in Modified Julian Days.
linesVector of TLE's.
eciPointer to cartpos in ECI frame.
3156 {
3157  uint16_t lindex=0;
3158  int32_t iretn;
3159 
3160  if (utc >= lines[lindex].utc)
3161  {
3162  for (uint16_t i=lindex; i<lines.size(); i++)
3163  {
3164  if (utc >= lines[i].utc)
3165  {
3166  lindex = i;
3167  }
3168  else {
3169  break;
3170  }
3171  }
3172  }
3173  else
3174  return (TLE_ERROR_OUTOFRANGE);
3175 
3176  iretn = tle2eci(utc, lines[lindex], eci);
3177  return iretn;
3178 }
int i
Definition: rw_test.cpp:37
int iretn
Definition: rw_test.cpp:37
#define TLE_ERROR_OUTOFRANGE
Definition: cosmos-errno.h:139
int tle2eci(double utc, tlestruc tle, cartpos &eci)
Definition: convertlib.cpp:3466
int sgp4 ( double  utc,
tlestruc  tle,
cartpos pos_teme 
)

SGP4 propagator algoritm

Parameters
utcSpecified time as Modified Julian Date
tleTwo Line Element structure, given as pointer to a tlestruc
pos_temeresult from SGP4 algorithm is a cartesian state given in TEME frame, as pointer to a cartpos
3187 {
3188  // rmatrix pm = {{{{0.}}}};
3189  // static int lsnumber=-99;
3190  static double c1=0.;
3191  static double cosio=0. ,x3thm1=0. , xnodp=0. ,aodp=0.,isimp=0.,eta=0.,sinio=0. ,ximth2=0.,c4=0.,c5=0.;
3192  static double xmdot=0.,omgdot=0., xnodot=0.,omgcof=0.,xmcof=0., xnodcf=0.,t2cof=0.,xlcof=0.,aycof=0.;
3193  int i;
3194  double temp, temp1, temp2, temp3, temp4, temp5, temp6;
3195  double tempa, tempe, templ;
3196  double ao, a1, c2, c3, coef, coef1, theta4, c1sq;
3197  double theta2, betao2, betao, delo, del1, s4, qoms24, x1m5th, xhdot1;
3198  double perige, eosq, pinvsq, tsi, etasq, eeta, psisq, g, xmdf;
3199  double tsince, omgadf, alpha, xnoddf, xmp, tsq, xnode, delomg, delm;
3200  double tcube, tfour, a, e, xl, beta, axn, xn, xll, ayn, capu, aynl;
3201  double xlt, sinepw, cosepw, epw, ecose, esine, pl, r, elsq;
3202  double rdot, rfdot, cosu, sinu, u, sin2u, cos2u, uk, rk, ux, uy, uz;
3203  double vx, vy, vz, xinck, rdotk, rfdotk, sinuk, cosuk, sinik, cosik, xnodek;
3204  double xmx, xmy, sinnok, cosnok;
3205  // locstruc loc;
3206  static double lutc=0.;
3207  static uint16_t lsnumber=0;
3208 
3209  static double delmo,sinmo,x7thm1,d2,d3,d4,t3cof,t4cof,t5cof, betal;
3210 
3211  if (tle.utc != lutc || tle.snumber != lsnumber)
3212  {
3213  if (tle.e < .00000000001)
3214  {
3215  tle.e = .00000000001;
3216  }
3217  // RECOVER ORIGINAL MEAN MOTION ( xnodp ) AND SEMIMAJOR AXIS (aodp)
3218  // FROM INPUT ELEMENTS
3219  a1=pow((SGP4_XKE/ tle.mm ),SGP4_TOTHRD);
3220  cosio = cos(tle.i);
3221  theta2=cosio * cosio;
3222  x3thm1 =3.*theta2-1.;
3223  eosq = tle.e * tle.e;
3224  betao2=1.- eosq;
3225  betao=sqrt(betao2);
3226  del1=1.5*SGP4_CK2*x3thm1 /(a1*a1*betao*betao2);
3227  ao=a1*(1.-del1*(.5*SGP4_TOTHRD+del1*(1.+134./81.*del1)));
3228  delo=1.5*SGP4_CK2*x3thm1 /(ao*ao*betao*betao2);
3229  xnodp = tle.mm /(1.+delo);
3230  aodp=ao/(1.-delo);
3231  // INITIALIZATION
3232  // FOR PERIGEE LESS THAN 220 KILOMETERS, THE isimp FLAG IS SET AND
3233  // THE EQUATIONS ARE TRUNCATED TO LINEAR VARIATION IN sqrt A AND
3234  // QUADRATIC VARIATION IN MEAN ANOMALY. ALSO, THE c3 TERM, THE
3235  // DELTA alpha TERM, AND THE DELTA M TERM ARE DROPPED.
3236  isimp=0;
3237  if((aodp*(1.- tle.e)/SGP4_AE) < (220./SGP4_XKMPER+SGP4_AE))
3238  isimp=1;
3239  // FOR PERIGEE BELOW 156 KM, THE VALUES OF
3240  // S AND SGP4_QOMS2T ARE ALTERED
3241  s4=SGP4_S;
3242  qoms24=SGP4_QOMS2T;
3243  perige=(aodp*(1.- tle.e )-SGP4_AE)*SGP4_XKMPER;
3244  if(perige < 156.)
3245  {
3246  s4=perige-78.;
3247  if(perige <= 98.)
3248  {
3249  s4=20.;
3250  qoms24=pow(((120.-s4)*SGP4_AE/SGP4_XKMPER),4.);
3251  s4=s4/SGP4_XKMPER+SGP4_AE;
3252  }
3253  }
3254  pinvsq = 1./(aodp*aodp*betao2*betao2);
3255  tsi =1./(aodp-s4);
3256  eta=aodp* tle.e * tsi;
3257  etasq=eta*eta;
3258  eeta= tle.e *eta;
3259  psisq=fabs(1.-etasq);
3260  coef=qoms24*pow(tsi,4.);
3261  coef1=coef/pow(psisq,3.5);
3262  c2=coef1* xnodp *(aodp*(1.+1.5*etasq+eeta*(4.+etasq))+.75* SGP4_CK2*tsi/psisq*x3thm1 *(8.+3.*etasq*(8.+etasq)));
3263  c1 = tle.bstar *c2;
3264  sinio =sin( tle.i );
3265  g =-SGP4_XJ3/SGP4_CK2*pow(SGP4_AE,3.);
3266  c3 =coef*tsi*g* xnodp *SGP4_AE*sinio / tle.e;
3267  ximth2 =1.-theta2;
3268  c4 =2.* xnodp *coef1*aodp*betao2*(eta* (2.+.5*etasq)+ tle.e *(.5+2.*etasq)-2.*SGP4_CK2*tsi/ (aodp*psisq)*(-3.*x3thm1 *(1.-2.*eeta+etasq* (1.5-.5*eeta))+.75*ximth2*(2.*etasq-eeta* (1.+etasq))*cos(2.* tle.ap )));
3269  c5 =2.*coef1*aodp*betao2*(1.+2.75*(etasq+eeta)+eeta*etasq);
3270  theta4 =theta2*theta2;
3271  temp1 =3.*SGP4_CK2*pinvsq* xnodp;
3272  temp2 = temp1*SGP4_CK2*pinvsq;
3273  temp3 =1.25*SGP4_CK4*pinvsq*pinvsq* xnodp;
3274  xmdot = xnodp +.5* temp1*betao*x3thm1 +.0625* temp2*betao* (13.-78.*theta2+137.*theta4);
3275  x1m5th =1.-5.*theta2;
3276  omgdot =-.5* temp1*x1m5th+.0625* temp2*(7.-114.*theta2+ 395.*theta4)+ temp3*(3.-36.*theta2+49.*theta4);
3277  xhdot1 =- temp1*cosio;
3278  xnodot =xhdot1+(.5* temp2*(4.-19.*theta2)+2.* temp3*(3.- 7.*theta2))*cosio;
3279  omgcof = tle.bstar *c3*cos( tle.ap );
3280  xmcof =-SGP4_TOTHRD*coef* tle.bstar *SGP4_AE/eeta;
3281  xnodcf =3.5*betao2*xhdot1*c1;
3282  t2cof =1.5*c1;
3283  xlcof =.125*g*sinio *(3.+5.*cosio )/(1.+cosio );
3284  aycof =.25*g*sinio;
3285  delmo =pow((1.+eta*cos( tle.ma )),3.);
3286  sinmo =sin( tle.ma );
3287  x7thm1 =7.*theta2-1.;
3288  if(isimp != 1)
3289  {
3290  c1sq=c1*c1;
3291  d2=4.*aodp*tsi*c1sq;
3292  temp =d2*tsi*c1/3.;
3293  d3=(17.*aodp+s4)* temp;
3294  d4=.5* temp *aodp*tsi*(221.*aodp+31.*s4)*c1;
3295  t3cof=d2+2.*c1sq;
3296  t4cof=.25*(3.*d3+c1*(12.*d2+10.*c1sq));
3297  t5cof=.2*(3.*d4+12.*c1*d3+6.*d2*d2+15.*c1sq*( 2.*d2+c1sq));
3298  }
3299  lsnumber = tle.snumber;
3300  lutc = tle.utc;
3301  }
3302 
3303  // UPDATE FOR SECULAR GRAVITY AND ATMOSPHERIC DRAG
3304  tsince = (utc - tle.utc) * SGP4_XMNPDA;
3305  xmdf = tle.ma +xmdot*tsince;
3306  omgadf= tle.ap +omgdot*tsince;
3307  xnoddf= tle.raan + xnodot*tsince;
3308  alpha=omgadf;
3309  xmp = xmdf;
3310  tsq=tsince*tsince;
3311  xnode= xnoddf+ xnodcf*tsq;
3312  tempa=1.-c1*tsince;
3313  tempe= tle.bstar *c4*tsince;
3314  templ=t2cof*tsq;
3315  if(isimp != 1)
3316  {
3317  delomg=omgcof*tsince;
3318  delm=xmcof*(pow((1.+eta*cos( xmdf )),3.)-delmo);
3319  temp =delomg+delm;
3320  xmp = xmdf + temp;
3321  alpha=omgadf- temp;
3322  tcube=tsq*tsince;
3323  tfour=tsince*tcube;
3324  tempa = tempa-d2*tsq-d3*tcube-d4*tfour;
3325  tempe = tempe+ tle.bstar *c5*(sin( xmp )-sinmo);
3326  templ = templ+t3cof*tcube+ tfour*(t4cof+tsince*t5cof);
3327  }
3328  a =aodp* tempa * tempa;
3329  e = tle.e - tempe;
3330  xl= xmp +alpha+ xnode+ xnodp * templ;
3331  beta=sqrt(1.-e*e);
3332  xn=SGP4_XKE/pow(a,1.5);
3333  // LONG PERIOD PERIODICS
3334  axn=e*cos(alpha);
3335  temp =1./(a*beta*beta);
3336  xll= temp *xlcof*axn;
3337  aynl= temp *aycof;
3338  xlt=xl+xll;
3339  ayn=e*sin(alpha)+aynl;
3340  // SOLVE KEplERS EQUATION;
3341  capu=ranrm(xlt- xnode);
3342  temp2=capu;
3343  for (i=1; i<=10; i++)
3344  {
3345  sinepw=sin( temp2);
3346  cosepw=cos( temp2);
3347  temp3=axn*sinepw;
3348  temp4=ayn*cosepw;
3349  temp5=axn*cosepw;
3350  temp6=ayn*sinepw;
3351  epw=(capu- temp4+ temp3- temp2)/(1.- temp5- temp6)+ temp2;
3352  if(fabs(epw- temp2) <= SGP4_E6A)
3353  break;
3354  temp2=epw;
3355  }
3356  // SHORT PERIOD PRELIMINARY QUANTITIES;
3357  ecose= temp5+ temp6;
3358  esine= temp3- temp4;
3359  elsq=axn*axn+ayn*ayn;
3360  temp =1.-elsq;
3361  pl=a* temp;
3362  r=a*(1.-ecose);
3363  temp1=1./r;
3364  rdot=SGP4_XKE*sqrt(a)*esine* temp1;
3365  rfdot=SGP4_XKE*sqrt(pl)* temp1;
3366  temp2=a* temp1;
3367  betal=sqrt( temp );
3368  temp3=1./(1.+betal);
3369  cosu = temp2*(cosepw-axn+ayn*esine* temp3);
3370  sinu= temp2*(sinepw-ayn-axn*esine* temp3);
3371  u=actan(sinu, cosu );
3372  sin2u=2.*sinu* cosu;
3373  cos2u =2.* cosu * cosu -1.;
3374  temp =1./pl;
3375  temp1=SGP4_CK2* temp;
3376  temp2= temp1* temp;
3377  // UPDATE FOR SHORT PERIODICS;
3378  rk =r*(1.-1.5* temp2*betal*x3thm1 )+.5* temp1*ximth2* cos2u;
3379  uk=u-.25* temp2*x7thm1*sin2u;
3380  xnodek= xnode+1.5* temp2*cosio *sin2u;
3381  xinck= tle.i +1.5* temp2*cosio *sinio * cos2u;
3382  rdotk=rdot-xn* temp1*ximth2*sin2u;
3383  rfdotk=rfdot+xn* temp1*(ximth2* cos2u +1.5*x3thm1 );
3384  // ORIENTATION VECTORS;
3385  sinuk =sin(uk);
3386  cosuk=cos(uk);
3387  sinik =sin(xinck);
3388  cosik =cos(xinck);
3389  sinnok=sin( xnodek);
3390  cosnok=cos( xnodek);
3391  xmx=-sinnok* cosik;
3392  xmy=cosnok* cosik;
3393  ux=xmx* sinuk +cosnok* cosuk;
3394  uy=xmy* sinuk +sinnok* cosuk;
3395  uz= sinik * sinuk;
3396  vx=xmx* cosuk-cosnok* sinuk;
3397  vy=xmy* cosuk-sinnok* sinuk;
3398  vz= sinik * cosuk;
3399  // POSITION AND VELOCITY in TEME
3400  pos_teme.s = pos_teme.v = pos_teme.a = rv_zero();
3401 
3402  pos_teme.s.col[0] = 1000. * SGP4_XKMPER * rk *ux;
3403  pos_teme.s.col[1] = 1000. * SGP4_XKMPER * rk *uy;
3404  pos_teme.s.col[2] = 1000. * SGP4_XKMPER * rk *uz;
3405  pos_teme.v.col[0] = 1000. * SGP4_XKMPER * (rdotk*ux+rfdotk*vx) / 60.;
3406  pos_teme.v.col[1] = 1000. * SGP4_XKMPER * (rdotk*uy+rfdotk*vy) / 60.;
3407  pos_teme.v.col[2] = 1000. * SGP4_XKMPER * (rdotk*uz+rfdotk*vz) / 60.;
3408 
3409  return 0;
3410 }
Definition: eci2kep_test.cpp:33
rvector a
Acceleration.
Definition: convertdef.h:167
int i
Definition: rw_test.cpp:37
#define SGP4_CK2
Definition: convertdef.h:97
#define SGP4_CK4
Definition: convertdef.h:98
double ranrm(double angle)
Definition: timelib.cpp:1109
#define SGP4_E6A
Definition: convertdef.h:99
double actan(double y, double x)
ArcTan, limited to range 0-2PI.
Definition: mathlib.cpp:2174
#define SGP4_XKE
Definition: convertdef.h:104
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
#define SGP4_XMNPDA
Definition: convertdef.h:106
rvector s
Location.
Definition: convertdef.h:163
Definition: eci2kep_test.cpp:33
#define SGP4_TOTHRD
Definition: convertdef.h:102
Definition: eci2kep_test.cpp:33
static double coef[360+1][360+1][2]
Definition: physicslib.cpp:39
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
#define SGP4_QOMS2T
Definition: convertdef.h:100
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
Definition: eci2kep_test.cpp:33
double e
Eccentricity (unitless)
Definition: convertdef.h:936
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
double col[3]
Definition: vector.h:55
#define SGP4_XJ3
Definition: convertdef.h:103
#define SGP4_S
Definition: convertdef.h:101
double utc
Definition: convertdef.h:923
double i
Inclination (radians)
Definition: convertdef.h:932
#define SGP4_AE
Definition: convertdef.h:107
rvector v
Velocity.
Definition: convertdef.h:165
double bstar
Drag (1/Earth radii)
Definition: convertdef.h:930
#define SGP4_XKMPER
Definition: convertdef.h:105
uint16_t snumber
Definition: convertdef.h:926
int32_t eci2tle ( double  utc,
cartpos  eci,
tlestruc tle 
)

TLE from ECI.

Convert an ECI state vector into an SGP4 TLE

Parameters
utcUTC time of ECI State Vector and TLE
eciState Vector to convert, stored as cartpos
tleTwo Line Element, stored as tlestruc
3419 {
3420  // ICRF to Mean of Data (undo Precession)
3421  rmatrix bm;
3422  gcrf2j2000(&bm);
3423  eci.s = rv_mmult(bm,eci.s);
3424  eci.v = rv_mmult(bm,eci.v);
3425 
3426  rmatrix pm;
3427  j20002mean(utc,&pm);
3428  eci.s = rv_mmult(pm,eci.s);
3429  eci.v = rv_mmult(pm,eci.v);
3430 
3431  // Mean of Date to True of Date (undo Nutation)
3432  rmatrix nm;
3433  mean2true(utc,&nm);
3434  eci.s = rv_mmult(nm,eci.s);
3435  eci.v = rv_mmult(nm,eci.v);
3436 
3437  // True of Date to Uniform of Date (undo Equation of Equinoxes)
3438  rmatrix sm;
3439  true2teme(utc, &sm);
3440  eci.s = rv_mmult(sm,eci.s);
3441  eci.v = rv_mmult(sm,eci.v);
3442 
3443  // Convert to Keplerian Elements
3444  kepstruc kep;
3445  eci2kep(eci, kep);
3446 
3447  // Store in relevant parts of TLE
3448  tle.orbit = 0;
3449  tle.ap = kep.ap;
3450  tle.e = kep.e;
3451  tle.i = kep.i;
3452  tle.ma = kep.ma;
3453  tle.mm = kep.mm * 60.; // Keplerian in SI units (radians / seconds), convert to radians / minute.
3454  tle.raan = kep.raan;
3455  tle.utc = utc;
3456 
3457  return 0;
3458 }
int32_t eci2kep(cartpos &eci, kepstruc &kep)
Definition: convertlib.cpp:2934
double mm
Mean Motion.
Definition: convertdef.h:561
double e
Eccentricity.
Definition: convertdef.h:540
double ma
Mean Anomoly.
Definition: convertdef.h:555
int32_t true2teme(double ep0, rmatrix *rm)
Definition: convertlib.cpp:2429
int32_t gcrf2j2000(rmatrix *rm)
Definition: convertlib.cpp:2823
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
uint32_t orbit
Definition: convertdef.h:943
rvector s
Location.
Definition: convertdef.h:163
int32_t j20002mean(double ep1, rmatrix *pm)
Definition: convertlib.cpp:2779
3x3 element generic matrix
Definition: matrix.h:41
int32_t mean2true(double ep0, rmatrix *pm)
Rotate Mean of Epoch to True of Epoch.
Definition: convertlib.cpp:2486
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
double raan
Right Ascension of the Ascending Node in radians.
Definition: convertdef.h:549
Classical elements structure.
Definition: convertdef.h:529
double e
Eccentricity (unitless)
Definition: convertdef.h:936
double ap
Argument of Perigee.
Definition: convertdef.h:551
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
double i
Orbital Inclination in radians.
Definition: convertdef.h:547
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
double utc
Definition: convertdef.h:923
double i
Inclination (radians)
Definition: convertdef.h:932
rvector v
Velocity.
Definition: convertdef.h:165
int tle2eci ( double  utc,
tlestruc  tle,
cartpos eci 
)

Convert a Two Line Element into a location at the specified time.

Parameters
utcSpecified time as Modified Julian Date
tleTwo Line Element, given as pointer to a tlestruc
eciConverted location, given as pointer to a cartpos
3467 {
3468 
3469  // call sgp4, eci is passed by pointer
3470  // cartpos *teme;
3471  sgp4(utc, tle, eci);
3472 
3473 
3474  //eci = *teme;
3475 
3476  // Uniform of Date to True of Date (Equation of Equinoxes)
3477  rmatrix sm;
3478  teme2true(utc, &sm);
3479  eci.s = rv_mmult(sm,eci.s);
3480  eci.v = rv_mmult(sm,eci.v);
3481 
3482  // True of Date to Mean of Date (Nutation)
3483  rmatrix nm;
3484  true2mean(utc,&nm);
3485  eci.s = rv_mmult(nm,eci.s);
3486  eci.v = rv_mmult(nm,eci.v);
3487 
3488  // Mean of Date to ICRF (precession)
3489  rmatrix pm;
3490  mean2j2000(utc,&pm);
3491  eci.s = rv_mmult(pm,eci.s);
3492  eci.v = rv_mmult(pm,eci.v);
3493 
3494  rmatrix bm;
3495  j20002gcrf(&bm);
3496  eci.s = rv_mmult(bm,eci.s);
3497  eci.v = rv_mmult(bm,eci.v);
3498 
3499  eci.utc = utc;
3500 
3501  return 0;
3502 }
double utc
UTC of Position.
Definition: convertdef.h:161
int32_t j20002gcrf(rmatrix *rm)
Definition: convertlib.cpp:2831
rvector s
Location.
Definition: convertdef.h:163
int32_t true2mean(double ep0, rmatrix *pm)
Rotate True of Epoch to Mean of Epoch.
Definition: convertlib.cpp:2512
3x3 element generic matrix
Definition: matrix.h:41
int sgp4(double utc, tlestruc tle, cartpos &pos_teme)
Definition: convertlib.cpp:3186
int32_t teme2true(double ep0, rmatrix *rm)
Definition: convertlib.cpp:2421
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector v
Velocity.
Definition: convertdef.h:165
int32_t mean2j2000(double ep0, rmatrix *pm)
Rotate Mean of Epoch to J2000.
Definition: convertlib.cpp:2563
tlestruc get_line ( uint16_t  index,
vector< tlestruc lines 
)

Get TLE from array of TLE's.

Return the indexed entry from an array of tlestruc. If the index is larger than the size of the array, an empty TLE with time set to zero is returned.

Parameters
indexIndex into the array.
linesArray of TLE's.
Returns
Indexed TLE.
3513 {
3514  tlestruc ttle;
3515 
3516  if (lines.size() <= 0 || index >= lines.size())
3517  {
3518  ttle.utc = 0.;
3519  return (ttle);
3520  }
3521  else
3522  {
3523  return (lines[index]);
3524  }
3525 }
In units for the SGP4 propogator (not NORAD TLE itself).
Definition: convertdef.h:921
double utc
Definition: convertdef.h:923
int32_t loadTLE ( char *  fname,
tlestruc tle 
)

Load TLE from file. TODO!!! create new class for dealing with TLEs.

Load Two Line Element file into TLE structure

Parameters
fnameName of file containing elements
tlestructure to contain TLE elements
Returns
0 if parsing was sucessfull, otherwise a negative error.
3536 {
3537  FILE *fdes;
3538  uint16_t year;
3539  double jday;
3540  int32_t bdragm, bdrage, ecc;
3541  char ibuf[81], tlename[81];
3542  int i;
3543 
3544  if ((fdes=fopen(fname,"r")) == nullptr)
3545  return (-1);
3546 
3547  tlecount = 0;
3548 
3549  // Name Line
3550  char* ichar = fgets(tlename,80,fdes);
3551  if (ichar == nullptr || feof(fdes))
3552  return (-1);
3553 
3554  for (i=strlen(tlename)-1; i>0; i--)
3555  {
3556  if (tlename[i]!=' ' && tlename[i]!='\r' && tlename[i]!='\n')
3557  break;
3558  }
3559  tlename[i+1] = 0;
3560 
3561  while (!feof(fdes))
3562  {
3563  strcpy(tle.name,tlename);
3564 
3565  // Line 1
3566  if (fgets(ibuf,80,fdes) == nullptr)
3567  break;
3568  sscanf(&ibuf[2],"%5hu",&tle.snumber);
3569  sscanf(&ibuf[9],"%6s",tle.id);
3570  sscanf(&ibuf[18],"%2hu",&year);
3571  if (year < 57)
3572  year += 2000;
3573  else
3574  year += 1900;
3575  sscanf(&ibuf[20],"%12lf",&jday);
3576  tle.utc = cal2mjd((int)year,1,0.);
3577  tle.utc += jday;
3578  if (strlen(ibuf) > 50)
3579  {
3580  sscanf(&ibuf[53],"%6d%2d",&bdragm,&bdrage);
3581  tle.bstar = pow(10.,bdrage)*bdragm/1.e5;
3582  }
3583  else
3584  tle.bstar = 0.;
3585 
3586  // Line 2
3587  char* ichar = fgets(ibuf,80,fdes);
3588  if (ichar != NULL)
3589  {
3590  ibuf[68] = 0;
3591  sscanf(&ibuf[8],"%8lf %8lf %7d %8lf %8lf %11lf%5u",&tle.i,&tle.raan,&ecc,&tle.ap,&tle.ma,&tle.mm,&tle.orbit);
3592  tle.i = RADOF(tle.i);
3593  tle.raan = RADOF(tle.raan);
3594  tle.ap = RADOF(tle.ap);
3595  tle.ma = RADOF(tle.ma);
3596  tle.mm *= D2PI/1440.;
3597  tle.e = ecc / 1.e7;
3598  }
3599  }
3600  fclose(fdes);
3601  return 0;
3602 }
int i
Definition: rw_test.cpp:37
char ibuf[1000]
Definition: razor_imu.cpp:43
string tlename
Definition: fast_contacts.cpp:39
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
uint32_t orbit
Definition: convertdef.h:943
static char fname[100]
Definition: geomag.cpp:89
static uint16_t tlecount
Definition: convertlib.cpp:47
char id[9]
Definition: convertdef.h:928
double cal2mjd(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second, int32_t nsecond)
Calendar representation to Modified Julian Day - full.
Definition: timelib.cpp:294
char name[25]
Definition: convertdef.h:925
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
double e
Eccentricity (unitless)
Definition: convertdef.h:936
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
double utc
Definition: convertdef.h:923
double i
Inclination (radians)
Definition: convertdef.h:932
double bstar
Drag (1/Earth radii)
Definition: convertdef.h:930
uint16_t snumber
Definition: convertdef.h:926
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int32_t load_lines ( string  fname,
vector< tlestruc > &  lines 
)

Load TLE from file. TODO!!! Rename Function to loadTle and create new class for dealing with TLEs.

Load Two Line Element file into array of TLE's

Parameters
fnameName of file containing elements
linesArray of tlestruc structures to contain elements
Returns
A 32 bit signed integer indicating number of elements, otherwise a negative error.
3613 {
3614  FILE *fdes;
3615  uint16_t year;
3616  double jday;
3617  int32_t bdragm, bdrage, ecc;
3618  char ibuf[81], tlename[81];
3619  int i;
3620  tlestruc tle;
3621 
3622  if ((fdes=fopen(fname.c_str(),"r")) == nullptr)
3623  return (-1);
3624 
3625  tlecount = 0;
3626 
3627  // Name Line
3628  char* ichar = fgets(tlename,80,fdes);
3629  if (ichar == nullptr || feof(fdes))
3630  return (-1);
3631 
3632  for (i=strlen(tlename)-1; i>0; i--)
3633  {
3634  if (tlename[i]!=' ' && tlename[i]!='\r' && tlename[i]!='\n')
3635  break;
3636  }
3637  tlename[i+1] = 0;
3638 
3639  while (!feof(fdes))
3640  {
3641  strcpy(tle.name,tlename);
3642 
3643  // Line 1
3644  if (fgets(ibuf,80,fdes) == nullptr)
3645  break;
3646  uint16_t cs = 0;
3647  for (uint16_t i=0; i<68; ++i)
3648  {
3649  if (ibuf[i] >= '0' && ibuf[i] <= '9')
3650  {
3651  cs =(cs + (ibuf[i] - '0'));
3652  }
3653  else if (ibuf[i] == '-')
3654  {
3655  cs =(cs + 1);
3656  }
3657  }
3658  cs = cs % 10;
3659  sscanf(&ibuf[2],"%5hu",&tle.snumber);
3660  sscanf(&ibuf[9],"%6s",tle.id);
3661  sscanf(&ibuf[18],"%2hu",&year);
3662  if (year < 57)
3663  year += 2000;
3664  else
3665  year += 1900;
3666  sscanf(&ibuf[20],"%12lf",&jday);
3667  tle.utc = cal2mjd((int)year,1,0.);
3668  tle.utc += jday;
3669  if (strlen(ibuf) > 50)
3670  {
3671  sscanf(&ibuf[53],"%6d%2d",&bdragm,&bdrage);
3672  tle.bstar = pow(10.,bdrage)*bdragm/1.e5;
3673  }
3674  else
3675  tle.bstar = 0.;
3676 
3677  // Line 2
3678  char* ichar = fgets(ibuf,80,fdes);
3679  if (ichar != NULL)
3680  {
3681  cs = 0;
3682  for (uint16_t i=0; i<68; ++i)
3683  {
3684  if (ichar[i] >= '0' && ichar[i] <= '9')
3685  {
3686  cs =(cs + (ichar[i] - '0'));
3687  }
3688  else if (ichar[i] == '-')
3689  {
3690  cs =(cs + 1);
3691  }
3692  }
3693  cs = cs % 10;
3694  ibuf[68] = 0;
3695  sscanf(&ibuf[8],"%8lf %8lf %7d %8lf %8lf %11lf%5u",&tle.i,&tle.raan,&ecc,&tle.ap,&tle.ma,&tle.mm,&tle.orbit);
3696  tle.i = RADOF(tle.i);
3697  tle.raan = RADOF(tle.raan);
3698  tle.ap = RADOF(tle.ap);
3699  tle.ma = RADOF(tle.ma);
3700  tle.mm *= D2PI/1440.;
3701  tle.e = ecc / 1.e7;
3702  lines.push_back(tle);
3703  }
3704  }
3705  fclose(fdes);
3706  return (lines.size());
3707 }
In units for the SGP4 propogator (not NORAD TLE itself).
Definition: convertdef.h:921
static std::vector< tlestruc > tle
Definition: agent_antenna.cpp:177
int i
Definition: rw_test.cpp:37
char ibuf[1000]
Definition: razor_imu.cpp:43
string tlename
Definition: fast_contacts.cpp:39
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
uint32_t orbit
Definition: convertdef.h:943
static char fname[100]
Definition: geomag.cpp:89
static uint16_t tlecount
Definition: convertlib.cpp:47
char id[9]
Definition: convertdef.h:928
double cal2mjd(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second, int32_t nsecond)
Calendar representation to Modified Julian Day - full.
Definition: timelib.cpp:294
char name[25]
Definition: convertdef.h:925
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
double e
Eccentricity (unitless)
Definition: convertdef.h:936
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
double utc
Definition: convertdef.h:923
double i
Inclination (radians)
Definition: convertdef.h:932
double bstar
Drag (1/Earth radii)
Definition: convertdef.h:930
uint16_t snumber
Definition: convertdef.h:926
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int32_t load_lines_multi ( string  fname,
vector< tlestruc > &  lines 
)

Load Two Line Element file for multiple satellites into array of TLE's

Parameters
fnameName of file containing elements
linesArray of tlestruc structures to contain elements
Returns
A 32 bit signed integer indicating number of elements, otherwise a negative error.
3715 {
3716  FILE *fdes;
3717  uint16_t year;
3718  double jday;
3719  int32_t bdragm, bdrage, ecc;
3720  char ibuf[81], tlename[81];
3721  int i;
3722  tlestruc tle;
3723 
3724  if ((fdes=fopen(fname.c_str(),"r")) == nullptr)
3725  return (-1);
3726 
3727  tlecount = 0;
3728 
3729  while (!feof(fdes))
3730  {
3731  // Name Line
3732  char* ichar = fgets(tlename,80,fdes);
3733  if (ichar == nullptr || feof(fdes))
3734  break;
3735 
3736  for (i=strlen(tlename)-1; i>0; i--)
3737  {
3738  if (tlename[i]!=' ' && tlename[i]!='\r' && tlename[i]!='\n')
3739  break;
3740  }
3741  tlename[i+1] = 0;
3742 
3743  strcpy(tle.name,tlename);
3744 
3745  // Line 1
3746  if (fgets(ibuf,80,fdes) == nullptr)
3747  break;
3748  sscanf(&ibuf[2],"%5hu",&tle.snumber);
3749  sscanf(&ibuf[9],"%6s",tle.id);
3750  sscanf(&ibuf[18],"%2hu",&year);
3751  if (year < 57)
3752  year += 2000;
3753  else
3754  year += 1900;
3755  sscanf(&ibuf[20],"%12lf",&jday);
3756  tle.utc = cal2mjd((int)year,1,0.);
3757  tle.utc += jday;
3758  if (strlen(ibuf) > 50)
3759  {
3760  sscanf(&ibuf[53],"%6d%2d",&bdragm,&bdrage);
3761  tle.bstar = pow(10.,bdrage)*bdragm/1.e5;
3762  }
3763  else
3764  tle.bstar = 0.;
3765 
3766  // Line 2
3767  ichar = fgets(ibuf,80,fdes);
3768  if (ichar != NULL)
3769  {
3770  ibuf[68] = 0;
3771  sscanf(&ibuf[8],"%8lf %8lf %7d %8lf %8lf %11lf%5u",&tle.i,&tle.raan,&ecc,&tle.ap,&tle.ma,&tle.mm,&tle.orbit);
3772  tle.i = RADOF(tle.i);
3773  tle.raan = RADOF(tle.raan);
3774  tle.ap = RADOF(tle.ap);
3775  tle.ma = RADOF(tle.ma);
3776  tle.mm *= D2PI/1440.;
3777  tle.e = ecc / 1.e7;
3778  lines.push_back(tle);
3779  }
3780  }
3781  fclose(fdes);
3782  return (lines.size());
3783 }
In units for the SGP4 propogator (not NORAD TLE itself).
Definition: convertdef.h:921
static std::vector< tlestruc > tle
Definition: agent_antenna.cpp:177
int i
Definition: rw_test.cpp:37
char ibuf[1000]
Definition: razor_imu.cpp:43
string tlename
Definition: fast_contacts.cpp:39
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
uint32_t orbit
Definition: convertdef.h:943
static char fname[100]
Definition: geomag.cpp:89
static uint16_t tlecount
Definition: convertlib.cpp:47
char id[9]
Definition: convertdef.h:928
double cal2mjd(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second, int32_t nsecond)
Calendar representation to Modified Julian Day - full.
Definition: timelib.cpp:294
char name[25]
Definition: convertdef.h:925
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
double e
Eccentricity (unitless)
Definition: convertdef.h:936
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
double utc
Definition: convertdef.h:923
double i
Inclination (radians)
Definition: convertdef.h:932
double bstar
Drag (1/Earth radii)
Definition: convertdef.h:930
uint16_t snumber
Definition: convertdef.h:926
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int32_t load_stk ( string  filename,
stkstruc stkdata 
)

Load STK elements.

Load a table of locations calculated in STK. Format is expected to be J2000; position, velocity and acceleration; in X, Y, and Z; all in meters.

Parameters
filenameName of file containing positions.
stkdatastkstruc holding satellite position.
Returns
The number of entries in the table, otherwise a negative error.
3793 {
3794  FILE *fdes;
3795  int32_t maxcount;
3796  int32_t iretn;
3797  cposstruc *tpos;
3798  char ibuf[250];
3799 
3800  if ((fdes=fopen(filename.c_str(),"r")) == nullptr)
3801  return (STK_ERROR_NOTFOUND);
3802 
3803  maxcount = 1000;
3804  stkdata.pos = (cposstruc *)calloc(maxcount,sizeof(cposstruc));
3805  stkdata.count = 0;
3806  while (!feof(fdes))
3807  {
3808  char* ichar = fgets(ibuf,250,fdes);
3809  if (ichar == nullptr || feof(fdes))
3810  break;
3811  if ((iretn=sscanf(ibuf,"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&stkdata.pos[stkdata.count].pos.utc,&stkdata.pos[stkdata.count].pos.s.col[0],&stkdata.pos[stkdata.count].pos.s.col[1],&stkdata.pos[stkdata.count].pos.s.col[2],&stkdata.pos[stkdata.count].pos.v.col[0],&stkdata.pos[stkdata.count].pos.v.col[1],&stkdata.pos[stkdata.count].pos.v.col[2],&stkdata.pos[stkdata.count].pos.a.col[0],&stkdata.pos[stkdata.count].pos.a.col[1],&stkdata.pos[stkdata.count].pos.a.col[2])) == 10)
3812  {
3813  stkdata.pos[stkdata.count].utc = stkdata.pos[stkdata.count].pos.utc;
3814  stkdata.count++;
3815  if (!(stkdata.count%1000))
3816  {
3817  maxcount += 1000;
3818  tpos = stkdata.pos;
3819  stkdata.pos = (cposstruc *)calloc(maxcount,sizeof(cposstruc));
3820  memcpy(stkdata.pos,tpos,(maxcount-1000)*sizeof(cposstruc));
3821  free(tpos);
3822  }
3823  }
3824  else
3825  iretn = 0;
3826  }
3827  fclose(fdes);
3828  if (stkdata.count)
3829  {
3830  stkdata.dt = ((stkdata.pos[9].utc - stkdata.pos[0].utc))/9.;
3831  }
3832  return (stkdata.count);
3833 }
cposstruc * pos
Array of positions.
Definition: convertdef.h:1006
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
char ibuf[1000]
Definition: razor_imu.cpp:43
int iretn
Definition: rw_test.cpp:37
#define STK_ERROR_NOTFOUND
Definition: cosmos-errno.h:132
rvector s
Location.
Definition: convertdef.h:163
double utc
UTC as Modified Julian Day.
Definition: convertdef.h:218
double dt
Time step in Modified Julian Days.
Definition: convertdef.h:1004
cartpos pos
Cartesian structure with all elements of position.
Definition: convertdef.h:220
Cartesian position with time.
Definition: convertdef.h:215
double col[3]
Definition: vector.h:55
size_t count
Number of positions.
Definition: convertdef.h:1002
rvector v
Velocity.
Definition: convertdef.h:165
int stk2eci ( double  utc,
stkstruc stk,
cartpos eci 
)

ECI from STK data.

Return an interpolated cartpos from time and STK data

Parameters
utcUTC in Modified Julian Days
stkStructure containing array of STK positions
eciStructure to return position in
Returns
0 if successful, otherwise negative error
3843 {
3844  int32_t index, i, j;
3845  double findex;
3846  uvector t{}, p{}, su{}, vu{}, au{};
3847  rmatrix s, v, a;
3848 
3849  findex = ((utc-stk.pos[0].utc)/stk.dt)+.5;
3850  if (findex < 1)
3851  {
3852  findex = 1.;
3853  }
3854  if (findex >= stk.count)
3855  {
3856  findex = stk.count - 1;
3857  }
3858 
3859  findex = (int)findex + ((utc-stk.pos[(int)findex].utc)/stk.dt) + .5;
3860 
3861  index = (int)findex-1;
3862  if (index < 0)
3863  return (STK_ERROR_LOWINDEX);
3864 
3865  if (index > (int32_t)stk.count-3)
3866  return (STK_ERROR_HIGHINDEX);
3867 
3868 
3869  for (i=0; i<3; i++)
3870  {
3871  t.a4[i] = utc-stk.pos[index+i].utc;
3872  for (j=0; j<3; j++)
3873  {
3874  s.row[j].col[i] = stk.pos[index+i].pos.s.col[j];
3875  v.row[j].col[i] = stk.pos[index+i].pos.v.col[j];
3876  a.row[j].col[i] = stk.pos[index+i].pos.a.col[j];
3877  }
3878  }
3879 
3880  eci.utc = utc;
3881  eci.s = eci.v = eci.a = rv_zero();
3882 
3883  for (j=0; j<3; j++)
3884  {
3885  su.r = s.row[j];
3886  p = rv_fitpoly(t,su,2);
3887  // eci.s.col[j] = p.a4[0] + utc * (p.a4[1] + utc * p.a4[2]);
3888  eci.s.col[j] = p.a4[0];
3889  vu.r = v.row[j];
3890  p = rv_fitpoly(t,vu,2);
3891  // eci.v.col[j] = p.a4[0] + utc * (p.a4[1] + utc * p.a4[2]);
3892  eci.v.col[j] = p.a4[0];
3893  au.r = a.row[j];
3894  p = rv_fitpoly(t,au,2);
3895  // eci.a.col[j] = p.a4[0] + utc * (p.a4[1] + utc * p.a4[2]);
3896  eci.a.col[j] = p.a4[0];
3897  }
3898 
3899  return 0;
3900 }
Quaternion/Rvector Union.
Definition: mathlib.h:155
cposstruc * pos
Array of positions.
Definition: convertdef.h:1006
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
int i
Definition: rw_test.cpp:37
static double * p
Definition: gauss_jackson_test.cpp:42
rvector s
Location.
Definition: convertdef.h:163
3x3 element generic matrix
Definition: matrix.h:41
double utc
UTC as Modified Julian Day.
Definition: convertdef.h:218
double dt
Time step in Modified Julian Days.
Definition: convertdef.h:1004
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
cartpos pos
Cartesian structure with all elements of position.
Definition: convertdef.h:220
Definition: eci2kep_test.cpp:33
double col[3]
Definition: vector.h:55
uvector rv_fitpoly(uvector x, uvector y, uint32_t order)
Perform nth order polynomial fit.
Definition: mathlib.cpp:1507
#define STK_ERROR_HIGHINDEX
Definition: cosmos-errno.h:130
size_t count
Number of positions.
Definition: convertdef.h:1002
rvector row[3]
Definition: matrix.h:43
#define STK_ERROR_LOWINDEX
Definition: cosmos-errno.h:129
rvector v
Velocity.
Definition: convertdef.h:165
std::ostream& operator<< ( std::ostream &  out,
const cartpos a 
)
3903 {
3904  out << a.utc << "\t" << a.s << "\t" << a.v << "\t" << a.a << "\t" << a.pass;
3905  return out;
3906 }
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
rvector s
Location.
Definition: convertdef.h:163
rvector v
Velocity.
Definition: convertdef.h:165
std::istream& operator>> ( std::istream &  in,
cartpos a 
)
3909 {
3910  in >> a.utc >> a.s >> a.v >> a.a >> a.pass;
3911  return in;
3912 }
rvector a
Acceleration.
Definition: convertdef.h:167
double utc
UTC of Position.
Definition: convertdef.h:161
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
rvector s
Location.
Definition: convertdef.h:163
rvector v
Velocity.
Definition: convertdef.h:165
std::ostream& operator<< ( std::ostream &  out,
const cposstruc a 
)
3915 {
3916  out << a.utc << "\t" << a.pos;
3917  return out;
3918 }
double utc
UTC as Modified Julian Day.
Definition: convertdef.h:218
cartpos pos
Cartesian structure with all elements of position.
Definition: convertdef.h:220
std::istream& operator>> ( std::istream &  in,
cposstruc a 
)
3921 {
3922  in >> a.utc >> a.pos;
3923  return in;
3924 }
double utc
UTC as Modified Julian Day.
Definition: convertdef.h:218
cartpos pos
Cartesian structure with all elements of position.
Definition: convertdef.h:220
std::ostream& operator<< ( std::ostream &  out,
const geoidpos a 
)
3927 {
3928  out<<a.utc<<"\t"<<a.s<<"\t"<<a.v<<"\t"<<a.a<<"\t"<<a.pass;
3929  return out;
3930 }
double utc
Definition: convertdef.h:261
gvector a
Acceleration vector.
Definition: convertdef.h:267
gvector s
Position vector.
Definition: convertdef.h:263
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
gvector v
Velocity vector.
Definition: convertdef.h:265
std::istream& operator>> ( std::istream &  in,
geoidpos a 
)
3933 {
3934  in >> a.utc >> a.s >> a.v >> a.a >> a.pass;
3935  return in;
3936 }
double utc
Definition: convertdef.h:261
gvector a
Acceleration vector.
Definition: convertdef.h:267
gvector s
Position vector.
Definition: convertdef.h:263
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:269
gvector v
Velocity vector.
Definition: convertdef.h:265
std::ostream& operator<< ( std::ostream &  out,
const spherpos a 
)
3939 {
3940  out<<a.utc<<"\t"<<a.s<<"\t"<<a.v<<"\t"<<a.a<<"\t"<<a.pass;
3941  return out;
3942 }
svector s
Position vector.
Definition: convertdef.h:318
svector v
Velocity vector.
Definition: convertdef.h:320
double utc
Definition: convertdef.h:316
svector a
Acceleration vector.
Definition: convertdef.h:322
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:324
std::istream& operator>> ( std::istream &  in,
spherpos a 
)
3945 {
3946  in >> a.utc >> a.s >> a.v >> a.a >> a.pass;
3947  return in;
3948 }
svector s
Position vector.
Definition: convertdef.h:318
svector v
Velocity vector.
Definition: convertdef.h:320
double utc
Definition: convertdef.h:316
svector a
Acceleration vector.
Definition: convertdef.h:322
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:324
std::ostream& operator<< ( std::ostream &  out,
const aattstruc a 
)
3951 {
3952  out<<a.utc<<"\t"<<a.s<<"\t"<<a.v<<"\t"<<a.a;
3953  return out;
3954 }
avector a
Definition: convertdef.h:370
avector v
Definition: convertdef.h:369
avector s
Definition: convertdef.h:368
double utc
Definition: convertdef.h:367
std::istream& operator>> ( std::istream &  in,
aattstruc a 
)
3957 {
3958  in >> a.utc >> a.s >> a.v >> a.a;
3959  return in;
3960 }
avector a
Definition: convertdef.h:370
avector v
Definition: convertdef.h:369
avector s
Definition: convertdef.h:368
double utc
Definition: convertdef.h:367
std::ostream& operator<< ( std::ostream &  out,
const quatatt a 
)
3963 {
3964  out<<a.utc<<"\t"<<a.s<<"\t"<<a.v<<"\t"<<a.a;
3965  return out;
3966 }
rvector v
Definition: convertdef.h:412
quaternion s
Definition: convertdef.h:411
double utc
Definition: convertdef.h:410
rvector a
Definition: convertdef.h:413
std::istream& operator>> ( std::istream &  in,
quatatt a 
)
3969 {
3970  in >> a.utc >> a.s >> a.v >> a.a;
3971  return in;
3972 }
rvector v
Definition: convertdef.h:412
quaternion s
Definition: convertdef.h:411
double utc
Definition: convertdef.h:410
rvector a
Definition: convertdef.h:413
std::ostream& operator<< ( std::ostream &  out,
const dcmatt a 
)
3975 {
3976  out<<a.utc<<"\t"<<a.s<<"\t"<<a.v<<"\t"<<a.a;
3977  return out;
3978 }
rvector a
2nd derivative
Definition: convertdef.h:431
double utc
Definition: convertdef.h:425
rvector v
1st derivative
Definition: convertdef.h:429
rmatrix s
0th derivative
Definition: convertdef.h:427
std::istream& operator>> ( std::istream &  in,
dcmatt a 
)
3981 {
3982  in >> a.utc >> a.s >> a.v >> a.a;
3983  return in;
3984 }
rvector a
2nd derivative
Definition: convertdef.h:431
double utc
Definition: convertdef.h:425
rvector v
1st derivative
Definition: convertdef.h:429
rmatrix s
0th derivative
Definition: convertdef.h:427
std::ostream& operator<< ( std::ostream &  out,
const qatt a 
)
3987 {
3988  out<<a.utc<<"\t"<<a.s<<"\t"<<a.v<<"\t"<<a.a<<"\t"<<a.pass;
3989  return out;
3990 }
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
double utc
Definition: convertdef.h:477
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
std::istream& operator>> ( std::istream &  in,
qatt a 
)
3993 {
3994  in >> a.utc >> a.s >> a.v >> a.a >> a.pass;
3995  return in;
3996 }
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
double utc
Definition: convertdef.h:477
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:485
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
std::ostream& operator<< ( std::ostream &  out,
const kepstruc a 
)
3999 {
4000  out <<a.utc<<"\t"
4001  <<a.orbit<<"\t"
4002  <<a.period<<"\t"
4003  <<a.a<<"\t"
4004  <<a.e<<"\t"
4005  <<a.h<<"\t"
4006  <<a.beta<<"\t"
4007  <<a.eta<<"\t"
4008  <<a.i<<"\t"
4009  <<a.raan<<"\t"
4010  <<a.ap<<"\t"
4011  <<a.alat<<"\t"
4012  <<a.ma<<"\t"
4013  <<a.ta<<"\t"
4014  <<a.ea<<"\t"
4015  <<a.mm<<"\t"
4016  <<a.fa;
4017  return out;
4018 }
double ta
True Anomoly.
Definition: convertdef.h:557
double mm
Mean Motion.
Definition: convertdef.h:561
double utc
UTC time of state vector in MJD.
Definition: convertdef.h:532
double e
Eccentricity.
Definition: convertdef.h:540
double ma
Mean Anomoly.
Definition: convertdef.h:555
rvector h
Angular Momentum vector.
Definition: convertdef.h:542
double eta
Definition: convertdef.h:545
uint32_t orbit
Orbit number.
Definition: convertdef.h:534
double period
Orbital Period in seconds.
Definition: convertdef.h:536
double fa
Definition: convertdef.h:562
double raan
Right Ascension of the Ascending Node in radians.
Definition: convertdef.h:549
double ap
Argument of Perigee.
Definition: convertdef.h:551
double i
Orbital Inclination in radians.
Definition: convertdef.h:547
double beta
Solar Beta Angle in radians.
Definition: convertdef.h:544
double a
Semi-Major Axis in meters.
Definition: convertdef.h:538
double ea
Eccentric Anomoly.
Definition: convertdef.h:559
double alat
Argument of Latitude.
Definition: convertdef.h:553
std::istream& operator>> ( std::istream &  in,
kepstruc a 
)
4021 {
4022  in >>a.utc
4023  >>a.orbit
4024  >>a.period
4025  >>a.a
4026  >>a.e
4027  >>a.h
4028  >>a.beta
4029  >>a.eta
4030  >>a.i
4031  >>a.raan
4032  >>a.ap
4033  >>a.alat
4034  >>a.ma
4035  >>a.ta
4036  >>a.ea
4037  >>a.mm
4038  >>a.fa;
4039  return in;
4040 }
double ta
True Anomoly.
Definition: convertdef.h:557
double mm
Mean Motion.
Definition: convertdef.h:561
double utc
UTC time of state vector in MJD.
Definition: convertdef.h:532
double e
Eccentricity.
Definition: convertdef.h:540
double ma
Mean Anomoly.
Definition: convertdef.h:555
rvector h
Angular Momentum vector.
Definition: convertdef.h:542
double eta
Definition: convertdef.h:545
uint32_t orbit
Orbit number.
Definition: convertdef.h:534
double period
Orbital Period in seconds.
Definition: convertdef.h:536
double fa
Definition: convertdef.h:562
double raan
Right Ascension of the Ascending Node in radians.
Definition: convertdef.h:549
double ap
Argument of Perigee.
Definition: convertdef.h:551
double i
Orbital Inclination in radians.
Definition: convertdef.h:547
double beta
Solar Beta Angle in radians.
Definition: convertdef.h:544
double a
Semi-Major Axis in meters.
Definition: convertdef.h:538
double ea
Eccentric Anomoly.
Definition: convertdef.h:559
double alat
Argument of Latitude.
Definition: convertdef.h:553
std::ostream& operator<< ( std::ostream &  out,
const bodypos a 
)
4043 {
4044  out << a.sepangle << "\t" << a.size << "\t" << a.radiance;
4045  return out;
4046 }
double radiance
Definition: convertdef.h:572
double size
Definition: convertdef.h:571
double sepangle
Definition: convertdef.h:570
std::istream& operator<< ( std::istream &  in,
bodypos a 
)
4049 {
4050  in >> a.sepangle >> a.size >> a.radiance;
4051  return in;
4052 }
double radiance
Definition: convertdef.h:572
double size
Definition: convertdef.h:571
double sepangle
Definition: convertdef.h:570
std::ostream& operator<< ( std::ostream &  out,
const extrapos a 
)
4055 {
4056  out <<a.utc<<"\t"
4057  <<a.tt<<"\t"
4058  <<a.ut<<"\t"
4059  <<a.tdb<<"\t"
4060  <<a.j2e<<"\t"
4061  <<a.dj2e<<"\t"
4062  <<a.ddj2e<<"\t"
4063  <<a.e2j<<"\t"
4064  <<a.de2j<<"\t"
4065  <<a.dde2j<<"\t"
4066  <<a.j2t<<"\t"
4067  <<a.j2s<<"\t"
4068  <<a.t2j<<"\t"
4069  <<a.s2j<<"\t"
4070  <<a.s2t<<"\t"
4071  <<a.ds2t<<"\t"
4072  <<a.t2s<<"\t"
4073  <<a.dt2s<<"\t"
4074  <<a.sun2earth<<"\t"
4075  <<a.sun2moon<<"\t"
4076  <<a.closest;
4077  return out;
4078 }
cartpos sun2earth
Definition: convertdef.h:605
rmatrix j2s
Definition: convertdef.h:598
rmatrix dt2s
Definition: convertdef.h:604
rmatrix ddj2e
Definition: convertdef.h:592
rmatrix ds2t
Definition: convertdef.h:602
double tt
Terrestrial Time.
Definition: convertdef.h:584
double utc
Coordinated Universal Time.
Definition: convertdef.h:582
cartpos sun2moon
Definition: convertdef.h:606
uint16_t closest
Definition: convertdef.h:607
rmatrix t2s
Definition: convertdef.h:603
rmatrix s2j
Definition: convertdef.h:600
rmatrix de2j
Definition: convertdef.h:595
double tdb
Dynamical Barycentric Time.
Definition: convertdef.h:588
rmatrix dde2j
Definition: convertdef.h:596
rmatrix t2j
Definition: convertdef.h:599
rmatrix dj2e
Definition: convertdef.h:591
rmatrix e2j
Transform from Geocentric to ICRF.
Definition: convertdef.h:594
rmatrix s2t
Definition: convertdef.h:601
double ut
UT0.
Definition: convertdef.h:586
rmatrix j2t
Definition: convertdef.h:597
rmatrix j2e
Transform from ICRF to Geocentric.
Definition: convertdef.h:590
std::istream& operator>> ( std::istream &  in,
extrapos a 
)
4081 {
4082  in >>a.utc
4083  >>a.tt
4084  >>a.ut
4085  >>a.tdb
4086  >>a.j2e
4087  >>a.dj2e
4088  >>a.ddj2e
4089  >>a.e2j
4090  >>a.de2j
4091  >>a.dde2j
4092  >>a.j2t
4093  >>a.j2s
4094  >>a.t2j
4095  >>a.s2j
4096  >>a.s2t
4097  >>a.ds2t
4098  >>a.t2s
4099  >>a.dt2s
4100  >>a.sun2earth
4101  >>a.sun2moon
4102  >>a.closest;
4103  return in;
4104 }
cartpos sun2earth
Definition: convertdef.h:605
rmatrix j2s
Definition: convertdef.h:598
rmatrix dt2s
Definition: convertdef.h:604
rmatrix ddj2e
Definition: convertdef.h:592
rmatrix ds2t
Definition: convertdef.h:602
double tt
Terrestrial Time.
Definition: convertdef.h:584
double utc
Coordinated Universal Time.
Definition: convertdef.h:582
cartpos sun2moon
Definition: convertdef.h:606
uint16_t closest
Definition: convertdef.h:607
rmatrix t2s
Definition: convertdef.h:603
rmatrix s2j
Definition: convertdef.h:600
rmatrix de2j
Definition: convertdef.h:595
double tdb
Dynamical Barycentric Time.
Definition: convertdef.h:588
rmatrix dde2j
Definition: convertdef.h:596
rmatrix t2j
Definition: convertdef.h:599
rmatrix dj2e
Definition: convertdef.h:591
rmatrix e2j
Transform from Geocentric to ICRF.
Definition: convertdef.h:594
rmatrix s2t
Definition: convertdef.h:601
double ut
UT0.
Definition: convertdef.h:586
rmatrix j2t
Definition: convertdef.h:597
rmatrix j2e
Transform from ICRF to Geocentric.
Definition: convertdef.h:590
std::ostream& operator<< ( std::ostream &  out,
const extraatt a 
)
4107 {
4108  out << a.utc << "\t" << a.j2b << "\t" << a.b2j;
4109  return out;
4110 }
rmatrix j2b
Transform from ICRF to Body frame.
Definition: convertdef.h:694
rmatrix b2j
Transform from Body frame to ICRF.
Definition: convertdef.h:696
double utc
Coordinated Universal Time.
Definition: convertdef.h:692
std::istream& operator>> ( std::istream &  in,
extraatt a 
)
4113 {
4114  in >> a.utc >> a.j2b >> a.b2j;
4115  return in;
4116 }
rmatrix j2b
Transform from ICRF to Body frame.
Definition: convertdef.h:694
rmatrix b2j
Transform from Body frame to ICRF.
Definition: convertdef.h:696
double utc
Coordinated Universal Time.
Definition: convertdef.h:692
std::ostream& operator<< ( std::ostream &  out,
const posstruc a 
)
4119 {
4120  out << a.utc << "\t"
4121  << a.icrf << "\t"
4122  << a.eci << "\t"
4123  << a.sci << "\t"
4124  << a.geoc << "\t"
4125  << a.selc << "\t"
4126  << a.geod << "\t"
4127  << a.selg << "\t"
4128  << a.geos << "\t"
4129  << a.extra << "\t"
4130  << a.earthsep << "\t"
4131  << a.moonsep << "\t"
4132  << a.sunsize << "\t"
4133  << a.sunradiance;
4134  return out;
4135 }
spherpos geos
Definition: convertdef.h:743
cartpos selc
Definition: convertdef.h:740
cartpos geoc
Definition: convertdef.h:739
float moonsep
Separation between sun/satellite and sun/limbofmoon vectors in radians.
Definition: convertdef.h:748
float earthsep
Separation between sun/satellite and sun/limbofearth vectors in radians.
Definition: convertdef.h:746
float sunradiance
Watts per square meter per steradian.
Definition: convertdef.h:752
geoidpos selg
Definition: convertdef.h:742
double utc
Definition: convertdef.h:735
extrapos extra
Definition: convertdef.h:744
cartpos sci
Definition: convertdef.h:738
float sunsize
Radius of sun in radians.
Definition: convertdef.h:750
cartpos eci
Definition: convertdef.h:737
geoidpos geod
Definition: convertdef.h:741
cartpos icrf
Definition: convertdef.h:736
std::istream& operator>> ( std::istream &  in,
posstruc a 
)
4138 {
4139  in >> a.utc
4140  >> a.icrf
4141  >> a.eci
4142  >> a.sci
4143  >> a.geoc
4144  >> a.selc
4145  >> a.geod
4146  >> a.selg
4147  >> a.geos
4148  >> a.extra
4149  >> a.earthsep
4150  >> a.moonsep
4151  >> a.sunsize
4152  >> a.sunradiance;
4153  return in;
4154 }
spherpos geos
Definition: convertdef.h:743
cartpos selc
Definition: convertdef.h:740
cartpos geoc
Definition: convertdef.h:739
float moonsep
Separation between sun/satellite and sun/limbofmoon vectors in radians.
Definition: convertdef.h:748
float earthsep
Separation between sun/satellite and sun/limbofearth vectors in radians.
Definition: convertdef.h:746
float sunradiance
Watts per square meter per steradian.
Definition: convertdef.h:752
geoidpos selg
Definition: convertdef.h:742
double utc
Definition: convertdef.h:735
extrapos extra
Definition: convertdef.h:744
cartpos sci
Definition: convertdef.h:738
float sunsize
Radius of sun in radians.
Definition: convertdef.h:750
cartpos eci
Definition: convertdef.h:737
geoidpos geod
Definition: convertdef.h:741
cartpos icrf
Definition: convertdef.h:736
std::ostream& operator<< ( std::ostream &  out,
const attstruc a 
)
4157 {
4158  out << a.utc << "\t"
4159  << a.topo << "\t"
4160  << a.lvlh << "\t"
4161  << a.geoc << "\t"
4162  << a.selc << "\t"
4163  << a.icrf << "\t"
4164  << a.extra;
4165  return out;
4166 }
qatt geoc
Definition: convertdef.h:828
qatt lvlh
Definition: convertdef.h:827
qatt selc
Definition: convertdef.h:829
qatt icrf
Definition: convertdef.h:830
qatt topo
Definition: convertdef.h:826
extraatt extra
Definition: convertdef.h:831
double utc
Definition: convertdef.h:825
std::istream& operator>> ( std::istream &  in,
attstruc a 
)
4169 {
4170  in >> a.utc
4171  >> a.topo
4172  >> a.lvlh
4173  >> a.geoc
4174  >> a.selc
4175  >> a.icrf
4176  >> a.extra;
4177  return in;
4178 }
qatt geoc
Definition: convertdef.h:828
qatt lvlh
Definition: convertdef.h:827
qatt selc
Definition: convertdef.h:829
qatt icrf
Definition: convertdef.h:830
qatt topo
Definition: convertdef.h:826
extraatt extra
Definition: convertdef.h:831
double utc
Definition: convertdef.h:825
std::ostream& operator<< ( std::ostream &  out,
const locstruc a 
)
4181 {
4182  out << a.utc << "\t"
4183  << a.pos << "\t"
4184  << a.att;
4185  return out;
4186 }
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
attstruc att
attstruc for this time.
Definition: convertdef.h:883
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
std::istream& operator>> ( std::istream &  in,
locstruc a 
)
4189 {
4190  in >> a.utc
4191  >> a.pos
4192  >> a.att;
4193  return in;
4194 }
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
attstruc att
attstruc for this time.
Definition: convertdef.h:883
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
int32_t pos_eci2selc ( locstruc loc)
int32_t pos_eci2sci ( locstruc loc)
int32_t pos_sci2eci ( locstruc loc)
int32_t pos_selc2eci ( locstruc loc)
int32_t pos_eci2selc ( locstruc loc)
int32_t pos_eci2sci ( locstruc loc)
int32_t pos_sci2eci ( locstruc loc)
int32_t pos_selc2eci ( locstruc loc)
double mjd2year ( double  mjd)

Year from MJD.

Return the Decimal Year for the provided MJD

Parameters
mjdModified Julian Data
Returns
Decimal year.
998 {
999  double day, doy, dyear;
1000  int32_t month, year;
1001 
1002  mjd2ymd(mjd,year,month,day,doy);
1003  dyear = year + (doy-1) / (365.+isleap(year));
1004  return (dyear);
1005 }
int32_t mjd2ymd(double mjd, int32_t &year, int32_t &month, double &day)
MJD to Year, Month, and Decimal Day (overloaded)
Definition: timelib.cpp:217
int16_t isleap(int32_t year)
Check for Leap year.
Definition: timelib.cpp:1122
double mjd
Definition: udp_send.cpp:41
double mjd2gmst ( double  mjd)
int32_t geos2geoc ( spherpos geos,
cartpos geoc 
)
int32_t geoc2geos ( cartpos geoc,
spherpos geos 
)
int32_t selg2selc ( geoidpos selg,
cartpos selc 
)
int32_t tle2sgp4 ( tlestruc  tle,
sgp4struc sgp4 
)
4199 {
4200  sgp4.i = DEGOF(tle.i);
4201  sgp4.ap = DEGOF(tle.ap);
4202  sgp4.bstar = tle.bstar;
4203  sgp4.e = tle.e;
4204  sgp4.ma = DEGOF(tle.ma);
4205  sgp4.mm = tle.mm * 1440. / D2PI;
4206  calstruc cal = mjd2cal(tle.utc);
4207  sgp4.ep = (cal.year - 2000.) * 1000. + cal.doy + cal.hour / 24. + cal.minute / 1440. + (cal.second + cal.nsecond / 1e9) / 86400.;
4208  sgp4.raan = DEGOF(tle.raan);
4209  return 0;
4210 }
calstruc mjd2cal(double mjd)
MJD to Calendar.
Definition: timelib.cpp:180
double bstar
Definition: convertdef.h:1023
int32_t hour
Definition: timelib.h:112
int32_t nsecond
Definition: timelib.h:115
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
Definition: timelib.h:106
double e
Definition: convertdef.h:1017
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
double ap
Definition: convertdef.h:1021
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
int32_t minute
Definition: timelib.h:113
double ep
Definition: convertdef.h:1029
double e
Eccentricity (unitless)
Definition: convertdef.h:936
double ma
Definition: convertdef.h:1027
double mm
Definition: convertdef.h:1025
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double i
Definition: convertdef.h:1015
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
int32_t year
Definition: timelib.h:108
int32_t second
Definition: timelib.h:114
int32_t doy
Definition: timelib.h:111
double utc
Definition: convertdef.h:923
double raan
Definition: convertdef.h:1019
double i
Inclination (radians)
Definition: convertdef.h:932
double bstar
Drag (1/Earth radii)
Definition: convertdef.h:930
int32_t sgp42tle ( sgp4struc  sgp4,
tlestruc tle 
)
4213 {
4214  tle.i = RADOF(sgp4.i);
4215  tle.ap = RADOF(sgp4.ap);
4216  tle.bstar = sgp4.bstar;
4217  tle.e = sgp4.e;
4218  tle.ma = RADOF(sgp4.ma);
4219  tle.mm = sgp4.mm * D2PI / 1440. ;
4220  tle.raan = RADOF(sgp4.raan);
4221  int year = sgp4.ep / 1000;
4222  double jday = sgp4.ep - (year *1000);
4223  if (year < 57)
4224  year += 2000;
4225  else
4226  year += 1900;
4227  tle.utc = cal2mjd((int)year,1,0.);
4228  tle.utc += jday;
4229 
4230  return 0;
4231 }
double bstar
Definition: convertdef.h:1023
double mm
Mean motion (radians / minute)
Definition: convertdef.h:942
double raan
Right ascension of ascending node (radians)
Definition: convertdef.h:934
double e
Definition: convertdef.h:1017
double cal2mjd(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second, int32_t nsecond)
Calendar representation to Modified Julian Day - full.
Definition: timelib.cpp:294
double ap
Definition: convertdef.h:1021
double ap
Argument of perigee (radians)
Definition: convertdef.h:938
double ep
Definition: convertdef.h:1029
double e
Eccentricity (unitless)
Definition: convertdef.h:936
double ma
Definition: convertdef.h:1027
double mm
Definition: convertdef.h:1025
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double i
Definition: convertdef.h:1015
double ma
Mean anomaly (radians)
Definition: convertdef.h:940
double utc
Definition: convertdef.h:923
double raan
Definition: convertdef.h:1019
double i
Inclination (radians)
Definition: convertdef.h:932
double bstar
Drag (1/Earth radii)
Definition: convertdef.h:930
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29
int tle_checksum ( char *  line)
4234  {
4235  const int TLE_LINE_LENGTH = 69; // Ignore current checksum.
4236  int checksum = 0;
4237 
4238  for (int i = 0; i < TLE_LINE_LENGTH; i++) {
4239  if (line[i] == '-') {
4240  checksum++;
4241  }
4242  else if (isdigit(line[i])) {
4243  checksum += line[i] - '0';
4244  } // Ignore whitespace.
4245  }
4246 
4247  return checksum % 10;
4248 }
int i
Definition: rw_test.cpp:37
int32_t eci2tlestring ( cartpos  eci,
string &  tle,
std::string  ref_tle,
double  bstar = 0 
)