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

Functions

double currentmjd (double offset)
 Current UTC in Modified Julian Days. More...
 
double currentmjd ()
 
unsigned long int get_unix_time ()
 
string get_local_time ()
 
double unix2utc (struct timeval unixtime)
 Unix time to UTC. More...
 
double unix2utc (double unixtime)
 Unix time to UTC. More...
 
struct timeval utc2unix (double utc)
 UTC to Unix time. More...
 
double utc2unixseconds (double utc)
 UTC to Unix time. More...
 
calstruc mjd2cal (double mjd)
 MJD to Calendar. More...
 
int32_t mjd2ymd (double mjd, int32_t &year, int32_t &month, double &day)
 MJD to Year, Month, and Decimal Day (overloaded) More...
 
int32_t mjd2ymd (double mjd, int32_t &year, int32_t &month, double &day, double &doy)
 MJD to Year, Month, Decimal Day, and Julian Day (overloaded) More...
 
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. More...
 
double cal2mjd (double year)
 Calendar representation YYYY.ffff to Modified Julian Day - overloaded. More...
 
double cal2mjd (int32_t year, double dayOfYear)
 Calendar representation YYYY,DDD.ffff to Modified Julian Day - overloaded. More...
 
double cal2mjd (int32_t year, int32_t month, double day)
 Calendar representation to Modified Julian Day - shortened. More...
 
double cal2mjd (calstruc date)
 Calendar representation to Modified Julian Day - structure. More...
 
double gregorianToModJulianDate (int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, double second)
 
double utc2jcentt (double mjd)
 TT Julian Century. More...
 
double utc2jcenut1 (double mjd)
 UT1 Julian Century. More...
 
rvector utc2nuts (double mjd)
 Nutation values. More...
 
double utc2dpsi (double mjd)
 Nutation Delta Psi value. More...
 
double utc2depsilon (double mjd)
 Nutation Delta Epsilon value. More...
 
double utc2epsilon (double mjd)
 Nutation Epsilon value. More...
 
double utc2L (double mjd)
 Nutation L value. More...
 
double utc2Lp (double mjd)
 Nutation L prime value. More...
 
double utc2F (double mjd)
 Nutation F value. More...
 
double utc2D (double mjd)
 Nutation D value. More...
 
double utc2omega (double mjd)
 Nutation omega value. More...
 
double utc2zeta (double utc)
 Precession zeta value. More...
 
double utc2z (double utc)
 Precession z value. More...
 
double utc2theta (double utc)
 Precession theta value. More...
 
double utc2dut1 (double mjd)
 Calculate DUT1. More...
 
double utc2ut1 (double mjd)
 Convert UTC to UT1. More...
 
double julcen (double mjd)
 Julian Century. More...
 
double utc2tdb (double mjd)
 Convert UTC to TDB. More...
 
double tt2utc (double mjd)
 Convert TT to UTC. More...
 
double utc2tt (double mjd)
 Convert UTC to TT. More...
 
double utc2gps (double utc)
 Convert UTC to GPS. More...
 
double gps2utc (double gps)
 Convert GPS to UTC. More...
 
void gps2week (double gps, uint32_t &week, double &seconds)
 GPS Weeks and Seconds from GPS time. More...
 
double week2gps (uint32_t week, double seconds)
 GPS Time from GPS Week and Seconds. More...
 
double mjd2year (double mjd)
 Year from MJD. More...
 
double mjd2doy (double mjd)
 Day of Year from MJD. More...
 
double utc2era (double mjd)
 Earth Rotation Angle. More...
 
double utc2gast (double mjd)
 UTC to GAST. More...
 
double utc2gmst1982 (double mjd)
 UTC (Modified Julian Day) to GMST. More...
 
double utc2gmst2000 (double utc)
 
double ranrm (double angle)
 
int16_t isleap (int32_t year)
 Check for Leap year. More...
 
int32_t load_iers ()
 Load IERS Polar Motion, UT1-UTC, Leap Seconds. More...
 
int32_t leap_seconds (double mjd)
 Leap Seconds. More...
 
cvector polar_motion (double mjd)
 Polar motion. More...
 
string utc2unixdate (double utc)
 Time for setting unix date. More...
 
string utc2iso8601 (double utc)
 ISO 8601 version of time. More...
 
double iso86012utc (string date)
 
string mjd2iso8601 (double mjd)
 
int32_t dayFraction2hms (double dayFraction, int32_t *hour, int32_t *minute, int32_t *second)
 
int32_t mjdToGregorian (double mjd, int32_t &year, int32_t &month, int32_t &day, int32_t &hour, int32_t &minute, int32_t &second)
 
string mjdToGregorian (double mjd)
 
string mjdToGregorianFormat (double mjd)
 
string mjdToGregorianDDMMMYYYY (double mjd)
 
string mjdToGregorianDDMmmYYYY (double mjd)
 
string seconds2DDHHMMSS (double elapsed_seconds)
 Convert Elapsed Time in Seconds to Human Readable Format (used for GPS simulator) More...
 
double mjd2jd (double mjd)
 Modified Julian Day to Julian Day. More...
 
double jd2mjd (double jd)
 Julian Day to Modified Julian Day. More...
 
int32_t timed_countdown (int32_t seconds, int32_t step, string message)
 
int32_t mjdToGregorian (double mjd, int32_t *year, int32_t *month, int32_t *day, int32_t *hour, int32_t *minute, int32_t *second)
 
int32_t mjd2tlef (double mjd, string &tle)
 Convert mjd to the TLE epoch format. More...
 
double tt2tdb (double mjd)
 
double set_local_clock (double utc_to)
 

Detailed Description

Function Documentation

double currentmjd ( double  offset)

Current UTC in Modified Julian Days.

Parameters
offsetMJD offset to be apllied to turn actual time in to simulated time.
Returns
simulated time in Modified Julian Days.
66 {
67  double mjd;
68 
69  // unfortunatelly MSVC does not support gettimeofday
70 #ifdef COSMOS_WIN_BUILD_MSVC
71  TimeUtils tu;
72  mjd = unix2utc(tu.secondsSinceEpoch() + _timezone);
73 #else
74  struct timeval mytime;
75  gettimeofday(&mytime, NULL);
76  mjd = unix2utc(mytime);
77 #endif
78  return mjd+offset;
79 }
double unix2utc(struct timeval unixtime)
Unix time to UTC.
Definition: timelib.cpp:120
double secondsSinceEpoch()
Definition: timeutils.cpp:91
double mjd
Definition: udp_send.cpp:41
Definition: timeutils.h:46
double currentmjd ( )
82 {
83  return currentmjd(0.);
84 }
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
unsigned long get_unix_time ( )
87 {
88  unsigned long int unix_time = time(NULL);
89  return unix_time;
90 }
string get_local_time ( )
93 {
94  time_t rawtime;
95  struct tm * timeinfo;
96 
97  time (&rawtime);
98  timeinfo = localtime (&rawtime);
99  //printf ("Current local time and date: %s", asctime(timeinfo));
100 
101  int year = 1900 + timeinfo->tm_year;
102  int month = 1 + timeinfo->tm_mon;
103  int day = timeinfo->tm_mday;
104  int hour = timeinfo->tm_hour;
105  int minute = timeinfo->tm_min;
106  int second = timeinfo->tm_sec;
107 
108  char time_string[25];
109 
110  sprintf(time_string, "%04d-%02d-%02dT%02d%02d%02d", year, month, day, hour, minute, second);
111 
112  return string(time_string);
113 }
double unix2utc ( struct timeval  unixtime)

Unix time to UTC.

Convert Unix time in a timeval structure to a double precision number representing Mofidied Julian Day.

Parameters
unixtimeUnix time to be converted.
Returns
UTC as Modified Julian day.
121 {
122  double utc;
123  utc = MJD_UNIX_OFFSET + (unixtime.tv_sec + unixtime.tv_usec / 1000000.) / 86400.;
124 
125  return utc;
126 }
#define MJD_UNIX_OFFSET
Definition: timelib.h:73
double unix2utc ( double  unixtime)

Unix time to UTC.

Convert Unix time in seconds to a double precision number representing Mofidied Julian Day.

Parameters
unixtimeUnix time in decimal seconds.
Returns
UTC as Modified Julian day.
134 {
135  double utc;
136  struct tm *mytm;
137  time_t thetime;
138 
139  thetime = (time_t)unixtime;
140  mytm = gmtime(&thetime);
141  utc = cal2mjd(mytm->tm_year+1900,mytm->tm_mon+1,mytm->tm_mday);
142  utc += ((mytm->tm_hour + (mytm->tm_min + (mytm->tm_sec + (unixtime-(time_t)unixtime)) / 60.) / 60.) / 24.);
143 
144  return utc;
145 }
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
struct timeval utc2unix ( double  utc)

