Index: /trunk/ippScripts/scripts/register_imfile.pl
===================================================================
--- /trunk/ippScripts/scripts/register_imfile.pl	(revision 30276)
+++ /trunk/ippScripts/scripts/register_imfile.pl	(revision 30277)
@@ -10,5 +10,6 @@
 my $date = `date`;
 print "\n\n";
-print "Starting script $0 on $host at $date\n\n";
+my $cmd_line = join ' ', @ARGV;
+print "Starting script $0 $cmd_line on $host at $date\n\n";
 
 use vars qw( $VERSION );
@@ -399,11 +400,51 @@
 	$second =~ s/Z//;
     }
-    if (($hour >= $ss_hour)&&($minute >= $ss_minute)&&($second >= $ss_second)) {
-	if (($hour <= $sr_hour)&&($minute <= $sr_minute)&&($second <= $sr_second)) {
-	    return(1);
+#     print "this exposure: $hour $minute $second\n";
+#     print "sunset:        $ss_hour $ss_minute $ss_second\n";
+#     print "sunrise:       $sr_hour $sr_minute $sr_second\n";
+#     printf "Hss: %d Mss: %d Sss: %d\n",($hour >= $ss_hour),($minute >= $ss_minute),($second >= $ss_second);
+#     printf "Hsr: %d Msr: %d Ssr: %d\n",($hour <= $sr_hour),($minute <= $sr_minute),($second <= $sr_second);
+
+    if (($hour > $ss_hour)&&($hour <= 24)) {
+	return(1); # After sunset by more than an hour, before midnight
+    }
+    elsif ($hour == $ss_hour) {
+	if ($minute > $ss_minute) {
+	    return(1); # After sunset by more than a minute
 	}
-    }
-    
-    return(0);
+	elsif ($minute == $ss_minute) {
+	    if ($second >= $ss_second) {
+		return(1); # After sunset by more than a second
+	    }
+	    else {
+		return(0);
+	    }
+	}
+	else {
+	    return(0);
+	}
+    }
+    elsif (($hour < $sr_hour)&&($hour >= 0)) {
+	return(1); # Before sunrise by more than an hour, but after midnight
+    }
+    elsif ($hour == $sr_hour) {
+	if ($minute < $sr_minute) {
+	    return(1); # Before sunrise by more than a minute
+	}
+	elsif ($minute == $sr_minute) {
+	    if ($second <= $sr_second) {
+		return(1); # Before sunrise by more than a second
+	    }
+	    else {
+		return(0);
+	    }
+	}
+	else {
+	    return(0);
+	}
+    }
+    else {
+	return(0); # We should never get here.
+    }
 }
 
Index: /trunk/ippTools/share/regtool_checkburntoolimfile.sql
===================================================================
--- /trunk/ippTools/share/regtool_checkburntoolimfile.sql	(revision 30276)
+++ /trunk/ippTools/share/regtool_checkburntoolimfile.sql	(revision 30277)
@@ -1,4 +1,4 @@
 SELECT DISTINCT
-       exp_name,
+       summitExp.exp_name,
        rawImfile.uri,
        summitExp.dateobs AS registered,
@@ -31,4 +31,4 @@
 	     AND summitExp.dateobs <= '@DATEOBS_END@'
 	     AND summitImfile.class_id = '@CLASS_ID@'
-	     AND (exp_name <= '@EXP_NAME@')                                                                     
+	     AND (summitExp.exp_name <= '@EXP_NAME@')                                                                     
 ORDER BY summitExp.dateobs
Index: /trunk/ippTools/src/regtool.c
===================================================================
--- /trunk/ippTools/src/regtool.c	(revision 30276)
+++ /trunk/ippTools/src/regtool.c	(revision 30277)
@@ -95,5 +95,5 @@
             psAbort("invalid option (this should not happen)");
     }
-
+    psTrace("regtool",9,"Attempting to free config\n");
     psFree(config);
     pmConfigDone();
@@ -204,4 +204,8 @@
 
   // convert regular class_id format to summitImfile.class_id format
+  rep = psStringCopy(class_id);
+  psFree(class_id);
+  class_id = rep;
+  
   psStringSubstitute(&class_id,"ota","XY");
   
@@ -211,5 +215,5 @@
   psStringSubstitute(&query,dateobs_end,"@DATEOBS_END@");
 
-  fprintf(stderr,"%s",query);
+  // fprintf(stderr,"%s",query);
 
   if (!p_psDBRunQuery(config->dbh, query)) {
@@ -237,5 +241,4 @@
   if (!psArrayLength(output)) {
     psTrace("regtool", PS_LOG_INFO, "no rows found");
-    psFree(output);
     return true;
   }
