[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

moon code



PureBytes Links

Trading Reference Links

Here are a couple of routines that will do the trick.

Clyde

= = = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = =

{  MOON EFFECTS by Bradley E. Schaefer
   Calculate illumination (synodic) phase

   This program helps anyone who needs to know the Moon's
   phase (age), distance, and position along the ecliptic on
   any date within several thousand years in the past or future.
   To illustrate its application, Bradley Schaefer applied it
   to a number of famous events influenced by the Moon in
   World War II.  His article appeared in Sky & Telescope for
   April 1994, page 86.
}
Vars: VV(0),J(0),IP(0),mday(0);

J = DateToJulian(Date) ;
VV = (J + 7.5 - 2451550.1) / 29.530588853;  {7.5 to adjust to reality}
VV = FracPortion(VV);                  {probably due to Omega}
IF VV < 0 THEN VV = VV + 1;             {DTJ function.}

Moonday_V2 = VV * 29.530588853;            { Moon's age in days  }


= = = = = = = = = = = = = = = = = = = = = = = = = == = = = = = = =

{
  Function Moondays returns the number of days since a new moon.
  The values returned range between 0 and 29.
  (0 = new, and 15 is a full moon to +/- 2 day accuracy.)
  
  Author: Gary Funck, gary@xxxxxxxxxxxx, 7/15/97
  No restrictions on use/copying. No warranties, expressed/implied.

  This code uses an approximation described in the the "Astro FAQ";
  summarized below:

  Subject: C.11  How do I calculate the phase of the moon?
  Author: Bill Jefferys <bill@xxxxxxxxxxxxxxxxxxx>
  
  John Horton Conway (the Princeton mathematician who is responsible for
  "the Game of Life") wrote a book with Guy and Berlekamp, _Winning
  Ways_, that describes in Volume 2 a number of useful calendrical
  rules.  One of these is an easy "in your head" algorithm for
  calculating the phase of the Moon, good to a day or better depending
  on whether you use his refinements or not.
  
  In the 20th century, calculate the remainder upon dividing the
  last two digits of the year by 19; if greater than 9, subtract
  19 from this to get a number between -9 and 9. 
  
  Multiply the result by 11 and reduce modulo 30 to obtain a
  number between -29 and +29.
  
  Add the day of the month and the number of the month (except
  for Jan and Feb use 3 and 4 for the month number instead of
  1 and 2).
  
  Subtract 4.
  
  Reduce modulo 30 to get a number between 0 and 29. This is
  the age of the Moon.
  
  Example: What was the phase of the Moon on D-Day (June 6,
  1944)?
  
  Answer: 44/19=2 remainder 6.
  
  6*11=66, reduce modulo 30 to get 6.
  
  Add 6+6 to this and subtract 4: 6+6+6-4=14; the Moon was (nearly)
  full. I understand that the planners of D-day did care about the phase
  of the Moon, either because of illumination or because of tides. I
  think that Don Olsen recently discussed this in _Sky and Telescope_
  (within the past several years).
  
  In the 21st century use -8.3 days instead of -4 for the last number.
  
  Conway also gives refinements for the leap year cycle and also
  for the slight variations in the lengths of months; what I have
  given should be good to +/- a day or so.
}
inputs: dt(numericsimple);
variables: x1(0), x2(0), x3(0), x4(0);
    x1 = Mod(year(dt), 19);
    if x1 > 9 then x1 = x1 - 19;
    x2 = Mod(x1 * 11, 30);
    x3 = month(dt);
    if month(dt) < 3 then x3 = x3 + 2;
    x4 = x2 + dayofmonth(dt) + x3 - 4;
    Moondays = Mod(x4, 30);


 
- - - - - - - - - - - - - - - - - - - - -  - - - - - - -
Clyde Lee   Chairman/CEO          (Home of SwingMachine)
SYTECH Corporation          email: clydelee@xxxxxxxxxxxx  
7910 Westglen, Suite 105       Office:    (713) 783-9540
Houston,  TX  77063               Fax:    (713) 783-1092
Details at:                      www.theswingmachine.com
- - - - - - - - - - - - - - - - - - - -  - - - - - - - -