Index: /trunk/tools/bills/comparep2detections
===================================================================
--- /trunk/tools/bills/comparep2detections	(revision 39115)
+++ /trunk/tools/bills/comparep2detections	(revision 39116)
@@ -8,5 +8,4 @@
 use File::Basename;
 use PS::IPP::Config 1.01 qw( :standard );
-
 
 my $joinType = '1and2';
@@ -20,5 +19,5 @@
 GetOptions(
     "testdata=s"        =>  \$testdata,
-#    "sasdata=s"         =>  \$sasdata,
+    "sasdata=s"         =>  \$sasdata,
     "release=s"         =>  \$release,
     "join=s"            =>  \$joinType,
@@ -34,6 +33,5 @@
 
 die "need one of --testdata or --release\n" 
-    unless defined $testdata or defined $release;
-
+    unless defined $testdata or defined $release or defined $sasdata;
 
 
@@ -48,4 +46,14 @@
 my $stilts = "java -jar $stiltsJar";
 
+my $command;
+
+# find exp_id and exp_name.
+$command = "$stilts tcat in=$in'#'FrameMeta icmd='keepcols \"frameID frameName\";' ofmt=ascii | grep -v '#'";
+my $line = `$command`;
+chomp $line;
+my ($exp_id, $exp_name) = split " ", $line;
+
+print "$exp_id $exp_name\n" if $verbose;
+
 # file name for concatenated detection extensions
 my $detcat = "cat." . basename($in);
@@ -53,6 +61,6 @@
 runcommand( "concatp2batch $in $detcat");
 
-# find exp_id. XXX: I think that we could use file batch name for this or require user to supply it as an argument
-my $command = "$stilts tcat in=$detcat icmd='head 1;keepcols imageID;' ofmt=ascii | grep -v '#'";
+if (0) {
+$command = "$stilts tcat in=$detcat icmd='head 1;keepcols imageID;' ofmt=ascii | grep -v '#'";
 my $imageID = `$command`;
 # XXX TODO: check for success
@@ -60,4 +68,5 @@
 my $exp_id = int($imageID / 100);
 print "exp_id is $exp_id\n" if $verbose;
+}
 
 my $smf;
@@ -65,9 +74,13 @@
 #    my $testdata = "/data/ippc19.0/home/bills/ipp/ippToPsps/test/testdata";
     $smf = sprintf "%s/test.%02d.smf", $testdata, $exp_id;
-#} elsif ($sasdata) {
-    # this attempted hack did not work
-#    die "only exp_id 1 works right now for sasdata\n" unless $exp_id eq 1;
-#
-#    $smf = sprintf "%s/o5748g0363o.358745.cm.1218981.smf", $sasdata;
+} elsif ($sasdata) {
+    # go find the smf for this exposure in the sasdata directory
+    my $pattern = "$sasdata/$exp_name*.smf";
+    my @smfs = glob($pattern);
+
+    # there should only be one of these
+    $smf = $smfs[0];
+
+    die "failed to find smf for $exp_name in sasdata\n" unless $smf;
 } else {
     # XXX: look up the smf for the exposure here
@@ -79,18 +92,12 @@
     die "failed to find path_base for $exp_id\n" unless $path_base;
     $smf = "$path_base.smf";
-    print "$smf for $exp_id is $smf\n";
 }
+print "$smf for $exp_id is $smf\n" if $verbose;
 
 my $ippcat = "cat." . basename($smf);
 
-if ($smf =~ /^neb:/) {
-    my $ipprc = PS::IPP::Config->new();
-    my $resolved = $ipprc->file_resolve($smf);
-    die "failed to resolve $smf\n" unless $resolved;
-    $smf = $resolved;
-}
-
 $command = "concatsmf $smf $ippcat";
 $command .= " --test" if $testdata;
+$command .= " --exp_id $exp_id" if $sasdata;
 
 runcommand($command);
@@ -106,4 +113,5 @@
 $command = "adddeltacolumns $matched $out";
 $command .= " --check" if $check;
+$command .= " --save-temps" if $save_temps;
 
 runcommand($command);
