Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit cd8ffb2

Browse files
author
user
committed
Add version 1.0
First X11 version by John Mackin. Posted to the comp.sources.x Usenet newsgroup on 1990-09-30. Downloaded from: https://ftp.sunet.se/mirror/archive/ftp.sunet.se/pub/usenet/ftp.uu.net/comp.sources.x/volume9/sunclock/part01.gz
0 parents  commit cd8ffb2

12 files changed

+3043
-0
lines changed

Imakefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Compile options:
3+
#
4+
# Set -DNEW_CTIME if using the table-driven version of ctime (i.e., if
5+
# your struct tm contains a tm_zone field)
6+
# Set -DBIGFONT= and -DSMALLFONT= whatever fonts you like
7+
# Pick -O or -g
8+
#
9+
10+
CDEBUGFLAGS=-DBIGFONT=\"9x15\" -DSMALLFONT=\"6x10\" -g
11+
12+
SRCS=sunclock.c bitmaps.c astro.c
13+
OBJS=sunclock.o bitmaps.o astro.o
14+
LOCAL_LIBRARIES=$(XLIB) -lm
15+
DEPLIBS= # I don't know what I'm doing, and I hate imake!
16+
17+
ComplexProgramTarget(sunclock)

Makefile.dist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Compile options:
3+
#
4+
# Set -DSYSV if on System V
5+
# Set -DNEW_CTIME if using the table-driven version of ctime (i.e., if
6+
# your struct tm contains a tm_zone field)
7+
# Set -DBIGFONT= and -DSMALLFONT= whatever fonts you like
8+
# Pick -O or -g
9+
#
10+
11+
CFLAGS=-DBIGFONT=\"9x15\" -DSMALLFONT=\"6x10\" -g
12+
13+
OFILES=sunclock.o bitmaps.o astro.o
14+
15+
sunclock: $(OFILES)
16+
cc $(CFLAGS) $(OFILES) -o $@ -lX11 -lm

README

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Sun Clock - X11 Version 1.0
2+
3+
X11 version by John Mackin, <john@cs.su.oz.AU>, based on a Suntools program
4+
by John Walker, <kelvin@acad.uu.NET>.
5+
6+
This program is a clock that shows which portion of the Earth's surface is
7+
illuminated by the Sun. It is designed to be usually iconic, but can be
8+
opened for a larger display with the time updated every second and both the
9+
local timezone and UTC displayed. The Suntools version had a menu that
10+
allowed you to speed up time, show different dates, etc., but I have
11+
never implemented any of that in the X version; there is some support
12+
for it in the code, however.
13+
14+
The program should have been written using Xt rather than raw Xlib, and I
15+
tried that at first. I couldn't get the icon window to work, though, so I
16+
abandoned that version. Hence, the program does _not_ accept most Xt-style
17+
command line options; valid options are given in the manual page.
18+
19+
The program has been tested on a number of different clients (MIPS, Sun,
20+
VAX) and servers (MIPS colour console, Sun MIT mono, NCD-16/19), under X11R3
21+
and R4. If you find bugs, please report them to me, john@cs.su.oz.AU.
22+
23+
To build the program, decide whether you want to use imake or not. If you
24+
don't, link Makefile.dist to Makefile, and edit it, otherwise edit the
25+
Imakefile and use xmkmf. The program uses two fonts, one for the icon
26+
display and one for the large window display. The names of these fonts
27+
are compiled in. The font names comes from -DBIGFONT and -DSMALLFONT
28+
in the Makefile. If you are not using imake, you will need to supply
29+
a -DSYSV option if you are System V. You should supply -DNEW_CTIME if
30+
you are using the table-driven ctime and a "struct tm" contains
31+
a tm_zone field. If neither of the ways of getting the local timezone
32+
name works on your system, please let me know.
33+
34+
The original Suntools program, in case you want it, was posted as Volume 1,
35+
Issue 79 of comp.sources.sun.
36+
37+
This program is public domain and may be freely copied as long as the
38+
notices at the top of sunclock.c remain intact.