UTC to Unix time.

Convert UTC in Modified Julian Day to a timeval structure representing Unix time.

Parameters
utcas Modified Julian Day.
Returns
Timeval structure with Unix time.
153 {
154  struct timeval unixtime;
155  double unixseconds = 86400. * (utc - MJD_UNIX_OFFSET);
156  unixtime.tv_sec = (int)unixseconds;
157  unixtime.tv_usec = 1000000. * (unixseconds - unixtime.tv_sec);
158 
159  return unixtime;
160 }
#define MJD_UNIX_OFFSET
Definition: timelib.h:73
double utc2unixseconds ( double  utc)

UTC to Unix time.

Convert UTC in Modified Julian Day to a double representing Unix time.

Parameters
utcas Modified Julian Day.
Returns
Double with Unix time.
168 {
169  double unixseconds = 86400. * (utc - MJD_UNIX_OFFSET);
170 
171  return unixseconds;
172 }
#define MJD_UNIX_OFFSET
Definition: timelib.h:73
calstruc mjd2cal ( double  mjd)

MJD to Calendar.

Convert Modified Julian Day to Calendar Year, Month, Day, Hour, Minute, Second and Nanosecond.

Parameters
mjdModified Julian Day
Returns
Calendar representation in calstruc
181 {
182  static double lmjd = 0.;
183  static calstruc date;
184 
185  if (lmjd != mjd)
186  {
187  double dom;
188  double doy;
189 
190  lmjd = mjd;
191 
192  mjd2ymd(mjd, date.year, date.month, dom, doy);
193  date.doy = (int32_t)doy;
194  date.dom = (int32_t)dom;
195  doy = (doy - date.doy) * 24.;
196  date.hour = (int32_t)doy;
197  doy = (doy - date.hour) * 60.;
198  date.minute = (int32_t)doy;
199  doy = (doy - date.minute) * 60.;
200  date.second = (int32_t)doy;
201  doy = (doy - date.second) * 1e9;
202  date.nsecond = (int32_t)(doy + .5);
203  }
204 
205  return date;
206 }
int32_t dom
Definition: timelib.h:110
int32_t hour
Definition: timelib.h:112
int32_t nsecond
Definition: timelib.h:115
Definition: timelib.h:106
int32_t month
Definition: timelib.h:109
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
double mjd
Definition: udp_send.cpp:41
int32_t minute
Definition: timelib.h:113
int32_t year
Definition: timelib.h:108
int32_t second
Definition: timelib.h:114
int32_t doy
Definition: timelib.h:111
int32_t mjd2ymd ( double  mjd,
int32_t &  year,
int32_t &  month,
double &  day 
)

MJD to Year, Month, and Decimal Day (overloaded)

Convert Modified Julian Day to Calendar Year, Month, Decimal Day. basically it just calls mjd2ymd with all the arguments

Parameters
mjdModified Julian Day
yearPointer to return Calendar Year
monthPointer to return Calendar Month
dayPointer to return Decimal Day of the Month
Returns
0, otherwise negative error
218 {
219  double doy;
220  return mjd2ymd(mjd, year, month, day, doy);
221 }
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
double mjd
Definition: udp_send.cpp:41
int32_t mjd2ymd ( double  mjd,
int32_t &  year,
int32_t &  month,
double &  day,
double &  doy 
)

MJD to Year, Month, Decimal Day, and Julian Day (overloaded)

Convert Modified Julian Day to Calendar Year, Month, Decimal Day.

Parameters
mjdModified Julian Day
yearPointer to return Calendar Year
monthPointer to return Calendar Month
dayPointer to return Decimal Day of the Month
doyPointer to return Decimal Day of the Year
Returns
0, otherwise negative error
233 {
234  static double lmjd = 0.;
235  static int32_t lyear = 1858;
236  static int32_t lmonth = 11;
237  static double lday = 17.;
238  static double ldoy = 321.;
239 
240  if (mjd != lmjd)
241  {
242  int32_t a, b, c, d, e, z, alpha;
243  double f;
244 
245  lmjd = mjd;
246  mjd += 2400001.;
247  z = (int32_t)mjd;
248  f = mjd - z;
249 
250  if (z<2299161)
251  a = z;
252  else
253  {
254  alpha = (int32_t)((z - 1867216.25)/36524.25);
255  a = z +1 + alpha - (int32_t)(alpha/4);
256  }
257 
258  b = a + 1524;
259  c = (int32_t)((b - 122.1)/365.25);
260  d = (int32_t)(365.25*c);
261  e = (int32_t)((b - d)/30.6001);
262 
263  lday = b - d - (int32_t)(30.6001 * e) + f;
264  if (e < 14)
265  lmonth = e - 1;
266  else
267  lmonth = e - 13;
268  if (lmonth > 2)
269  lyear = c - 4716;
270  else
271  lyear = c - 4715;
272  ldoy = (int32_t)((275 * lmonth)/9) - (2-isleap(lyear))*(int32_t)((lmonth+9)/12) + lday - 30;
273  }
274 
275  year = lyear;
276  month = lmonth;
277  day = lday;
278  doy = ldoy;
279  return 0;
280 }
Definition: eci2kep_test.cpp:33
long b
Definition: jpegint.h:371
int16_t isleap(int32_t year)
Check for Leap year.
Definition: timelib.cpp:1122
double mjd
Definition: udp_send.cpp:41
Definition: eci2kep_test.cpp:33
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.

Convert a full calendar representation of date and time to MJD. If month is given as zero, then day will be taken as day of the year.

Parameters
yearFull representation of year.
monthCalendar month, or zero.
dayDay of month if 1 <= month <=12, otherwise day of year.
hourHour of day (0-23)
minuteMinute of day (0-59)
secondSecond of day (0-59)
nsecondNanosecond of day (0-999999999)
Returns
Modified Julian Day
295 {
296  double mjd;
297  calstruc date;
298 
299  date.year = year;
300  date.month = month;
301  if (month == 0)
302  {
303  date.dom = 0;
304  date.doy = day;
305  }
306  else
307  {
308  date.dom = day;
309  date.doy = 0;
310  }
311  date.hour = hour;
312  date.minute = minute;
313  date.second = second;
314  date.nsecond = nsecond;
315 
316  mjd = cal2mjd(date);
317 
318  return mjd;
319 }
int32_t dom
Definition: timelib.h:110
int32_t hour
Definition: timelib.h:112
int32_t nsecond
Definition: timelib.h:115
Definition: timelib.h:106
int32_t month
Definition: timelib.h:109
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 mjd
Definition: udp_send.cpp:41
int32_t minute
Definition: timelib.h:113
int32_t year
Definition: timelib.h:108
int32_t second
Definition: timelib.h:114
int32_t doy
Definition: timelib.h:111
double cal2mjd ( double  year)

Calendar representation YYYY.ffff to Modified Julian Day - overloaded.

Convert a shortened calendar representation of date to MJD.

Parameters
yearFull representation of decimal year.
Returns
Modified Julian Day
327 {
328  double dyear;
329  double dday;
330 
331  dday = 365. * modf(year, &dyear);
332 
333  return cal2mjd(static_cast<int32_t>(dyear), 0 , dday);
334 }
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 cal2mjd ( int32_t  year,
double  dayOfYear 
)

Calendar representation YYYY,DDD.ffff to Modified Julian Day - overloaded.

Convert a shortened calendar representation of date to MJD. Day argument is day of year.

Parameters
yearFull representation of year.
dayOfYearday of year.
Returns
Modified Julian Day
344 {
345  return cal2mjd(year, 0 , dayOfYear);
346 }
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 cal2mjd ( int32_t  year,
int32_t  month,
double  day 
)

Calendar representation to Modified Julian Day - shortened.

Convert a shortened calendar representation of date to MJD. Time is taken from the fractional part of the day. If month is given as zero, then day will be taken as day of the year.

