Index: /trunk/ippScripts/scripts/register_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/register_imfile.pl	(revision 19720)
+++ /trunk/ippScripts/scripts/register_imfile.pl	(revision 19721)
@@ -21,4 +21,6 @@
 use PS::IPP::Metadata::Config;
 use PS::IPP::Metadata::Stats;
+
+my $PI = 3.141592653589793238462643383279502;
 
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
@@ -74,4 +76,7 @@
        { name => "FPA.TELESCOPE",  type => "constant", flag => "-telescope",       dtype => "string" }, # Telescope
        { name => "FPA.CAMERA",     type => "constant", flag => "-inst",            dtype => "string" }, # Instrument
+       { name => "FPA.LONGITUDE",  type => "constant", flag => "-longitude",       dtype => "float"  }, # Site longitude
+       { name => "FPA.LATITUDE",   type => "constant", flag => "-latitude",        dtype => "float"  }, # Site latitude
+       { name => "FPA.ELEVATION",  type => "constant", flag => "-elevation",       dtype => "float"  }, # Site elevation
        { name => "FPA.M1X",        type => "constant", flag => "-m1_x",            dtype => "float"  }, # M1X
        { name => "FPA.M1Y",        type => "constant", flag => "-m1_y",            dtype => "float"  }, # M1Y
@@ -172,4 +177,34 @@
 $command .= $stats->cmdflags();
 
+# determine solar-system parameters
+my $longitude = $stats->value_for_flag ("-longitude");
+my $latitude  = $stats->value_for_flag ("-latitude");
+my $elevation = $stats->value_for_flag ("-elevation");
+my $ra        = $stats->value_for_flag ("-ra");
+my $dec       = $stats->value_for_flag ("-decl");
+my $dateobs   = $stats->value_for_flag ("-dateobs");
+
+# if the needed data is available, pass it to sunmoon:
+if ($longitude && $latitude && $ra && $dec && $dateobs) {
+    
+    $longitude *= 12.0 / $PI; # longitude is reported in West radians; sunmoon wants it in West Hours
+    $latitude *= 180.0 / $PI; # latitude is reported in North radians; sunmoon wants it in North Degrees
+    $ra *= 180.0 / $PI; # ra is reported in radians; sunmoon wants it in degrees
+    $dec *= 180.0 / $PI; # dec is reported in radians; sunmoon wants it in degrees
+
+    my $sunmoon_cmd = "sunmoon -latitude $latitude -longitude $longitude -elevation $elevation $ra $dec $dateobs";
+    my $sunmoon_data = `$sunmoon_cmd`;
+    chomp $sunmoon_data;
+
+    # print STDERR "run: $sunmoon_cmd\n";
+    # print STDERR "got: $sunmoon_data\n";
+
+    if ($?) {
+	warn ("failure running $sunmoon_cmd, not supplying\n");
+    } else {
+	$command .= " $sunmoon_data";
+    }
+}
+
 $now_time = localtime();
 printf STDERR "\nrunning regtool update: %s\n", $now_time if $verbose;