astro.c

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* Sun clock - astronomical routines.
3+
*/
4+
5+
#include "sunclock.h"
6+
7+
/* JDATE -- Convert internal GMT date and time to Julian day
8+
and fraction. */
9+
10+
long
11+
jdate(t)
12+
struct tm *t;
13+
{
14+
long c, m, y;
15+
16+
y = t->tm_year + 1900;
17+
m = t->tm_mon + 1;
18+
if (m > 2)
19+
m = m - 3;
20+
else {
21+
m = m + 9;
22+
y--;
23+
}
24+
c = y / 100L; /* Compute century */
25+
y -= 100L * c;
26+
return t->tm_mday + (c * 146097L) / 4 + (y * 1461L) / 4 +
27+
(m * 153L + 2) / 5 + 1721119L;
28+
}
29+
30+
/* JTIME -- Convert internal GMT date and time to astronomical
31+
Julian time (i.e. Julian date plus day fraction,
32+
expressed as a double). */
33+
34+
double
35+
jtime(t)
36+
struct tm *t;
37+
{
38+
return (jdate(t) - 0.5) +
39+
(((long) t->tm_sec) +
40+
60L * (t->tm_min + 60L * t->tm_hour)) / 86400.0;
41+
}
42+
43+
/* KEPLER -- Solve the equation of Kepler. */
44+
45+
double
46+
kepler(m, ecc)
47+
double m, ecc;
48+
{
49+
double e, delta;
50+
#define EPSILON 1E-6
51+
52+
e = m = dtr(m);
53+
do {
54+
delta = e - ecc * sin(e) - m;
55+
e -= delta / (1 - ecc * cos(e));
56+
} while (abs(delta) > EPSILON);
57+
return e;
58+
}
59+
60+
/* SUNPOS -- Calculate position of the Sun. JD is the Julian date
61+
of the instant for which the position is desired and
62+
APPARENT should be nonzero if the apparent position
63+
(corrected for nutation and aberration) is desired.
64+
The Sun's co-ordinates are returned in RA and DEC,
65+
both specified in degrees (divide RA by 15 to obtain
66+
hours). The radius vector to the Sun in astronomical
67+
units is returned in RV and the Sun's longitude (true
68+
or apparent, as desired) is returned as degrees in
69+
SLONG. */
70+
71+
sunpos(jd, apparent, ra, dec, rv, slong)
72+
double jd;
73+
int apparent;
74+
double *ra, *dec, *rv, *slong;
75+
{
76+
double t, t2, t3, l, m, e, ea, v, theta, omega,
77+
eps;
78+
79+
/* Time, in Julian centuries of 36525 ephemeris days,
80+
measured from the epoch 1900 January 0.5 ET. */
81+
82+
t = (jd - 2415020.0) / 36525.0;
83+
t2 = t * t;
84+
t3 = t2 * t;
85+
86+
/* Geometric mean longitude of the Sun, referred to the
87+
mean equinox of the date. */
88+
89+
l = fixangle(279.69668 + 36000.76892 * t + 0.0003025 * t2);
90+
91+
/* Sun's mean anomaly. */
92+
93+
m = fixangle(358.47583 + 35999.04975*t - 0.000150*t2 - 0.0000033*t3);
94+
95+
/* Eccentricity of the Earth's orbit. */
96+
97+
e = 0.01675104 - 0.0000418 * t - 0.000000126 * t2;
98+
99+
/* Eccentric anomaly. */
100+
101+
ea = kepler(m, e);
102+
103+
/* True anomaly */
104+
105+
v = fixangle(2 * rtd(atan(sqrt((1 + e) / (1 - e)) * tan(ea / 2))));
106+
107+
/* Sun's true longitude. */
108+
109+
theta = l + v - m;
110+
111+
/* Obliquity of the ecliptic. */
112+
113+
eps = 23.452294 - 0.0130125 * t - 0.00000164 * t2 + 0.000000503 * t3;
114+
115+
/* Corrections for Sun's apparent longitude, if desired. */
116+
117+
if (apparent) {
118+
omega = fixangle(259.18 - 1934.142 * t);
119+
theta = theta - 0.00569 - 0.00479 * sin(dtr(omega));
120+
eps += 0.00256 * cos(dtr(omega));
121+
}
122+
123+
/* Return Sun's longitude and radius vector */
124+
125+
*slong = theta;
126+
*rv = (1.0000002 * (1 - e * e)) / (1 + e * cos(dtr(v)));
127+
128+
/* Determine solar co-ordinates. */
129+
130+
*ra =
131+
fixangle(rtd(atan2(cos(dtr(eps)) * sin(dtr(theta)), cos(dtr(theta)))));
132+
*dec = rtd(asin(sin(dtr(eps)) * sin(dtr(theta))));
133+
}
134+
135+
/* GMST -- Calculate Greenwich Mean Siderial Time for a given
136+
instant expressed as a Julian date and fraction. */
137+
138+
double
139+
gmst(jd)
140+
double jd;
141+
{
142+
double t, theta0;
143+
144+
145+
/* Time, in Julian centuries of 36525 ephemeris days,
146+
measured from the epoch 1900 January 0.5 ET. */
147+
148+
t = ((floor(jd + 0.5) - 0.5) - 2415020.0) / 36525.0;
149+
150+
theta0 = 6.6460656 + 2400.051262 * t + 0.00002581 * t * t;
151+
152+
t = (jd + 0.5) - (floor(jd + 0.5));
153+
154+
theta0 += (t * 24.0) * 1.002737908;
155+
156+
theta0 = (theta0 - 24.0 * (floor(theta0 / 24.0)));
157+
158+
return theta0;
159+
}

