Index: trunk/tools/ghostbuster.pl
===================================================================
--- trunk/tools/ghostbuster.pl	(revision 41312)
+++ trunk/tools/ghostbuster.pl	(revision 41313)
@@ -1,31 +1,37 @@
-#! /usr/local/bin/perl -w
-
-use Getopt::Std;
-
-getopts('hvxC',\%opt);
-
-if (exists($opt{h})) {
-    print STDERR "./ghostbuster.pl <inlist>\n";
-    print STDERR "   inlist format: exp_name RA DEC\n";
-    print STDERR "   options:       -h    This help.\n";
-    print STDERR "                  -v    Be more verbose.\n";
-    print STDERR "                  -x    Don't bother with images.\n";
-
-    exit(1);
-}
+#!/usr/bin/env perl
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+use DBI;
+use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock'; # Socket for mysql
+
+# this saves the original arguments for later reporting
+my @ARGS = @ARGV;
+
+GetOptions(
+    'dbname|d=s'        => \$dbname,   # Database name
+    'verbose'           => \$verbose,  # Print to stdout
+    'expname|d=s'       => \$exp_name,  # exposure name
+    'ra|d=s'            => \$ra,       # ra
+    'dec|d=s'           => \$dec,      # dec
+    'noimage'           => \$noimage,  # Don't bother with images
+    'chip'              => \$chip,     # chip mode?
+    ) or pod2usage( 2 );
+pod2usage( -msg => "Unknown option(s): @ARGV", -exitval => 2 ) if @ARGV;
+
+# database connection information:
+$dbhost = 'ippdb08';
+$dbname = 'gpc1' unless defined $dbname;
+$dbuser = 'ippuser';
+$dbpass = 'ippuser';
 
 open (L,">>ghostbuster.log");
 
-while (<>) {
-    chomp;
-    ($exp_name,$ra,$dec) = split /\s+/;
-    if (exists($opt{v})) {
-	print "Working on $exp_name at position $ra $dec\n";
-    }
-    
-    $smf = (split /\n/, `find_images.pl -EVFD -n $exp_name`)[-1];
-    if (exists($opt{v})) {
-	print "  Found SMF: $smf\n";
-    }
+if (1) { 
+    if ($verbose) { print "Working on $exp_name at position $ra $dec\n"; }
+
+    $smf = (split /\n/, `find_images.pl -EVFD -n $exp_name -z $dbname`)[-1];
+    if ($verbose) { print "  Found SMF: $smf\n"; }
 
     open(C,">./${exp_name}.coord");
@@ -35,9 +41,6 @@
     $coords = (split /\n/, `ppCoord -astrom $smf -radec ${exp_name}.coord`)[-1];
     @results = split /\s+/,$coords;
-
-    if (exists($opt{v})) {
-	print "  Obtained coordinate transform: $coords\n";
-    }
-    
+    if ($verbose) { print "  Obtained coordinate transform: $coords\n"; }
+   
     unless (defined($results[5])&&
 	    (abs($results[0] - $ra) < 1e-3)&&
@@ -52,6 +55,6 @@
 
     $raw_file = '';
-    unless(exists($opt{x})) {
-	chomp($raw_file = `find_images.pl -RY -n $exp_name -O $ota`);
+    unless($noimage) {
+	chomp($raw_file = `find_images.pl -RY -n $exp_name -O $ota -z $dbname`);
 	if ($opt{C}) {
 	    system("ppImage -file neb:///${raw_file} ./${exp_name} -recipe PPIMAGE CHIP  -Db CHIP.FITS TRUE ");
@@ -66,7 +69,6 @@
 	push @ds9s, "./${exp_name}.${chip}.ch.fits -regions format xy -regions system image -regions ./${exp_name}.reg -pan to $x_pos $y_pos image ";	
     }
-    if (exists($opt{v})) {
-	print "  Summary: $exp_name $ra $dec $x_pos $y_pos $chip $ota $smf $raw_file\n";
-    }
+    if ($verbose) { print "  Summary: $exp_name $ra $dec $x_pos $y_pos $chip $ota $smf $raw_file\n"; }
+
     # Determine if cross talk and extract magnitudes
     $cell_x = -1;
@@ -106,7 +108,6 @@
     #rule 1
     
-    if ($opt{v}) {
-	print ">> $ota_x $ota_y $cell_x $cell_y\n";
-    }
+
+    if ($verbose) { print ">> $ota_x $ota_y $cell_x $cell_y\n"; }
 
     if (($ota_x == 2)&&($cell_x == 3)) {
@@ -252,6 +253,11 @@
 close(L);
 
-unless(exists($opt{x})) {
+unless($noimage) {
     $options = join " ", @ds9s;
     system("ds9 $options");
 }
+
+
+
+
+