Parameters
yearFull representation of year.
monthCalendar month, or zero.
dayDay of month if 1 <= month <=12, otherwise day of year.
Returns
Modified Julian Day
359 {
360  double mjd;
361  calstruc date;
362 
363  date.year = year;
364  date.month = month;
365  if (month == 0)
366  {
367  date.dom = 0;
368  date.doy = 1;
369  }
370  else
371  {
372  date.dom = 1;
373  date.doy = 0;
374  }
375  date.hour = date.minute = date.second = date.nsecond = 0;
376 
377  mjd = cal2mjd(date);
378  // Add day-1 because absolute date starts at day 0, but JD and DOM start at 1
379  mjd += day - 1.;
380 
381  return mjd;
382 }
int32_t dom
Definition: timelib.h:110
int32_t hour
Definition: timelib.h:112
int32_t nsecond
Definition: timelib.h:115
Definition: timelib.h:106
int32_t month
Definition: timelib.h:109
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 mjd
Definition: udp_send.cpp:41
int32_t minute
Definition: timelib.h:113
int32_t year
Definition: timelib.h:108
int32_t second
Definition: timelib.h:114
int32_t doy
Definition: timelib.h:111
double cal2mjd ( calstruc  date)

Calendar representation to Modified Julian Day - structure.

Convert a full calendar representation of date and time to MJD. If month is given as zero, then day will be taken as day of the year.

Parameters
dateFull representation of date and time in calstruc.
Returns
Modified Julian Day
391 {
392  double mjd;
393  int32_t a, b;
394 
395  if (date.year < -4712)
396  return (-2400001.);
397 
398  switch (date.month)
399  {
400  case 0:
401  ++date.month;
402  case 1:
403  case 2:
404  date.year--;
405  date.month += 12;
406  case 3:
407  case 4:
408  case 5:
409  case 6:
410  case 7:
411  case 8:
412  case 9:
413  case 10:
414  case 11:
415  case 12:
416  a = (int32_t)(date.year / 100);
417  if ((date.year > 1582) || (date.year == 1582 && date.month > 10) || (date.year == 1582 && date.month == 10 && date.dom > 4))
418  b = 2 - a + (int32_t)(a/4);
419  else
420  b = 0;
421  break;
422  default:
423  return (-2400001.);
424  }
425  if (date.dom)
426  {
427  mjd = (int32_t)(365.25 * (date.year+4716)) + (int32_t)(30.6001*(date.month+1)) + date.dom + b - 2401525.;
428  }
429  else
430  {
431  mjd = (int32_t)(365.25 * (date.year+4716)) + (int32_t)(30.6001*(date.month+1)) + date.doy + b - 2401525.;
432  }
433  mjd += ((date.hour + (date.minute + (date.second + date.nsecond / 1e9) / 60.) / 60.) / 24.);
434 
435  return (mjd);
436 }
int32_t dom
Definition: timelib.h:110
int32_t hour
Definition: timelib.h:112
long b
Definition: jpegint.h:371
int32_t nsecond
Definition: timelib.h:115
int32_t month
Definition: timelib.h:109
double mjd
Definition: udp_send.cpp:41
Definition: eci2kep_test.cpp:33
int32_t minute
Definition: timelib.h:113
int32_t year
Definition: timelib.h:108
int32_t second
Definition: timelib.h:114
int32_t doy
Definition: timelib.h:111
double gregorianToModJulianDate ( int32_t  year,
int32_t  month,
int32_t  day,
int32_t  hour,
int32_t  minute,
double  second 
)

Get Modified Julian Date from Gregorian Calendar Date in UTC

Parameters
year
month
day
hour
minute
second(for high precision mjd)
Returns
mjd (Modified Julian Date)
450 {
451 
452  double dayFraction = hour/24.0 + minute/(1440.) + second/(86400.);
453  double mjd = cal2mjd(year, month, day + dayFraction); //cal2mjd2
454  return mjd;
455 }
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 mjd
Definition: udp_send.cpp:41
double utc2jcentt ( double  mjd)

TT Julian Century.

Caculate the number of centuries since J2000, Terrestrial Time, for the provided date.

Parameters
mjdDate in Modified Julian Day.
Returns
Julian century in decimal form, otherwise negative error.
463 {
464  static double lmjd=0.;
465  static double lcalc=0.;
466 
467  if (mjd != lmjd)
468  {
469  double tt = utc2tt(mjd);
470  if (tt <= 0.)
471  {
472  lcalc = tt;
473  }
474  else
475  {
476  lcalc = (tt - 51544.5) / 36525.;
477  lmjd = mjd;
478  }
479  }
480  return (lcalc);
481 }
double mjd
Definition: udp_send.cpp:41
double utc2tt(double mjd)
Convert UTC to TT.
Definition: timelib.cpp:884
double utc2jcenut1 ( double  mjd)

UT1 Julian Century.

Caculate the number of centuries since J2000, UT1, for the provided date.

Parameters
mjdDate in Modified Julian Day.
Returns
Julian century in decimal form.
489 {
490  static double lmjd=0.;
491  static double lcalc=0.;
492 
493  if (mjd != lmjd)
494  {
495  lcalc = (utc2ut1(mjd)-51544.5) / 36525.;
496  lmjd = mjd;
497  }
498  return (lcalc);
499 }
double mjd
Definition: udp_send.cpp:41
double utc2ut1(double mjd)
Convert UTC to UT1.
Definition: timelib.cpp:792
rvector utc2nuts ( double  mjd)

Nutation values.

Calculate the nutation values from the JPL Ephemeris for the provided UTC date. Values are in order: Psi, Epsilon, dPsi, dEpsilon. Units are radians and radians/second.

Parameters
mjdUTC in Modified Julian Day.
Returns
Nutation values in an rvector.
509 {
510  static double lmjd=0.;
511  static uvector lcalc={{{0.,0.,0.},0.}};
512 
513  if (mjd != lmjd)
514  {
515  double tt = utc2tt(mjd);
516  if (tt > 0.)
517  {
518  jplnut(tt,(double *)&lcalc.a4);
519  lmjd = mjd;
520  }
521  }
522  return (lcalc.r);
523 }
Quaternion/Rvector Union.
Definition: mathlib.h:155
rvector r
Definition: mathlib.h:161
int32_t jplnut(double utc, double nuts[])
Nutations from JPL Ephemeris.
Definition: ephemlib.cpp:90
double mjd
Definition: udp_send.cpp:41
double a4[4]
Definition: mathlib.h:167
double utc2tt(double mjd)
Convert UTC to TT.
Definition: timelib.cpp:884
double utc2dpsi ( double  mjd)

Nutation Delta Psi value.

Calculate the Delta Psi value (nutation in longitude), for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
Delta Psi in radians.
532 {
533  static double lmjd=0.;
534  static double lcalc=0.;
535  rvector nuts;
536 
537  if (mjd != lmjd)
538  {
539  nuts = utc2nuts(mjd);
540  lcalc = nuts.col[0];
541  lmjd = mjd;
542  }
543  return (lcalc);
544 }
3 element generic row vector
Definition: vector.h:53
double mjd
Definition: udp_send.cpp:41
double col[3]
Definition: vector.h:55
rvector utc2nuts(double mjd)
Nutation values.
Definition: timelib.cpp:508
double utc2depsilon ( double  mjd)

Nutation Delta Epsilon value.

Calculate the Delta Psi value (nutation in obliquity), for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
Delta Psi in radians.longitudilon
553 {
554  static double lmjd=0.;
555  static double lcalc=0.;
556  rvector nuts;
557 
558  if (mjd != lmjd)
559  {
560  nuts = utc2nuts(mjd);
561  lcalc = nuts.col[1];
562  lmjd = mjd;
563  }
564  return (lcalc);
565 }
3 element generic row vector
Definition: vector.h:53
double mjd
Definition: udp_send.cpp:41
double col[3]
Definition: vector.h:55
rvector utc2nuts(double mjd)
Nutation values.
Definition: timelib.cpp:508
double utc2epsilon ( double  mjd)

Nutation Epsilon value.

Calculate the Epsilon value (obliquity of the ecliptic), for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
Epsilon in radians.
574 {
575  // Vallado, et al, AAS-06_134, eq. 17
576  static double lmjd=0.;
577  static double lcalc=0.;
578  double jcen;
579 
580  if (mjd != lmjd)
581  {
582  jcen = utc2jcentt(mjd);
583  lcalc = DAS2R*(84381.406+jcen*(-46.836769+jcen*(-.0001831+jcen*(0.0020034+jcen*(-0.000000576+jcen*(-0.0000000434))))));
584  lcalc = ranrm(lcalc);
585  lmjd = mjd;
586  }
587  return (lcalc);
588 }
double ranrm(double angle)
Definition: timelib.cpp:1109
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double mjd
Definition: udp_send.cpp:41
double utc2L ( double  mjd)

Nutation L value.

