aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2016-01-03 02:15:31 +0100
committerMattias Andrée <maandree@member.fsf.org>2016-01-03 02:15:31 +0100
commitab80d705ed719244d6bee81a02b596061d90323f (patch)
tree0c2666b1cbc61b67db31d902a1d20e73bef223a9 /src
parenton -l (diff)
downloadradharc-ab80d705ed719244d6bee81a02b596061d90323f.tar.gz
radharc-ab80d705ed719244d6bee81a02b596061d90323f.tar.bz2
radharc-ab80d705ed719244d6bee81a02b596061d90323f.tar.xz
in case of time-travel
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src')
-rw-r--r--src/radharc.c25
-rw-r--r--src/solar.c23
2 files changed, 30 insertions, 18 deletions
diff --git a/src/radharc.c b/src/radharc.c
index 7b5f1e5..2c5e8c6 100644
--- a/src/radharc.c
+++ b/src/radharc.c
@@ -20,6 +20,30 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "settings.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+/**
+ * Exit if time the is before year 0 in J2000.
+ */
+#if defined(TIMETRAVELLER)
+static void
+check_timetravel(const char *argv0)
+{
+ struct timespec now;
+ if (clock_gettime(CLOCK_REALTIME, &now))
+ perror(argv0 ? argv0 : "radharc"), exit(1);
+ if (now.tv_nsec < (time_t)946728000L)
+ fprintf(stderr, "We have detected that you are a time-traveller"
+ "(or your clock is not configured correctly.)"
+ "Please recompile with -DTIMETRAVELLER"
+ "(or correct your clock.)"), exit(1);
+}
+#else
+# define check_timetravel(_) /* do nothing */
+#endif
@@ -28,6 +52,7 @@ main(int argc, char *argv[])
{
struct settings settings;
+ check_timetravel(*argv);
parse_command_line(argc, argv, &settings);
return 0;
diff --git a/src/solar.c b/src/solar.c
index 038443f..98aaab3 100644
--- a/src/solar.c
+++ b/src/solar.c
@@ -116,24 +116,11 @@ elevation_from_hour_angle(double latitude, double declination, double hour_angle
static inline double
sun_geometric_mean_longitude(double tm)
{
- double rc = pow(0.0003032 * tm, 2.0) + 36000.76983 * tm + 280.46646;
- return radians(fmod(rc, 360.0));
- /*
- CANNIBALISERS:
- The result of this function should always be positive, this
- means that after division modulo 360 but before `radians`,
- you will need to add 360 if the value is negative. This can
- only happen if `tm` is negative, which can only happen for date
- times before 2000-(01)Jan-01 12:00:00 UTC par division modulo
- implementations with the signess of at least the left operand.
- More precively, it happens between circa 1970-(01)Jan-11
- 16:09:02 UTC and circa 374702470660351740 seconds before
- January 1, 1970 00:00 UTC, which is so far back in time
- it cannot be reliable pinned down to the right year, but it
- is without a shadow of a doubt looooong before the Earth
- was formed, is right up there with the age of the Milky Way
- and the universe itself.
- */
+ double rc = fmod(pow(0.0003032 * tm, 2.0) + 36000.76983 * tm + 280.46646, 360.0);
+#if defined(TIMETRAVELLER)
+ rc = rc < 0.0 ? (rc + 360.0) : rc;
+#endif
+ return radians(rc);
}
/**