Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use constant Julian start day #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define e6a 1.0E-6
#define tothrd 6.6666666666666666E-1 /* 2/3 */
#define xj2 1.0826158E-3 /* J2 Harmonic (WGS '72) */
#define xj3 -2.53881E-6 /* J3 Harmonic (WGS '72) */
#define xj3 -2.53881E-6 /* J3 Harmonic (WGS '72) */
#define xj4 -1.65597E-6 /* J4 Harmonic (WGS '72) */
#define xke 7.43669161E-2
#define xkmper 6.378137E3 /* WGS 84 Earth radius km */
Expand Down Expand Up @@ -60,5 +60,8 @@
/* doppler calculation */
#define SPEED_OF_LIGHT 299792458.0

/* Date/Time constants */
#define JULIAN_START_DAY 315446400


#endif
15 changes: 4 additions & 11 deletions src/julian_date.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 1
#include <predict/predict.h>
#include "defs.h"
#include <stdio.h>


Expand Down Expand Up @@ -48,15 +49,7 @@ time_t mktime_utc(const struct tm* timeinfo_utc)
**/
time_t get_julian_start_day()
{
struct tm start_time;
start_time.tm_sec = 0;
start_time.tm_min = 0;
start_time.tm_hour = 0;
start_time.tm_mday = 31;
start_time.tm_mon = 11;
start_time.tm_year = 1979-1900;
start_time.tm_isdst = 0;
return mktime_utc(&start_time);
return JULIAN_START_DAY;
}

#define NUM_SECONDS_IN_DAY (24.0*60.0*60.0)
Expand All @@ -71,10 +64,10 @@ time_t predict_from_julian(predict_julian_date_t date)
{
double seconds_since = date*NUM_SECONDS_IN_DAY;
time_t ret_time = get_julian_start_day();

//add number of seconds since julian start day to the julian start day, get current time_t
struct tm timeinfo;
gmtime_r(&ret_time, &timeinfo);
gmtime_r(&ret_time, &timeinfo);
timeinfo.tm_sec += seconds_since;
ret_time = mktime_utc(&timeinfo);
return ret_time;
Expand Down