mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-05-19 06:17:03 -04:00
C demo: Calculate true solar time from the Sun's hour angle.
This commit is contained in:
@@ -39,6 +39,9 @@ Shows how to calculate sunrise, sunset, moonrise, and moonset times.
|
||||
### [Seasons](seasons.c)
|
||||
Calculates the equinoxes and solstices for a given calendar year.
|
||||
|
||||
### [Solar Time](solar_time.c)
|
||||
An example of how to use the Sun's hour angle to calculate true solar time.
|
||||
|
||||
### [Triangulate](triangulate.c)
|
||||
Given the geographic coordinates of two observers, and angular
|
||||
directions they are looking in, determines geographic coordinates
|
||||
|
||||
@@ -14,7 +14,7 @@ else
|
||||
fi
|
||||
|
||||
mkdir -p bin
|
||||
for name in gravity galactic camera moonphase positions linux_riseset riseset seasons culminate horizon lunar_eclipse triangulate ecliptic_vector; do
|
||||
for name in solar_time gravity galactic camera moonphase positions linux_riseset riseset seasons culminate horizon lunar_eclipse triangulate ecliptic_vector; do
|
||||
rm -f bin/${name}
|
||||
echo "Compiling ${name}.c"
|
||||
gcc ${BUILDOPT} -Wall -Werror -o bin/${name} -I../../source/c ../../source/c/astronomy.c astro_demo_common.c ${name}.c -lm ||
|
||||
|
||||
1
demo/c/correct/solar_time.txt
Normal file
1
demo/c/correct/solar_time.txt
Normal file
@@ -0,0 +1 @@
|
||||
True solar time = 11.6286 hours (11:37:42.979)
|
||||
@@ -16,6 +16,7 @@ rm -f test/*.txt
|
||||
mkdir -p test
|
||||
[[ "$1" == "nobuild" ]] || ./build || Fail "Error building example programs."
|
||||
|
||||
TestDemo solar_time +38.88 -77.03 2023-02-12T17:00:00Z
|
||||
TestDemo camera 29 -81 2021-03-22T02:45:00Z
|
||||
TestDemo moonphase 2019-06-15T09:15:32.987Z
|
||||
TestDemo positions +45.6 -90.7 2018-11-30T17:55:07.234Z
|
||||
|
||||
49
demo/c/solar_time.c
Normal file
49
demo/c/solar_time.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
solar_time.c - by Don Cross - 2019-06-11
|
||||
|
||||
Example C program for Astronomy Engine:
|
||||
https://github.com/cosinekitty/astronomy
|
||||
|
||||
Given an observer's geographic latitude and longitude,
|
||||
and an optional date and time, this program displays
|
||||
true solar time for that observer and time.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "astro_demo_common.h"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
int error;
|
||||
astro_observer_t observer;
|
||||
astro_time_t time;
|
||||
astro_func_result_t ha;
|
||||
double solarTimeHours;
|
||||
int hour, minute, second, milli;
|
||||
|
||||
error = ParseArgs(argc, argv, &observer, &time);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
ha = Astronomy_HourAngle(BODY_SUN, &time, observer);
|
||||
if (ha.status != ASTRO_SUCCESS)
|
||||
{
|
||||
printf("ERROR %d in Astronomy_HourAngle().\n", ha.status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
solarTimeHours = fmod(ha.value + 12.0, 24.0);
|
||||
|
||||
milli = (int)round(solarTimeHours * 3600000.0);
|
||||
second = milli / 1000;
|
||||
milli %= 1000;
|
||||
minute = second / 60;
|
||||
second %= 60;
|
||||
hour = minute / 60;
|
||||
minute %= 60;
|
||||
hour %= 24;
|
||||
|
||||
printf("True solar time = %0.4lf hours (%02d:%02d:%02d.%03d)\n", solarTimeHours, hour, minute, second, milli);
|
||||
return 0;
|
||||
}
|
||||
1
demo/c/test/.gitignore
vendored
1
demo/c/test/.gitignore
vendored
@@ -12,3 +12,4 @@ galactic.txt
|
||||
triangulate.txt
|
||||
gravity.txt
|
||||
worldmap.txt
|
||||
solar_time.txt
|
||||
|
||||
Reference in New Issue
Block a user