Index: trunk/tools/gpc1_find_images.pl
===================================================================
--- trunk/tools/gpc1_find_images.pl	(revision 25853)
+++ trunk/tools/gpc1_find_images.pl	(revision 25853)
@@ -0,0 +1,191 @@
+#! /usr/bin/perl -w
+
+use DBI;
+use Getopt::Std;
+getopts('hFARCPp:BMDWvx:n:c:w:O:S:',\%opt);
+#getopt('xncwOS:hARCW',\%opt);
+unless (exists($opt{O})) {
+    $opt{O} = '';
+}
+unless (exists($opt{S})) {
+    $opt{S} = '';
+}
+if (exists($opt{A})) {
+    $opt{A} = 1;
+}
+else {
+    $opt{A} = 0;
+}
+if (exists($opt{M})) {
+    $opt{M} = 1;
+}
+else {
+    $opt{M} = 0;
+}
+if (exists($opt{D})) {
+    $opt{D} = 1;
+}
+else {
+    $opt{D} = 0;
+}
+
+unless (exists($opt{p})) {
+    $opt{p} = 0;
+}
+
+if (exists($opt{h})) {
+    print "USAGE find_images.pl ... \n";
+    print "          -h              This help\n";
+    print "          -R              Return raw data.\n";
+    print "          -C              Return chip stage data.\n";
+    print "          -W              Return warp stage data.\n";
+    print "          -A              Return not just fits images.\n";
+    print "          -F              Convert to real filenames.\n";
+    print "          -P              Return previous image to this.\n";
+    print "          -B              Return burntool table.\n";
+    print "          -M              Include masks in results.\n";
+    print "          -D              Return only pre-destreaked images.\n";
+    print "          -v              Be verbose on output.\n";
+    print " \n";
+    print "          -x <exp_id>     Specify a exp_id.\n";
+    print "          -c <chip_id>    ...\n";
+    print "          -w <warp_id>    ...\n";
+    print "          -n <exp_name>   ...\n";
+    print " \n";
+    print "          -O <XYxy>       Return a specific chip.\n";
+    print "          -S <skycell.X>  Return a specific skycell.\n";
+    exit(0);
+}
+
+
+# Set up the database
+use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock';
+$dbname = 'gpc1';
+$dbserver = 'ippdb01';
+$dbuser = 'ipp';
+$dbpass = 'ipp';
+$db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
+                   "mysql_socket=" . DB_SOCKET(),
+                   ${dbuser},${dbpass}, 
+		   { RaiseError => 1, AutoCommit => 1}
+		   ) or die "Unable to connect to database $DBI::errstr\n";
+
+$sth_base = "SELECT warp_id,warpRun.workdir,chipRun.chip_id,chipRun.workdir,rawExp.exp_name,rawExp.exp_id,rawExp.workdir,rawExp.dateobs,rawExp.pon_time from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING (exp_id)";
+# What do we have?
+@sth_adds = ();
+
+if (exists($opt{x})) {
+    push @sth_adds, "rawExp.exp_id = $opt{x}";
+}
+if (exists($opt{n})) {
+    push @sth_adds, "rawExp.exp_name = '$opt{n}'";
+}
+if (exists($opt{c})) {
+    push @sth_adds, "chipRun.chip_id = $opt{c}";
+}
+if (exists($opt{w})) {
+    push @sth_adds, "warpRun.warp_id = $opt{w}";
+}
+if ($#sth_adds != -1) {
+    $sth_add = join ' AND ', @sth_adds;
+    $sth = $sth_base . " WHERE " . $sth_add;
+}
+else {
+    die "Probable mistake.";
+}
+#print STDERR "### $sth\n";
+$dr = $db->selectall_arrayref( $sth );
+
+foreach $rr (@{ $dr }) {
+    ($warp_id, $warp_workdir, $chip_id, $chip_workdir, 
+     $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime) = @{ $rr };
+#    print (join "\t", @{ $rr }) . "\n";
+    $exp_pontime = 0; # To stop warnings, but I want this around.
+    if (exists($opt{P})) {
+	$sth_previous = "SELECT exp_name from rawExp where dateobs < '$exp_dateobs' order by dateobs desc limit 1";
+	$prev_dr = $db->selectall_arrayref( $sth_previous );
+	$prev_exp_name = ${ ${ $prev_dr }[0] }[0];
+	$previous_cmd = "$0  -n $prev_exp_name";
+	if (exists($opt{R})) { $previous_cmd .= ' -R '; }
+	if (exists($opt{C})) { $previous_cmd .= ' -C '; }
+	if (exists($opt{W})) { $previous_cmd .= ' -W '; }
+	if (exists($opt{B})) { $previous_cmd .= ' -B '; }
+	if (exists($opt{v})) { $previous_cmd .= ' -v '; }
+	if ($opt{A}) { $previous_cmd .= ' -A '; }
+	if ($opt{M}) { $previous_cmd .= ' -M '; }
+	if ($opt{D}) { $previous_cmd .= ' -D '; }
+	if ($opt{O} ne '') { $previous_cmd .= " -O $opt{O} "; }
+	if ($opt{S} ne '') { $previous_cmd .= " -S $opt{S} "; }
+	if ($opt{p} > 1) {
+	    $opt{p} -= 1;
+	    $previous_cmd .= " -P -p $opt{p} ";
+	}
+	if (exists($opt{v})) {
+	    print STDERR "# $previous_cmd\n";
+	}
+	system($previous_cmd);
+#	exit(0);
+    }
+    
+
+
+    @scan = ();
+    if (exists($opt{R})||exists($opt{B})) {
+	open(NLS,"neb-ls $exp_workdir/${exp_name}/ |") || die "can't neb-ls";
+	while (<NLS>) {
+	    chomp;
+	    if (($_ =~ /${opt{O}}/)&&((($opt{A})) || ($_ =~ /fits/))) {
+		if (exists($opt{B})) {
+		    $_ =~ s/.fits$/.burn.tbl/;
+		}
+		push @scan, $_;
+	    }
+	}
+	close(NLS);
+    }
+    if (exists($opt{C})) {
+	open(NLS,"neb-ls $chip_workdir/${exp_name}.${exp_id}/ |") || die "can't neb-ls";
+	while (<NLS>) {
+	    chomp;
+	    if (($_ =~ /${exp_id}.ch/)&&($_ =~ /$chip_id/)&&($_ =~ /$opt{O}/)&&
+		((($opt{A})) || (($_ =~ /fits/) &&
+				 ($opt{M} || ($_ !~ /mk.fits/)) &&
+				 ($_ !~ /wt.fits/)))) {
+		if ($opt{D} && ($_ !~ /SR/)) {
+		    next;
+		}
+		push @scan, $_;
+
+	    }
+	}
+	close(NLS);
+    }
+    if (exists($opt{W})) {
+	open(NLS,"neb-ls $warp_workdir/${exp_name}.${exp_id}/ |") || die "can't neb-ls";
+	while (<NLS>) {
+	    chomp;
+#	    print "$_\n";
+	    if (($_ =~ /wrp.${warp_id}.$opt{S}/) && ((($opt{A})) || (($_ =~ /fits/) &&
+								     ($opt{M} || ($_ !~ /mask/)) &&
+								     ($_ !~ /wt/)))) {
+		if ($opt{D} && ($_ !~ /SR/)) {
+		    next;
+		}
+		push @scan, $_;
+	    }
+	}
+    }
+    %uniq = ();
+    foreach $f (@scan) {
+	unless (exists($uniq{$f})) {
+	    $uniq{$f} = 1;
+	    if (exists($opt{F})) {
+		chomp($f = `neb-locate --path $f`);
+	    }
+	    print "$f\n";
+	    if (exists($opt{v})) {
+		print STDERR "$f\n";
+	    }
+	}
+    }
+}
Index: trunk/tools/neb-ds9.pl
===================================================================
--- trunk/tools/neb-ds9.pl	(revision 25853)
+++ trunk/tools/neb-ds9.pl	(revision 25853)
@@ -0,0 +1,23 @@
+#! /usr/bin/perl -w
+
+use Getopt::Std;
+getopts('AM',\%opt);
+
+$cmd = 'ds9 -scale mode zscale ';
+
+unless (exists($opt{A})) {
+    $cmd .= " -wcs align yes ";
+}
+
+foreach $neb (@ARGV) {
+    chomp($real_file = `neb-locate --path $neb`);
+    unless ($real_file =~ /no instances found/) {
+	if (($real_file =~ /ota/)||(exists($opt{M}))) {
+	    $cmd .= "-medatacube $real_file ";
+	}
+	else {
+	    $cmd .= " $real_file ";
+	}
+    }
+}
+system("$cmd");
