Index: trunk/tools/microtest.pl
===================================================================
--- trunk/tools/microtest.pl	(revision 27442)
+++ trunk/tools/microtest.pl	(revision 27443)
@@ -9,4 +9,5 @@
 use IPC::Cmd 0.36 qw( can_run run );
 use File::Temp qw( tempfile );
+use PS::IPP::Config;
 
 my $ppCoord = can_run('ppCoord') or die "Can't find ppCoord";
@@ -35,4 +36,6 @@
     and defined $label;
 
+my $ipprc = PS::IPP::Config->new() or die "Unable to set up IPP configuration";
+
 # Database connection
 my $db = DBI->connect( "DBI:mysql:database=$db_name;host=$db_host;mysql_socket=" . DB_SOCKET(),
@@ -44,7 +47,7 @@
 # Exposures of interest
 my $exps = $db->selectall_arrayref(
-        "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";
+    "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'",
+    { Slice => {} }
+    ) or die "Unable to execute SQL: $DBI::errstr";
 
 foreach my $exp (@$exps) {
@@ -56,8 +59,8 @@
 
     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;
+    die "Cannot find clusters file $clusters" unless $ipprc->file_exists($clusters);
 
     my $astrom = "${cam_path}.smf"; # Astrometry file
-    die "Cannot find astrometry file $astrom" unless -e $astrom;
+    die "Cannot find astrometry file $astrom" unless $ipprc->file_exists($astrom);
 
     # Format the clusters file
@@ -69,5 +72,6 @@
         $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/;
+        print $radecFile "$ra $dec\n" if
+            defined $ra and defined $dec and $ra !~ /[[:alpha:]]/ and $dec !~ /[[:alpha:]]/;
     }
     close $clustersFile;
@@ -77,5 +81,5 @@
         die "Unable to execute SQL: $DBI::errstr";
 
-    open my $outFile, "${name}_clusters.xy" or die "Cannot open output file: $!";
+    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
@@ -85,5 +89,6 @@
         die "Unable to run ppCoord" unless $success;
 
-        foreach my $line (@$stdout_buf) {
+        my @lines = split(/\n/, join("", @$stdout_buf));
+        foreach my $line (@lines) {
             my @line = split /\s+/, $line;
 