bitmaps.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
/*
3+
* bitmaps for sun clock, X11 version
4+
*/
5+
6+
#define DEFINE_BITS
7+
8+
#include "bitmaps.h"

bitmaps.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* bitmaps for sun clock, X11 version; header file
3+
*/
4+
5+
#ifdef DEFINE_BITS
6+
#define EXTERN
7+
#else
8+
#define EXTERN extern
9+
#endif
10+
11+
#define icon_map_width 126
12+
#define icon_map_height 63
13+
EXTERN char icon_map_bits[]
14+
#ifdef DEFINE_BITS
15+
#include "icon.bits.h"
16+
#else
17+
;
18+
#endif
19+
20+
#define large_map_width 640
21+
#define large_map_height 320
22+
EXTERN char large_map_bits[]
23+
#ifdef DEFINE_BITS
24+
#include "large.bits.h"
25+
#else
26+
;
27+
#endif

icon.bits.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
= {
2+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
4+
0x00,0x00,0x00,0x00,0x00,0xc0,0xff,0xff,0xff,0x07,0x00,0x00,0x10,0x00,0x00,
5+
0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xff,0x03,0xe0,0x07,0xfe,0xf0,0x3f,0xc0,
6+
0x0f,0x00,0x00,0x00,0x00,0x00,0xf8,0xff,0xff,0x07,0x80,0x01,0x7e,0x00,0x7c,
7+
0xc0,0x3f,0xe0,0x01,0x00,0x00,0x00,0xf8,0xff,0x1f,0x0c,0xe0,0x01,0x00,0x00,
8+
0xff,0x7d,0xfb,0xef,0x07,0x00,0xc1,0x1f,0xfe,0xff,0xff,0x38,0xf0,0x18,0xf0,
9+
0x03,0xef,0x0f,0xa0,0xff,0x7f,0x16,0x73,0xf0,0xff,0xff,0xff,0x3b,0x78,0x00,
10+
0xbc,0xff,0xff,0x03,0x06,0x00,0xe6,0x1f,0x7f,0x00,0xb8,0xfb,0xff,0x33,0xcf,
11+
0x07,0xfe,0x7f,0xc0,0x0f,0x00,0x00,0x00,0x18,0x7c,0x06,0xf0,0xf3,0xff,0xf1,
12+
0xc1,0x83,0xf7,0x1f,0x00,0x00,0x00,0x00,0xe0,0x1c,0xf0,0xff,0xe1,0x67,0xe8,
13+
0xe1,0x00,0xf0,0xff,0x0f,0x00,0x00,0x00,0x80,0xff,0x07,0xc0,0xc3,0x83,0xcd,
14+
0xbd,0x03,0x00,0x70,0xff,0x0b,0x00,0x00,0x06,0xe0,0xf0,0x00,0xf8,0x00,0x07,
15+
0x18,0x2f,0x0e,0x00,0xf8,0x3f,0xc0,0x00,0x03,0x1e,0xe0,0x71,0x00,0x1f,0x00,
16+
0x0f,0xb8,0x8d,0x0f,0x00,0xf8,0x00,0x60,0x00,0x02,0x0c,0x80,0x31,0x00,0x00,
17+
0x00,0x1c,0x8e,0xdf,0x1f,0x00,0x60,0x00,0x28,0x18,0x00,0x00,0xc0,0x19,0x00,
18+
0x00,0x00,0x08,0xc8,0xef,0x1b,0x00,0x40,0x0f,0xcf,0x8d,0x0f,0x00,0xe0,0x0f,
19+
0x00,0x00,0x00,0x08,0x08,0xff,0x01,0x00,0xf8,0x9f,0xde,0x0d,0x03,0x00,0xb8,
20+
0x03,0x00,0x00,0x00,0x08,0x00,0x77,0x00,0x10,0xc8,0xff,0xbd,0x03,0x00,0x80,
21+
0xcf,0x00,0x00,0x00,0x00,0x18,0x00,0x10,0x00,0x70,0xf8,0xef,0xb7,0x01,0x00,
22+
0x80,0xef,0x00,0x00,0x00,0x00,0x70,0x00,0x1c,0x00,0x00,0x78,0xc7,0x04,0x00,
23+
0x00,0x80,0xfd,0x00,0x00,0x00,0x00,0xc0,0x80,0x07,0x00,0x00,0x0b,0xfc,0xc7,
24+
0x00,0x00,0x80,0x19,0x00,0x00,0x00,0x00,0xc0,0xf1,0x06,0x00,0x00,0x0e,0x00,
25+
0xc6,0x03,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0xc0,0x13,0x0c,0x00,0x00,0x06,
26+
0x00,0x8e,0x3f,0x00,0x80,0x01,0x00,0x00,0x80,0x00,0x00,0x17,0x0f,0x00,0x00,
27+
0x03,0x00,0x0f,0xe7,0x70,0xf8,0x01,0x00,0x00,0x80,0x01,0x00,0xf4,0xff,0x00,
28+
0x00,0x03,0x00,0x1c,0xc6,0xd8,0x18,0x01,0x00,0x00,0x00,0x00,0x00,0xfc,0xfb,
29+
0x01,0x00,0x02,0x00,0x18,0x83,0x8c,0x99,0x01,0x00,0x00,0x00,0x00,0x00,0xe0,
30+
0x03,0x00,0x00,0x03,0x0c,0xf8,0x81,0xc5,0x9b,0x03,0x00,0x00,0x00,0x00,0x00,
31+
0x01,0xf3,0x03,0x00,0x06,0x0c,0xe0,0x00,0x47,0x9f,0x03,0x40,0x02,0x00,0x00,
32+
0x00,0x01,0xff,0x07,0x00,0x44,0x00,0x80,0x00,0x47,0x8f,0x07,0x40,0x02,0x00,
33+
0x00,0x00,0x00,0x0c,0x1c,0x00,0xfc,0x03,0xc4,0x00,0xc6,0xef,0x06,0x00,0x00,
34+
0x00,0x00,0x00,0x00,0x08,0x30,0x00,0x00,0x03,0x67,0x00,0x80,0xff,0x0e,0x00,
35+
0x00,0x00,0x00,0x00,0xc0,0x0c,0xf0,0x00,0x00,0x13,0x37,0x00,0x80,0xd7,0x5f,
36+
0x00,0x08,0x00,0x00,0x00,0x40,0x0c,0xb0,0x03,0x00,0x12,0x1b,0x00,0x00,0xff,
37+
0xff,0x0d,0x08,0x00,0x00,0x00,0x00,0x04,0x00,0x06,0x00,0x06,0x09,0x00,0x00,
38+
0xfe,0x61,0x1f,0x00,0x00,0x40,0x00,0x00,0x0c,0x00,0x04,0x06,0x84,0x09,0x00,
39+
0x00,0xf8,0xc7,0x77,0x00,0x00,0x40,0x00,0x00,0x18,0x00,0x06,0x00,0x04,0xb9,
40+
0x00,0x00,0x80,0xbb,0x07,0x00,0x00,0x00,0x00,0x00,0x50,0x00,0x02,0x00,0x04,
41+
0xf3,0x00,0x00,0x00,0xae,0x01,0x01,0x00,0x20,0x00,0x00,0x70,0x00,0x02,0x30,
42+
0xcc,0xff,0x00,0x00,0x00,0xe3,0x03,0x03,0x00,0x20,0x00,0x00,0x40,0x00,0x03,
43+
0x00,0x4c,0xe4,0x02,0x00,0xc0,0x01,0x86,0x03,0x00,0x00,0x00,0x00,0x40,0xc0,
44+
0x01,0x00,0x0c,0x64,0x02,0x00,0x60,0x00,0x0c,0x01,0x00,0x00,0x00,0x00,0x40,
45+
0x60,0x00,0x00,0x08,0x66,0x00,0x00,0x60,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
46+
0x60,0x60,0x00,0x00,0x18,0x03,0x00,0x00,0xe0,0xe1,0x08,0x00,0x00,0x00,0x00,
47+
0x00,0x20,0x30,0x00,0x00,0x90,0x01,0x00,0x00,0xc0,0xfe,0x08,0x00,0x00,0x00,
48+
0x00,0x00,0x20,0x1c,0x00,0x00,0xf0,0x00,0x00,0x00,0xc0,0x63,0x0c,0x0c,0x00,
49+
0x00,0x00,0x00,0x20,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x07,0x1c,
50+
0x00,0x00,0x00,0x00,0x20,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
51+
0x1c,0x00,0x00,0x00,0x00,0x30,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
52+
0x03,0x0f,0x00,0x00,0x00,0x00,0xb0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
53+
0x00,0x00,0x07,0x00,0x00,0x00,0x00,0xb0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
54+
0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0xf0,0x06,0x00,0x00,0x00,0x00,0x00,
55+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x01,0x06,0x00,0x00,0x00,
56+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
57+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
58+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,
59+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x03,
60+
0x00,0x00,0x00,0x00,0x1f,0xfc,0xff,0xff,0x01,0x00,0x00,0x00,0x00,0x00,0xf8,
61+
0x03,0x00,0x00,0x08,0xff,0xe1,0x07,0x00,0x00,0x7f,0x00,0x00,0x00,0x00,0xf8,
62+
0xfb,0x02,0x00,0xf8,0xff,0x01,0x00,0x00,0x00,0x00,0xc0,0x03,0x00,0xe0,0xff,
63+
0x3f,0x7f,0x03,0xc0,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x03,0x80,0x3f,
64+
0x06,0x00,0x80,0x1f,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x01,0x60,
65+
0x0f,0x00,0x00,0x00,0xe0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x01,
66+
0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,
67+
0x1f,0x07,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
68+
0x80,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
69+
0x00,0x00,0x00};

0 commit comments

Comments
 (0)