home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-10-26 | 51.5 KB | 2,035 lines |
- *** /tmp/,RCSt1a05555 Wed Jul 19 20:46:02 1989
- --- moon.c Wed Jul 19 20:29:00 1989
- ***************
- *** 1,5
- /*
- ! * $Header: moon.c,v 2.1 89/05/09 14:19:22 billr Exp $
- */
- /*
- * moon.c
-
- --- 1,5 -----
- /*
- ! * $Header: moon.c,v 2.2 89/07/19 20:28:12 billr Exp $
- */
- /*
- * moon.c
- ***************
- *** 9,15
- * Bill Randle, Tektronix, Inc. to interface to the calentool
- * program.
- */
- ! #include "ct.h" /* for the NO_SUN_MOON #define */
- #ifndef NO_SUN_MOON
-
- /*
-
- --- 9,15 -----
- * Bill Randle, Tektronix, Inc. to interface to the calentool
- * program.
- */
- ! #include "ct.h" /* for the NO_SUN_MOON #define */
- #ifndef NO_SUN_MOON
-
- /*
- ***************
- *** 16,22
-
- A Moon for the Sun
-
- ! Release 2.0
-
- Designed and implemented by John Walker in December 1987,
- revised and updated in February of 1988.
-
- --- 16,22 -----
-
- A Moon for the Sun
-
- ! Release 2.3
-
- Designed and implemented by John Walker in December 1987,
- revised and updated in February of 1988.
- ***************
- *** 20,25
-
- Designed and implemented by John Walker in December 1987,
- revised and updated in February of 1988.
-
- cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect
-
-
- --- 20,26 -----
-
- Designed and implemented by John Walker in December 1987,
- revised and updated in February of 1988.
- + revised and updated again in June of 1988 by Ron Hitchens
-
- Make with:
-
- ***************
- *** 21,26
- Designed and implemented by John Walker in December 1987,
- revised and updated in February of 1988.
-
- cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect
-
- Adding appropriate floating point options to your hardware. This
-
- --- 22,29 -----
- revised and updated in February of 1988.
- revised and updated again in June of 1988 by Ron Hitchens
-
- + Make with:
- +
- cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect
-
- Adding appropriate floating point options to your hardware. This
- ***************
- *** 75,80
- program. Please leave the original attribution information intact so
- that credit and blame may be properly apportioned.
-
- */
-
- /* Astronomical constants */
-
- --- 78,147 -----
- program. Please leave the original attribution information intact so
- that credit and blame may be properly apportioned.
-
- + Revision history:
- +
- + 1.0 11/5/87 First version. Only displayed icon, no
- + open window information display.
- +
- + 2.0 3/27/88 First posting to comp.sources.unix.
- +
- + 2.1 6/16/88 Bug fix. Table of phases didn't update
- + at the moment of the new moon. Call on
- + phasehunt didn't convert civil Julian date
- + to astronomical Julian date. Reported by
- + Dag Bruck (dag@control.lth.se).
- +
- + 2.2 2/27/89 Michael McClary (michael@xanadu.COM)
- + Added moon map, derived from the sun "fullmoon"
- + image file. (It has not been checked for
- + rotation from the correct orientation. Also, a
- + fixed icon doesn't model the librations of the
- + moon as viewed from the earth.) Also: tweaked
- + corners of icon.
- +
- + 2.3 6/7/89 Bug fix. Table of phases skipped the phases
- + for July 1989. This occurred due to sloppy
- + maintenance of the synodic month index in the
- + interchange of information between phasehunt()
- + and meanphase(). I simplified and corrected
- + the handling of the month index as phasehunt()
- + steps along and removed unneeded code from
- + meanphase(). Reported by Bill Randle of
- + Tektronix, Inc. (billr@saab.CNA.TEK.COM).
- +
- + Additional History:
- +
- + June 1988 Modified by Ron Hitchens to produce version 2.1
- + modified icon generation to show surface texture
- + on visible moon face. Eliminated "illegal" direct
- + modification of icon image memory.
- + added a menu to allow switching in and out of
- + test mode, for entertainment value mostly.
- + reworked timer behaviour so that process doesn't
- + wake up unnecessarily.
- + trap sigwinch signals to notice more easily when the
- + tool opens and closes.
- + modified layout of information in open window display
- + to reduce the amount of pixels modified in each
- + update. Batched pixwin updates so that only one
- + screen rasterop per cycle is done.
- + changed open window to display white-on-black for a
- + more aesthetic look, and to suggest the effect of
- + looking at the moon in the nighttime sky.
- + setup default tool and canvas colors to be the same
- + as B&W monochrome, for those us lucky enough to have
- + color monitors and who have the default monochrome
- + colors set to something other than B&W (I like white
- + on dark blue myself)
- + various code reformatting and pretty-printing to suit
- + my own coding taste (I got a bit carried away).
- + code tweaking to make lint happy.
- + returned my hacked version to John.
- +
- + Ron Hitchens
- + ronbo@vixen.uucp
- + ...!uunet!cs.utexas.edu!vixen!ronbo
- + hitchens@cs.utexas.edu
- */
-
-
- ***************
- *** 77,82
-
- */
-
- /* Astronomical constants */
-
- #define epoch 2444238.5 /* 1980 January 0.0 */
-
- --- 144,167 -----
- hitchens@cs.utexas.edu
- */
-
- +
- + #include <stdio.h>
- + #include <math.h>
- + #include <sys/time.h>
- +
- + #include <suntool/sunview.h>
- + #include <suntool/canvas.h>
- +
- + #define TINYFONT "/usr/lib/fonts/fixedwidthfonts/screen.r.7"
- +
- + /*
- + * define standard B/W monochrome colors as defaults in case we're running
- + * on a color system with the monochrome colors set differently
- + */
- + #define FG_DEFAULT { 0, 0, 0 } /* black */
- + #define BG_DEFAULT { 255, 255, 255 } /* white */
- +
- +
- /* Astronomical constants */
-
- #define epoch 2444238.5 /* 1980 January 0.0 */
- ***************
- *** 80,86
- /* Astronomical constants */
-
- #define epoch 2444238.5 /* 1980 January 0.0 */
- ! #define J1970 2440587.5 /* VAX clock Epoch 1970 Jan 1 (0h UT) */
-
- /* Constants defining the Sun's apparent orbit */
-
-
- --- 165,171 -----
- /* Astronomical constants */
-
- #define epoch 2444238.5 /* 1980 January 0.0 */
- ! #define J1970 2440587.5 /* VAX clock Epoch 1970 Jan 1 (0h UT) */
-
- /* Constants defining the Sun's apparent orbit */
-
- ***************
- *** 114,122
-
- #define earthrad 6378.16 /* Radius of Earth in kilometres */
-
- - #include <stdio.h>
- - #include <math.h>
- - #include <sys/time.h>
-
- #include <suntool/sunview.h>
- #include <suntool/canvas.h>
-
- --- 199,204 -----
-
- #define earthrad 6378.16 /* Radius of Earth in kilometres */
-
-
- #define PI 3.14159265358979323846 /* Assume not near black hole nor in
- Tennessee */
- ***************
- *** 118,174
- #include <math.h>
- #include <sys/time.h>
-
- - #include <suntool/sunview.h>
- - #include <suntool/canvas.h>
- -
- - /* Icon definition. This is just a black field with rounded corners
- - that blend into the root desktop pattern. The image of the moon and
- - the text are added by the program later. */
- -
- - static short moon_img[64][4] = {
- - /* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 */
- - 0x8FFF,0xFFFF,0xFFFF,0xFFE8,0x9FFF,0xFFFF,0xFFFF,0xFFF8,
- - 0x3FFF,0xFFFF,0xFFFF,0xFFFE,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
- - 0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xBFFF,0xFFFF,0xFFFF,0xFFFC,
- - 0x3FFF,0xFFFF,0xFFFF,0xFFFA,0x27FF,0xFFFF,0xFFFF,0xFFE2
- - };
- - DEFINE_ICON_FROM_IMAGE(moon_icon, moon_img);
- - mpr_static(icon_mpr, 64, 64, 1, moon_img);
- -
- - extern Canvas mcanvas;
- - extern Pixfont *font;
- - extern char *monthnames[];
- - static Pixwin *cpw;
- - static int charhgt, charwid;
- -
- #define PI 3.14159265358979323846 /* Assume not near black hole nor in
- Tennessee */
-
-
- --- 200,205 -----
- #define earthrad 6378.16 /* Radius of Earth in kilometres */
-
-
- #define PI 3.14159265358979323846 /* Assume not near black hole nor in
- Tennessee */
-
- ***************
- *** 182,188
- #define dsin(x) (sin(torad((x)))) /* Sin from deg */
- #define dcos(x) (cos(torad((x)))) /* Cos from deg */
-
- - /* Forward functions */
-
- double jtime(), phase();
- void phasehunt();
-
- --- 213,218 -----
- #define dsin(x) (sin(torad((x)))) /* Sin from deg */
- #define dcos(x) (cos(torad((x)))) /* Cos from deg */
-
-
- /*
- * Moon image. This is a standard icon-sized picture of the moon's face.
- ***************
- *** 184,192
-
- /* Forward functions */
-
- ! double jtime(), phase();
- ! void phasehunt();
- ! void drawmoon(), jyear(), jhms();
-
-
- /* DRAWMOON -- Construct icon for moon, given phase of moon. */
-
- --- 214,224 -----
- #define dcos(x) (cos(torad((x)))) /* Cos from deg */
-
-
- ! /*
- ! * Moon image. This is a standard icon-sized picture of the moon's face.
- ! * The visible part, as calculated by the current time, is extracted from
- ! * this image to create the displayed image.
- ! */
-
- static short moon_img [] = {
- #include "moon.icon"
- ***************
- *** 188,193
- void phasehunt();
- void drawmoon(), jyear(), jhms();
-
-
- /* DRAWMOON -- Construct icon for moon, given phase of moon. */
-
-
- --- 220,229 -----
- * this image to create the displayed image.
- */
-
- + static short moon_img [] = {
- + #include "moon.icon"
- + };
- + mpr_static(moon_mpr, 64, 64, 1, moon_img);
-
- extern Pixfont *font; /* pointer to regular icon font */
- extern Pixfont *sfont; /* pointer to tiny icon font */
- ***************
- *** 189,195
- void drawmoon(), jyear(), jhms();
-
-
- ! /* DRAWMOON -- Construct icon for moon, given phase of moon. */
-
- static void drawmoon(ph)
- double ph;
-
- --- 225,239 -----
- };
- mpr_static(moon_mpr, 64, 64, 1, moon_img);
-
- ! extern Pixfont *font; /* pointer to regular icon font */
- ! extern Pixfont *sfont; /* pointer to tiny icon font */
- ! extern Canvas mcanvas; /* handle for the canvas */
- ! extern char *monthnames[];
- ! static Pixrect *icon_mpr; /* actual displayed pixrect */
- ! static Pixwin *cpw; /* pointer to the canvas' pixwin */
- ! static int charhgt, charwid; /* default std font height/width */
- ! static int info_col;
- ! static struct timezone tzp;
-
- static char *labels [] = {
- "Moon phase:",
- ***************
- *** 191,198
-
- /* DRAWMOON -- Construct icon for moon, given phase of moon. */
-
- ! static void drawmoon(ph)
- ! double ph;
- {
- int i, j, lx, rx;
- int lb[4];
-
- --- 235,265 -----
- static int info_col;
- static struct timezone tzp;
-
- ! static char *labels [] = {
- ! "Moon phase:",
- ! "Age of moon:",
- ! "Moon's distance:",
- ! "Moon subtends:",
- ! "Last new moon:",
- ! "First quarter:",
- ! "Full moon:",
- ! "Last quarter:",
- ! "Next new moon:"
- ! };
- !
- ! /* Forward functions */
- ! static double jtime(), phase();
- ! static void phasehunt(), set_mode();
- ! static void drawmoon(), jyear(), jhms();
- !
- !
- ! /*
- ! * DRAWMOON -- Construct icon for moon, given phase of moon.
- ! */
- !
- ! static void drawmoon (ph, src_pr, dst_pr)
- ! double ph;
- ! Pixrect *src_pr, *dst_pr;
- {
- register int i, lx, rx;
- register double cp, xscale;
- ***************
- *** 194,202
- static void drawmoon(ph)
- double ph;
- {
- ! int i, j, lx, rx;
- ! int lb[4];
- ! double cp, xscale;
-
- xscale = cos(2 * PI * ph);
- for (i = 0; i < 24; i++) {
-
- --- 261,272 -----
- double ph;
- Pixrect *src_pr, *dst_pr;
- {
- ! register int i, lx, rx;
- ! register double cp, xscale;
- ! #define RADIUS 27.0
- ! #define IRADIUS 27
- ! #define OFFSET 28
- ! #define CENTER 32
-
- /* Clear the destination pixrect to all one-bits (black) */
- pr_rop (dst_pr, 0, 0, 64, 64, PIX_SET, (Pixrect *)0, 0, 0);
- ***************
- *** 198,219
- int lb[4];
- double cp, xscale;
-
- ! xscale = cos(2 * PI * ph);
- ! for (i = 0; i < 24; i++) {
- ! lb[0] = lb[1] = lb[2] = lb[3] = 0xFFFF;
- ! cp = 24.0 * cos(asin(i / 24.0));
- ! if (ph < 0.5) {
- ! rx = 32 + cp;
- ! lx = 32 + xscale * cp;
- ! } else {
- ! lx = 33 - cp;
- ! rx = 33 - xscale * cp;
- ! }
- ! for (j = lx; j <= rx; j++) {
- ! lb[j >> 4] &= (0x8000 >> (j & 0xF)) ^ 0xFFFF;
- ! }
- ! for (j = 0; j < 4; j++)
- ! moon_img[28 + i][j] = moon_img[28 - i][j] = lb[j];
- }
- }
-
-
- --- 268,298 -----
- #define OFFSET 28
- #define CENTER 32
-
- ! /* Clear the destination pixrect to all one-bits (black) */
- ! pr_rop (dst_pr, 0, 0, 64, 64, PIX_SET, (Pixrect *)0, 0, 0);
- !
- ! xscale = cos (2 * PI * ph);
- ! for (i = 0; i < IRADIUS; i++) {
- ! cp = RADIUS * cos (asin (i / RADIUS));
- ! if (ph < 0.5) {
- ! rx = CENTER + cp;
- ! lx = CENTER + xscale * cp;
- ! } else {
- ! lx = CENTER - cp;
- ! rx = CENTER - xscale * cp;
- ! }
- !
- ! /*
- ! * We now know the left and right endpoints of the scan line
- ! * for this y coordinate. We raster-op the corresponding
- ! * scanlines from the source pixrect to the destination
- ! * pixrect, offsetting to properly place it in the pixrect and
- ! * reflecting vertically.
- ! */
- ! pr_rop (dst_pr, lx, OFFSET + i, (rx - lx) + 1, 1, PIX_SRC,
- ! src_pr, lx, OFFSET + i);
- ! pr_rop (dst_pr, lx, OFFSET - i, (rx - lx) + 1, 1, PIX_SRC,
- ! src_pr, lx, OFFSET - i);
- }
- }
-
- ***************
- *** 217,222
- }
- }
-
- /* MOON_DATA -- print useful info about the moon */
-
- moon_data(seconds)
-
- --- 296,307 -----
- }
- }
-
- + #define prt(y) pw_text(cpw, info_col, charhgt*(y), PIX_SRC, font, tbuf)
- + #define prtxy(x,y) pw_text(cpw, charwid*(y+1), charhgt*(x), PIX_SRC,\
- + font,tbuf)
- + #define EPL(x) (x), (x) == 1 ? "" : "s"
- + #define APOS(x) (x + 11)
- +
- /* MOON_DATA -- print useful info about the moon */
-
- moon_data(seconds)
- ***************
- *** 222,238
- moon_data(seconds)
- long seconds;
- {
- ! int lunation, wclosed;
- ! long t;
- ! double jd, p, aom, cphase, cdist, cangdia, csund, csuang, lptime;
- ! double phasar[5];
- ! struct pr_prpos tloc;
- ! char amsg[12], tbuf[80];
- ! static double faketime = 0.0;
- ! static short moonilast[64][4] = {0};
- ! int yy, mm, dd, hh, mmm, ss;
- ! Pixfont *pfont;
- ! struct tm *gm, *ltm, *localtime();
- struct timeval tvp;
- struct timezone tzp;
- long clock;
-
- --- 307,320 -----
- moon_data(seconds)
- long seconds;
- {
- ! int lunation, wclosed;
- ! int i, yy, mm, dd, hh, mmm, ss;
- ! int aom_d, aom_h, aom_m;
- ! long t;
- ! double jd, p, aom, cphase, cdist, cangdia, csund, csuang;
- ! double phasar [5];
- ! char tbuf[80];
- ! struct tm *gm, *ltm, *localtime();
- struct timeval tvp;
- struct pr_prpos tloc;
- struct pr_size txt_size;
- ***************
- *** 234,240
- Pixfont *pfont;
- struct tm *gm, *ltm, *localtime();
- struct timeval tvp;
- ! struct timezone tzp;
- long clock;
- char *atp, *asctime();
-
-
- --- 316,323 -----
- char tbuf[80];
- struct tm *gm, *ltm, *localtime();
- struct timeval tvp;
- ! struct pr_prpos tloc;
- ! struct pr_size txt_size;
- long clock;
- char *atp, *asctime();
-
- ***************
- *** 238,245
- long clock;
- char *atp, *asctime();
-
- !
- ! pfont = pf_open("/usr/lib/fonts/fixedwidthfonts/screen.r.7");
- cpw = canvas_pixwin(mcanvas);
- charwid = font->pf_defaultsize.x;
- charhgt = font->pf_defaultsize.y;
-
- --- 321,328 -----
- long clock;
- char *atp, *asctime();
-
- ! icon_mpr = mem_create (64, 64, 1);
- ! pr_rop (icon_mpr, 0, 0, 64, 64, PIX_SRC, &moon_mpr, 0, 0);
- cpw = canvas_pixwin(mcanvas);
- charwid = font->pf_defaultsize.x;
- charhgt = font->pf_defaultsize.y;
- ***************
- *** 243,249
- cpw = canvas_pixwin(mcanvas);
- charwid = font->pf_defaultsize.x;
- charhgt = font->pf_defaultsize.y;
- ! jd = jtime((gm = gmtime(&seconds)));
- gettimeofday(&tvp, &tzp); /* for timezone info */
- p = phase(jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
- drawmoon(p);
-
- --- 326,333 -----
- cpw = canvas_pixwin(mcanvas);
- charwid = font->pf_defaultsize.x;
- charhgt = font->pf_defaultsize.y;
- ! info_col = charwid * 20;
- ! jd = jtime ((gm = gmtime (&seconds)));
- gettimeofday(&tvp, &tzp); /* for timezone info */
- p = phase (jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
- aom_d = (int) aom;
- ***************
- *** 245,258
- charhgt = font->pf_defaultsize.y;
- jd = jtime((gm = gmtime(&seconds)));
- gettimeofday(&tvp, &tzp); /* for timezone info */
- ! p = phase(jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
- ! drawmoon(p);
- ! sprintf(amsg, " %dd %dh ",
- ! (int) aom, ((int) (24 * (aom - floor(aom)))));
- ! tloc.pr = (Pixrect *) icon_get(&moon_icon, ICON_IMAGE);
- ! tloc.pos.x = 2;
- ! tloc.pos.y = 62;
- ! pf_text(tloc, PIX_NOT(PIX_SRC), pfont, amsg);
-
- /* Only update icon if it changed (this eliminates gratuitous
- flashing of the icon on-screen). */
-
- --- 329,338 -----
- info_col = charwid * 20;
- jd = jtime ((gm = gmtime (&seconds)));
- gettimeofday(&tvp, &tzp); /* for timezone info */
- ! p = phase (jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
- ! aom_d = (int) aom;
- ! aom_h = (int) (24 * (aom - floor(aom)));
- ! aom_m = (int) (1440 * (aom - floor(aom))) % 60;
-
- drawmoon(p, &moon_mpr, icon_mpr);
-
- ***************
- *** 254,261
- tloc.pos.y = 62;
- pf_text(tloc, PIX_NOT(PIX_SRC), pfont, amsg);
-
- ! /* Only update icon if it changed (this eliminates gratuitous
- ! flashing of the icon on-screen). */
-
- if (bcmp(moonilast, moon_img, sizeof moon_img) != 0)
- bcopy(moon_img, moonilast, sizeof moon_img);
-
- --- 334,340 -----
- aom_h = (int) (24 * (aom - floor(aom)));
- aom_m = (int) (1440 * (aom - floor(aom))) % 60;
-
- ! drawmoon(p, &moon_mpr, icon_mpr);
-
- if (aom_d == 0) {
- (void)sprintf(tbuf, "%dh %dm", aom_h, aom_m);
- ***************
- *** 257,264
- /* Only update icon if it changed (this eliminates gratuitous
- flashing of the icon on-screen). */
-
- ! if (bcmp(moonilast, moon_img, sizeof moon_img) != 0)
- ! bcopy(moon_img, moonilast, sizeof moon_img);
-
- /* Update textual information for open window */
-
-
- --- 336,351 -----
-
- drawmoon(p, &moon_mpr, icon_mpr);
-
- ! if (aom_d == 0) {
- ! (void)sprintf(tbuf, "%dh %dm", aom_h, aom_m);
- ! } else {
- ! (void)sprintf(tbuf, "%dd %dh", aom_d, aom_h);
- ! }
- ! txt_size = pf_textwidth (strlen (tbuf), sfont, tbuf);
- ! tloc.pos.x = (64 - txt_size.x) / 2;
- ! tloc.pos.y = 63;
- ! tloc.pr = icon_mpr;
- ! pf_text (tloc, PIX_NOT(PIX_SRC), sfont, tbuf);
-
- /* Update textual information for open window */
-
- ***************
- *** 262,269
-
- /* Update textual information for open window */
-
- ! #define prt(x) pw_text(cpw, charwid, charhgt * (x), PIX_SRC, font, tbuf)
- ! #define prtxy(x,y) pw_text(cpw,charwid*(y+1),charhgt*(x),PIX_SRC,font,tbuf)
-
- sprintf(tbuf, "Moon phase: %d%% [0%% = New, 100%% = Full] ",
- (int) (cphase * 100));
-
- --- 349,356 -----
-
- /* Update textual information for open window */
-
- ! /* start batching updates to the pixwin */
- ! pw_batch_on (cpw);
-
- paint_labels();
- /* moon phase */
- ***************
- *** 265,272
- #define prt(x) pw_text(cpw, charwid, charhgt * (x), PIX_SRC, font, tbuf)
- #define prtxy(x,y) pw_text(cpw,charwid*(y+1),charhgt*(x),PIX_SRC,font,tbuf)
-
- ! sprintf(tbuf, "Moon phase: %d%% [0%% = New, 100%% = Full] ",
- ! (int) (cphase * 100));
- prt(1);
-
- /* Information about the Moon */
-
- --- 352,361 -----
- /* start batching updates to the pixwin */
- pw_batch_on (cpw);
-
- ! paint_labels();
- ! /* moon phase */
- ! (void)sprintf (tbuf, "%d%% [0%% = New, 100%% = Full] ",
- ! (int) (cphase * 100));
- prt(1);
-
- /* Information about the Moon */
- ***************
- *** 271,281
-
- /* Information about the Moon */
-
- ! #define EPL(x) (x), (x) == 1 ? "" : "s"
- ! sprintf(tbuf,
- ! "Age of moon: %d day%s, %d hour%s, %d minute%s. ",
- ! EPL((int) aom), EPL(((int) (24 * (aom - floor(aom))))),
- ! EPL(((int) (1440 * (aom - floor(aom)))) % 60));
- prt(2);
- sprintf(tbuf,
- "Moon's distance: %ld kilometres, %.1f Earth radii. ",
-
- --- 360,368 -----
-
- /* Information about the Moon */
-
- ! /* age of moon */
- ! (void)sprintf (tbuf, "%d day%s, %d hour%s, %d minute%s. ",
- ! EPL(aom_d), EPL(aom_h), EPL(aom_m));
- prt(2);
-
- /* moon distance */
- ***************
- *** 277,285
- EPL((int) aom), EPL(((int) (24 * (aom - floor(aom))))),
- EPL(((int) (1440 * (aom - floor(aom)))) % 60));
- prt(2);
- ! sprintf(tbuf,
- ! "Moon's distance: %ld kilometres, %.1f Earth radii. ",
- ! (long) cdist, cdist / earthrad);
- prt(3);
- sprintf(tbuf,
- "Moon subtends: %.4f degrees. ", cangdia);
-
- --- 364,373 -----
- (void)sprintf (tbuf, "%d day%s, %d hour%s, %d minute%s. ",
- EPL(aom_d), EPL(aom_h), EPL(aom_m));
- prt(2);
- !
- ! /* moon distance */
- ! (void)sprintf (tbuf, "%ld kilometres, %.1f Earth radii. ",
- ! (long) cdist, cdist / earthrad);
- prt(3);
-
- /* moon subtends */
- ***************
- *** 281,288
- "Moon's distance: %ld kilometres, %.1f Earth radii. ",
- (long) cdist, cdist / earthrad);
- prt(3);
- ! sprintf(tbuf,
- ! "Moon subtends: %.4f degrees. ", cangdia);
- prt(4);
- /* Draw the moon icon in the text window */
- pw_rop(cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC,
-
- --- 369,377 -----
- (void)sprintf (tbuf, "%ld kilometres, %.1f Earth radii. ",
- (long) cdist, cdist / earthrad);
- prt(3);
- !
- ! /* moon subtends */
- ! (void)sprintf (tbuf, "%.4f degrees. ", cangdia);
- prt(4);
-
- /* paint the moon's image in the upper right of the canvas */
- ***************
- *** 284,292
- sprintf(tbuf,
- "Moon subtends: %.4f degrees. ", cangdia);
- prt(4);
- - /* Draw the moon icon in the text window */
- - pw_rop(cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC,
- - &icon_mpr, 0, 0);
-
-
- /* Calculate times of phases of this lunation. */
-
- --- 373,378 -----
- /* moon subtends */
- (void)sprintf (tbuf, "%.4f degrees. ", cangdia);
- prt(4);
-
- /* paint the moon's image in the upper right of the canvas */
- pw_rop (cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC, icon_mpr, 0, 0);
- ***************
- *** 288,293
- pw_rop(cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC,
- &icon_mpr, 0, 0);
-
-
- /* Calculate times of phases of this lunation. */
-
-
- --- 374,381 -----
- (void)sprintf (tbuf, "%.4f degrees. ", cangdia);
- prt(4);
-
- + /* paint the moon's image in the upper right of the canvas */
- + pw_rop (cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC, icon_mpr, 0, 0);
-
- /*
- * Calculate times of phases of this lunation.
- ***************
- *** 289,295
- &icon_mpr, 0, 0);
-
-
- ! /* Calculate times of phases of this lunation. */
-
- #define APOS(x) (x + 11)
- phasehunt(jd, phasar);
-
- --- 377,386 -----
- /* paint the moon's image in the upper right of the canvas */
- pw_rop (cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC, icon_mpr, 0, 0);
-
- ! /*
- ! * Calculate times of phases of this lunation.
- ! */
- ! phasehunt(jd + 0.5, phasar);
-
- for (i = 0; i < 5; i++) {
- fmt_phase_time (phasar[i], tbuf);
- ***************
- *** 291,310
-
- /* Calculate times of phases of this lunation. */
-
- ! #define APOS(x) (x + 11)
- ! phasehunt(jd, phasar);
- ! lptime = phasar[0];
- ! lunation = floor(((lptime + 7) - lunatbase) / synmonth) + 1;
- ! /* convert to seconds local time, so we can use localtime()
- ! to handle dst calculations */
- ! clock = (long)((lptime - J1970) * 24. * 3600.);
- ! ltm = localtime(&clock);
- ! sprintf(tbuf,
- ! "Last new moon: %02d:%02d %s %2d %s %d ",
- ! ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- ! prt(APOS(0));
- ! sprintf(tbuf, "Lunation %d ", lunation);
- ! prtxy(APOS(0), 52);
-
- lptime = phasar[1];
- /* convert to seconds local time, so we can use localtime()
-
- --- 382,391 -----
- */
- phasehunt(jd + 0.5, phasar);
-
- ! for (i = 0; i < 5; i++) {
- ! fmt_phase_time (phasar[i], tbuf);
- ! prt(APOS(i));
- ! }
-
- lunation = floor(((phasar[0] + 7) - lunatbase) / synmonth) + 1;
- (void)sprintf(tbuf, "Lunation %d ", lunation);
- ***************
- *** 306,320
- sprintf(tbuf, "Lunation %d ", lunation);
- prtxy(APOS(0), 52);
-
- ! lptime = phasar[1];
- ! /* convert to seconds local time, so we can use localtime()
- ! to handle dst calculations */
- ! clock = (long)((lptime - J1970) * 24. * 3600.);
- ! ltm = localtime(&clock);
- ! sprintf(tbuf,
- ! "First quarter: %02d:%02d %s %2d %s %d ",
- ! ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- ! prt(APOS(1));
-
- lptime = phasar[2];
- /* convert to seconds local time, so we can use localtime()
-
- --- 387,397 -----
- prt(APOS(i));
- }
-
- ! lunation = floor(((phasar[0] + 7) - lunatbase) / synmonth) + 1;
- ! (void)sprintf(tbuf, "Lunation %d ", lunation);
- ! prtxy(APOS(0), 49);
- ! (void)sprintf(tbuf, "Lunation %d ", lunation + 1);
- ! prtxy(APOS(4), 49);
-
- /* flush the pixwin updates to the screen */
- pw_batch_off (cpw);
- ***************
- *** 316,330
- ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- prt(APOS(1));
-
- ! lptime = phasar[2];
- ! /* convert to seconds local time, so we can use localtime()
- ! to handle dst calculations */
- ! clock = (long)((lptime - J1970) * 24. * 3600.);
- ! ltm = localtime(&clock);
- ! sprintf(tbuf,
- ! "Full moon: %02d:%02d %s %2d %s %d ",
- ! ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- ! prt(APOS(2));
-
- lptime = phasar[3];
- /* convert to seconds local time, so we can use localtime()
-
- --- 393,400 -----
- (void)sprintf(tbuf, "Lunation %d ", lunation + 1);
- prtxy(APOS(4), 49);
-
- ! /* flush the pixwin updates to the screen */
- ! pw_batch_off (cpw);
-
- return;
- }
- ***************
- *** 326,340
- ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- prt(APOS(2));
-
- ! lptime = phasar[3];
- ! /* convert to seconds local time, so we can use localtime()
- ! to handle dst calculations */
- ! clock = (long)((lptime - J1970) * 24. * 3600.);
- ! ltm = localtime(&clock);
- ! sprintf(tbuf,
- ! "Last quarter: %02d:%02d %s %2d %s %d ",
- ! ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- ! prt(APOS(3));
-
- lptime = phasar[4];
- /* convert to seconds local time, so we can use localtime()
-
- --- 396,404 -----
- /* flush the pixwin updates to the screen */
- pw_batch_off (cpw);
-
- ! return;
- ! }
- ! #undef APOS
-
-
- /*
- ***************
- *** 336,342
- ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- prt(APOS(3));
-
- ! lptime = phasar[4];
- /* convert to seconds local time, so we can use localtime()
- to handle dst calculations */
- clock = (long)rint((lptime - J1970) * 24. * 3600.);
-
- --- 400,418 -----
- }
- #undef APOS
-
- !
- ! /*
- ! * FMT_PHASE_TIME -- Format the provided julian date into the provided buffer
- ! * in local time format for screen display
- ! */
- !
- ! fmt_phase_time (utime, buf)
- ! double utime;
- ! char *buf;
- ! {
- ! long clock;
- ! struct tm *ltm, *localtime();
- !
- /* convert to seconds local time, so we can use localtime()
- to handle dst calculations */
- clock = (long)((utime - J1970) * 24. * 3600.);
- ***************
- *** 339,345
- lptime = phasar[4];
- /* convert to seconds local time, so we can use localtime()
- to handle dst calculations */
- ! clock = (long)rint((lptime - J1970) * 24. * 3600.);
- ltm = localtime(&clock);
- sprintf(tbuf,
- "Next new moon: %02d:%02d %s %2d %s %d ",
-
- --- 415,421 -----
-
- /* convert to seconds local time, so we can use localtime()
- to handle dst calculations */
- ! clock = (long)((utime - J1970) * 24. * 3600.);
- ltm = localtime(&clock);
- (void)sprintf (buf, " %02d:%02d %s %2d %s %d ",
- ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- ***************
- *** 341,353
- to handle dst calculations */
- clock = (long)rint((lptime - J1970) * 24. * 3600.);
- ltm = localtime(&clock);
- ! sprintf(tbuf,
- ! "Next new moon: %02d:%02d %s %2d %s %d ",
- ! ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- ! prt(APOS(4));
- ! sprintf(tbuf, "Lunation %d ", lunation + 1);
- ! prtxy(APOS(4), 52);
- ! #undef APOS
- }
-
- /* JDATE -- Convert internal GMT date and time to Julian day
-
- --- 417,424 -----
- to handle dst calculations */
- clock = (long)((utime - J1970) * 24. * 3600.);
- ltm = localtime(&clock);
- ! (void)sprintf (buf, " %02d:%02d %s %2d %s %d ",
- ! ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- }
-
-
- ***************
- *** 350,357
- #undef APOS
- }
-
- - /* JDATE -- Convert internal GMT date and time to Julian day
- - and fraction. */
-
- static long jdate(t)
- struct tm *t;
-
- --- 421,426 -----
- ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
- }
-
-
- /*
- * PAINT_LABELS -- Draw the labels into the canvas (open) window and right
- ***************
- *** 353,360
- /* JDATE -- Convert internal GMT date and time to Julian day
- and fraction. */
-
- ! static long jdate(t)
- ! struct tm *t;
- {
- long c, m, y;
-
-
- --- 422,435 -----
- }
-
-
- ! /*
- ! * PAINT_LABELS -- Draw the labels into the canvas (open) window and right
- ! * justify them. Done once at startup. We paint the labels
- ! * separately to minimize the amount of screen real-estate
- ! * being modified on each update.
- ! */
- !
- ! paint_labels ()
- {
- int i;
-
- ***************
- *** 356,362
- static long jdate(t)
- struct tm *t;
- {
- ! long c, m, y;
-
- y = t->tm_year + 1900;
- m = t->tm_mon + 1;
-
- --- 431,437 -----
-
- paint_labels ()
- {
- ! int i;
-
- for (i = 0; i < 4; i++) {
- pw_text (cpw, charwid * (17 - strlen (labels [i])),
- ***************
- *** 358,363
- {
- long c, m, y;
-
- y = t->tm_year + 1900;
- m = t->tm_mon + 1;
- if (m > 2)
-
- --- 433,463 -----
- {
- int i;
-
- + for (i = 0; i < 4; i++) {
- + pw_text (cpw, charwid * (17 - strlen (labels [i])),
- + charhgt * (i + 1), PIX_SRC,
- + font, labels[i]);
- + }
- + for (i = 4; i < 9; i++) {
- + pw_text (cpw, charwid * (17 - strlen (labels [i])),
- + charhgt * (i + 7), PIX_SRC,
- + font, labels[i]);
- + }
- + }
- +
- +
- + /*
- + * JDATE -- Convert internal GMT date and time to Julian day
- + * and fraction.
- + */
- +
- + static
- + long
- + jdate (t)
- + struct tm *t;
- + {
- + long c, m, y;
- +
- y = t->tm_year + 1900;
- m = t->tm_mon + 1;
- if (m > 2) {
- ***************
- *** 360,370
-
- y = t->tm_year + 1900;
- m = t->tm_mon + 1;
- ! if (m > 2)
- ! m = m - 3;
- ! else {
- ! m = m + 9;
- ! y--;
- }
- c = y / 100L; /* Compute century */
- y -= 100L * c;
-
- --- 460,470 -----
-
- y = t->tm_year + 1900;
- m = t->tm_mon + 1;
- ! if (m > 2) {
- ! m = m - 3;
- ! } else {
- ! m = m + 9;
- ! y--;
- }
- c = y / 100L; /* Compute century */
- y -= 100L * c;
- ***************
- *** 368,375
- }
- c = y / 100L; /* Compute century */
- y -= 100L * c;
- ! return t->tm_mday + (c * 146097L) / 4 + (y * 1461L) / 4 +
- ! (m * 153L + 2) / 5 + 1721119L;
- }
-
- /* JTIME -- Convert internal GMT date and time to astronomical Julian
-
- --- 468,475 -----
- }
- c = y / 100L; /* Compute century */
- y -= 100L * c;
- ! return (t->tm_mday + (c * 146097L) / 4 + (y * 1461L) / 4 +
- ! (m * 153L + 2) / 5 + 1721119L);
- }
-
-
- ***************
- *** 372,380
- (m * 153L + 2) / 5 + 1721119L;
- }
-
- - /* JTIME -- Convert internal GMT date and time to astronomical Julian
- - time (i.e. Julian date plus day fraction, expressed as
- - a double). */
-
- static double jtime(t)
- struct tm *t;
-
- --- 472,477 -----
- (m * 153L + 2) / 5 + 1721119L);
- }
-
-
- /*
- * JTIME -- Convert internal GMT date and time to astronomical Julian
- ***************
- *** 376,383
- time (i.e. Julian date plus day fraction, expressed as
- a double). */
-
- ! static double jtime(t)
- ! struct tm *t;
- {
- return (jdate(t) - 0.5) +
- (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
-
- --- 473,488 -----
- }
-
-
- ! /*
- ! * JTIME -- Convert internal GMT date and time to astronomical Julian
- ! * time (i.e. Julian date plus day fraction, expressed as
- ! * a double).
- ! */
- !
- ! static
- ! double
- ! jtime (t)
- ! struct tm *t;
- {
- return (jdate (t) - 0.5) +
- (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
- ***************
- *** 379,385
- static double jtime(t)
- struct tm *t;
- {
- ! return (jdate(t) - 0.5) +
- (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
- }
-
-
- --- 484,490 -----
- jtime (t)
- struct tm *t;
- {
- ! return (jdate (t) - 0.5) +
- (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
- }
-
- ***************
- *** 383,390
- (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
- }
-
- - /* JYEAR -- Convert Julian date to year, month, day, which are
- - returned via integer pointers to integers. */
-
- static void jyear(td, yy, mm, dd)
- double td;
-
- --- 488,493 -----
- (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
- }
-
-
- /*
- * JYEAR -- Convert Julian date to year, month, day, which are
- ***************
- *** 386,394
- /* JYEAR -- Convert Julian date to year, month, day, which are
- returned via integer pointers to integers. */
-
- ! static void jyear(td, yy, mm, dd)
- ! double td;
- ! int *yy, *mm, *dd;
- {
- double j, d, y, m;
-
-
- --- 489,504 -----
- }
-
-
- ! /*
- ! * JYEAR -- Convert Julian date to year, month, day, which are
- ! * returned via integer pointers to integers.
- ! */
- !
- ! static
- ! void
- ! jyear (td, yy, mm, dd)
- ! double td;
- ! int *yy, *mm, *dd;
- {
- double j, d, y, m;
-
- ***************
- *** 392,398
- {
- double j, d, y, m;
-
- ! td += 0.5; /* Astronomical to civil */
- j = floor(td);
- j = j - 1721119.0;
- y = floor(((4 * j) - 1) / 146097.0);
-
- --- 502,508 -----
- {
- double j, d, y, m;
-
- ! td += 0.5; /* Astronomical to civil */
- j = floor(td);
- j = j - 1721119.0;
- y = floor(((4 * j) - 1) / 146097.0);
- ***************
- *** 406,412
- d = floor((d + 5.0) / 5.0);
- y = (100.0 * y) + j;
- if (m < 10.0)
- ! m = m + 3;
- else {
- m = m - 9;
- y = y + 1;
-
- --- 516,522 -----
- d = floor((d + 5.0) / 5.0);
- y = (100.0 * y) + j;
- if (m < 10.0)
- ! m = m + 3;
- else {
- m = m - 9;
- y = y + 1;
- ***************
- *** 408,415
- if (m < 10.0)
- m = m + 3;
- else {
- ! m = m - 9;
- ! y = y + 1;
- }
- *yy = y;
- *mm = m;
-
- --- 518,525 -----
- if (m < 10.0)
- m = m + 3;
- else {
- ! m = m - 9;
- ! y = y + 1;
- }
- *yy = y;
- *mm = m;
- ***************
- *** 416,422
- *dd = d;
- }
-
- - /* JHMS -- Convert Julian time to hour, minutes, and seconds. */
-
- static void jhms(j, h, m, s)
- double j;
-
- --- 526,531 -----
- *dd = d;
- }
-
-
- /*
- * JHMS -- Convert Julian time to hour, minutes, and seconds.
- ***************
- *** 418,426
-
- /* JHMS -- Convert Julian time to hour, minutes, and seconds. */
-
- ! static void jhms(j, h, m, s)
- ! double j;
- ! int *h, *m, *s;
- {
- long ij;
-
-
- --- 527,541 -----
- }
-
-
- ! /*
- ! * JHMS -- Convert Julian time to hour, minutes, and seconds.
- ! */
- !
- ! static
- ! void
- ! jhms(j, h, m, s)
- ! double j;
- ! int *h, *m, *s;
- {
- long ij;
-
- ***************
- *** 424,430
- {
- long ij;
-
- ! j += 0.5; /* Astronomical to civil */
- ij = (j - floor(j)) * 86400.0;
- *h = ij / 3600L;
- *m = (ij / 60L) % 60L;
-
- --- 539,545 -----
- {
- long ij;
-
- ! j += 0.5; /* Astronomical to civil */
- ij = (j - floor(j)) * 86400.0;
- *h = ij / 3600L;
- *m = (ij / 60L) % 60L;
- ***************
- *** 431,447
- *s = ij % 60L;
- }
-
- - /* MEANPHASE -- Calculates mean phase of the Moon for a given
- - base date and desired phase:
- - 0.0 New Moon
- - 0.25 First quarter
- - 0.5 Full moon
- - 0.75 Last quarter
- - Beware!!! This routine returns meaningless
- - results for any other phase arguments. Don't
- - attempt to generalise it without understanding
- - that the motion of the moon is far more complicated
- - that this calculation reveals. */
-
- static double meanphase(sdate, phase, usek)
- double sdate, phase;
-
- --- 546,551 -----
- *s = ij % 60L;
- }
-
-
- /*
- * MEANPHASE -- Calculates mean phase of the Moon for a given
- ***************
- *** 443,451
- that the motion of the moon is far more complicated
- that this calculation reveals. */
-
- ! static double meanphase(sdate, phase, usek)
- ! double sdate, phase;
- ! double *usek;
- {
- int yy, mm, dd;
- double k, t, t2, t3, nt1;
-
- --- 547,567 -----
- }
-
-
- ! /*
- ! * MEANPHASE -- Calculates mean phase of the Moon for a given
- ! * base date. This argument K to this function is
- ! * the precomputed synodic month index, given by:
- ! *
- ! * K = (year - 1900) * 12.3685
- ! *
- ! * where year is expressed as a year and fractional
- ! * year.
- ! */
- !
- ! static
- ! double
- ! meanphase (sdate, k)
- ! double sdate, k;
- {
- double t, t2, t3, nt1;
-
- ***************
- *** 447,454
- double sdate, phase;
- double *usek;
- {
- ! int yy, mm, dd;
- ! double k, t, t2, t3, nt1;
-
- jyear(sdate, &yy, &mm, &dd);
-
-
- --- 563,569 -----
- meanphase (sdate, k)
- double sdate, k;
- {
- ! double t, t2, t3, nt1;
-
- /* Time in Julian centuries from 1900 January 0.5 */
- t = (sdate - 2415020.0) / 36525;
- ***************
- *** 450,459
- int yy, mm, dd;
- double k, t, t2, t3, nt1;
-
- - jyear(sdate, &yy, &mm, &dd);
- -
- - k = (yy + ((mm - 1) * (1.0 / 12.0)) - 1900) * 12.3685;
- -
- /* Time in Julian centuries from 1900 January 0.5 */
- t = (sdate - 2415020.0) / 36525;
- t2 = t * t; /* Square for frequent use */
-
- --- 565,570 -----
- {
- double t, t2, t3, nt1;
-
- /* Time in Julian centuries from 1900 January 0.5 */
- t = (sdate - 2415020.0) / 36525;
- t2 = t * t; /* Square for frequent use */
- ***************
- *** 459,465
- t2 = t * t; /* Square for frequent use */
- t3 = t2 * t; /* Cube for frequent use */
-
- - *usek = k = floor(k) + phase;
- nt1 = 2415020.75933 + synmonth * k
- + 0.0001178 * t2
- - 0.000000155 * t3
-
- --- 570,575 -----
- t2 = t * t; /* Square for frequent use */
- t3 = t2 * t; /* Cube for frequent use */
-
- nt1 = 2415020.75933 + synmonth * k
- + 0.0001178 * t2
- - 0.000000155 * t3
- ***************
- *** 461,469
-
- *usek = k = floor(k) + phase;
- nt1 = 2415020.75933 + synmonth * k
- ! + 0.0001178 * t2
- ! - 0.000000155 * t3
- ! + 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
-
- return nt1;
- }
-
- --- 571,579 -----
- t3 = t2 * t; /* Cube for frequent use */
-
- nt1 = 2415020.75933 + synmonth * k
- ! + 0.0001178 * t2
- ! - 0.000000155 * t3
- ! + 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
-
- return nt1;
- }
- ***************
- *** 468,477
- return nt1;
- }
-
- - /* TRUEPHASE -- Given a K value used to determine the
- - mean phase of the new moon, and a phase
- - selector (0.0, 0.25, 0.5, 0.75), obtain
- - the true, corrected phase time. */
-
- static double truephase(k, phase)
- double k, phase;
-
- --- 578,583 -----
- return nt1;
- }
-
-
- /*
- * TRUEPHASE -- Given a K value used to determine the
- ***************
- *** 473,480
- selector (0.0, 0.25, 0.5, 0.75), obtain
- the true, corrected phase time. */
-
- ! static double truephase(k, phase)
- ! double k, phase;
- {
- double t, t2, t3, pt, m, mprime, f;
- int apcor = FALSE;
-
- --- 579,595 -----
- }
-
-
- ! /*
- ! * TRUEPHASE -- Given a K value used to determine the
- ! * mean phase of the new moon, and a phase
- ! * selector (0.0, 0.25, 0.5, 0.75), obtain
- ! * the true, corrected phase time.
- ! */
- !
- ! static
- ! double
- ! truephase(k, phase)
- ! double k, phase;
- {
- double t, t2, t3, pt, m, mprime, f;
- int apcor = FALSE;
- ***************
- *** 545,551
- apcor = TRUE;
- }
- if (!apcor) {
- ! fprintf(stderr, "TRUEPHASE called with invalid phase selector.\n");
- abort();
- }
- return pt;
-
- --- 660,667 -----
- apcor = TRUE;
- }
- if (!apcor) {
- ! (void)fprintf (stderr,
- ! "TRUEPHASE called with invalid phase selector.\n");
- abort();
- }
- return pt;
- ***************
- *** 551,560
- return pt;
- }
-
- - /* PHASEHUNT -- Find time of phases of the moon which surround
- - the current date. Five phases are found, starting
- - and ending with the new moons which bound the
- - current lunation. */
-
- static void phasehunt(sdate, phases)
- double sdate;
-
- --- 667,672 -----
- return pt;
- }
-
-
- /*
- * PHASEHUNT -- Find time of phases of the moon which surround
- ***************
- *** 556,564
- and ending with the new moons which bound the
- current lunation. */
-
- ! static void phasehunt(sdate, phases)
- ! double sdate;
- ! double phases[5];
- {
- double adate, k1, k2, nt1, nt2;
-
-
- --- 668,685 -----
- }
-
-
- ! /*
- ! * PHASEHUNT -- Find time of phases of the moon which surround
- ! * the current date. Five phases are found, starting
- ! * and ending with the new moons which bound the
- ! * current lunation.
- ! */
- !
- ! static
- ! void
- ! phasehunt (sdate, phases)
- ! double sdate;
- ! double phases [5];
- {
- int yy, mm, dd;
- double adate, k1, k2, nt1, nt2;
- ***************
- *** 560,566
- double sdate;
- double phases[5];
- {
- ! double adate, k1, k2, nt1, nt2;
-
- adate = sdate - 45;
- nt1 = meanphase(adate, 0.0, &k1);
-
- --- 681,688 -----
- double sdate;
- double phases [5];
- {
- ! int yy, mm, dd;
- ! double adate, k1, k2, nt1, nt2;
-
- adate = sdate - 45;
- jyear(adate, &yy, &mm, &dd);
- ***************
- *** 563,569
- double adate, k1, k2, nt1, nt2;
-
- adate = sdate - 45;
- ! nt1 = meanphase(adate, 0.0, &k1);
- while (TRUE) {
- adate += synmonth;
- nt2 = meanphase(adate, 0.0, &k2);
-
- --- 685,694 -----
- double adate, k1, k2, nt1, nt2;
-
- adate = sdate - 45;
- ! jyear(adate, &yy, &mm, &dd);
- ! k1 = floor((yy + ((mm - 1) * (1.0 / 12.0)) - 1900) * 12.3685);
- !
- ! adate = nt1 = meanphase(adate, k1);
- while (TRUE) {
- adate += synmonth;
- k2 = k1 + 1;
- ***************
- *** 565,576
- adate = sdate - 45;
- nt1 = meanphase(adate, 0.0, &k1);
- while (TRUE) {
- ! adate += synmonth;
- ! nt2 = meanphase(adate, 0.0, &k2);
- ! if (nt1 <= sdate && nt2 > sdate)
- ! break;
- ! nt1 = nt2;
- ! k1 = k2;
- }
- phases[0] = truephase(k1, 0.0);
- phases[1] = truephase(k1, 0.25);
-
- --- 690,702 -----
-
- adate = nt1 = meanphase(adate, k1);
- while (TRUE) {
- ! adate += synmonth;
- ! k2 = k1 + 1;
- ! nt2 = meanphase(adate, k2);
- ! if (nt1 <= sdate && nt2 > sdate)
- ! break;
- ! nt1 = nt2;
- ! k1 = k2;
- }
- phases[0] = truephase(k1, 0.0);
- phases[1] = truephase(k1, 0.25);
- ***************
- *** 579,585
- phases[4] = truephase(k2, 0.0);
- }
-
- - /* KEPLER -- Solve the equation of Kepler. */
-
- static double kepler(m, ecc)
- double m, ecc;
-
- --- 705,710 -----
- phases[4] = truephase(k2, 0.0);
- }
-
-
- /*
- * KEPLER -- Solve the equation of Kepler.
- ***************
- *** 581,588
-
- /* KEPLER -- Solve the equation of Kepler. */
-
- ! static double kepler(m, ecc)
- ! double m, ecc;
- {
- double e, delta;
- #define EPSILON 1E-6
-
- --- 706,719 -----
- }
-
-
- ! /*
- ! * KEPLER -- Solve the equation of Kepler.
- ! */
- !
- ! static
- ! double
- ! kepler(m, ecc)
- ! double m, ecc;
- {
- double e, delta;
- #define EPSILON 1E-6
- ***************
- *** 589,597
-
- e = m = torad(m);
- do {
- ! delta = e - ecc * sin(e) - m;
- ! e -= delta / (1 - ecc * cos(e));
- ! } while (abs(delta) > EPSILON);
- return e;
- }
-
-
- --- 720,728 -----
-
- e = m = torad(m);
- do {
- ! delta = e - ecc * sin(e) - m;
- ! e -= delta / (1 - ecc * cos(e));
- ! } while (abs (delta) > EPSILON);
- return e;
- }
-
- ***************
- *** 595,601
- return e;
- }
-
- - /* PHASE -- Calculate phase of moon as a fraction:
-
- The argument is the time for which the phase is requested,
- expressed as a Julian date and fraction. Returns the terminator
-
- --- 726,731 -----
- return e;
- }
-
-
- /*
- * PHASE -- Calculate phase of moon as a fraction:
- ***************
- *** 597,610
-
- /* PHASE -- Calculate phase of moon as a fraction:
-
- ! The argument is the time for which the phase is requested,
- ! expressed as a Julian date and fraction. Returns the terminator
- ! phase angle as a percentage of a full circle (i.e., 0 to 1),
- ! and stores into pointer arguments the illuminated fraction of
- ! the Moon's disc, the Moon's age in days and fraction, the
- ! distance of the Moon from the centre of the Earth, and the
- ! angular diameter subtended by the Moon as seen by an observer
- ! at the centre of the Earth.
-
- */
-
-
- --- 727,744 -----
- }
-
-
- ! /*
- ! * PHASE -- Calculate phase of moon as a fraction:
- ! *
- ! * The argument is the time for which the phase is requested,
- ! * expressed as a Julian date and fraction. Returns the terminator
- ! * phase angle as a percentage of a full circle (i.e., 0 to 1),
- ! * and stores into pointer arguments the illuminated fraction of
- ! * the Moon's disc, the Moon's age in days and fraction, the
- ! * distance of the Moon from the centre of the Earth, and the
- ! * angular diameter subtended by the Moon as seen by an observer
- ! * at the centre of the Earth.
- ! */
-
- static
- double
- ***************
- *** 606,621
- angular diameter subtended by the Moon as seen by an observer
- at the centre of the Earth.
-
- ! */
- !
- ! static double phase(pdate, pphase, mage, dist, angdia, sudist, suangdia)
- ! double pdate;
- ! double *pphase; /* Illuminated fraction */
- ! double *mage; /* Age of moon in days */
- ! double *dist; /* Distance in kilometres */
- ! double *angdia; /* Angular diameter in degrees */
- ! double *sudist; /* Distance to Sun */
- ! double *suangdia; /* Sun's angular diameter */
- {
-
- double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
-
- --- 740,755 -----
- * at the centre of the Earth.
- */
-
- ! static
- ! double
- ! phase (pdate, pphase, mage, dist, angdia, sudist, suangdia)
- ! double pdate;
- ! double *pphase; /* Illuminated fraction */
- ! double *mage; /* Age of moon in days */
- ! double *dist; /* Distance in kilometres */
- ! double *angdia; /* Angular diameter in degrees */
- ! double *sudist; /* Distance to Sun */
- ! double *suangdia; /* Sun's angular diameter */
- {
-
- double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
- ***************
- *** 618,628
- double *suangdia; /* Sun's angular diameter */
- {
-
- ! double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
- ! mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon, BetaM,
- ! MoonAge, MoonPhase,
- ! MoonDist, MoonDFrac, MoonAng, MoonPar,
- ! F, SunDist, SunAng;
-
- /* Calculation of the Sun's position */
-
-
- --- 752,762 -----
- double *suangdia; /* Sun's angular diameter */
- {
-
- ! double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
- ! mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon, BetaM,
- ! MoonAge, MoonPhase,
- ! MoonDist, MoonDFrac, MoonAng, MoonPar,
- ! F, SunDist, SunAng;
-
- /* Calculation of the Sun's position */
-
- ***************
- *** 626,636
-
- /* Calculation of the Sun's position */
-
- ! Day = pdate - epoch; /* Date within epoch */
- ! N = fixangle((360 / 365.2422) * Day); /* Mean anomaly of the Sun */
- ! M = fixangle(N + elonge - elongp); /* Convert from perigee
- ! co-ordinates to epoch 1980.0 */
- ! Ec = kepler(M, eccent); /* Solve equation of Kepler */
- Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
- Ec = 2 * todeg(atan(Ec)); /* True anomaly */
- Lambdasun = fixangle(Ec + elongp); /* Sun's geocentric ecliptic
-
- --- 760,770 -----
-
- /* Calculation of the Sun's position */
-
- ! Day = pdate - epoch; /* Date within epoch */
- ! N = fixangle((360 / 365.2422) * Day); /* Mean anomaly of the Sun */
- ! M = fixangle(N + elonge - elongp); /* Convert from perigee
- ! co-ordinates to epoch 1980.0 */
- ! Ec = kepler(M, eccent); /* Solve equation of Kepler */
- Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
- Ec = 2 * todeg(atan(Ec)); /* True anomaly */
- Lambdasun = fixangle(Ec + elongp); /* Sun's geocentric ecliptic
- ***************
- *** 632,640
- co-ordinates to epoch 1980.0 */
- Ec = kepler(M, eccent); /* Solve equation of Kepler */
- Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
- ! Ec = 2 * todeg(atan(Ec)); /* True anomaly */
- ! Lambdasun = fixangle(Ec + elongp); /* Sun's geocentric ecliptic
- ! longitude */
- /* Orbital distance factor */
- F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
- SunDist = sunsmax / F; /* Distance to Sun in km */
-
- --- 766,774 -----
- co-ordinates to epoch 1980.0 */
- Ec = kepler(M, eccent); /* Solve equation of Kepler */
- Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
- ! Ec = 2 * todeg(atan(Ec)); /* True anomaly */
- ! Lambdasun = fixangle(Ec + elongp); /* Sun's geocentric ecliptic
- ! longitude */
- /* Orbital distance factor */
- F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
- SunDist = sunsmax / F; /* Distance to Sun in km */
- ***************
- *** 637,644
- longitude */
- /* Orbital distance factor */
- F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
- ! SunDist = sunsmax / F; /* Distance to Sun in km */
- ! SunAng = F * sunangsiz; /* Sun's angular size in degrees */
-
-
- /* Calculation of the Moon's position */
-
- --- 771,778 -----
- longitude */
- /* Orbital distance factor */
- F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
- ! SunDist = sunsmax / F; /* Distance to Sun in km */
- ! SunAng = F * sunangsiz; /* Sun's angular size in degrees */
-
-
- /* Calculation of the Moon's position */
- ***************
- *** 725,728
- *suangdia = SunAng;
- return fixangle(MoonAge) / 360.0;
- }
- ! #endif /* NO_SUN_MOON */
-
- --- 859,862 -----
- *suangdia = SunAng;
- return fixangle(MoonAge) / 360.0;
- }
- ! #endif /* NO_SUN_MOON */
-