| Sunrise/Sunset Calculator Timed events can be tied to sunrise and sunset using this
Perl-based utility. The program uses a lookup table generated to match the exact
location of a user's computer, and automatically adjusts for daylight savings time.
This code was developed and tested under RedHat Linux 6.1.
Description
Accurate sunrise and sunset data can be used to time
events such as turning on security systems and watering lawns.This
routine returns the local sunset or sunrise times for today's date.
Using a database of official sunrise and sunset times available from NOAA,
the program must lookup the required data by finding the row and column
corresponding to today's date. This process begins by finding the row in the file corresponding to the day of the month. This is possible
using a simple 'grep' command to extract the line beginning with the day. Then,
by moving across to the corresponding month column, the required data
is returned.
| NOAA Table for the Year 2000

|
Scheduling Events for Sunrise/Sunset
The usual way to schedule events under Linux is to use the 'cron' utility;
however, this method repeats events only at fixed times. Events tied to sunrise
can be scheduled by running a 'cron' job in the early hours of the day to
execute a setup program which looks up the time of sunrise and, in turn,
launches an 'at' command with the desired time. It is also possible to
add or subtract a few minutes around sunrise, as required.
The standard Unix command 'at' will execute the contents of the file "source" at the sunrise time provided.
% at -f source sunrise_time
Where to Get the Table for the Year
The NOAA website may be found at:
http://aa.usno.navy.mil/AA/data/docs/RS_OneYear.html
Depending on the accuracy needed, the table for the Year 2000 could also serve for future years, as it includes Feb 29, if required. Sunrise and sunset times do not change substantially from one year to the next.
|