# The astro package, initiated January 07, 2013

package.checkclib('astro');  # has C dynamic link library been found ?

astro.initstring :=
   'astro package v1.0.2 as of May 21, 2014\n';

# Provides an easier-to-use interface to `astro.sunriseset`. Longitudes and latitudes can be given in form
# of two tables containing degrees (a number), minutes  (a number), seconds (a number), and the orientation
# (the single character 'N', 'S', 'W', or 'E').
# The return is a table with the indices 'riseset', 'civil', 'astro', and 'nautical' times containing the
# rise and set times in `tm` representation. The index 'south' holds the time where the Sun is at south.
# See `astro.sunriseset` for further information.

# The function uses the `tm` time notation of the `clock` package.

# Example: astro.sun(2013, 1, 7, [6, 46, 58, 'E'], [51, 13, 32, 'N'])

# 07.01.2013

astro.sun := proc(y :: number, m :: number, d :: number, lon :: table, lat :: table) is
   local r := [astro.sunriseset(y, m, d,
      astro.dmstodec(unpack(lon)), astro.dmstodec(unpack(lat)))];
   if unassigned(clock) then import clock fi;
   r := clock.dectotm -> values(r, 1, 2, 4, 5, 7, 8, 10, 11, 13);
   return ['riseset' ~ [r[1], r[2]], 'civil' ~ [r[4], r[5]], 'nautical' ~ [r[7], r[8]], 'astro' ~ [r[10], r[11]],
     'south' ~ r[13]]
end;


# Provides an easier-to-use interface to `astro.moonriseset` and `astro.moonphase`. The first four arguments represent
# the year, month, day, and hour, all of type number. Longitudes and latitudes can be given in form of two tables
# containing degrees (a number), minutes  (a number), seconds (a number), and the orientation (the single character
# 'N', 'S', 'W', or 'E').
# The return is a table with the indices 'riseset', containing the rise and set times of the Moon in `tm`
# representation, and the index 'phase' which holds the computed Lunar phase (a float and an integer).

# See `astro.moonriseset` and `astro.moonphase` for further information.

# The function uses the `tm` time notation of the `clock` package.

# Example: astro.moon(2013, 1, 7, 0, [7, 6, 0, 'E'], [50, 43, 48, 'N'])

# 08.01.2013

astro.moon := proc(y :: number, m :: number, d :: number, h :: number, lon :: table, lat :: table) is
   local r := [astro.moonriseset(y, m, d,
      astro.dmstodec(unpack(lon)), astro.dmstodec(unpack(lat)))];
   if unassigned(clock) then import clock fi;
   r := clock.dectotm -> r;
   return ['riseset' ~ [r[1], r[2]], 'phase' ~ [astro.moonphase(y, m, d, h)]]
end;