Calculate the L value, for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
L in radians.
596 {
597  static double lmjd=0.;
598  static double lcalc=0.;
599  double jcen;
600 
601  if (mjd != lmjd)
602  {
603  jcen = utc2jcentt(mjd);
604  lcalc = DAS2R*(485868.249036+jcen*(1717915923.2178+jcen*(31.8792+jcen*(.051635+jcen*(-.0002447)))));
605  lcalc = ranrm(lcalc);
606  lmjd = mjd;
607  }
608  return (lcalc);
609 }
double ranrm(double angle)
Definition: timelib.cpp:1109
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double mjd
Definition: udp_send.cpp:41
double utc2Lp ( double  mjd)

Nutation L prime value.

Calculate the L prime value, for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
L prime in radians.
617 {
618  static double lmjd=0.;
619  static double lcalc=0.;
620  double jcen;
621 
622  if (mjd != lmjd)
623  {
624  jcen = utc2jcentt(mjd);
625  lcalc = DAS2R*(1287104.79305+jcen*(129596581.0481+jcen*(-.5532+jcen*(.000136+jcen*(-.00001149)))));
626  lcalc = ranrm(lcalc);
627  lmjd = mjd;
628  }
629  return (lcalc);
630 }
double ranrm(double angle)
Definition: timelib.cpp:1109
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double mjd
Definition: udp_send.cpp:41
double utc2F ( double  mjd)

Nutation F value.

Calculate the F value, for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
F in radians.
638 {
639  static double lmjd=0.;
640  static double lcalc=0.;
641  double jcen;
642 
643  if (mjd != lmjd)
644  {
645  jcen = utc2jcentt(mjd);
646  lcalc = DAS2R*(335779.526232+jcen*(1739527262.8478+jcen*(-12.7512+jcen*(-.001037+jcen*(.00000417)))));
647  lcalc = ranrm(lcalc);
648  lmjd = mjd;
649  }
650  return (lcalc);
651 }
double ranrm(double angle)
Definition: timelib.cpp:1109
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double mjd
Definition: udp_send.cpp:41
double utc2D ( double  mjd)

Nutation D value.

Calculate the D value, for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
D in radians.
659 {
660  static double lmjd=0.;
661  static double lcalc=0.;
662  double jcen;
663 
664  if (mjd != lmjd)
665  {
666  jcen = utc2jcentt(mjd);
667  lcalc = DAS2R*(1072260.70369+jcen*(1602961601.209+jcen*(-6.3706+jcen*(.006593+jcen*(-.00003169)))));
668  lcalc = ranrm(lcalc);
669  lmjd = mjd;
670  }
671  return (lcalc);
672 }
double ranrm(double angle)
Definition: timelib.cpp:1109
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double mjd
Definition: udp_send.cpp:41
double utc2omega ( double  mjd)

Nutation omega value.

Calculate the omega value, for use in the Nutation matrix, for the provided UTC date.

Parameters
mjdUTC in Modified Julian Day.
Returns
Omega in radians.
680 {
681  static double lmjd=0.;
682  static double lcalc=0.;
683  double jcen;
684 
685  if (mjd != lmjd)
686  {
687  jcen = utc2jcentt(mjd);
688  lcalc = DAS2R*(450160.398036+jcen*(-6962890.5431+jcen*(7.4722+jcen*(.007702+jcen*(-.00005939)))));
689  lcalc = ranrm(lcalc);
690  lmjd = mjd;
691  }
692  return (lcalc);
693 }
double ranrm(double angle)
Definition: timelib.cpp:1109
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double mjd
Definition: udp_send.cpp:41
double utc2zeta ( double  utc)

Precession zeta value.

Calculate angle zeta used in the calculation of Precession, re. Capitaine, et. al, A&A, 412, 567-586 (2003) Expressions for IAU 2000 precession quantities Equation 40

Parameters
utcEpoch in Modified Julian Day.
Returns
Zeta in radians
704 {
705  double ttc = utc2jcentt(utc);
706  // double zeta = (2.650545 + ttc*(2306.083227 + ttc*(0.2988499 + ttc*(0.01801828 + ttc*(-0.000005971 + ttc*(0.0000003173))))))*DAS2R;
707  // Vallado, eqn. 3-88
708  double zeta = (ttc*(2306.2181 + ttc*(0.30188 + ttc*(0.017998))))*DAS2R;
709  return zeta;
710 }
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
__inline_double zeta(double zz, double zl)
Definition: nrlmsise-00.cpp:379
double utc2z ( double  utc)

Precession z value.

Calculate angle z used in the calculation of Precession, re. Capitaine, et. al, A&A, 412, 567-586 (2003) Expressions for IAU 2000 precession quantities Equation 40

Parameters
utcEpoch in Modified Julian Day.
Returns
Zeta in radians
721 {
722  double ttc = utc2jcentt(utc);
723  // double z = (-2.650545 + ttc*(2306.077181 + ttc*(1.0927348 + ttc*(0.01826837 + ttc*(-0.000028596 + ttc*(0.0000002904))))))*DAS2R;
724  // Vallado, eqn. 3-88
725  double z = (ttc*(2306.2181 + ttc*(1.09468 + ttc*(0.018203))))*DAS2R;
726  return z;
727 }
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double utc2theta ( double  utc)

Precession theta value.

Calculate angle theta used in the calculation of Precession, re. Capitaine, et. al, A&A, 412, 567-586 (2003) Expressions for IAU 2000 precession quantities Equation 40

Parameters
utcEpoch in Modified Julian Day.
Returns
Zeta in radians
738 {
739  double ttc = utc2jcentt(utc);
740  // double theta = ttc*(2004.191903 + ttc*(-0.4294934 + ttc*(-0.04182264 + ttc*(-0.000007089 + ttc*(-0.0000001274)))))*DAS2R;
741  // Vallado, eqn. 3-88
742  double theta = ttc*(2004.3109 + ttc*(-0.42665 + ttc*(-0.041833)))*DAS2R;
743  return theta;
744 }
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double utc2dut1 ( double  mjd)

Calculate DUT1.

Calculate DUT1 = UT1 - UTC, based on lookup in IERS Bulletin A.

Parameters
mjdUTC in Modified Julian Day.
Returns
DUT1 in Modified Julian Day, otherwise 0.
752 {
753  static double lmjd=0.;
754  static double lcalc = 0.;
755  double frac;
756  // uint32_t mjdi;
757  uint32_t iersidx;
758 
759  if (mjd != lmjd)
760  {
761  if (load_iers() && iers.size() > 2)
762  {
763  if ((uint32_t)mjd >= iersbase)
764  {
765  if ((iersidx=(uint32_t)mjd-iersbase) > iers.size())
766  {
767  iersidx = iers.size() - 2;
768  }
769  }
770  else
771  {
772  iersidx = 0;
773  }
774  // mjdi = (uint32_t)mjd;
775  frac = mjd - (uint32_t)mjd;
776  lcalc = ((frac*iers[1+iersidx].dutc+(1.-frac)*iers[iersidx].dutc)/86400.);
777  lmjd = mjd;
778  }
779  else
780  lcalc = 0.;
781  }
782  return (lcalc);
783 }
static vector< iersstruc > iers
Definition: timelib.cpp:48
static uint32_t iersbase
Definition: timelib.cpp:49
int32_t load_iers()
Load IERS Polar Motion, UT1-UTC, Leap Seconds.
Definition: timelib.cpp:1158
double mjd
Definition: udp_send.cpp:41
double utc2ut1 ( double  mjd)

Convert UTC to UT1.

Convert Coordinated Universal Time to Universal Time by correcting for the offset between them at the given time. Table of DUT1 is first initialized from disk if it hasn't yet been.

Parameters
mjdUTC in Modified Julian Day.
Returns
UTC1 in Modified Julian Day, otherwise 0.
793 {
794  static double lmjd=0.;
795  static double lut=0.;
796 
797  if (mjd != lmjd)
798  {
799  if (load_iers())
800  {
801  lut = mjd + utc2dut1(mjd);
802  lmjd = mjd;
803  }
804  else
805  lut = 0.;
806  }
807  return (lut);
808 }
double utc2dut1(double mjd)
Calculate DUT1.
Definition: timelib.cpp:751
int32_t load_iers()
Load IERS Polar Motion, UT1-UTC, Leap Seconds.
Definition: timelib.cpp:1158
double mjd
Definition: udp_send.cpp:41
double julcen ( double  mjd)

Julian Century.

Convert time supplied in Modified Julian Day to the Julian Century.

Parameters
mjdTime in Modified Julian Day.
Returns
Decimal century.
816 {
817  return ((mjd - 51544.5) / 36525.);
818 }
double mjd
Definition: udp_send.cpp:41
double utc2tdb ( double  mjd)

Convert UTC to TDB.

Convert Coordinated Universal Time to Barycentric Dynamical Time by correcting for the mean variations as a function of Julian days since 4713 BC Jan 1.5.

