# watches / lunar / generate-sunrise

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61``` ```#!/opt/local/bin/perl # Generate the set of sunrise times for every day of the year # for the given latitude. # # This should handle the far northern or southern values better. # Currently bad data will be generated. I'm sorry to all of you # North Pole users! # use warnings; use strict; use Astro::Sunrise; die "Usage: \$0 longitude latitude (in degrees)\n" unless @ARGV == 2; my \$longitude = shift; my \$latitude = shift; my \$year = 2011; my \$tz = -5; my \$text_output = 0; for my \$month (1..12) { for my \$day (1..31) { my (\$sunrise,\$sunset) = sunrise( \$year, \$month, \$day, \$longitude, \$latitude, \$tz, 0 ); # Convert into minutes past midnight my (\$h,\$m) = split /:/, \$sunrise; \$sunrise = \$h * 60 + \$m; (\$h,\$m) = split /:/, \$sunset; \$sunset = \$h * 60 + \$m; if (\$text_output) { # Output a printf "%d %d %d %d\n", \$month, \$day, \$sunrise, \$sunset, ; } else { # Output the time as a packed array of 16-bit ints print pack("nn", \$sunrise, \$sunset); } } # Output an extra day so that we have 32 days per month print pack("nn", 0, 0) unless \$text_output } ```