home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / calentool / patch4b / patches04b
Encoding:
Text File  |  1989-10-26  |  51.5 KB  |  2,035 lines

  1. *** /tmp/,RCSt1a05555    Wed Jul 19 20:46:02 1989
  2. --- moon.c    Wed Jul 19 20:29:00 1989
  3. ***************
  4. *** 1,5
  5.   /*
  6. !  * $Header: moon.c,v 2.1 89/05/09 14:19:22 billr Exp $
  7.    */
  8.   /*
  9.    * moon.c
  10.  
  11. --- 1,5 -----
  12.   /*
  13. !  * $Header: moon.c,v 2.2 89/07/19 20:28:12 billr Exp $
  14.    */
  15.   /*
  16.    * moon.c
  17. ***************
  18. *** 9,15
  19.    * Bill Randle, Tektronix, Inc. to interface to the calentool
  20.    * program.
  21.    */
  22. ! #include "ct.h"        /* for the NO_SUN_MOON #define */
  23.   #ifndef NO_SUN_MOON
  24.   
  25.   /*
  26.  
  27. --- 9,15 -----
  28.    * Bill Randle, Tektronix, Inc. to interface to the calentool
  29.    * program.
  30.    */
  31. ! #include "ct.h"     /* for the NO_SUN_MOON #define */
  32.   #ifndef NO_SUN_MOON
  33.   
  34.   /*
  35. ***************
  36. *** 16,22
  37.   
  38.       A Moon for the Sun
  39.   
  40. !     Release 2.0
  41.   
  42.       Designed and implemented by John Walker in December 1987,
  43.       revised and updated in February of 1988.
  44.  
  45. --- 16,22 -----
  46.   
  47.       A Moon for the Sun
  48.   
  49. !     Release 2.3
  50.   
  51.       Designed and implemented by John Walker in December 1987,
  52.       revised and updated in February of 1988.
  53. ***************
  54. *** 20,25
  55.   
  56.       Designed and implemented by John Walker in December 1987,
  57.       revised and updated in February of 1988.
  58.   
  59.       cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect
  60.   
  61.  
  62. --- 20,26 -----
  63.   
  64.       Designed and implemented by John Walker in December 1987,
  65.       revised and updated in February of 1988.
  66. +     revised and updated again in June of 1988 by Ron Hitchens
  67.   
  68.       Make with:
  69.   
  70. ***************
  71. *** 21,26
  72.       Designed and implemented by John Walker in December 1987,
  73.       revised and updated in February of 1988.
  74.   
  75.       cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect
  76.   
  77.       Adding  appropriate  floating  point  options  to your hardware.  This
  78.  
  79. --- 22,29 -----
  80.       revised and updated in February of 1988.
  81.       revised and updated again in June of 1988 by Ron Hitchens
  82.   
  83. +     Make with:
  84.       cc -O moontool.c -o moontool -lm -lsuntool -lsunwindow -lpixrect
  85.   
  86.       Adding  appropriate  floating  point  options  to your hardware.  This
  87. ***************
  88. *** 75,80
  89.       program.  Please leave the original attribution information intact    so
  90.       that credit and blame may be properly apportioned.
  91.   
  92.   */
  93.   
  94.   /*  Astronomical constants  */
  95.  
  96. --- 78,147 -----
  97.       program.  Please leave the original attribution information intact    so
  98.       that credit and blame may be properly apportioned.
  99.   
  100. +    Revision history:
  101. +         1.0  11/5/87   First version.  Only displayed icon, no
  102. +                        open window information display.
  103. +         2.0  3/27/88   First posting to comp.sources.unix.
  104. +         2.1  6/16/88   Bug fix.  Table of phases didn't update
  105. +                        at the moment of the new moon.  Call on
  106. +                        phasehunt didn't convert civil Julian date
  107. +                        to astronomical Julian date.  Reported by
  108. +                        Dag Bruck (dag@control.lth.se).
  109. +         2.2  2/27/89   Michael McClary  (michael@xanadu.COM)
  110. +                        Added moon map, derived from the sun "fullmoon"
  111. +                        image file.  (It has not been checked for
  112. +                        rotation from the correct orientation.  Also, a
  113. +                        fixed icon doesn't model the librations of the
  114. +                        moon as viewed from the earth.) Also: tweaked
  115. +                        corners of icon.
  116. +         2.3  6/7/89    Bug fix.  Table of phases skipped the phases
  117. +                        for July 1989.  This occurred due to sloppy
  118. +                        maintenance of the synodic month index in the
  119. +                        interchange of information between phasehunt()
  120. +                        and meanphase().  I simplified and corrected
  121. +                        the handling of the month index as phasehunt()
  122. +                        steps along and removed unneeded code from
  123. +                        meanphase().  Reported by Bill Randle of
  124. +                        Tektronix, Inc. (billr@saab.CNA.TEK.COM).
  125. + Additional History:
  126. +     June 1988    Modified by Ron Hitchens to produce version 2.1
  127. +             modified icon generation to show surface texture
  128. +              on visible moon face.  Eliminated "illegal" direct
  129. +              modification of icon image memory.
  130. +             added a menu to allow switching in and out of
  131. +              test mode, for entertainment value mostly.
  132. +             reworked timer behaviour so that process doesn't
  133. +              wake up unnecessarily.
  134. +             trap sigwinch signals to notice more easily when the
  135. +              tool opens and closes.
  136. +             modified layout of information in open window display
  137. +              to reduce the amount of pixels modified in each
  138. +              update.  Batched pixwin updates so that only one
  139. +              screen rasterop per cycle is done.
  140. +             changed open window to display white-on-black for a
  141. +              more aesthetic look, and to suggest the effect of
  142. +              looking at the moon in the nighttime sky.
  143. +             setup default tool and canvas colors to be the same
  144. +              as B&W monochrome, for those us lucky enough to have
  145. +              color monitors and who have the default monochrome
  146. +              colors set to something other than B&W (I like white
  147. +              on dark blue myself)
  148. +             various code reformatting and pretty-printing to suit
  149. +              my own coding taste (I got a bit carried away).
  150. +             code tweaking to make lint happy.
  151. +             returned my hacked version to John.
  152. +             Ron Hitchens
  153. +                 ronbo@vixen.uucp
  154. +                 ...!uunet!cs.utexas.edu!vixen!ronbo
  155. +                 hitchens@cs.utexas.edu
  156.   */
  157.   
  158.   
  159. ***************
  160. *** 77,82
  161.   
  162.   */
  163.   
  164.   /*  Astronomical constants  */
  165.   
  166.   #define epoch        2444238.5       /* 1980 January 0.0 */
  167.  
  168. --- 144,167 -----
  169.                   hitchens@cs.utexas.edu
  170.   */
  171.   
  172. + #include <stdio.h>
  173. + #include <math.h>
  174. + #include <sys/time.h>
  175. + #include <suntool/sunview.h>
  176. + #include <suntool/canvas.h>
  177. + #define TINYFONT    "/usr/lib/fonts/fixedwidthfonts/screen.r.7"
  178. + /*
  179. +  * define standard B/W monochrome colors as defaults in case we're running
  180. +  * on a color system with the monochrome colors set differently
  181. +  */
  182. + #define FG_DEFAULT    { 0, 0, 0 }        /* black */
  183. + #define BG_DEFAULT    { 255, 255, 255 }    /* white */
  184.   /*  Astronomical constants  */
  185.   
  186.   #define epoch        2444238.5       /* 1980 January 0.0 */
  187. ***************
  188. *** 80,86
  189.   /*  Astronomical constants  */
  190.   
  191.   #define epoch        2444238.5       /* 1980 January 0.0 */
  192. ! #define    J1970        2440587.5       /* VAX clock Epoch 1970 Jan 1 (0h UT) */
  193.   
  194.   /*  Constants defining the Sun's apparent orbit  */
  195.   
  196.  
  197. --- 165,171 -----
  198.   /*  Astronomical constants  */
  199.   
  200.   #define epoch        2444238.5       /* 1980 January 0.0 */
  201. ! #define J1970       2440587.5      /* VAX clock Epoch 1970 Jan 1 (0h UT) */
  202.   
  203.   /*  Constants defining the Sun's apparent orbit  */
  204.   
  205. ***************
  206. *** 114,122
  207.   
  208.   #define earthrad    6378.16       /* Radius of Earth in kilometres */
  209.   
  210. - #include <stdio.h>
  211. - #include <math.h>
  212. - #include <sys/time.h>
  213.   
  214.   #include <suntool/sunview.h>
  215.   #include <suntool/canvas.h>
  216.  
  217. --- 199,204 -----
  218.   
  219.   #define earthrad    6378.16       /* Radius of Earth in kilometres */
  220.   
  221.   
  222.   #define PI 3.14159265358979323846  /* Assume not near black hole nor in
  223.                         Tennessee */
  224. ***************
  225. *** 118,174
  226.   #include <math.h>
  227.   #include <sys/time.h>
  228.   
  229. - #include <suntool/sunview.h>
  230. - #include <suntool/canvas.h>
  231. - /* Icon definition.  This is just a black field with rounded corners
  232. -    that blend into the root desktop pattern. The image of the moon and
  233. -    the text are added by the program later. */
  234. - static short moon_img[64][4] = {
  235. - /* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 */
  236. -     0x8FFF,0xFFFF,0xFFFF,0xFFE8,0x9FFF,0xFFFF,0xFFFF,0xFFF8,
  237. -     0x3FFF,0xFFFF,0xFFFF,0xFFFE,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
  238. -     0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  239. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  240. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  241. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  242. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  243. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  244. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  245. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  246. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  247. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  248. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  249. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  250. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  251. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  252. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  253. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  254. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  255. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  256. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  257. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  258. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  259. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  260. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  261. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  262. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  263. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  264. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
  265. -     0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x7FFF,0xFFFF,0xFFFF,0xFFFE,
  266. -     0xFFFF,0xFFFF,0xFFFF,0xFFFE,0xBFFF,0xFFFF,0xFFFF,0xFFFC,
  267. -     0x3FFF,0xFFFF,0xFFFF,0xFFFA,0x27FF,0xFFFF,0xFFFF,0xFFE2
  268. - };
  269. - DEFINE_ICON_FROM_IMAGE(moon_icon, moon_img);
  270. - mpr_static(icon_mpr, 64, 64, 1, moon_img);
  271. - extern Canvas mcanvas;
  272. - extern Pixfont *font;
  273. - extern char *monthnames[];
  274. - static Pixwin *cpw;
  275. - static int charhgt, charwid;
  276.   #define PI 3.14159265358979323846  /* Assume not near black hole nor in
  277.                         Tennessee */
  278.   
  279.  
  280. --- 200,205 -----
  281.   #define earthrad    6378.16       /* Radius of Earth in kilometres */
  282.   
  283.   
  284.   #define PI 3.14159265358979323846  /* Assume not near black hole nor in
  285.                         Tennessee */
  286.   
  287. ***************
  288. *** 182,188
  289.   #define dsin(x) (sin(torad((x))))              /* Sin from deg */
  290.   #define dcos(x) (cos(torad((x))))              /* Cos from deg */
  291.   
  292. - /*  Forward functions  */
  293.   
  294.   double jtime(), phase();
  295.   void phasehunt();
  296.  
  297. --- 213,218 -----
  298.   #define dsin(x) (sin(torad((x))))              /* Sin from deg */
  299.   #define dcos(x) (cos(torad((x))))              /* Cos from deg */
  300.   
  301.   
  302.   /*
  303.    * Moon image.  This is a standard icon-sized picture of the moon's face.
  304. ***************
  305. *** 184,192
  306.   
  307.   /*  Forward functions  */
  308.   
  309. ! double jtime(), phase();
  310. ! void phasehunt();
  311. ! void drawmoon(), jyear(), jhms();
  312.   
  313.   
  314.   /*  DRAWMOON  --  Construct icon for moon, given phase of moon.  */
  315.  
  316. --- 214,224 -----
  317.   #define dcos(x) (cos(torad((x))))              /* Cos from deg */
  318.   
  319.   
  320. ! /*
  321. !  * Moon image.  This is a standard icon-sized picture of the moon's face.
  322. !  * The visible part, as calculated by the current time, is extracted from
  323. !  * this image to create the displayed image.
  324. !  */
  325.   
  326.   static short moon_img [] = {
  327.   #include "moon.icon"
  328. ***************
  329. *** 188,193
  330.   void phasehunt();
  331.   void drawmoon(), jyear(), jhms();
  332.   
  333.   
  334.   /*  DRAWMOON  --  Construct icon for moon, given phase of moon.  */
  335.   
  336.  
  337. --- 220,229 -----
  338.    * this image to create the displayed image.
  339.    */
  340.   
  341. + static short moon_img [] = {
  342. + #include "moon.icon"
  343. + };
  344. + mpr_static(moon_mpr, 64, 64, 1, moon_img);
  345.   
  346.   extern Pixfont    *font;            /* pointer to regular icon font */
  347.   extern Pixfont    *sfont;            /* pointer to tiny icon font */
  348. ***************
  349. *** 189,195
  350.   void drawmoon(), jyear(), jhms();
  351.   
  352.   
  353. ! /*  DRAWMOON  --  Construct icon for moon, given phase of moon.  */
  354.   
  355.   static void drawmoon(ph)
  356.   double ph;
  357.  
  358. --- 225,239 -----
  359.   };
  360.   mpr_static(moon_mpr, 64, 64, 1, moon_img);
  361.   
  362. ! extern Pixfont    *font;            /* pointer to regular icon font */
  363. ! extern Pixfont    *sfont;            /* pointer to tiny icon font */
  364. ! extern Canvas    mcanvas;            /* handle for the canvas */
  365. ! extern char *monthnames[];
  366. ! static Pixrect    *icon_mpr;        /* actual displayed pixrect */
  367. ! static Pixwin    *cpw;            /* pointer to the canvas' pixwin */
  368. ! static int    charhgt, charwid;    /* default std font height/width */
  369. ! static int info_col;
  370. ! static struct timezone tzp;
  371.   
  372.   static char *labels [] = {
  373.       "Moon phase:",
  374. ***************
  375. *** 191,198
  376.   
  377.   /*  DRAWMOON  --  Construct icon for moon, given phase of moon.  */
  378.   
  379. ! static void drawmoon(ph)
  380. ! double ph;
  381.   {
  382.       int i, j, lx, rx;
  383.       int lb[4];
  384.  
  385. --- 235,265 -----
  386.   static int info_col;
  387.   static struct timezone tzp;
  388.   
  389. ! static char *labels [] = {
  390. !     "Moon phase:",
  391. !     "Age of moon:",
  392. !     "Moon's distance:",
  393. !     "Moon subtends:",
  394. !     "Last new moon:",
  395. !     "First quarter:",
  396. !     "Full moon:",
  397. !     "Last quarter:",
  398. !     "Next new moon:"
  399. ! };
  400. ! /*  Forward functions  */
  401. ! static double        jtime(), phase();
  402. ! static void        phasehunt(), set_mode();
  403. ! static void        drawmoon(), jyear(), jhms();
  404. ! /*
  405. !  * DRAWMOON  --  Construct icon for moon, given phase of moon.
  406. !  */
  407. ! static void drawmoon (ph, src_pr, dst_pr)
  408. ! double        ph;
  409. ! Pixrect        *src_pr, *dst_pr;
  410.   {
  411.       register int    i, lx, rx;
  412.       register double    cp, xscale;
  413. ***************
  414. *** 194,202
  415.   static void drawmoon(ph)
  416.   double ph;
  417.   {
  418. !     int i, j, lx, rx;
  419. !     int lb[4];
  420. !     double cp, xscale;
  421.   
  422.       xscale = cos(2 * PI * ph);
  423.       for (i = 0; i < 24; i++) {
  424.  
  425. --- 261,272 -----
  426.   double        ph;
  427.   Pixrect        *src_pr, *dst_pr;
  428.   {
  429. !     register int    i, lx, rx;
  430. !     register double    cp, xscale;
  431. ! #define RADIUS        27.0
  432. ! #define IRADIUS        27
  433. ! #define OFFSET        28
  434. ! #define CENTER        32
  435.   
  436.       /* Clear the destination pixrect to all one-bits (black) */
  437.       pr_rop (dst_pr, 0, 0, 64, 64, PIX_SET, (Pixrect *)0, 0, 0);
  438. ***************
  439. *** 198,219
  440.       int lb[4];
  441.       double cp, xscale;
  442.   
  443. !     xscale = cos(2 * PI * ph);
  444. !     for (i = 0; i < 24; i++) {
  445. !        lb[0] = lb[1] = lb[2] = lb[3] = 0xFFFF;
  446. !        cp = 24.0 * cos(asin(i / 24.0));
  447. !        if (ph < 0.5) {
  448. !           rx = 32 + cp;
  449. !           lx = 32 + xscale * cp;
  450. !        } else {
  451. !           lx = 33 - cp;
  452. !           rx = 33 - xscale * cp;
  453. !        }
  454. !        for (j = lx; j <= rx; j++) {
  455. !           lb[j >> 4] &= (0x8000 >> (j & 0xF)) ^ 0xFFFF;
  456. !        }
  457. !        for (j = 0; j < 4; j++)
  458. !           moon_img[28 + i][j] = moon_img[28 - i][j] = lb[j];
  459.       }
  460.   }
  461.   
  462.  
  463. --- 268,298 -----
  464.   #define OFFSET        28
  465.   #define CENTER        32
  466.   
  467. !     /* Clear the destination pixrect to all one-bits (black) */
  468. !     pr_rop (dst_pr, 0, 0, 64, 64, PIX_SET, (Pixrect *)0, 0, 0);
  469. !     xscale = cos (2 * PI * ph);
  470. !     for (i = 0; i < IRADIUS; i++) {
  471. !         cp = RADIUS * cos (asin (i / RADIUS));
  472. !         if (ph < 0.5) {
  473. !             rx = CENTER + cp;
  474. !             lx = CENTER + xscale * cp;
  475. !         } else {
  476. !             lx = CENTER - cp;
  477. !             rx = CENTER - xscale * cp;
  478. !         }
  479. !         /*
  480. !          * We now know the left and right endpoints of the scan line
  481. !          * for this y coordinate.  We raster-op the corresponding
  482. !          * scanlines from the source pixrect to the destination
  483. !          * pixrect, offsetting to properly place it in the pixrect and
  484. !          * reflecting vertically.
  485. !          */
  486. !         pr_rop (dst_pr, lx, OFFSET + i, (rx - lx) + 1, 1, PIX_SRC,
  487. !             src_pr, lx, OFFSET + i);
  488. !         pr_rop (dst_pr, lx, OFFSET - i, (rx - lx) + 1, 1, PIX_SRC,
  489. !             src_pr, lx, OFFSET - i);
  490.       }
  491.   }
  492.   
  493. ***************
  494. *** 217,222
  495.       }
  496.   }
  497.   
  498.   /*  MOON_DATA  -- print useful info about the moon */
  499.   
  500.   moon_data(seconds)
  501.  
  502. --- 296,307 -----
  503.       }
  504.   }
  505.   
  506. + #define prt(y) pw_text(cpw, info_col, charhgt*(y), PIX_SRC, font, tbuf)
  507. + #define prtxy(x,y) pw_text(cpw, charwid*(y+1), charhgt*(x), PIX_SRC,\
  508. +     font,tbuf)
  509. + #define EPL(x) (x), (x) == 1 ? "" : "s"
  510. + #define APOS(x) (x + 11)
  511.   /*  MOON_DATA  -- print useful info about the moon */
  512.   
  513.   moon_data(seconds)
  514. ***************
  515. *** 222,238
  516.   moon_data(seconds)
  517.   long seconds;
  518.   {
  519. !     int lunation, wclosed;
  520. !     long t;
  521. !     double jd, p, aom, cphase, cdist, cangdia, csund, csuang, lptime;
  522. !     double phasar[5];
  523. !     struct pr_prpos tloc;
  524. !     char amsg[12], tbuf[80];
  525. !     static double faketime = 0.0;
  526. !     static short moonilast[64][4] = {0};
  527. !     int yy, mm, dd, hh, mmm, ss;
  528. !     Pixfont *pfont;
  529. !     struct tm *gm, *ltm, *localtime();
  530.       struct timeval tvp;
  531.       struct timezone tzp;
  532.       long clock;
  533.  
  534. --- 307,320 -----
  535.   moon_data(seconds)
  536.   long seconds;
  537.   {
  538. !     int        lunation, wclosed;
  539. !     int        i, yy, mm, dd, hh, mmm, ss;
  540. !     int        aom_d, aom_h, aom_m;
  541. !     long        t;
  542. !     double        jd, p, aom, cphase, cdist, cangdia, csund, csuang;
  543. !     double        phasar [5];
  544. !     char        tbuf[80];
  545. !     struct tm    *gm, *ltm, *localtime();
  546.       struct timeval tvp;
  547.       struct pr_prpos    tloc;
  548.       struct pr_size    txt_size;
  549. ***************
  550. *** 234,240
  551.       Pixfont *pfont;
  552.       struct tm *gm, *ltm, *localtime();
  553.       struct timeval tvp;
  554. !     struct timezone tzp;
  555.       long clock;
  556.       char *atp, *asctime();
  557.   
  558.  
  559. --- 316,323 -----
  560.       char        tbuf[80];
  561.       struct tm    *gm, *ltm, *localtime();
  562.       struct timeval tvp;
  563. !     struct pr_prpos    tloc;
  564. !     struct pr_size    txt_size;
  565.       long clock;
  566.       char *atp, *asctime();
  567.   
  568. ***************
  569. *** 238,245
  570.       long clock;
  571.       char *atp, *asctime();
  572.   
  573. !     pfont = pf_open("/usr/lib/fonts/fixedwidthfonts/screen.r.7");
  574.       cpw = canvas_pixwin(mcanvas);
  575.       charwid = font->pf_defaultsize.x;
  576.       charhgt = font->pf_defaultsize.y;
  577.  
  578. --- 321,328 -----
  579.       long clock;
  580.       char *atp, *asctime();
  581.   
  582. !     icon_mpr = mem_create (64, 64, 1);
  583. !     pr_rop (icon_mpr, 0, 0, 64, 64, PIX_SRC, &moon_mpr, 0, 0);
  584.       cpw = canvas_pixwin(mcanvas);
  585.       charwid = font->pf_defaultsize.x;
  586.       charhgt = font->pf_defaultsize.y;
  587. ***************
  588. *** 243,249
  589.       cpw = canvas_pixwin(mcanvas);
  590.       charwid = font->pf_defaultsize.x;
  591.       charhgt = font->pf_defaultsize.y;
  592. !     jd = jtime((gm = gmtime(&seconds)));
  593.       gettimeofday(&tvp, &tzp); /* for timezone info */
  594.       p = phase(jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
  595.       drawmoon(p);
  596.  
  597. --- 326,333 -----
  598.       cpw = canvas_pixwin(mcanvas);
  599.       charwid = font->pf_defaultsize.x;
  600.       charhgt = font->pf_defaultsize.y;
  601. !     info_col = charwid * 20;
  602. !     jd = jtime ((gm = gmtime (&seconds)));
  603.       gettimeofday(&tvp, &tzp); /* for timezone info */
  604.       p = phase (jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
  605.       aom_d = (int) aom;
  606. ***************
  607. *** 245,258
  608.       charhgt = font->pf_defaultsize.y;
  609.       jd = jtime((gm = gmtime(&seconds)));
  610.       gettimeofday(&tvp, &tzp); /* for timezone info */
  611. !     p = phase(jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
  612. !     drawmoon(p);
  613. !         sprintf(amsg, " %dd %dh  ",
  614. !        (int) aom, ((int) (24 * (aom - floor(aom)))));
  615. !     tloc.pr = (Pixrect *) icon_get(&moon_icon, ICON_IMAGE);
  616. !     tloc.pos.x = 2;
  617. !     tloc.pos.y = 62;
  618. !     pf_text(tloc, PIX_NOT(PIX_SRC), pfont, amsg);
  619.   
  620.       /* Only update icon if it changed (this eliminates gratuitous
  621.          flashing of the icon on-screen). */
  622.  
  623. --- 329,338 -----
  624.       info_col = charwid * 20;
  625.       jd = jtime ((gm = gmtime (&seconds)));
  626.       gettimeofday(&tvp, &tzp); /* for timezone info */
  627. !     p = phase (jd, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
  628. !     aom_d = (int) aom;
  629. !     aom_h = (int) (24 * (aom - floor(aom)));
  630. !     aom_m = (int) (1440 * (aom - floor(aom))) % 60;
  631.   
  632.       drawmoon(p, &moon_mpr, icon_mpr);
  633.   
  634. ***************
  635. *** 254,261
  636.       tloc.pos.y = 62;
  637.       pf_text(tloc, PIX_NOT(PIX_SRC), pfont, amsg);
  638.   
  639. !     /* Only update icon if it changed (this eliminates gratuitous
  640. !        flashing of the icon on-screen). */
  641.   
  642.       if (bcmp(moonilast, moon_img, sizeof moon_img) != 0)
  643.          bcopy(moon_img, moonilast, sizeof moon_img);
  644.  
  645. --- 334,340 -----
  646.       aom_h = (int) (24 * (aom - floor(aom)));
  647.       aom_m = (int) (1440 * (aom - floor(aom))) % 60;
  648.   
  649. !     drawmoon(p, &moon_mpr, icon_mpr);
  650.   
  651.       if (aom_d == 0) {
  652.           (void)sprintf(tbuf, "%dh %dm", aom_h, aom_m);
  653. ***************
  654. *** 257,264
  655.       /* Only update icon if it changed (this eliminates gratuitous
  656.          flashing of the icon on-screen). */
  657.   
  658. !     if (bcmp(moonilast, moon_img, sizeof moon_img) != 0)
  659. !        bcopy(moon_img, moonilast, sizeof moon_img);
  660.   
  661.       /* Update textual information for open window */
  662.   
  663.  
  664. --- 336,351 -----
  665.   
  666.       drawmoon(p, &moon_mpr, icon_mpr);
  667.   
  668. !     if (aom_d == 0) {
  669. !         (void)sprintf(tbuf, "%dh %dm", aom_h, aom_m);
  670. !     } else {
  671. !         (void)sprintf(tbuf, "%dd %dh", aom_d, aom_h);
  672. !     }
  673. !     txt_size = pf_textwidth (strlen (tbuf), sfont, tbuf);
  674. !     tloc.pos.x = (64 - txt_size.x) / 2;
  675. !     tloc.pos.y = 63;
  676. !     tloc.pr = icon_mpr;
  677. !     pf_text (tloc, PIX_NOT(PIX_SRC), sfont, tbuf);
  678.   
  679.       /* Update textual information for open window */
  680.   
  681. ***************
  682. *** 262,269
  683.   
  684.       /* Update textual information for open window */
  685.   
  686. ! #define prt(x) pw_text(cpw, charwid, charhgt * (x), PIX_SRC, font, tbuf)
  687. ! #define prtxy(x,y) pw_text(cpw,charwid*(y+1),charhgt*(x),PIX_SRC,font,tbuf)
  688.   
  689.           sprintf(tbuf, "Moon phase:      %d%%   [0%% = New, 100%% = Full]  ",
  690.          (int) (cphase * 100));
  691.  
  692. --- 349,356 -----
  693.   
  694.       /* Update textual information for open window */
  695.   
  696. !     /* start batching updates to the pixwin */
  697. !     pw_batch_on (cpw);
  698.   
  699.       paint_labels();
  700.       /* moon phase */
  701. ***************
  702. *** 265,272
  703.   #define prt(x) pw_text(cpw, charwid, charhgt * (x), PIX_SRC, font, tbuf)
  704.   #define prtxy(x,y) pw_text(cpw,charwid*(y+1),charhgt*(x),PIX_SRC,font,tbuf)
  705.   
  706. !         sprintf(tbuf, "Moon phase:      %d%%   [0%% = New, 100%% = Full]  ",
  707. !        (int) (cphase * 100));
  708.       prt(1);
  709.   
  710.       /* Information about the Moon */
  711.  
  712. --- 352,361 -----
  713.       /* start batching updates to the pixwin */
  714.       pw_batch_on (cpw);
  715.   
  716. !     paint_labels();
  717. !     /* moon phase */
  718. !     (void)sprintf (tbuf, "%d%%   [0%% = New, 100%% = Full]  ",
  719. !         (int) (cphase * 100));
  720.       prt(1);
  721.   
  722.       /* Information about the Moon */
  723. ***************
  724. *** 271,281
  725.   
  726.       /* Information about the Moon */
  727.   
  728. ! #define EPL(x) (x), (x) == 1 ? "" : "s"
  729. !     sprintf(tbuf,
  730. !            "Age of moon:     %d day%s, %d hour%s, %d minute%s.       ",
  731. !        EPL((int) aom), EPL(((int) (24 * (aom - floor(aom))))),
  732. !        EPL(((int) (1440 * (aom - floor(aom)))) % 60));
  733.       prt(2);
  734.       sprintf(tbuf,
  735.              "Moon's distance: %ld kilometres, %.1f Earth radii.  ",
  736.  
  737. --- 360,368 -----
  738.   
  739.       /* Information about the Moon */
  740.   
  741. !     /* age of moon */
  742. !     (void)sprintf (tbuf, "%d day%s, %d hour%s, %d minute%s.       ",
  743. !         EPL(aom_d), EPL(aom_h), EPL(aom_m));
  744.       prt(2);
  745.   
  746.       /* moon distance */
  747. ***************
  748. *** 277,285
  749.          EPL((int) aom), EPL(((int) (24 * (aom - floor(aom))))),
  750.          EPL(((int) (1440 * (aom - floor(aom)))) % 60));
  751.       prt(2);
  752. !     sprintf(tbuf,
  753. !            "Moon's distance: %ld kilometres, %.1f Earth radii.  ",
  754. !        (long) cdist, cdist / earthrad);
  755.       prt(3);
  756.       sprintf(tbuf,
  757.              "Moon subtends:   %.4f degrees.       ", cangdia);
  758.  
  759. --- 364,373 -----
  760.       (void)sprintf (tbuf, "%d day%s, %d hour%s, %d minute%s.       ",
  761.           EPL(aom_d), EPL(aom_h), EPL(aom_m));
  762.       prt(2);
  763. !     /* moon distance */
  764. !     (void)sprintf (tbuf, "%ld kilometres, %.1f Earth radii.  ",
  765. !         (long) cdist, cdist / earthrad);
  766.       prt(3);
  767.   
  768.       /* moon subtends */
  769. ***************
  770. *** 281,288
  771.              "Moon's distance: %ld kilometres, %.1f Earth radii.  ",
  772.          (long) cdist, cdist / earthrad);
  773.       prt(3);
  774. !     sprintf(tbuf,
  775. !            "Moon subtends:   %.4f degrees.       ", cangdia);
  776.       prt(4);
  777.       /* Draw the moon icon in the text window */
  778.       pw_rop(cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC,
  779.  
  780. --- 369,377 -----
  781.       (void)sprintf (tbuf, "%ld kilometres, %.1f Earth radii.  ",
  782.           (long) cdist, cdist / earthrad);
  783.       prt(3);
  784. !     /* moon subtends */
  785. !     (void)sprintf (tbuf, "%.4f degrees.       ", cangdia);
  786.       prt(4);
  787.   
  788.       /* paint the moon's image in the upper right of the canvas */
  789. ***************
  790. *** 284,292
  791.       sprintf(tbuf,
  792.              "Moon subtends:   %.4f degrees.       ", cangdia);
  793.       prt(4);
  794. -     /* Draw the moon icon in the text window */
  795. -     pw_rop(cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC,
  796. -        &icon_mpr, 0, 0);
  797.   
  798.   
  799.       /* Calculate times of phases of this lunation. */
  800.  
  801. --- 373,378 -----
  802.       /* moon subtends */
  803.       (void)sprintf (tbuf, "%.4f degrees.       ", cangdia);
  804.       prt(4);
  805.   
  806.       /* paint the moon's image in the upper right of the canvas */
  807.       pw_rop (cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC, icon_mpr, 0, 0);
  808. ***************
  809. *** 288,293
  810.       pw_rop(cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC,
  811.          &icon_mpr, 0, 0);
  812.   
  813.   
  814.       /* Calculate times of phases of this lunation. */
  815.   
  816.  
  817. --- 374,381 -----
  818.       (void)sprintf (tbuf, "%.4f degrees.       ", cangdia);
  819.       prt(4);
  820.   
  821. +     /* paint the moon's image in the upper right of the canvas */
  822. +     pw_rop (cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC, icon_mpr, 0, 0);
  823.   
  824.       /*
  825.        * Calculate times of phases of this lunation.
  826. ***************
  827. *** 289,295
  828.          &icon_mpr, 0, 0);
  829.   
  830.   
  831. !     /* Calculate times of phases of this lunation. */
  832.   
  833.   #define APOS(x) (x + 11)
  834.       phasehunt(jd, phasar);
  835.  
  836. --- 377,386 -----
  837.       /* paint the moon's image in the upper right of the canvas */
  838.       pw_rop (cpw, 60 * charwid, charhgt, 64, 64, PIX_SRC, icon_mpr, 0, 0);
  839.   
  840. !     /*
  841. !      * Calculate times of phases of this lunation.
  842. !      */
  843. !     phasehunt(jd + 0.5, phasar);
  844.   
  845.       for (i = 0; i < 5; i++) {
  846.           fmt_phase_time (phasar[i], tbuf);
  847. ***************
  848. *** 291,310
  849.   
  850.       /* Calculate times of phases of this lunation. */
  851.   
  852. ! #define APOS(x) (x + 11)
  853. !     phasehunt(jd, phasar);
  854. !     lptime = phasar[0];
  855. !     lunation = floor(((lptime + 7) - lunatbase) / synmonth) + 1;
  856. !     /* convert to seconds local time, so we can use localtime()
  857. !        to handle dst calculations */
  858. !     clock = (long)((lptime - J1970) * 24. * 3600.);
  859. !     ltm = localtime(&clock);
  860. !     sprintf(tbuf,
  861. !            "Last new moon:   %02d:%02d %s %2d %s %d             ",
  862. !        ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  863. !     prt(APOS(0));
  864. !         sprintf(tbuf, "Lunation %d    ", lunation);
  865. !     prtxy(APOS(0), 52);
  866.   
  867.       lptime = phasar[1];
  868.       /* convert to seconds local time, so we can use localtime()
  869.  
  870. --- 382,391 -----
  871.        */
  872.       phasehunt(jd + 0.5, phasar);
  873.   
  874. !     for (i = 0; i < 5; i++) {
  875. !         fmt_phase_time (phasar[i], tbuf);
  876. !         prt(APOS(i));
  877. !     }
  878.   
  879.       lunation = floor(((phasar[0] + 7) - lunatbase) / synmonth) + 1;
  880.       (void)sprintf(tbuf, "Lunation %d ", lunation);
  881. ***************
  882. *** 306,320
  883.           sprintf(tbuf, "Lunation %d    ", lunation);
  884.       prtxy(APOS(0), 52);
  885.   
  886. !     lptime = phasar[1];
  887. !     /* convert to seconds local time, so we can use localtime()
  888. !        to handle dst calculations */
  889. !     clock = (long)((lptime - J1970) * 24. * 3600.);
  890. !     ltm = localtime(&clock);
  891. !     sprintf(tbuf,
  892. !            "First quarter:   %02d:%02d %s %2d %s %d              ",
  893. !        ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  894. !     prt(APOS(1));
  895.   
  896.       lptime = phasar[2];
  897.       /* convert to seconds local time, so we can use localtime()
  898.  
  899. --- 387,397 -----
  900.           prt(APOS(i));
  901.       }
  902.   
  903. !     lunation = floor(((phasar[0] + 7) - lunatbase) / synmonth) + 1;
  904. !     (void)sprintf(tbuf, "Lunation %d ", lunation);
  905. !     prtxy(APOS(0), 49);                  
  906. !     (void)sprintf(tbuf, "Lunation %d ", lunation + 1);
  907. !     prtxy(APOS(4), 49);
  908.   
  909.       /* flush the pixwin updates to the screen */
  910.       pw_batch_off (cpw);
  911. ***************
  912. *** 316,330
  913.          ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  914.       prt(APOS(1));
  915.   
  916. !     lptime = phasar[2];
  917. !     /* convert to seconds local time, so we can use localtime()
  918. !        to handle dst calculations */
  919. !     clock = (long)((lptime - J1970) * 24. * 3600.);
  920. !     ltm = localtime(&clock);
  921. !     sprintf(tbuf,
  922. !            "Full moon:       %02d:%02d %s %2d %s %d              ",
  923. !        ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  924. !     prt(APOS(2));
  925.   
  926.       lptime = phasar[3];
  927.       /* convert to seconds local time, so we can use localtime()
  928.  
  929. --- 393,400 -----
  930.       (void)sprintf(tbuf, "Lunation %d ", lunation + 1);
  931.       prtxy(APOS(4), 49);
  932.   
  933. !     /* flush the pixwin updates to the screen */
  934. !     pw_batch_off (cpw);
  935.   
  936.       return;
  937.   }
  938. ***************
  939. *** 326,340
  940.          ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  941.       prt(APOS(2));
  942.   
  943. !     lptime = phasar[3];
  944. !     /* convert to seconds local time, so we can use localtime()
  945. !        to handle dst calculations */
  946. !     clock = (long)((lptime - J1970) * 24. * 3600.);
  947. !     ltm = localtime(&clock);
  948. !     sprintf(tbuf,
  949. !            "Last quarter:    %02d:%02d %s %2d %s %d              ",
  950. !        ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  951. !     prt(APOS(3));
  952.   
  953.       lptime = phasar[4];
  954.       /* convert to seconds local time, so we can use localtime()
  955.  
  956. --- 396,404 -----
  957.       /* flush the pixwin updates to the screen */
  958.       pw_batch_off (cpw);
  959.   
  960. !     return;
  961. ! }
  962. ! #undef APOS
  963.   
  964.   
  965.   /*
  966. ***************
  967. *** 336,342
  968.          ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  969.       prt(APOS(3));
  970.   
  971. !     lptime = phasar[4];
  972.       /* convert to seconds local time, so we can use localtime()
  973.          to handle dst calculations */
  974.       clock = (long)rint((lptime - J1970) * 24. * 3600.);
  975.  
  976. --- 400,418 -----
  977.   }
  978.   #undef APOS
  979.   
  980. ! /*
  981. !  * FMT_PHASE_TIME -- Format the provided julian date into the provided buffer
  982. !  *        in local time format for screen display
  983. !  */
  984. ! fmt_phase_time (utime, buf)
  985. !     double    utime;
  986. !     char    *buf;
  987. ! {
  988. !     long    clock;
  989. !     struct tm    *ltm, *localtime();
  990.       /* convert to seconds local time, so we can use localtime()
  991.          to handle dst calculations */
  992.       clock = (long)((utime - J1970) * 24. * 3600.);
  993. ***************
  994. *** 339,345
  995.       lptime = phasar[4];
  996.       /* convert to seconds local time, so we can use localtime()
  997.          to handle dst calculations */
  998. !     clock = (long)rint((lptime - J1970) * 24. * 3600.);
  999.       ltm = localtime(&clock);
  1000.       sprintf(tbuf,
  1001.              "Next new moon:   %02d:%02d %s %2d %s %d              ",
  1002.  
  1003. --- 415,421 -----
  1004.   
  1005.       /* convert to seconds local time, so we can use localtime()
  1006.          to handle dst calculations */
  1007. !     clock = (long)((utime - J1970) * 24. * 3600.);
  1008.       ltm = localtime(&clock);
  1009.       (void)sprintf (buf, " %02d:%02d %s %2d %s %d             ",
  1010.       ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  1011. ***************
  1012. *** 341,353
  1013.          to handle dst calculations */
  1014.       clock = (long)rint((lptime - J1970) * 24. * 3600.);
  1015.       ltm = localtime(&clock);
  1016. !     sprintf(tbuf,
  1017. !            "Next new moon:   %02d:%02d %s %2d %s %d              ",
  1018. !        ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  1019. !     prt(APOS(4));
  1020. !         sprintf(tbuf, "Lunation %d    ", lunation + 1);
  1021. !     prtxy(APOS(4), 52);
  1022. ! #undef APOS
  1023.   }
  1024.   
  1025.   /*  JDATE  --  Convert internal GMT date and time to Julian day
  1026.  
  1027. --- 417,424 -----
  1028.          to handle dst calculations */
  1029.       clock = (long)((utime - J1970) * 24. * 3600.);
  1030.       ltm = localtime(&clock);
  1031. !     (void)sprintf (buf, " %02d:%02d %s %2d %s %d             ",
  1032. !     ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  1033.   }
  1034.   
  1035.   
  1036. ***************
  1037. *** 350,357
  1038.   #undef APOS
  1039.   }
  1040.   
  1041. - /*  JDATE  --  Convert internal GMT date and time to Julian day
  1042. -            and fraction.  */
  1043.   
  1044.   static long jdate(t)
  1045.   struct tm *t;
  1046.  
  1047. --- 421,426 -----
  1048.       ltm->tm_hour, ltm->tm_min, timezone(tzp.tz_minuteswest, ltm->tm_isdst), ltm->tm_mday, monthnames[ltm->tm_mon], ltm->tm_year+1900);
  1049.   }
  1050.   
  1051.   
  1052.   /*
  1053.    * PAINT_LABELS -- Draw the labels into the canvas (open) window and right
  1054. ***************
  1055. *** 353,360
  1056.   /*  JDATE  --  Convert internal GMT date and time to Julian day
  1057.              and fraction.  */
  1058.   
  1059. ! static long jdate(t)
  1060. ! struct tm *t;
  1061.   {
  1062.       long c, m, y;
  1063.   
  1064.  
  1065. --- 422,435 -----
  1066.   }
  1067.   
  1068.   
  1069. ! /*
  1070. !  * PAINT_LABELS -- Draw the labels into the canvas (open) window and right
  1071. !  *        justify them.  Done once at startup.  We paint the labels
  1072. !  *        separately to minimize the amount of screen real-estate
  1073. !  *        being modified on each update.
  1074. !  */
  1075. ! paint_labels ()
  1076.   {
  1077.       int    i;
  1078.   
  1079. ***************
  1080. *** 356,362
  1081.   static long jdate(t)
  1082.   struct tm *t;
  1083.   {
  1084. !     long c, m, y;
  1085.   
  1086.       y = t->tm_year + 1900;
  1087.       m = t->tm_mon + 1;
  1088.  
  1089. --- 431,437 -----
  1090.   
  1091.   paint_labels ()
  1092.   {
  1093. !     int    i;
  1094.   
  1095.       for (i = 0; i < 4; i++) {
  1096.           pw_text (cpw, charwid * (17 - strlen (labels [i])),
  1097. ***************
  1098. *** 358,363
  1099.   {
  1100.       long c, m, y;
  1101.   
  1102.       y = t->tm_year + 1900;
  1103.       m = t->tm_mon + 1;
  1104.       if (m > 2)
  1105.  
  1106. --- 433,463 -----
  1107.   {
  1108.       int    i;
  1109.   
  1110. +     for (i = 0; i < 4; i++) {
  1111. +         pw_text (cpw, charwid * (17 - strlen (labels [i])),
  1112. +             charhgt * (i + 1), PIX_SRC,
  1113. +             font, labels[i]);
  1114. +     }
  1115. +     for (i = 4; i < 9; i++) {
  1116. +         pw_text (cpw, charwid * (17 - strlen (labels [i])),
  1117. +             charhgt * (i + 7), PIX_SRC,
  1118. +             font, labels[i]);
  1119. +     }
  1120. + }
  1121. + /*
  1122. +  * JDATE  --  Convert internal GMT date and time to Julian day
  1123. +  *           and fraction.
  1124. +  */
  1125. + static
  1126. + long
  1127. + jdate (t)
  1128. +     struct tm    *t;
  1129. + {
  1130. +     long        c, m, y;
  1131.       y = t->tm_year + 1900;
  1132.       m = t->tm_mon + 1;
  1133.       if (m > 2) {
  1134. ***************
  1135. *** 360,370
  1136.   
  1137.       y = t->tm_year + 1900;
  1138.       m = t->tm_mon + 1;
  1139. !     if (m > 2)
  1140. !        m = m - 3;
  1141. !     else {
  1142. !        m = m + 9;
  1143. !        y--;
  1144.       }
  1145.       c = y / 100L;           /* Compute century */
  1146.       y -= 100L * c;
  1147.  
  1148. --- 460,470 -----
  1149.   
  1150.       y = t->tm_year + 1900;
  1151.       m = t->tm_mon + 1;
  1152. !     if (m > 2) {
  1153. !         m = m - 3;
  1154. !     } else {
  1155. !         m = m + 9;
  1156. !         y--;
  1157.       }
  1158.       c = y / 100L;           /* Compute century */
  1159.       y -= 100L * c;
  1160. ***************
  1161. *** 368,375
  1162.       }
  1163.       c = y / 100L;           /* Compute century */
  1164.       y -= 100L * c;
  1165. !     return t->tm_mday + (c * 146097L) / 4 + (y * 1461L) / 4 +
  1166. !         (m * 153L + 2) / 5 + 1721119L;
  1167.   }
  1168.   
  1169.   /* JTIME --    Convert internal GMT date and time to astronomical Julian
  1170.  
  1171. --- 468,475 -----
  1172.       }
  1173.       c = y / 100L;           /* Compute century */
  1174.       y -= 100L * c;
  1175. !     return (t->tm_mday + (c * 146097L) / 4 + (y * 1461L) / 4 +
  1176. !         (m * 153L + 2) / 5 + 1721119L);
  1177.   }
  1178.   
  1179.   
  1180. ***************
  1181. *** 372,380
  1182.           (m * 153L + 2) / 5 + 1721119L;
  1183.   }
  1184.   
  1185. - /* JTIME --    Convert internal GMT date and time to astronomical Julian
  1186. -            time (i.e. Julian date plus day fraction, expressed as
  1187. -            a double).  */
  1188.   
  1189.   static double jtime(t)
  1190.   struct tm *t;
  1191.  
  1192. --- 472,477 -----
  1193.           (m * 153L + 2) / 5 + 1721119L);
  1194.   }
  1195.   
  1196.   
  1197.   /*
  1198.    * JTIME --    Convert internal GMT date and time to astronomical Julian
  1199. ***************
  1200. *** 376,383
  1201.              time (i.e. Julian date plus day fraction, expressed as
  1202.              a double).  */
  1203.   
  1204. ! static double jtime(t)
  1205. ! struct tm *t;
  1206.   {
  1207.       return (jdate(t) - 0.5) + 
  1208.          (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
  1209.  
  1210. --- 473,488 -----
  1211.   }
  1212.   
  1213.   
  1214. ! /*
  1215. !  * JTIME --    Convert internal GMT date and time to astronomical Julian
  1216. !  *           time (i.e. Julian date plus day fraction, expressed as
  1217. !  *           a double).
  1218. !  */
  1219. ! static
  1220. ! double
  1221. ! jtime (t)
  1222. !     struct tm *t;
  1223.   {
  1224.       return (jdate (t) - 0.5) + 
  1225.          (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
  1226. ***************
  1227. *** 379,385
  1228.   static double jtime(t)
  1229.   struct tm *t;
  1230.   {
  1231. !     return (jdate(t) - 0.5) + 
  1232.          (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
  1233.   }
  1234.   
  1235.  
  1236. --- 484,490 -----
  1237.   jtime (t)
  1238.       struct tm *t;
  1239.   {
  1240. !     return (jdate (t) - 0.5) + 
  1241.          (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
  1242.   }
  1243.   
  1244. ***************
  1245. *** 383,390
  1246.          (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
  1247.   }
  1248.   
  1249. - /*  JYEAR  --  Convert Julian date to year, month, day, which are
  1250. -            returned via integer pointers to integers.  */
  1251.   
  1252.   static void jyear(td, yy, mm, dd)
  1253.   double td;
  1254.  
  1255. --- 488,493 -----
  1256.          (t->tm_sec + 60 * (t->tm_min + 60 * t->tm_hour)) / 86400.0;
  1257.   }
  1258.   
  1259.   
  1260.   /*
  1261.    * JYEAR  --  Convert Julian date to year, month, day, which are
  1262. ***************
  1263. *** 386,394
  1264.   /*  JYEAR  --  Convert Julian date to year, month, day, which are
  1265.              returned via integer pointers to integers.  */
  1266.   
  1267. ! static void jyear(td, yy, mm, dd)
  1268. ! double td;
  1269. ! int *yy, *mm, *dd;
  1270.   {
  1271.       double j, d, y, m;
  1272.   
  1273.  
  1274. --- 489,504 -----
  1275.   }
  1276.   
  1277.   
  1278. ! /*
  1279. !  * JYEAR  --  Convert Julian date to year, month, day, which are
  1280. !  *           returned via integer pointers to integers.  
  1281. !  */
  1282. ! static
  1283. ! void
  1284. ! jyear (td, yy, mm, dd)
  1285. !     double    td;
  1286. !     int    *yy, *mm, *dd;
  1287.   {
  1288.       double j, d, y, m;
  1289.   
  1290. ***************
  1291. *** 392,398
  1292.   {
  1293.       double j, d, y, m;
  1294.   
  1295. !     td += 0.5;           /* Astronomical to civil */
  1296.       j = floor(td);
  1297.       j = j - 1721119.0;
  1298.       y = floor(((4 * j) - 1) / 146097.0);
  1299.  
  1300. --- 502,508 -----
  1301.   {
  1302.       double j, d, y, m;
  1303.   
  1304. !     td += 0.5;                /* Astronomical to civil */
  1305.       j = floor(td);
  1306.       j = j - 1721119.0;
  1307.       y = floor(((4 * j) - 1) / 146097.0);
  1308. ***************
  1309. *** 406,412
  1310.       d = floor((d + 5.0) / 5.0);
  1311.       y = (100.0 * y) + j;
  1312.       if (m < 10.0)
  1313. !        m = m + 3;
  1314.       else {
  1315.          m = m - 9;
  1316.          y = y + 1;
  1317.  
  1318. --- 516,522 -----
  1319.       d = floor((d + 5.0) / 5.0);
  1320.       y = (100.0 * y) + j;
  1321.       if (m < 10.0)
  1322. !         m = m + 3;
  1323.       else {
  1324.           m = m - 9;
  1325.           y = y + 1;
  1326. ***************
  1327. *** 408,415
  1328.       if (m < 10.0)
  1329.          m = m + 3;
  1330.       else {
  1331. !        m = m - 9;
  1332. !        y = y + 1;
  1333.       }
  1334.       *yy = y;
  1335.       *mm = m;
  1336.  
  1337. --- 518,525 -----
  1338.       if (m < 10.0)
  1339.           m = m + 3;
  1340.       else {
  1341. !         m = m - 9;
  1342. !         y = y + 1;
  1343.       }
  1344.       *yy = y;
  1345.       *mm = m;
  1346. ***************
  1347. *** 416,422
  1348.       *dd = d;
  1349.   }
  1350.   
  1351. - /*  JHMS  --  Convert Julian time to hour, minutes, and seconds.  */
  1352.   
  1353.   static void jhms(j, h, m, s)
  1354.   double j;
  1355.  
  1356. --- 526,531 -----
  1357.       *dd = d;
  1358.   }
  1359.   
  1360.   
  1361.   /*
  1362.    * JHMS  --  Convert Julian time to hour, minutes, and seconds.
  1363. ***************
  1364. *** 418,426
  1365.   
  1366.   /*  JHMS  --  Convert Julian time to hour, minutes, and seconds.  */
  1367.   
  1368. ! static void jhms(j, h, m, s)
  1369. ! double j;
  1370. ! int *h, *m, *s;
  1371.   {
  1372.       long ij;
  1373.   
  1374.  
  1375. --- 527,541 -----
  1376.   }
  1377.   
  1378.   
  1379. ! /*
  1380. !  * JHMS  --  Convert Julian time to hour, minutes, and seconds.
  1381. !  */
  1382. ! static
  1383. ! void
  1384. ! jhms(j, h, m, s)
  1385. !     double j;
  1386. !     int *h, *m, *s;
  1387.   {
  1388.       long ij;
  1389.   
  1390. ***************
  1391. *** 424,430
  1392.   {
  1393.       long ij;
  1394.   
  1395. !     j += 0.5;           /* Astronomical to civil */
  1396.       ij = (j - floor(j)) * 86400.0;
  1397.       *h = ij / 3600L;
  1398.       *m = (ij / 60L) % 60L;
  1399.  
  1400. --- 539,545 -----
  1401.   {
  1402.       long ij;
  1403.   
  1404. !     j += 0.5;                /* Astronomical to civil */
  1405.       ij = (j - floor(j)) * 86400.0;
  1406.       *h = ij / 3600L;
  1407.       *m = (ij / 60L) % 60L;
  1408. ***************
  1409. *** 431,447
  1410.       *s = ij % 60L;
  1411.   }
  1412.   
  1413. - /*  MEANPHASE  --  Calculates mean phase of the Moon for a given
  1414. -            base date and desired phase:
  1415. -                0.0   New Moon
  1416. -                0.25  First quarter
  1417. -                0.5   Full moon
  1418. -                0.75  Last quarter
  1419. -             Beware!!!  This routine returns meaningless
  1420. -                     results for any other phase arguments.  Don't
  1421. -             attempt to generalise it without understanding
  1422. -             that the motion of the moon is far more complicated
  1423. -             that this calculation reveals. */
  1424.   
  1425.   static double meanphase(sdate, phase, usek)
  1426.   double sdate, phase;
  1427.  
  1428. --- 546,551 -----
  1429.       *s = ij % 60L;
  1430.   }
  1431.   
  1432.   
  1433.   /*
  1434.    * MEANPHASE  --  Calculates mean phase of the Moon for a given
  1435. ***************
  1436. *** 443,451
  1437.               that the motion of the moon is far more complicated
  1438.               that this calculation reveals. */
  1439.   
  1440. ! static double meanphase(sdate, phase, usek)
  1441. ! double sdate, phase;
  1442. ! double *usek;
  1443.   {
  1444.       int yy, mm, dd;
  1445.       double k, t, t2, t3, nt1;
  1446.  
  1447. --- 547,567 -----
  1448.   }
  1449.   
  1450.   
  1451. ! /*
  1452. !  * MEANPHASE  --  Calculates mean phase of the Moon for a given
  1453. !  *        base date.  This argument K to this function is
  1454. !  *        the precomputed synodic month index, given by:
  1455. !  *
  1456. !  *            K = (year - 1900) * 12.3685
  1457. !  *
  1458. !  *        where year is expressed as a year and fractional
  1459. !  *        year.
  1460. !  */
  1461. ! static
  1462. ! double
  1463. ! meanphase (sdate, k)
  1464. !     double    sdate, k;
  1465.   {
  1466.       double    t, t2, t3, nt1;
  1467.   
  1468. ***************
  1469. *** 447,454
  1470.   double sdate, phase;
  1471.   double *usek;
  1472.   {
  1473. !     int yy, mm, dd;
  1474. !     double k, t, t2, t3, nt1;
  1475.   
  1476.       jyear(sdate, &yy, &mm, &dd);
  1477.   
  1478.  
  1479. --- 563,569 -----
  1480.   meanphase (sdate, k)
  1481.       double    sdate, k;
  1482.   {
  1483. !     double    t, t2, t3, nt1;
  1484.   
  1485.       /* Time in Julian centuries from 1900 January 0.5 */
  1486.       t = (sdate - 2415020.0) / 36525;
  1487. ***************
  1488. *** 450,459
  1489.       int yy, mm, dd;
  1490.       double k, t, t2, t3, nt1;
  1491.   
  1492. -     jyear(sdate, &yy, &mm, &dd);
  1493. -     k = (yy + ((mm - 1) * (1.0 / 12.0)) - 1900) * 12.3685;
  1494.       /* Time in Julian centuries from 1900 January 0.5 */
  1495.       t = (sdate - 2415020.0) / 36525;
  1496.       t2 = t * t;           /* Square for frequent use */
  1497.  
  1498. --- 565,570 -----
  1499.   {
  1500.       double    t, t2, t3, nt1;
  1501.   
  1502.       /* Time in Julian centuries from 1900 January 0.5 */
  1503.       t = (sdate - 2415020.0) / 36525;
  1504.       t2 = t * t;           /* Square for frequent use */
  1505. ***************
  1506. *** 459,465
  1507.       t2 = t * t;           /* Square for frequent use */
  1508.       t3 = t2 * t;           /* Cube for frequent use */
  1509.   
  1510. -     *usek = k = floor(k) + phase;
  1511.       nt1 = 2415020.75933 + synmonth * k
  1512.             + 0.0001178 * t2
  1513.             - 0.000000155 * t3
  1514.  
  1515. --- 570,575 -----
  1516.       t2 = t * t;           /* Square for frequent use */
  1517.       t3 = t2 * t;           /* Cube for frequent use */
  1518.   
  1519.       nt1 = 2415020.75933 + synmonth * k
  1520.           + 0.0001178 * t2
  1521.           - 0.000000155 * t3
  1522. ***************
  1523. *** 461,469
  1524.   
  1525.       *usek = k = floor(k) + phase;
  1526.       nt1 = 2415020.75933 + synmonth * k
  1527. !           + 0.0001178 * t2
  1528. !           - 0.000000155 * t3
  1529. !           + 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
  1530.   
  1531.       return nt1;
  1532.   }
  1533.  
  1534. --- 571,579 -----
  1535.       t3 = t2 * t;           /* Cube for frequent use */
  1536.   
  1537.       nt1 = 2415020.75933 + synmonth * k
  1538. !         + 0.0001178 * t2
  1539. !         - 0.000000155 * t3
  1540. !         + 0.00033 * dsin(166.56 + 132.87 * t - 0.009173 * t2);
  1541.   
  1542.       return nt1;
  1543.   }
  1544. ***************
  1545. *** 468,477
  1546.       return nt1;
  1547.   }
  1548.   
  1549. - /*  TRUEPHASE  --  Given a K value used to determine the
  1550. -            mean phase of the new moon, and a phase
  1551. -            selector (0.0, 0.25, 0.5, 0.75), obtain
  1552. -            the true, corrected phase time.  */
  1553.   
  1554.   static double truephase(k, phase)
  1555.   double k, phase;
  1556.  
  1557. --- 578,583 -----
  1558.       return nt1;
  1559.   }
  1560.   
  1561.   
  1562.   /*
  1563.    * TRUEPHASE  --  Given a K value used to determine the
  1564. ***************
  1565. *** 473,480
  1566.              selector (0.0, 0.25, 0.5, 0.75), obtain
  1567.              the true, corrected phase time.  */
  1568.   
  1569. ! static double truephase(k, phase)
  1570. ! double k, phase;
  1571.   {
  1572.       double t, t2, t3, pt, m, mprime, f;
  1573.       int apcor = FALSE;
  1574.  
  1575. --- 579,595 -----
  1576.   }
  1577.   
  1578.   
  1579. ! /*
  1580. !  * TRUEPHASE  --  Given a K value used to determine the
  1581. !  *        mean phase of the new moon, and a phase
  1582. !  *        selector (0.0, 0.25, 0.5, 0.75), obtain
  1583. !  *        the true, corrected phase time.
  1584. !  */
  1585. ! static
  1586. ! double
  1587. ! truephase(k, phase)
  1588. !     double k, phase;
  1589.   {
  1590.       double t, t2, t3, pt, m, mprime, f;
  1591.       int apcor = FALSE;
  1592. ***************
  1593. *** 545,551
  1594.          apcor = TRUE;
  1595.       }
  1596.       if (!apcor) {
  1597. !            fprintf(stderr, "TRUEPHASE called with invalid phase selector.\n");
  1598.          abort();
  1599.       }
  1600.       return pt;
  1601.  
  1602. --- 660,667 -----
  1603.          apcor = TRUE;
  1604.       }
  1605.       if (!apcor) {
  1606. !            (void)fprintf (stderr,
  1607. !         "TRUEPHASE called with invalid phase selector.\n");
  1608.          abort();
  1609.       }
  1610.       return pt;
  1611. ***************
  1612. *** 551,560
  1613.       return pt;
  1614.   }
  1615.   
  1616. - /*  PHASEHUNT  --  Find time of phases of the moon which surround
  1617. -            the current date.  Five phases are found, starting
  1618. -            and ending with the new moons which bound the
  1619. -            current lunation.  */
  1620.   
  1621.   static void phasehunt(sdate, phases)
  1622.   double sdate;
  1623.  
  1624. --- 667,672 -----
  1625.       return pt;
  1626.   }
  1627.   
  1628.   
  1629.   /*
  1630.    * PHASEHUNT  --  Find time of phases of the moon which surround
  1631. ***************
  1632. *** 556,564
  1633.              and ending with the new moons which bound the
  1634.              current lunation.  */
  1635.   
  1636. ! static void phasehunt(sdate, phases)
  1637. ! double sdate;
  1638. ! double phases[5];
  1639.   {
  1640.       double adate, k1, k2, nt1, nt2;
  1641.   
  1642.  
  1643. --- 668,685 -----
  1644.   }
  1645.   
  1646.   
  1647. ! /*
  1648. !  * PHASEHUNT  --  Find time of phases of the moon which surround
  1649. !  *        the current date.  Five phases are found, starting
  1650. !  *        and ending with the new moons which bound the
  1651. !  *        current lunation.
  1652. !  */
  1653. ! static
  1654. ! void
  1655. ! phasehunt (sdate, phases)
  1656. !     double    sdate;
  1657. !     double    phases [5];
  1658.   {
  1659.       int    yy, mm, dd;
  1660.       double    adate, k1, k2, nt1, nt2;
  1661. ***************
  1662. *** 560,566
  1663.   double sdate;
  1664.   double phases[5];
  1665.   {
  1666. !     double adate, k1, k2, nt1, nt2;
  1667.   
  1668.       adate = sdate - 45;
  1669.       nt1 = meanphase(adate, 0.0, &k1);
  1670.  
  1671. --- 681,688 -----
  1672.       double    sdate;
  1673.       double    phases [5];
  1674.   {
  1675. !     int    yy, mm, dd;
  1676. !     double    adate, k1, k2, nt1, nt2;
  1677.   
  1678.       adate = sdate - 45;
  1679.       jyear(adate, &yy, &mm, &dd);
  1680. ***************
  1681. *** 563,569
  1682.       double adate, k1, k2, nt1, nt2;
  1683.   
  1684.       adate = sdate - 45;
  1685. !     nt1 = meanphase(adate, 0.0, &k1);
  1686.       while (TRUE) {
  1687.          adate += synmonth;
  1688.          nt2 = meanphase(adate, 0.0, &k2);
  1689.  
  1690. --- 685,694 -----
  1691.       double    adate, k1, k2, nt1, nt2;
  1692.   
  1693.       adate = sdate - 45;
  1694. !     jyear(adate, &yy, &mm, &dd);
  1695. !     k1 = floor((yy + ((mm - 1) * (1.0 / 12.0)) - 1900) * 12.3685);
  1696. !     adate = nt1 = meanphase(adate, k1);
  1697.       while (TRUE) {
  1698.           adate += synmonth;
  1699.           k2 = k1 + 1;
  1700. ***************
  1701. *** 565,576
  1702.       adate = sdate - 45;
  1703.       nt1 = meanphase(adate, 0.0, &k1);
  1704.       while (TRUE) {
  1705. !        adate += synmonth;
  1706. !        nt2 = meanphase(adate, 0.0, &k2);
  1707. !        if (nt1 <= sdate && nt2 > sdate)
  1708. !           break;
  1709. !        nt1 = nt2;
  1710. !        k1 = k2;
  1711.       }
  1712.       phases[0] = truephase(k1, 0.0);
  1713.       phases[1] = truephase(k1, 0.25);
  1714.  
  1715. --- 690,702 -----
  1716.   
  1717.       adate = nt1 = meanphase(adate, k1);
  1718.       while (TRUE) {
  1719. !         adate += synmonth;
  1720. !         k2 = k1 + 1;
  1721. !         nt2 = meanphase(adate, k2);
  1722. !         if (nt1 <= sdate && nt2 > sdate)
  1723. !             break;
  1724. !         nt1 = nt2;
  1725. !         k1 = k2;
  1726.       }
  1727.       phases[0] = truephase(k1, 0.0);
  1728.       phases[1] = truephase(k1, 0.25);
  1729. ***************
  1730. *** 579,585
  1731.       phases[4] = truephase(k2, 0.0);
  1732.   }
  1733.   
  1734. - /*  KEPLER  --    Solve the equation of Kepler.  */
  1735.   
  1736.   static double kepler(m, ecc)
  1737.   double m, ecc;
  1738.  
  1739. --- 705,710 -----
  1740.       phases[4] = truephase(k2, 0.0);
  1741.   }
  1742.   
  1743.   
  1744.   /*
  1745.    * KEPLER  --    Solve the equation of Kepler.
  1746. ***************
  1747. *** 581,588
  1748.   
  1749.   /*  KEPLER  --    Solve the equation of Kepler.  */
  1750.   
  1751. ! static double kepler(m, ecc)
  1752. ! double m, ecc;
  1753.   {
  1754.       double e, delta;
  1755.   #define EPSILON 1E-6
  1756.  
  1757. --- 706,719 -----
  1758.   }
  1759.   
  1760.   
  1761. ! /*
  1762. !  * KEPLER  --    Solve the equation of Kepler.
  1763. !  */
  1764. ! static
  1765. ! double
  1766. ! kepler(m, ecc)
  1767. !     double m, ecc;
  1768.   {
  1769.       double e, delta;
  1770.   #define EPSILON 1E-6
  1771. ***************
  1772. *** 589,597
  1773.   
  1774.       e = m = torad(m);
  1775.       do {
  1776. !        delta = e - ecc * sin(e) - m;
  1777. !        e -= delta / (1 - ecc * cos(e));
  1778. !     } while (abs(delta) > EPSILON);
  1779.       return e;
  1780.   }
  1781.   
  1782.  
  1783. --- 720,728 -----
  1784.   
  1785.       e = m = torad(m);
  1786.       do {
  1787. !         delta = e - ecc * sin(e) - m;
  1788. !         e -= delta / (1 - ecc * cos(e));
  1789. !     } while (abs (delta) > EPSILON);
  1790.       return e;
  1791.   }
  1792.   
  1793. ***************
  1794. *** 595,601
  1795.       return e;
  1796.   }
  1797.   
  1798. - /*  PHASE  --  Calculate phase of moon as a fraction:
  1799.   
  1800.       The argument is the time for which the phase is requested,
  1801.       expressed as a Julian date and fraction.  Returns the terminator
  1802.  
  1803. --- 726,731 -----
  1804.       return e;
  1805.   }
  1806.   
  1807.   
  1808.   /*
  1809.    * PHASE  --  Calculate phase of moon as a fraction:
  1810. ***************
  1811. *** 597,610
  1812.   
  1813.   /*  PHASE  --  Calculate phase of moon as a fraction:
  1814.   
  1815. !     The argument is the time for which the phase is requested,
  1816. !     expressed as a Julian date and fraction.  Returns the terminator
  1817. !     phase angle as a percentage of a full circle (i.e., 0 to 1),
  1818. !     and stores into pointer arguments the illuminated fraction of
  1819. !         the Moon's disc, the Moon's age in days and fraction, the
  1820. !     distance of the Moon from the centre of the Earth, and the
  1821. !     angular diameter subtended by the Moon as seen by an observer
  1822. !     at the centre of the Earth.
  1823.   
  1824.   */
  1825.   
  1826.  
  1827. --- 727,744 -----
  1828.   }
  1829.   
  1830.   
  1831. ! /*
  1832. !  * PHASE  --  Calculate phase of moon as a fraction:
  1833. !  *
  1834. !  *    The argument is the time for which the phase is requested,
  1835. !  *    expressed as a Julian date and fraction.  Returns the terminator
  1836. !  *    phase angle as a percentage of a full circle (i.e., 0 to 1),
  1837. !  *    and stores into pointer arguments the illuminated fraction of
  1838. !  *    the Moon's disc, the Moon's age in days and fraction, the
  1839. !  *    distance of the Moon from the centre of the Earth, and the
  1840. !  *    angular diameter subtended by the Moon as seen by an observer
  1841. !  *    at the centre of the Earth.
  1842. !  */
  1843.   
  1844.   static
  1845.   double
  1846. ***************
  1847. *** 606,621
  1848.       angular diameter subtended by the Moon as seen by an observer
  1849.       at the centre of the Earth.
  1850.   
  1851. ! */
  1852. ! static double phase(pdate, pphase, mage, dist, angdia, sudist, suangdia)
  1853. ! double pdate;
  1854. ! double *pphase;            /* Illuminated fraction */
  1855. ! double *mage;               /* Age of moon in days */
  1856. ! double *dist;               /* Distance in kilometres */
  1857. ! double *angdia;            /* Angular diameter in degrees */
  1858. ! double *sudist;            /* Distance to Sun */
  1859. ! double *suangdia;                  /* Sun's angular diameter */
  1860.   {
  1861.   
  1862.       double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
  1863.  
  1864. --- 740,755 -----
  1865.    *    at the centre of the Earth.
  1866.    */
  1867.   
  1868. ! static
  1869. ! double
  1870. ! phase (pdate, pphase, mage, dist, angdia, sudist, suangdia)
  1871. !     double    pdate;
  1872. !     double    *pphase;        /* Illuminated fraction */
  1873. !     double    *mage;            /* Age of moon in days */
  1874. !     double    *dist;            /* Distance in kilometres */
  1875. !     double    *angdia;        /* Angular diameter in degrees */
  1876. !     double    *sudist;        /* Distance to Sun */
  1877. !     double    *suangdia;        /* Sun's angular diameter */
  1878.   {
  1879.   
  1880.       double    Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
  1881. ***************
  1882. *** 618,628
  1883.   double *suangdia;                  /* Sun's angular diameter */
  1884.   {
  1885.   
  1886. !     double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
  1887. !            mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon, BetaM,
  1888. !            MoonAge, MoonPhase,
  1889. !            MoonDist, MoonDFrac, MoonAng, MoonPar,
  1890. !            F, SunDist, SunAng;
  1891.   
  1892.           /* Calculation of the Sun's position */
  1893.   
  1894.  
  1895. --- 752,762 -----
  1896.       double    *suangdia;        /* Sun's angular diameter */
  1897.   {
  1898.   
  1899. !     double    Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
  1900. !         mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon, BetaM,
  1901. !         MoonAge, MoonPhase,
  1902. !         MoonDist, MoonDFrac, MoonAng, MoonPar,
  1903. !         F, SunDist, SunAng;
  1904.   
  1905.           /* Calculation of the Sun's position */
  1906.   
  1907. ***************
  1908. *** 626,636
  1909.   
  1910.           /* Calculation of the Sun's position */
  1911.   
  1912. !     Day = pdate - epoch;        /* Date within epoch */
  1913. !     N = fixangle((360 / 365.2422) * Day); /* Mean anomaly of the Sun */
  1914. !     M = fixangle(N + elonge - elongp);    /* Convert from perigee
  1915. !                        co-ordinates to epoch 1980.0 */
  1916. !     Ec = kepler(M, eccent);     /* Solve equation of Kepler */
  1917.       Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
  1918.       Ec = 2 * todeg(atan(Ec));   /* True anomaly */
  1919.           Lambdasun = fixangle(Ec + elongp);  /* Sun's geocentric ecliptic
  1920.  
  1921. --- 760,770 -----
  1922.   
  1923.           /* Calculation of the Sun's position */
  1924.   
  1925. !     Day = pdate - epoch;            /* Date within epoch */
  1926. !     N = fixangle((360 / 365.2422) * Day);    /* Mean anomaly of the Sun */
  1927. !     M = fixangle(N + elonge - elongp);    /* Convert from perigee
  1928. !                          co-ordinates to epoch 1980.0 */
  1929. !     Ec = kepler(M, eccent);            /* Solve equation of Kepler */
  1930.       Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
  1931.       Ec = 2 * todeg(atan(Ec));        /* True anomaly */
  1932.           Lambdasun = fixangle(Ec + elongp);    /* Sun's geocentric ecliptic
  1933. ***************
  1934. *** 632,640
  1935.                          co-ordinates to epoch 1980.0 */
  1936.       Ec = kepler(M, eccent);     /* Solve equation of Kepler */
  1937.       Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
  1938. !     Ec = 2 * todeg(atan(Ec));   /* True anomaly */
  1939. !         Lambdasun = fixangle(Ec + elongp);  /* Sun's geocentric ecliptic
  1940. !                            longitude */
  1941.       /* Orbital distance factor */
  1942.       F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
  1943.       SunDist = sunsmax / F;        /* Distance to Sun in km */
  1944.  
  1945. --- 766,774 -----
  1946.                            co-ordinates to epoch 1980.0 */
  1947.       Ec = kepler(M, eccent);            /* Solve equation of Kepler */
  1948.       Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
  1949. !     Ec = 2 * todeg(atan(Ec));        /* True anomaly */
  1950. !         Lambdasun = fixangle(Ec + elongp);    /* Sun's geocentric ecliptic
  1951. !                             longitude */
  1952.       /* Orbital distance factor */
  1953.       F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
  1954.       SunDist = sunsmax / F;            /* Distance to Sun in km */
  1955. ***************
  1956. *** 637,644
  1957.                              longitude */
  1958.       /* Orbital distance factor */
  1959.       F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
  1960. !     SunDist = sunsmax / F;        /* Distance to Sun in km */
  1961. !         SunAng = F * sunangsiz;     /* Sun's angular size in degrees */
  1962.   
  1963.   
  1964.           /* Calculation of the Moon's position */
  1965.  
  1966. --- 771,778 -----
  1967.                               longitude */
  1968.       /* Orbital distance factor */
  1969.       F = ((1 + eccent * cos(torad(Ec))) / (1 - eccent * eccent));
  1970. !     SunDist = sunsmax / F;            /* Distance to Sun in km */
  1971. !         SunAng = F * sunangsiz;        /* Sun's angular size in degrees */
  1972.   
  1973.   
  1974.           /* Calculation of the Moon's position */
  1975. ***************
  1976. *** 725,728
  1977.       *suangdia = SunAng;
  1978.       return fixangle(MoonAge) / 360.0;
  1979.   }
  1980. ! #endif    /* NO_SUN_MOON */
  1981.  
  1982. --- 859,862 -----
  1983.       *suangdia = SunAng;
  1984.       return fixangle(MoonAge) / 360.0;
  1985.   }
  1986. ! #endif  /* NO_SUN_MOON */
  1987.