Parameters
mjdUTC in Modified Julian Day.
Returns
TDB in Modified Julian Day, otherwise 0.
827 {
828  static double lmjd=0.;
829  static double ltdb=0.;
830  double tt, g;
831 
832  if (mjd != lmjd)
833  {
834  tt = utc2tt(mjd);
835  if (tt > 0.)
836  {
837  g = 6.2400756746 + .0172019703436*(mjd-51544.5);
838  ltdb = (tt + (.001658*sin(g)+.000014*sin(2*g))/86400.);
839  lmjd = mjd;
840  }
841  }
842  return (ltdb);
843 }
double mjd
Definition: udp_send.cpp:41
double utc2tt(double mjd)
Convert UTC to TT.
Definition: timelib.cpp:884
double tt2utc ( double  mjd)

Convert TT to UTC.

Convert Terrestrial Dynamical Time to Coordinated Universal Time by correcting for the appropriate number of Leap Seconds. Leap Second table is first initialized from disk if it hasn't yet been.

Parameters
mjdTT in Modified Julian Day.
Returns
UTC in Modified Julian Day, otherwise 0.
853 {
854  uint32_t iersidx;
855  int32_t iretn;
856 
857  if ((iretn=load_iers()) && iers.size() > 1)
858  {
859  if ((uint32_t)mjd >= iersbase)
860  {
861  if ((iersidx=(uint32_t)mjd-iersbase) > iers.size())
862  {
863  iersidx = iers.size() - 1;
864  }
865  }
866  else
867  {
868  iersidx = 0;
869  return ((double)iretn);
870  }
871  return (mjd-(32.184+iers[iersidx].ls)/86400.);
872  }
873  else
874  return (0.);
875 }
static vector< iersstruc > iers
Definition: timelib.cpp:48
int iretn
Definition: rw_test.cpp:37
static uint32_t iersbase
Definition: timelib.cpp:49
int32_t load_iers()
Load IERS Polar Motion, UT1-UTC, Leap Seconds.
Definition: timelib.cpp:1158
double mjd
Definition: udp_send.cpp:41
double utc2tt ( double  mjd)

Convert UTC to TT.

Convert Coordinated Universal Time to Terrestrial Dynamical Time by correcting for the appropriate number of Leap Seconds. Leap Second table is first initialized from disk if it hasn't yet been.

Parameters
mjdUTC in Modified Julian Day.
Returns
TT in Modified Julian Day, otherwise negative error
885 {
886  static double lmjd=0.;
887  static double ltt=0.;
888  uint32_t iersidx=0;
889  int32_t iretn;
890 
891  if (mjd != lmjd)
892  {
893  if ((iretn=load_iers()) && iers.size() > 1)
894  {
895  if ((uint32_t)mjd >= iersbase)
896  {
897  if ((iersidx=(uint32_t)mjd-iersbase) > iers.size())
898  {
899  iersidx = iers.size() - 1;
900  }
901  }
902  else
903  {
904  iersidx = 0;
905  }
906  ltt = (mjd+(32.184+iers[iersidx].ls)/86400.);
907  lmjd = mjd;
908  return (ltt);
909  }
910  else
911  {
912  return ((double)iretn);
913  }
914  }
915  return (ltt);
916 }
static vector< iersstruc > iers
Definition: timelib.cpp:48
int iretn
Definition: rw_test.cpp:37
static uint32_t iersbase
Definition: timelib.cpp:49
int32_t load_iers()
Load IERS Polar Motion, UT1-UTC, Leap Seconds.
Definition: timelib.cpp:1158
double mjd
Definition: udp_send.cpp:41
double utc2gps ( double  utc)

Convert UTC to GPS.

Convert Coordinated Universal Time to GPS Time, correcting for the appropriate number of leap seconds. Leap Second table is first initialized from disk if it hasn't yet been.

Parameters
utcUTC expressed in Modified Julian Days
Returns
GPS Time expressed in Modified Julian Days, otherwise negative error
926 {
927  double gps;
928 
929  if ((gps=utc2tt(utc)) <= 0.)
930  {
931  return (gps);
932  }
933 
934  gps -= 51.184 / 86400.;
935 
936  return (gps);
937 }
double utc2tt(double mjd)
Convert UTC to TT.
Definition: timelib.cpp:884
double gps2utc ( double  gps)

Convert GPS to UTC.

Convert GPS Time to Coordinated Universal Time, correcting for the appropriate number of leap seconds. Leap Second table is first initialized from disk if it hasn't yet been.

Parameters
gpsGPS Time expressed in Modified Julian Days
Returns
UTC expressed in Modified Julian Days, otherwise 0.
947 {
948  double utc;
949 
950  gps += 51.184 / 86400.;
951 
952  if ((utc=tt2utc(gps)) <= 0.)
953  {
954  return (utc);
955  }
956 
957  return (utc);
958 }
double tt2utc(double mjd)
Convert TT to UTC.
Definition: timelib.cpp:852
void gps2week ( double  gps,
uint32_t &  week,
double &  seconds 
)

GPS Weeks and Seconds from GPS time.

Calculate the appropriate GPS week and remaining seconds from the provided GPS time.

Parameters
gpsGPS time expressed as Modified Julian Day
weekPointer to the returned GPS week.
secondsPonter to the returned GPS seconds.
968 {
969  double elapsed;
970 
971  elapsed = gps - 44244.;
972  week = (uint32_t)(elapsed / 7.);
973  seconds = 86400. * (elapsed - week * 7.);
974  // *week %= 1024;
975 }
double week2gps ( uint32_t  week,
double  seconds 
)

GPS Time from GPS Week and Seconds.

Calculate the appropriate GPS Time from the provided GPS Week and Seconds.

Parameters
weekGPS Week.
secondsGPS Seconds.
Returns
GPS Time as Modified Julian Day.
984 {
985  double elapsed;
986 
987  elapsed = 44244. + week * 7. + seconds / 86400.;
988 
989  return elapsed;
990 }
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 mjd2doy ( double  mjd)

Day of Year from MJD.

Return the Decimal Day of Year for the provided MJD

Parameters
mjdModified Julian Data
Returns
Decimal doy.
1013 {
1014  double day, doy;
1015  int32_t month, year;
1016 
1017  mjd2ymd(mjd,year,month,day,doy);
1018  return (doy);
1019 }
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
double mjd
Definition: udp_send.cpp:41
double utc2era ( double  mjd)

Earth Rotation Angle.

Calculate the Earth Rotation Angle for a given Earth Rotation Time based on the provided UTC.

Parameters
mjdCoordinated Universal Time as Modified Julian Day.
Returns
Earth Rotation Angle, theta, in radians.
1028 {
1029  static double lmjd=0.;
1030  static double ltheta=0.;
1031  double ut1;
1032 
1033  if (mjd != lmjd)
1034  {
1035  ut1 = utc2ut1(mjd);
1036  ltheta = D2PI * (.779057273264 + 1.00273781191135448 * (ut1 - 51544.5));
1037  // ltheta = ranrm(ltheta);
1038  }
1039 
1040  return (ltheta);
1041 }
double mjd
Definition: udp_send.cpp:41
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
double utc2ut1(double mjd)
Convert UTC to UT1.
Definition: timelib.cpp:792
double utc2gast ( double  mjd)

UTC to GAST.

Convert current UTC to Greenwhich Apparent Sidereal Time. Accounts for nutations.

Parameters
mjdUTC as Modified Julian Day
Returns
GAST as Modified Julian Day
1049 {
1050  static double lmjd=0.;
1051  static double lgast=0.;
1052  double omega, F, D;
1053 
1054  if (mjd != lmjd)
1055  {
1056  omega = utc2omega(mjd);
1057  F = utc2F(mjd);
1058  D = utc2D(mjd);
1059  lgast = utc2gmst1982(mjd) + utc2dpsi(mjd) * cos(utc2epsilon(mjd));
1060  lgast += DAS2R * .00264096 * sin(omega);
1061  lgast += DAS2R * .00006352 * sin(2.*omega);
1062  lgast += DAS2R * .00001175 * sin(2.*F - 2.*D + 3.*omega);
1063  lgast += DAS2R * .00001121 * sin(2.*F - 2.*D + omega);
1064  lgast = ranrm(lgast);
1065  lmjd = mjd;
1066  }
1067  return (lgast);
1068 }
double utc2D(double mjd)
Nutation D value.
Definition: timelib.cpp:658
double utc2omega(double mjd)
Nutation omega value.
Definition: timelib.cpp:679
double ranrm(double angle)
Definition: timelib.cpp:1109
const double DAS2R
Multiplicand for Seconds of Arc to Radians.
Definition: math/constants.h:22
double utc2F(double mjd)
Nutation F value.
Definition: timelib.cpp:637
double mjd
Definition: udp_send.cpp:41
double utc2epsilon(double mjd)
Nutation Epsilon value.
Definition: timelib.cpp:573
double utc2gmst1982(double mjd)
UTC (Modified Julian Day) to GMST.
Definition: timelib.cpp:1075
double utc2dpsi(double mjd)
Nutation Delta Psi value.
Definition: timelib.cpp:531
double utc2gmst1982 ( double  mjd)

