Index: trunk/tools/microtest.pl
===================================================================
--- trunk/tools/microtest.pl	(revision 27441)
+++ trunk/tools/microtest.pl	(revision 27442)
@@ -16,4 +16,5 @@
 my ($label);                               # Label of interest
 my ($verbose);                             # Verbosity?
+my ($save_temps);                          # Save temporary outputs?
 
 GetOptions(
@@ -24,4 +25,5 @@
            'label=s' => \$label, # Label of interest
            'verbose' => \$verbose, # Verbosity?
+    'save-temps' => \$save_temps,  # Save temporary outputs?
            ) or die "Unable to parse arguments.\n";
 die "Unknown option: @ARGV\n" if @ARGV;
@@ -42,5 +44,5 @@
 # Exposures of interest
 my $exps = $db->selectall_arrayref(
-        "SELECT exp_id, exp_name, magic_id, outroot FROM magicRun JOIN rawExp USING(exp_id) WHERE label = '$label' AND magicRun.state = 'full'",
+        "SELECT exp_id, exp_name, magic_id, magicRun.outroot AS magic_path, camProcessedExp.path_base AS cam_path FROM magicRun JOIN rawExp USING(exp_id) WHERE label = '$label' AND magicRun.state = 'full'",
         Slice => {}
         ) or die "Unable to execute SQL: $DBI::errstr";
@@ -50,12 +52,50 @@
     my $name = $exp->{exp_name}; # Exposure name
     my $magic = $exp->{magic_id}; # Magic identifier
-    my $outroot = $exp->{outroot}; # Output root for magic
+    my $magic_path = $exp->{magic_path}; # Output root for magic
+    my $cam_path = $exp->{cam_path}; # Output root for camera
 
-    my $clusters = "$outroot/$id/$id.mgc.$magic.verify/${id}_clusterPos.txt"; # File with cluster RA,Dec
+    my $clusters = "${magic_path}/$id/$id.mgc.$magic.verify/${id}_clusterPos.txt"; # File with cluster RA,Dec
     die "Cannot find clusters file $clusters" unless -e $clusters;
 
-    my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX",
-                                          UNLINK => !$save_temps, SUFFIX => '.fits' );
+    my $astrom = "${cam_path}.smf"; # Astrometry file
+    die "Cannot find astrometry file $astrom" unless -e $astrom;
 
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-        run(command => "$ppCoord  , verbose => $verbose);
+    # Format the clusters file
+    open my $clustersFile, "$clusters" or die "Cannot open clusters file $clusters: $!";
+    my ($radecFile, $radecName) = tempfile( "/tmp/microtest.XXXX",
+                                          UNLINK => !$save_temps, SUFFIX => '.dat' );
+    my @contents = <$clustersFile>; # Contents of clusters file
+    foreach my $line (@contents) {
+        $line =~ s/^\s*//;
+        my ($ra, $dec) = split /\s+/, $line;
+        print $radecFile "$ra $dec\n" if defined $ra and defined $dec and $ra !~ /\w/ and $dec !~ /\w/;
+    }
+    close $clustersFile;
+    close $radecFile;
+
+    my $raws = $db->selectcol_arrayref("SELECT uri FROM rawImfile where exp_id = $id") or
+        die "Unable to execute SQL: $DBI::errstr";
+
+    open my $outFile, "${name}_clusters.xy" or die "Cannot open output file: $!";
+    foreach my $raw (@$raws) {
+#        my $resolved = `neb-locate --path $raw`; # Resolved filename
+#        chomp $resolved;
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => "$ppCoord -astrom $astrom -raw $raw -radec $radecName", verbose => $verbose);
+        die "Unable to run ppCoord" unless $success;
+
+        foreach my $line (@$stdout_buf) {
+            my @line = split /\s+/, $line;
+
+            my $ra = $line[0];
+            my $dec = $line[1];
+            my $x = $line[3];
+            my $y = $line[4];
+            my $chip = $line[5];
+            my $cell = $line[6];
+
+            print $outFile "$chip $cell $x $y $ra $dec\n";
+        }
+    }
+    close $outFile;
+}
