Sun position
Sun position algorithm
demo4_multiple_sites.c

Repeated calculation of the Sun's position for three European sites simultaneously. This demo also shows the use of the sky_initTimeDetailed() function.

void demo4(void)
/*! Sample code using the greatly simplified calculation of the position
* of the Sun using interpolated coordinates (like demo2(), but also supporting
* multiple sites.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
{
Sky_DeltaTs deltaTs; /* Differences between timescales */
Sky_SiteProp site[3]; /* Properties of the sites */
Sky_SiteHorizon topo; /* Sun position, as seen from the site*/
double j2kUtc_d; /* Time, expressed as a count of days */
Sky_Times atime;
V3D_Vector terInterV;// unit vector in Terrestrial Intermed Ref Sys
char azStr[24], elStr[24];
int i, j;
/* Get the current time in days since 2000-01-01 Greenwich noon */
j2kUtc_d = sky_unixTimeToJ2kd(time(NULL));
/* Set up the various delta T values. Values are taken from Bulletin A of
* 23-Jul-2020, using the USNO prediction formula given on line 117:
* UT1-UTC = -0.2090 - 0.00011 (MJD - 59061) - (UT2-UT1)
* to calculate deltaUT_s. (We need to convert time in J2KD format to MJD
* form by adding 51544.5) */
sky_initTimeDetailed(j2kUtc_d + 51544.5,
59061, -0.2090, -0.00011,
37, &deltaTs);
/* Set up the fixed site data */
sky_setSiteLocation(51.5074, -0.1278, 11.0, &site[0]);
sky_setSiteTempPress(11.0, 1013.0, &site[0]);
sky_setSiteTimeZone(0.0, &site[0]);
sky_setSiteLocation(48.858093, 2.294694, 307.0, &site[1]);
sky_setSiteTempPress(12.0, 974.0, &site[1]);
sky_setSiteTimeZone(1.0, &site[1]);
sky_setSiteLocation(41.9028, 12.4964, 21.0, &site[2]);
sky_setSiteTempPress(15.0, 1010.0, &site[2]);
sky_setSiteTimeZone(1.0, &site[2]);
/* Set up the interpolation algorithm to calculate Sun positions */
skyfast_init(j2kUtc_d, 720, &deltaTs, &sun_nrelApparent);
printf("Fast sun calculation at multiple sites\n");
for (i = 0; i < 100; i++) {
/* Get sun position using interpolation */
j2kUtc_d = sky_unixTimeToJ2kd(time(NULL));
sky_updateTimes(j2kUtc_d, &deltaTs, &atime);
/* Get the approximate apparent coordinates by interpolation */
skyfast_getApprox(atime.j2kTT_cy, &approx);
/* Convert apparent coordinates to TIRS coordinates */
atime.j2kUT1_d,
approx.eqEq_rad,
&terInterV);
/* For each site, convert from TIRS coords to topocentric coords, and
write out the result */
for (j = 0; j < 3; j++) {
sky_siteTirsToTopo(&terInterV, approx.distance_au, &site[j], &topo);
printf("Site %d: ", j);
skyio_printJ2kd(j2kUtc_d + site[j].timeZone_d);
if (topo.azimuth_rad < 0.0) {
topo.azimuth_rad += TWOPI;
}
skyio_radToDmsStr(azStr, sizeof(azStr), topo.azimuth_rad, 2);
skyio_radToDmsStr(elStr, sizeof(elStr), topo.elevation_rad, 2);
printf(" Sun Azimuth: %s, Elevation: %s\n", azStr, elStr);
}
sleep(1); /* Just use a simple delay for this demo. */
}
}
Sky_TrueEquatorial::appCirsV
V3D_Vector appCirsV
Direction of object in apparent or CIRS coordinates (effectively a unit vector).
Definition: sky.h:110
Sky_DeltaTs
This structure contains relatively constant data, and is set up by one of the three functions sky_ini...
Definition: sky.h:166
skyio_radToDmsStr
static char * skyio_radToDmsStr(char destStr[], size_t destStrSize, double angle_rad, unsigned decimals)
Routine to take an angle in radian and return a string in degrees, arcminutes and arcseconds form - [...
Definition: skyio.h:111
sky_siteTirsToTopo
void sky_siteTirsToTopo(const V3D_Vector *terInterV, double dist_au, const Sky_SiteProp *site, Sky_SiteHorizon *topo)
Transform a coordinate vector from the Terrestrial Intermediate Reference System to topocentric Az/El...
Definition: sky-site.c:378
sky_updateTimes
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...
Definition: sky-time.c:206
Sky_TrueEquatorial
Struct used for holding an object's coordinates in equatorial apparent or Intermediate coordinates.
Definition: sky.h:106
skyfast_getApprox
void skyfast_getApprox(double t_cy, Sky_TrueEquatorial *approx)
Get the best approximation to the celestial object's apparent coordinates and distance,...
Definition: skyfast.c:234
sky_setSiteLocation
void sky_setSiteLocation(double latitude_deg, double longitude_deg, double height_m, Sky_SiteProp *site)
Initialise the site structure by calculating those site-related values that do not change with time.
Definition: sky-site.c:105
Sky_Times::j2kTT_cy
double j2kTT_cy
Julian centuries since J2000.0, TT timescale [T].
Definition: sky.h:188
Sky_Times
This structure contains the continuously varying time (and earth rotation) data, in various forms tha...
Definition: sky.h:184
Sky_TrueEquatorial::eqEq_rad
double eqEq_rad
Equation of the Equinoxes (radian).
Definition: sky.h:115
Sky_SiteProp
Site properties.
Definition: sky.h:315
sky0_appToTirs
void sky0_appToTirs(const V3D_Vector *appV, double j2kUT1_d, double eqEq_rad, V3D_Vector *terInterV)
Convert a position in geocentric apparent coordinates to geocentric coordinates in the Terrestrial In...
Definition: sky0.c:432
Sky_SiteHorizon::azimuth_rad
double azimuth_rad
azimuth (radian)
Definition: sky.h:131
skyfast_init
void skyfast_init(double tStartUtc_d, int fullRecalcInterval_mins, const Sky_DeltaTs *deltas, void(*getApparent)(double j2kTT_cy, Sky_TrueEquatorial *pos))
Initialise those items that take a long time to calculate, but which do not need to be recalculated f...
Definition: skyfast.c:111
TWOPI
#define TWOPI
,
Definition: general.h:160
Sky_TrueEquatorial::distance_au
double distance_au
Distance to object (Astronomical Units) or 0.0 for far distant objects (that is, those with negligibl...
Definition: sky.h:112
sky_initTimeDetailed
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...
Definition: sky-time.c:134
V3D_Vector
3x1 vector.
Definition: vectors3d.h:57
sky_unixTimeToJ2kd
double sky_unixTimeToJ2kd(time_t unixTime)
Convert a time in Unix system time format to days since 2000 Jan 1, noon UTC.
Definition: sky-time.c:275
sky_setSiteTimeZone
void sky_setSiteTimeZone(double timeZone_h, Sky_SiteProp *site)
Set the time zone offset for this site.
Definition: sky-site.c:293
sky_setSiteTempPress
void sky_setSiteTempPress(double temperature_degC, double pressure_hPa, Sky_SiteProp *site)
Set refraction coefficients based on atmospheric temperature and pressure at the site.
Definition: sky-site.c:261
sun_nrelApparent
void sun_nrelApparent(double j2kTT_cy, Sky_TrueEquatorial *pos)
Calculate the Sun's position as a unit vector and a distance, in apparent coordinates.
Definition: sun.c:211
skyio_printJ2kd
void skyio_printJ2kd(double j2kd)
Write out a J2KD as a calendar date and time.
Definition: skyio.c:426
Sky_SiteHorizon::elevation_rad
double elevation_rad
elevation (or altitude) (radian)
Definition: sky.h:132
Sky_Times::j2kUT1_d
double j2kUT1_d
days since J2000.0, UT1 timescale [Du]
Definition: sky.h:186
Sky_SiteHorizon
Coordinates of a celestial object in the horizon frame, in both rectangular and polar forms.
Definition: sky.h:129