Index: trunk/tools/microtest.pl
===================================================================
--- trunk/tools/microtest.pl	(revision 27611)
+++ trunk/tools/microtest.pl	(revision 27612)
@@ -16,7 +16,9 @@
 my ($db_host, $db_name, $db_user, $db_pw); # Database details
 my ($label);                               # Label of interest
+my ($exp_id);                              # Exposure of interest
 my ($group);                               # Data group
 my ($verbose);                             # Verbosity?
 my ($save_temps);                          # Save temporary outputs?
+my ($clusters_raw, $clusters_ds9, $streaks_ds9);     # Output modes
 
 GetOptions(
@@ -26,5 +28,9 @@
            'dbpass=s' => \$db_pw, # Database p/w
            'label=s' => \$label, # Label of interest
+    'exp_id=s' => \$exp_id,      # Exposure identifier of interest
     'data_group=s' => \$group,   # Data group
+    'clusters-raw' => \$clusters_raw,       # Output raw x,y for clusters?
+    'clusters-ds9' => \$clusters_ds9, # Output ds9 region files of clusters?
+    'streaks-ds9' => \$streaks_ds9,   # Output ds9 region files of streaks?
            'verbose' => \$verbose, # Verbosity?
     'save-temps' => \$save_temps,  # Save temporary outputs?
@@ -48,5 +54,7 @@
 
 # Exposures of interest
-my $sql = "SELECT DISTINCT exp_id, exp_name, magic_id, magicRun.workdir AS magic_path, camProcessedExp.path_base AS cam_path FROM magicRun JOIN rawExp USING(exp_id) JOIN diffRun USING(diff_id) JOIN diffInputSkyfile USING(diff_id) JOIN warpRun ON warpRun.warp_id = diffInputSkyfile.warp1 JOIN fakeRun USING(fake_id) JOIN camProcessedExp USING(cam_id) WHERE magicRun.label = '$label' AND magicRun.state = 'full'";
+my $sql = "SELECT DISTINCT exp_id, exp_name, magic_id, magicRun.workdir AS magic_path, camProcessedExp.path_base AS cam_path FROM magicRun JOIN rawExp USING(exp_id) JOIN diffRun USING(diff_id) JOIN diffInputSkyfile USING(diff_id) JOIN warpRun ON warpRun.warp_id = diffInputSkyfile.warp1 JOIN fakeRun USING(fake_id) JOIN camProcessedExp USING(cam_id) WHERE magicRun.state = 'full'";
+$sql .= " AND magicRun.label = '$label'" if defined $label;
+$sql .= " AND magicRun.exp_id = ${exp_id}" if defined $exp_id;
 $sql .= " AND magicRun.data_group = '$group'" if defined $group;
 my $exps = $db->selectall_arrayref($sql, { Slice => {} }) or die "Unable to execute SQL: $DBI::errstr";
@@ -63,4 +71,7 @@
     my $clusters = "${magic_path}/$id/$id.mgc.$magic.verify/${id}_clusterPos.txt"; # File with cluster RA,Dec
     die "Cannot find clusters file $clusters" unless $ipprc->file_exists($clusters);
+
+    my $streaks = "${magic_path}/$id/$id.mgc.$magic.root.streaks"; # File with streaks
+    die "Cannot find streaks file $streaks" unless $ipprc->file_exists($streaks);
 
     my $astrom = "${cam_path}.smf"; # Astrometry file
@@ -81,29 +92,48 @@
     close $radecFile;
 
-    my $raws = $db->selectcol_arrayref("SELECT uri FROM rawImfile where exp_id = $id") or
-        die "Unable to execute SQL: $DBI::errstr";
+    my $chips = $db->selectall_arrayref("SELECT class_id, uri FROM rawImfile where exp_id = $id",
+                                        { Slice => {} }
+        ) or die "Unable to execute SQL: $DBI::errstr";
 
-    open my $outFile, "> $label.${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;
+    open my $outFile, "> $label.${name}.clusters.xy" or die "Cannot open output file: $!" if defined $clusters_raw;
+    foreach my $chip (@$chips) {
+        my $class = $chip->{class_id};
+        my $uri = $chip->{uri};
 
-        my @lines = split(/\n/, join("", @$stdout_buf));
-        foreach my $line (@lines) {
-            my @line = split /\s+/, $line;
+        if (defined $clusters_raw) {
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => "$ppCoord -astrom $astrom -raw $uri -radec $radecName", verbose => $verbose);
+            die "Unable to run ppCoord" unless $success;
 
-            my $ra = $line[0];
-            my $dec = $line[1];
-            my $x = $line[3];
-            my $y = $line[4];
-            my $chip = $line[5];
-            my $cell = $line[6];
+            my @lines = split(/\n/, join("", @$stdout_buf));
+            foreach my $line (@lines) {
+                my @line = split /\s+/, $line;
 
-            print $outFile "$chip $cell $x $y $ra $dec\n";
+                my $ra = $line[0];
+                my $dec = $line[1];
+                my $x = $line[3];
+                my $y = $line[4];
+                my $chipName = $line[5];
+                my $cellName = $line[6];
+
+                print $outFile "$chipName $cellName $x $y $ra $dec\n";
+            }
         }
+
+        if (defined $clusters_ds9) {
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => "$ppCoord -astrom $astrom -radec $radecName -chip $class -ds9 $label.$name.clusters.$class.ds9 -ds9-color blue",
+                    verbose => $verbose);
+            die "Unable to run ppCoord" unless $success;
+        }
+
+        if (defined $streaks_ds9) {
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => "$ppCoord -astrom $astrom -streaks $streaks -chip $class -ds9 $label.$name.streaks.$class.ds9 -ds9-color red",
+                    verbose => $verbose);
+            die "Unable to run ppCoord" unless $success;
+        }
+
     }
-    close $outFile;
+    close $outFile if defined $clusters_raw;
 }
