Sun position
Sun position algorithm
|
54 #ifdef INCLUDE_MJD_ROUTINES
55 #define MJD_1JAN1970 40587
58 #define MJD_1JAN1904 16480
59 #define MJD_0JAN1900 15019
60 #define MJD_30DEC1899 15018
61 #define MJD_BASE 2400000.5
64 #define START_GREGORIAN 2299160.0
65 #define TIME_T_J2000 946728000
70 LOCAL double getDeltaUT1_s(
double mjdUtc,
74 LOCAL double calendarToJ2kd(
int year,
int month,
int day);
118 const double deltaTAI_s = 32.184;
124 deltaTT_s = deltaTAI_s + deltaAT_s;
127 deltaT_s = deltaTT_s - deltaUT_s;
175 deltaUT_s = getDeltaUT1_s(mjdUtc, usnoMjdBase, usnoCoeffC11, usnoCoeffC12);
242 int hour,
int minute,
double second,
266 jd2k = calendarToJ2kd(year, month, day);
268 timeOfDay_d = (second + 60.0 * (minute + 60.0 * (hour - tz_h))) / 86400.0;
292 return (
double)(unixTime - TIME_T_J2000) / 86400.0;
298 GLOBAL double sky_unixTimespecToJ2kd(
struct timespec uTs)
314 return ((
double)(uTs.tv_sec - TIME_T_J2000) + (
double)uTs.tv_nsec / 1e9)
359 j2kdate = floor(j2k_d);
360 timeOfDay = (j2k_d - j2kdate) * 24.0;
361 *hour = (int)timeOfDay;
362 timeOfDay = (timeOfDay - *hour) * 60.0;
363 *minute = (int)timeOfDay;
364 *second = (timeOfDay - *minute) * 60.0;
367 if ((
int)(*second + 0.0005) == 60) {
381 j = (int32_t)j2kdate + 2451545;
383 if (j <= START_GREGORIAN) {
386 n4 = 4 * (j + ((((4 * j - 17918) / 146097) * 3 + 2) >> 2) - 37);
389 n10 = 10 * (((n4 - 237) % 1461) >> 2) + 5;
391 *year = (int)(n4 / 1461 - 4712);
392 *month = (n10 / 306 + 2) % 12 + 1;
393 *day = (n10 % 306) / 10 + 1;
398 #ifdef INCLUDE_MJD_ROUTINES
399 GLOBAL double sky_calTimeToMjd(
int year,
int month,
int day,
400 int hour,
int minute,
double second,
422 mjd = calendarToJ2kd(year,month, day) +
MJD_J2000;
424 timeOfDay_d = (second + 60.0 * (minute + 60.0 * (hour - tz_h))) / 86400.0;
431 GLOBAL double sky_unixTimeToMjd(time_t unixTime)
445 return (
double)unixTime / 86400.0 + MJD_1JAN1970;
451 GLOBAL double sky_unixTimespecToMjd(
struct timespec uTs)
463 return ((
double)uTs.tv_sec + (
double)uTs.tv_nsec / 1e9) / 86400.0
470 GLOBAL void sky_updateTimesFromMjd(
double mjdUtc,
507 GLOBAL void sky_mjdToCalTime(
double mjd,
546 timeOfDay = (mjd - mjdate) * 24.0;
547 *hour = (int)timeOfDay;
548 timeOfDay = (timeOfDay - *hour) * 60.0;
549 *minute = (int)timeOfDay;
550 *second = (timeOfDay - *minute) * 60.0;
552 j = (int32_t)mjdate + 2400001;
554 if (j <= START_GREGORIAN) {
557 n4 = 4 * (j + (((4 * j - 17918) / 146097) * 3 + 2) / 4 - 37);
560 n10 = 10 * (((n4 - 237) % 1461) / 4) + 5;
562 *year = (int)(n4 / 1461 - 4712);
563 *month = (n10 / 306 + 2) % 12 + 1;
564 *day = (n10 % 306) / 10 + 1;
599 polar->xPolar_as = xPolar_as;
600 polar->yPolar_as = yPolar_as;
602 if ((xPolar_as == 0.0) && (yPolar_as == 0.0)) {
607 polar->correctionInUse =
false;
610 polar->correctionInUse =
true;
615 sPrime_as = -0.000047 * t_cy;
634 LOCAL double getDeltaUT1_s(
double mjdUtc,
650 const double A = 0.022;
651 const double B = -0.012;
652 const double C = -0.006;
653 const double D = 0.007;
659 double seasonalVariation;
666 delBYR = (mjdUtc - mjDateBYR) / bYear;
670 seasonalVariation = A * sin(
TWOPI * delBYR)
671 + B * cos(
TWOPI * delBYR)
672 + C * sin(4.0 *
PI * delBYR)
673 + D * cos(4.0 *
PI * delBYR);
678 deltaUT_s = usnoCoeffC11 + usnoCoeffC12 * (mjdUtc - usnoMjdBase)
686 LOCAL double calendarToJ2kd(
int year,
int month,
int day)
701 int32_t year32 = year;
702 int32_t month32 = month - 3;
711 j2kdi_d = ((1461 * (year32 + 4712)) >> 2) - 2451487;
712 j2kdi_d += (306 * month32 + 5) / 10 + day32;
713 if (j2kdi_d > -152386) {
716 j2kdi_d -= ((3 * (year32 / 100 - 11)) >> 2) + 7;
718 return (
double)j2kdi_d + 0.5;
#define TROP_CENT
Length of Tropical Century in days.
V3D_Matrix * v3d_multMxM(V3D_Matrix *destM, const V3D_Matrix *srcM1, const V3D_Matrix *srcM2)
Multiply 3x3 matrix by 3x3 matrix to give a new 3x3 matrix, as per [destM] = [srcM1]*[srcM2].
general.h - definitions of general use to (standard) C programs
void sky_j2kdToCalTime(double j2k_d, int *year, int *month, int *day, int *hour, int *minute, double *second)
This procedure converts the integral part of the date in "J2KD" form to a calendar date and the fract...
double deltaT_d
TT - UT1, scaled to days.
This structure contains relatively constant data, and is set up by one of the three functions sky_ini...
double deltaTT_d
TT - UTC, scaled to days.
astron.h - assorted definitions useful for astronomy
void sky_setPolarMotion(double xPolar_as, double yPolar_as, double t_cy, Sky_PolarMot *polar)
Update polar motion correction.
void sky_updateTimes(double j2kUtc_d, const Sky_DeltaTs *d, Sky_Times *t)
Convert the given "J2KD" in the UTC timescale to the other timescales, and pre-calculate some other q...
#define MJD_J2000
MJD of Fundamental Epoch J2000.0.
#define LOCAL
C has some very silly default behaviours.
double j2kTT_cy
Julian centuries since J2000.0, TT timescale [T].
#define REQUIRE_NOT_NULL(pointer_)
,
This structure contains the continuously varying time (and earth rotation) data, in various forms tha...
double era_rad
Earth Rotation Angle (radian) [θ].
double deltaUT_d
UT1 - UTC, scaled to days.
#define MJD_B1900
MJD of Besselian std epoch B1900.0.
static double arcsecToRad(double angle_as)
Returns angle_as converted from arcseconds to radians.
void sky_initTimeDetailed(double mjdUtc, double usnoMjdBase, double usnoCoeffC11, double usnoCoeffC12, int deltaAT_s, Sky_DeltaTs *d)
This is one of three alternative routines for setting up the various delta time values for use in ong...
double j2kTT_d
days since J2000.0, TT timescale [D]
double sky_unixTimeToJ2kd(time_t unixTime)
Convert a time in Unix system time format to days since 2000 Jan 1, noon UTC.
This structure contains polar motion parameters and a rotation matrix.
#define DEFINE_THIS_FILE
Leave DEFINE_THIS_FILE undefined.
void sky_initTime(int deltaAT_s, double deltaUT_s, Sky_DeltaTs *d)
This is one of three alternative routines for setting up the various delta time values for use in ong...
sky.h - structures and routines for astronomical observing & tracking
V3D_Matrix * v3d_createRotationMatrix(V3D_Matrix *destM, V3D_AxisNames axis, double angle_rad)
Creates a matrix to rotate a coordinate system about an axis.
#define JUL_CENT
Length of Julian Century in days.
double mjdUtc
Modified Julian Date (= JD - 2 400 000.5), UTC.
double j2kUT1_d
days since J2000.0, UT1 timescale [Du]
void sky_initTimeSimple(Sky_DeltaTs *d)
This is one of three alternative routines for setting up the various delta time values for use in ong...
double sky_calTimeToJ2kd(int year, int month, int day, int hour, int minute, double second, double tz_h)
Return the number of days (and fraction of a day) since noon 2000 Jan 1 (UTC) of the given calendar d...