UTC (Modified Julian Day) to GMST.

Convert current UT to Greenwhich Mean Sidereal Time

Parameters
mjdUT as Modified Julian Day
Returns
GMST as radians
1076 {
1077  static double lmjd=0.;
1078  static double lcalc=0.;
1079  double jcen;
1080 
1081  if (mjd != lmjd)
1082  {
1083  jcen = utc2jcentt(mjd);
1084  lcalc = utc2era(mjd) + DS2R*(.014506+jcen*(4612.156534+jcen*(1.3915817+jcen*(-.00000044+jcen*(-.000029956+jcen*(-.0000000368))))))/15.;
1085  lcalc = ranrm(lcalc);
1086  lmjd = mjd;
1087  }
1088 
1089  return (lcalc);
1090 }
double utc2era(double mjd)
Earth Rotation Angle.
Definition: timelib.cpp:1027
double ranrm(double angle)
Definition: timelib.cpp:1109
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double mjd
Definition: udp_send.cpp:41
const double DS2R
Multiplicand for Seconds of Time to Radians.
Definition: math/constants.h:20
double utc2gmst2000 ( double  utc)
1093 {
1094  static double lutc=0.;
1095  static double lgmst = 0.;
1096  double tt;
1097 
1098  if (utc != lutc)
1099  {
1100  // ut1 = utc2ut1(utc);
1101  tt = utc2jcentt(utc);
1102  lgmst = 24110.54841 + 8640184.812866 * utc2jcenut1(utc) + tt * tt * (0.093104 + tt * (-0.0000062));
1103  lgmst = ranrm(lgmst);
1104  }
1105 
1106  return lgmst;
1107 }
double utc2jcenut1(double mjd)
UT1 Julian Century.
Definition: timelib.cpp:488
double ranrm(double angle)
Definition: timelib.cpp:1109
double utc2jcentt(double mjd)
TT Julian Century.
Definition: timelib.cpp:462
double ranrm ( double  angle)
1110 {
1111  double result;
1112 
1113  result = fmod(angle,D2PI);
1114 
1115  return (result >= 0.)?result:result+D2PI;
1116 }
const double D2PI
Double precision 2*PI.
Definition: math/constants.h:16
int16_t isleap ( int32_t  year)

Check for Leap year.

Check whether the specified year (Gregorian or Julian calendar) is a Leap year.

Parameters
yearYear to check
Returns
0 if not a Leap year, 1 if a Leap year
1123 {
1124  if (!(year % 4))
1125  {
1126  if (!(year%100))
1127  {
1128  if (!(year%400))
1129  {
1130  return (1);
1131  }
1132  else
1133  {
1134  return 0;
1135  }
1136  }
1137  else
1138  {
1139  return 1;
1140  }
1141  }
1142  else
1143  {
1144  return 0;
1145  }
1146 }
int32_t load_iers ( )

Load IERS Polar Motion, UT1-UTC, Leap Seconds.

Allocate and load array for storing data from IERS file. Each record includes the MJD, the Polar Motion for X and Y in radians, UT1-UTC in seconds of time, and the number of Leap Seconds since the creation of TAI in 1958. The following are then defined:

  • TT = TAI +32.184
  • TAI = UTC + Leap_Seconds
  • UT1 = UTC + (UT1-UTC)
    Returns
    Number of records.
1159 {
1160  FILE *fdes;
1161  iersstruc tiers;
1162 
1163  if (iers.size() == 0)
1164  {
1165  string fname;
1166  int32_t iretn = get_cosmosresources(fname);
1167  if (iretn < 0)
1168  {
1169  return iretn;
1170  }
1171  fname += "/general/iers_pm_dut_ls.txt";
1172  if ((fdes=fopen(fname.c_str(),"r")) != NULL)
1173  {
1174  char data[100];
1175  while (fgets(data,100,fdes))
1176  {
1177  sscanf(data,"%u %lg %lg %lg %u",&tiers.mjd,&tiers.pmx,&tiers.pmy,&tiers.dutc,&tiers.ls);
1178  iers.push_back(tiers);
1179  }
1180  fclose(fdes);
1181  }
1182  if (iers.size())
1183  iersbase = iers[0].mjd;
1184  }
1185  return (iers.size());
1186 }
static vector< iersstruc > iers
Definition: timelib.cpp:48
int iretn
Definition: rw_test.cpp:37
uint32_t mjd
Definition: timelib.cpp:41
static uint32_t iersbase
Definition: timelib.cpp:49
uint32_t ls
Definition: timelib.cpp:45
Definition: timelib.cpp:39
string get_cosmosresources(bool create_flag)
Return COSMOS Resources Directory.
Definition: datalib.cpp:1337
double pmy
Definition: timelib.cpp:43
double pmx
Definition: timelib.cpp:42
static char fname[100]
Definition: geomag.cpp:89
double mjd
Definition: udp_send.cpp:41
double dutc
Definition: timelib.cpp:44
int32_t leap_seconds ( double  mjd)

Leap Seconds.

Returns number of leap seconds for provided Modified Julian Day.

Parameters
mjdProvided time.
Returns
Number of leap seconds, or 0.
1194 {
1195  uint32_t iersidx;
1196 
1197  if (load_iers() && iers.size() > 1)
1198  {
1199  if ((uint32_t)mjd >= iersbase)
1200  {
1201  if ((iersidx=(uint32_t)mjd-iersbase) > iers.size())
1202  {
1203  iersidx = iers.size() - 1;
1204  }
1205  }
1206  else
1207  {
1208  iersidx = 0;
1209  }
1210  return (iers[iersidx].ls);
1211  }
1212  else
1213  return 0;
1214 }
static vector< iersstruc > iers
Definition: timelib.cpp:48
static uint32_t iersbase
Definition: timelib.cpp:49
int32_t load_iers()
Load IERS Polar Motion, UT1-UTC, Leap Seconds.
Definition: timelib.cpp:1158
double mjd
Definition: udp_send.cpp:41
cvector polar_motion ( double  mjd)

Polar motion.

Returns polar motion in radians for provided Modified Julian Day.

Parameters
mjdProvided time.
Returns
Polar motion in rvector.
1222 {
1223  cvector pm;
1224  double frac;
1225  // uint32_t mjdi;
1226  uint32_t iersidx;
1227 
1228  pm = cv_zero();
1229  if (load_iers() && iers.size() > 2)
1230  {
1231  if ((uint32_t)mjd >= iersbase)
1232  {
1233  if ((iersidx=(uint32_t)mjd-iersbase) > iers.size())
1234  {
1235  iersidx = iers.size() - 2;
1236  }
1237  }
1238  else
1239  {
1240  iersidx = 0;
1241  }
1242  // mjdi = (uint32_t)mjd;
1243  frac = mjd - (uint32_t)mjd;
1244  pm = cv_zero();
1245  pm.x = frac*iers[1+iersidx].pmx+(1.-frac)*iers[iersidx].pmx;
1246  pm.y = frac*iers[1+iersidx].pmy+(1.-frac)*iers[iersidx].pmy;
1247  }
1248 
1249  return (pm);
1250 }
static vector< iersstruc > iers
Definition: timelib.cpp:48
static uint32_t iersbase
Definition: timelib.cpp:49
int32_t load_iers()
Load IERS Polar Motion, UT1-UTC, Leap Seconds.
Definition: timelib.cpp:1158
cvector cv_zero()
Zero cartesian vector.
Definition: vector.cpp:412
double mjd
Definition: udp_send.cpp:41
3 element cartesian vector
Definition: vector.h:107
string utc2unixdate ( double  utc)

Time for setting unix date.

Represent the given UTC on a format appropriate for setting Unix date format: MMDDhhmmYY.ss

