Trammell Hudson avatar Trammell Hudson committed 4e3015e

Sunrise generation script

Comments (0)

Files changed (1)

lunar/generate-sunrise

+#!/opt/local/bin/perl
+# Generate the set of sunrise times for every day of the year
+# for the given latitude.
+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
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.