Parameters
utcCoordinated Universal Time expressed in Modified Julian Days.
Returns
C++ String containing the Unix date.
1261 {
1262  char buffer[25];
1263  int32_t iy=0, im=0, id=0, ihh, imm, iss;
1264  double fd=0.;
1265 
1266  mjd2ymd(utc, iy, im, fd);
1267  id = static_cast <int32_t>(fd);
1268  fd -= id;
1269  ihh = static_cast <int32_t>(24 * fd);
1270  fd -= ihh / 24.;
1271  imm = static_cast <int32_t>(1440 * fd);
1272  fd -= imm / 1440.;
1273  iss = static_cast <int32_t>(86400 * fd + .5);
1274  sprintf(buffer, "%02d%02d%02d%02d%02d.%02d", im, id, ihh, imm, iy, iss);
1275 
1276  return string(buffer);
1277 }
int fd
Definition: arduino_lib.cpp:61
static char buffer[255]
Definition: propagator_simple.cpp:60
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
string utc2iso8601 ( double  utc)

ISO 8601 version of time.

Represent the given UTC as an extended calendar format ISO 8601 string in the format: YYYY-MM-DDTHH:MM:SS

Parameters
utcCoordinated Universal Time expressed in Modified Julian Days.
Returns
C++ String containing the ISO 8601 date.
1287 {
1288  char buffer[25];
1289  int32_t iy=0, im=0, id=0, ihh, imm, iss;
1290  double fd=0.;
1291 
1292  mjd2ymd(utc, iy, im, fd);
1293  id = (int32_t)fd;
1294  fd -= id;
1295  ihh = (int32_t)(24 * fd);
1296  fd -= ihh / 24.;
1297  imm = (int32_t)(1440 * fd);
1298  fd -= imm / 1440.;
1299  iss = (int32_t)(86400 * fd);
1300  sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d", iy, im, id, ihh, imm, iss);
1301 
1302  return string(buffer);
1303 }
int fd
Definition: arduino_lib.cpp:61
static char buffer[255]
Definition: propagator_simple.cpp:60
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
double iso86012utc ( string  date)
1306 {
1307  double utc = 0.;
1308  int32_t iy=0, im=0, id=0, ihh, imm, iss;
1309 
1310  sscanf(date.c_str(), "%d-%d-%dT%d:%d:%d", &iy, &im, &id, &ihh, &imm, &iss);
1311  utc = cal2mjd(iy, im, id, ihh, imm, iss);
1312  return utc;
1313 }
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
string mjd2iso8601 ( double  mjd)
1316  {
1317  return utc2iso8601(mjd);
1318 }
double mjd
Definition: udp_send.cpp:41
string utc2iso8601(double utc)
ISO 8601 version of time.
Definition: timelib.cpp:1286
int32_t dayFraction2hms ( double  dayFraction,
int32_t *  hour,
int32_t *  minute,
int32_t *  second 
)

Convert Modified Julian Date to Time of day (hour, minute, second.fff)

Parameters
dayFraction
hourPointer to return Hour of the day
minutePointer to return Minute of the day
secondPointer to return Second of the day (decimal)
Returns
0 or negative error.
1329 {
1330  double secs;
1331  *hour = (int32_t)(24. * dayFraction);
1332  dayFraction -= *hour / 24.;
1333  *minute = (int32_t)(1440. * dayFraction);
1334  dayFraction -= *minute / 1440.;
1335  secs = (86400. * dayFraction);
1336  // double secondOfMinute = (86400. * dayFraction);
1337  *second = (int32_t)round(secs);
1338 
1339  // don't let seconds be 60
1340  if (*second == 60.){
1341  *second = 0;
1342  *minute = *minute + 1;
1343  }
1344 
1345  // don't let minutes be 60
1346  if (*minute == 60){
1347  *minute = 0;
1348  *hour = *hour + 1;
1349  }
1350 
1351  return 0;
1352 }
int32_t mjdToGregorian ( double  mjd,
int32_t &  year,
int32_t &  month,
int32_t &  day,
int32_t &  hour,
int32_t &  minute,
int32_t &  second 
)

Convert Modified Julian Date to standard Gregorian Date-Time

Parameters
mjd(Modified Julian Days)
yearPointer to return Calendar Year
monthPointer to return Calendar Month
dayPointer to return Decimal Day of the Month
hourPointer to return Hour of the day
minutePointer to return Minute of the day
secondPointer to return Second of the day (decimal)
Returns
0 or negative error.
1366 {
1367 
1368  // double dayFraction;
1369  // mjd2ymdf(mjd,year,month,&dayFraction);
1370  // *day = (int)dayFraction;
1371 
1372  // int j;
1373  calstruc cal = mjd2cal(mjd); //, year, month, day, &dayFraction, &j);
1374  year = cal.year;
1375  month = cal.month;
1376  day = cal.dom;
1377  hour = cal.hour;
1378  minute = cal.minute;
1379  second = cal.second;
1380 
1381  // now remove the day part and keep the fraction only
1382  // dayFraction --;
1383  // dayFraction2hms(dayFraction,hour,minute,second);
1384  return 0;
1385 }
int32_t dom
Definition: timelib.h:110
calstruc mjd2cal(double mjd)
MJD to Calendar.
Definition: timelib.cpp:180
int32_t hour
Definition: timelib.h:112
Definition: timelib.h:106
int32_t month
Definition: timelib.h:109
double mjd
Definition: udp_send.cpp:41
int32_t minute
Definition: timelib.h:113
int32_t year
Definition: timelib.h:108
int32_t second
Definition: timelib.h:114
string mjdToGregorian ( double  mjd)

Convert Modified Julian Date to international standard Gregorian Date-Time in the format: YYYY-MM-DD HH:MM:SS (ex. 2014-09-15 12:00:00) (previously this function was named mjd2human)

Parameters
mjdTime in Modified Julian Days
Returns
gregorianDateTime (YYYY-MM-DD HH:MM:SS)
1395 {
1396  char gregorianDateTime[25];
1397  int year=0, month=0, day=0;
1398  int hour=0, minute=0, second=0;
1399 
1400  mjdToGregorian(mjd, year, month, day, hour, minute, second);
1401 
1402  sprintf(gregorianDateTime, "%04d-%02d-%02d %02d:%02d:%02d",
1403  year, month, day,
1404  hour, minute, second);
1405 
1406  return string(gregorianDateTime);
1407 }
int32_t mjdToGregorian(double mjd, int32_t &year, int32_t &month, int32_t &day, int32_t &hour, int32_t &minute, int32_t &second)
Definition: timelib.cpp:1364
double mjd
Definition: udp_send.cpp:41
string mjdToGregorianFormat ( double  mjd)

Convert Modified Julian Date to international standard Gregorian Date-Time in the format: YYYY-MM-DDTHHMMSS (ex. 2014-09-15T120000)

Parameters
mjdTime in Modified Julian Days
Returns
gregorianDateTime in the format (YYYY-MM-DDTHHMMSS)
1418 {
1419  char gregorianDateTime[25];
1420  int year=0, month=0, day=0;
1421  int hour=0, minute=0, second=0;
1422 
1423  mjdToGregorian(mjd, year, month, day, hour, minute, second);
1424 
1425  sprintf(gregorianDateTime, "%04d-%02d-%02dT%02d%02d%02d",
1426  year, month, day,
1427  hour, minute, second);
1428 
1429  return string(gregorianDateTime);
1430 }
int32_t mjdToGregorian(double mjd, int32_t &year, int32_t &month, int32_t &day, int32_t &hour, int32_t &minute, int32_t &second)
Definition: timelib.cpp:1364
double mjd
Definition: udp_send.cpp:41
string mjdToGregorianDDMMMYYYY ( double  mjd)

Convert Modified Julian Date to US standard Gregorian Date-Time with 3-letter month format: DD-MMM-YYYY HH:MM:SS (ex. 15-SEP-2014 12:00:00) (previously this function was named mjd2human2)

Parameters
mjdTime in Modified Julian Days
Returns
gregorianDateTime (YYYY-MM-DD HH:MM:SS)
1443 {
1444  char gregorianDateTime[25];
1445  int year=0, month=0, day=0, hour=0, minute=0, second=0;
1446  // double fd=0.; //?? is this fraction of day
1447 
1448  static const char month_name[][4] = {
1449  "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
1450  "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
1451  };
1452 
1453  //mjd2cal(mjd, &year, &month, &day, &fd, &j);
1454 
1455  mjdToGregorian(mjd, year, month, day, hour, minute, second);
1456 
1457  // hours = (int)(24 * fd);
1458  // fd -= hours / 24.;
1459  // minutes = (int)(1440 * fd);
1460  // fd -= minutes / 1440.;
1461  // seconds = (86400 * fd);
1462  // int int_seconds = (int)round(seconds);
1463  sprintf(gregorianDateTime, "%02d-%3s-%04d %02d:%02d:%02d",
1464  day, month_name[month-1], year,
1465  hour, minute, second);
1466 
1467  return string(gregorianDateTime);
1468 }
int32_t mjdToGregorian(double mjd, int32_t &year, int32_t &month, int32_t &day, int32_t &hour, int32_t &minute, int32_t &second)
Definition: timelib.cpp:1364
double mjd
Definition: udp_send.cpp:41
string mjdToGregorianDDMmmYYYY ( double  mjd)

Convert Modified Julian Date to US standard Gregorian Date-Time with 3-letter month format in small caps: DD mmm YYYY HH:MM:SS.FFF (15 Sep 2014 12:00:00.000) Used for STK remote (previously this function was named mjd2human3)

Parameters
mjdTime in Modified Julian Days
Returns
gregorianDateTime (YYYY-MM-DD HH:MM:SS)
1480 {
1481  char gregorianDateTime[50];
1482  int year=0, month=0, day=0, hour=0, minute=0, second=0;
1483  int msec = 0;
1484  // double fd=0.;
1485 
1486  static const char month_name[][4] = {
1487  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1488  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
1489  };
1490 
1491  // mjd2cal(mjd, &year, &month, &day, &fd, &j);
1492  mjdToGregorian(mjd, year, month, day, hour, minute, second);
1493  // hh = (int)(24 * fd);
1494  // fd -= hh / 24.;
1495  // min = (int)(1440 * fd);
1496  // fd -= min / 1440.;
1497  // sec = (int)(86400 * fd);
1498  // fd -= sec / 86400.;
1499  // msec = (int)(86400*1000 * fd);
1500  sprintf(gregorianDateTime, "%02d %3s %04d %02d:%02d:%02d.%03d",
1501  day, month_name[month-1], year,
1502  hour, minute, second, msec);
1503 
1504  return string(gregorianDateTime);
1505 }
int32_t mjdToGregorian(double mjd, int32_t &year, int32_t &month, int32_t &day, int32_t &hour, int32_t &minute, int32_t &second)
Definition: timelib.cpp:1364
double mjd
Definition: udp_send.cpp:41
string seconds2DDHHMMSS ( double  elapsed_seconds)

Convert Elapsed Time in Seconds to Human Readable Format (used for GPS simulator)

UTC string in the format: DD HH:MM:SS

Parameters
elapsed_seconds
Returns
C++ String containing human readable formated date.
1514  {
1515 
1516  char buffer[50];
1517 
1518  if (elapsed_seconds < 0){
1519  return "invalid time";
1520  }
1521 
1522  double days = elapsed_seconds/86400.; // convert to elapsed days
1523  int day = int(days); // get the day number
1524  double fd = days-day; // get the day fraction
1525  /*
1526  temp = elapsed_seconds - day * 86400; // get the seconds of the day
1527 
1528  int hour = temp/3600.; // get the number of hours
1529  temp = temp - hour*3600; // take off the number of seconds of the hours run
1530 
1531  //int min = ((elapsed_seconds) % 3600.)/60.;
1532  int min = temp/60; // get the number of minutes
1533 
1534  //int sec = (elapsed_seconds) % 60.;
1535  int sec = temp - min*60; // get the number of seconds
1536 
1537  int msec = (temp - sec)*1000; // get the number of miliseconds
1538 */
1539 
1540  int hour = (int)(24 * fd);
1541  fd -= hour / 24.;
1542  int min = (int)(1440 * fd);
1543  fd -= min / 1440.;
1544  int sec = (int)(86400 * fd);
1545  fd -= sec / 86400.;
1546  int msec = (int)round((86400*1000 * fd));
1547 
1548  if (msec == 1000){
1549  sec ++;
1550  msec = 0;
1551  }
1552  // specific format for SimGEN
1553  //sprintf(buffer,"%d %02d:%02d:%.2f", day, hour, min, sec);
1554  sprintf(buffer,"%02d:%02d:%02d.%03d", hour, min, sec, msec);
1555  return string(buffer);
1556 }
int fd
Definition: arduino_lib.cpp:61
static char buffer[255]
Definition: propagator_simple.cpp:60
double mjd2jd ( double  mjd)

Modified Julian Day to Julian Day.

Convert date in Modified Julian Day format to date in Julian Day format.

Parameters
mjdDate in Modified Julian Day format.
Returns
Date in Julian Day format.
1563  {
1564  return MJD2JD(mjd);
1565 }
#define MJD2JD(mjd)
Definition: timelib.h:75
double mjd
Definition: udp_send.cpp:41
double jd2mjd ( double  jd)

Julian Day to Modified Julian Day.

Convert date in Julian Day format to date in Modified Julian Day format.

Parameters
jdDate in Julian Day format.
Returns
Date in Modified Julian Day format.
1572  {
1573  return JD2MJD(jd);
1574 }
#define JD2MJD(jd)
Definition: timelib.h:76
int32_t timed_countdown ( int32_t  seconds,
int32_t  step,
string  message 
)
1577 {
1578  ElapsedTime et;
1579  ElapsedTime set;
1580 
1581  if (message.length())
1582  {
1583  printf("%s", message.c_str());
1584  fflush(stdout);
1585  }
1586 
1587  while (et.split() < seconds)
1588  {
1589  int32_t nextstep = static_cast <int32_t>((seconds - et.split()) / step);
1590  COSMOS_SLEEP((seconds - et.split()) - nextstep * step);
1591  printf("...%d", nextstep * step);
1592  fflush(stdout);
1593  }
1594  printf("\n");
1595  return 0;
1596 }
ElapsedTime et
Definition: agent_cpu_device_test.cpp:51
uint8_t message[300]
Definition: kpc9612p_send.cpp:36
Definition: elapsedtime.h:62
double split()
ElapsedTime::split, gets the current elapsed time since the start()
Definition: elapsedtime.cpp:234
int32_t mjdToGregorian ( double  mjd,
int32_t *  year,
int32_t *  month,
int32_t *  day,
int32_t *  hour,
int32_t *  minute,
int32_t *  second 
)
int32_t mjd2tlef ( double  mjd,
string &  tle 
)

Convert mjd to the TLE epoch format.

1613  {
1614  char year_buffer[3], days_buffer[13];
1615 
1616  // Compute our year field.
1617  sprintf(year_buffer, "%2d", static_cast<int>(floor(mjd2year(mjd))) % 1000);
1618 
1619  // Compute our days field.
1620  sprintf(days_buffer, "%012.8f", mjd2doy(mjd));
1621 
1622  tle = string(year_buffer) + string(days_buffer);
1623  return 0;
1624 }
double mjd2year(double mjd)
Year from MJD.
Definition: timelib.cpp:997
static std::vector< tlestruc > tle
Definition: agent_antenna.cpp:177
double mjd
Definition: udp_send.cpp:41
double mjd2doy(double mjd)
Day of Year from MJD.
Definition: timelib.cpp:1012
double tt2tdb ( double  mjd)
double set_local_clock ( double  utc_to)
1627 {
1628  int32_t iretn;
1629  double utc_from = currentmjd();
1630  double deltat = 86400.*(utc_to - utc_from);
1631 // printf("Set Local Clock %f\n", deltat);
1632  if (fabs(deltat) > 1.)
1633  {
1634  // Gross adjustment to system clock
1635 #if defined(COSMOS_WIN_OS)
1636  SYSTEMTIME newtime;
1637  SetSystemTime(&newtime);
1638 #else
1639  struct timeval newtime = utc2unix(utc_to);
1640 
1641  // TODO: check with Eric if this is the right way to set the time?
1642  iretn = settimeofday(&newtime, nullptr);
1643  if (iretn < 0)
1644  {
1645  return 0.;
1646  }
1647 #endif
1648  }
1649  else
1650  {
1651  // Fine adjustment using adjtime()
1652  if (fabs(deltat) > .001)
1653  {
1654 #if defined(COSMOS_WIN_OS)
1655  double newdelta;
1656  newdelta = deltat * 1e7;
1657  SetSystemTimeAdjustment(newdelta,false);
1658 #else
1659 
1660  struct timeval newdelta, olddelta;
1661  newdelta.tv_sec = deltat;
1662  newdelta.tv_usec = 100000. * (deltat - newdelta.tv_sec) + .5;
1663 
1664  // adjust the time
1665  iretn = adjtime(&newdelta, &olddelta);
1666  return 0.;
1667 #endif
1668  }
1669 
1670  }
1671  return deltat;
1672 }
int iretn
Definition: rw_test.cpp:37
struct timeval utc2unix(double utc)
UTC to Unix time.
Definition: timelib.cpp:152
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65