Index: /trunk/Ohana/src/perl/src/complete.addstar
===================================================================
--- /trunk/Ohana/src/perl/src/complete.addstar	(revision 2443)
+++ /trunk/Ohana/src/perl/src/complete.addstar	(revision 2443)
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+# get list of *o/*.smp
+@smplist = <*o/*.smp>;
+
+$i = 0;
+foreach $file (@smplist) {
+
+    # is NASTRO > 0?
+    ($tmp, $nastro) = split (" ", `echo $file | fields NASTRO`);
+    if ($nastro == 0) { next; }
+
+    # is file already in db?
+    ($path, $root) = split ("/", $file);
+    $answer = `imphotsearch -D CATDIR $catdir -name $root`;
+    if ($answer == "") { next; }
+
+    # addstar file
+    vsystem ("addstar -D CATDIR $catdir $file");
+
+    $i ++;
+    if ($i > 30) {exit;}
+}
+
+sub vsystem {
+    print STDERR "@_\n";
+#    my($status) = system ("@_");
+#    $status;
+}
+
+
Index: /trunk/Ohana/src/perl/src/elixir.rerun
===================================================================
--- /trunk/Ohana/src/perl/src/elixir.rerun	(revision 2443)
+++ /trunk/Ohana/src/perl/src/elixir.rerun	(revision 2443)
@@ -0,0 +1,152 @@
+#!/usr/bin/env perl
+
+# case 1: run on a list of MEF images:
+# case 2: run on a list from ptolemy.failure / ptolemy.success
+
+$complete = 0;
+$stds = 0;
+$demo = 0;
+@tARGV = ();
+for (; @ARGV > 0; ) {
+    if ($ARGV[0] eq "-C") {
+        $config = "$config -C $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-c") {
+        $config = "$config -c $ARGV[1]";
+        shift; shift; next;
+    }
+    if ($ARGV[0] eq "-D") {
+        $config = "$config -D $ARGV[1] $ARGV[2]";
+        shift; shift; shift; next;
+    }
+    if ($ARGV[0] eq "-stds") {
+	$stds = 1;
+        shift; next;
+    }
+    if ($ARGV[0] eq "-demo") {
+	$demo = 1;
+        shift; next;
+    }
+    if ($ARGV[0] eq "-complete") {
+	$complete = 1;
+        shift; next;
+    }
+    if ($ARGV[0] eq "-h") {
+	print "USAGE: elixir.rerun (list) (mode) [elixir options]\n";
+	print "  options: \n";
+	print "  -C config (set value of CONFIG variable)\n";
+	print "  -c config.file (specify alternate to config file)\n";
+	print "  -D key value (set value of key)\n";
+	print "  -stds (send output to STDS directory)\n";
+	print "  -complete (use sexcomplete not sextract)\n";
+	print "  -demo (show input list and command)\n";
+	exit 1;
+    }
+    @tARGV = (@tARGV, $ARGV[0]);
+    shift;
+}
+@ARGV = @tARGV;
+if (@ARGV != 2) { die "USAGE: elixir.rerun (list) (mode) [elixir options]\n"; }
+
+if ($stds) {
+    $catdir = `gconfig $config DB_STDS`; chop $catdir;
+    if ($?) { die "config error with CATDIR\n" }
+} else {
+    $catdir = `gconfig $config CATDIR`; chop $catdir;
+    if ($?) { die "config error with CATDIR\n" }
+}
+
+$tmpdir = `gconfig $config TMPDIR`; chop $tmpdir;
+if ($?) { die "config error with TMPDIR\n" }
+
+$input  = $ARGV[0];
+$mode   = $ARGV[1];
+
+# check on mode:
+if ($mode eq "fifo") { &getfifo; }
+if ($mode eq "mef")  { &getmef;  }
+
+die "ERROR: unknown mode $mode\n";
+
+sub getfifo {
+
+    $temp = `mktemp elixir.XXXXXX`; chop $temp;
+    $templog = `mktemp elixir-log.XXXXXX`; chop $templog;
+
+    open (FILE, "$input");
+    @list = <FILE>;
+    close (FILE);
+
+    # write input list in correct format to $temp
+    open (FILE, ">$temp");
+    foreach $line (@list) {
+	($raw, $root, $ccd, $inmode) = split (" ", $line);
+	print FILE "$raw $root $ccd $inmode\n";
+    }
+    &runelixir;
+}
+
+sub getmef {
+
+    $temp = `mktemp elixir.XXXXXX`; chop $temp;
+    $templog = `mktemp elixir-log.XXXXXX`; chop $templog;
+
+    @ccds = split (" ", `cameraconfig -ccds`);
+    if ($?) { die "error in cameraconfig -ccds\n"; }
+
+    @ccdn = split (" ", `cameraconfig -ccdn`);
+    if ($?) { die "error in cameraconfig -ccdn\n"; }
+
+    $Nccd = `cameraconfig -Nccd`; chop $Nccd;
+    if ($?) { die "error in cameraconfig -Nccd\n"; }
+
+    open (FILE, "$input");
+    @list = <FILE>;
+    close (FILE);
+
+    # write input list in correct format to $temp
+    open (FILE, ">$temp");
+    foreach $line (@list) {
+	($file) = split (" ", $line);
+	if ($line =~ m|^\s*$|) { next; } # skip blank lines
+	if ($line =~ m|^\s*\#|) { next; } # skip commented lines
+	
+	# must be absolute path for elixir to work anyway
+	@words = split ("/", $file);
+	$root = $words[-1];
+	$root =~ s/.fits$//;
+	for ($i = 0; $i < $Nccd; $i++) {
+	    printf FILE "$file %s/%s%02d %s MEF\n", $root, $root, $ccdn[$i], $ccds[$i];
+	}
+    }
+    &runelixir; 
+}
+
+sub runelixir {
+    
+    if ($demo) {  
+	if ($complete) {
+	    print "elixir -D mode sexcomplete -D CATDIR $catdir -D TMPDIR $tmpdir $temp >& $templog\n";
+	} else {
+	    print "elixir -D mode sextract -D CATDIR $catdir -D TMPDIR $tmpdir $temp >& $templog\n";
+	}
+	printf "list is in $temp\n";
+	exit 0;
+    }
+
+    # launch elixir for input list
+    if ($complete) {
+	vsystem ("elixir -D mode sexcomplete -D CATDIR $catdir -D TMPDIR $tmpdir $temp >& $templog &");
+    } else {
+	vsystem ("elixir -D mode sextract -D CATDIR $catdir -D TMPDIR $tmpdir $temp >& $templog &");
+    }
+    exit 0;
+}
+
+sub vsystem {
+    print STDERR "@_\n";
+    $status = system ("@_");
+    $status;
+}
+
Index: /trunk/Ohana/src/perl/src/fixcoords2
===================================================================
--- /trunk/Ohana/src/perl/src/fixcoords2	(revision 2443)
+++ /trunk/Ohana/src/perl/src/fixcoords2	(revision 2443)
@@ -0,0 +1,77 @@
+#!/usr/bin/env perl
+
+# USAGE: fixcoords (input) (output) (ref) (chip)
+use Math::Trig;
+# $DEG_RAD = 57.298688;
+# $RAD_DEG = 0.017452406;
+$DEG_RAD = 57.29577951;
+$RAD_DEG = 0.017453292;
+
+if (@ARGV != 4) { die "USAGE: fixcoords (input) (output) (ref) (chip)\n"; }
+
+$input  = $ARGV[0];
+$output = $ARGV[1];
+$ref    = $ARGV[2];
+$chip   = $ARGV[3];
+
+if (! -f $input) { die "file $input not found\n"; }
+
+# load astrometric terms from header of reference:
+
+$answer = `echo $ref | fields CRPIX1 CRPIX2 CRVAL1 CRVAL2 NASTRO`;
+($file, $crpix1, $crpix2, $crval1, $crval2, $Nastro) = split (" ", $answer);
+if ($Nastro == 0) { die "no astrometry solution in header\n"; }
+
+$answer = `echo $ref | fields PC001001 PC001002 PC002001 PC002002 CDELT1 CDELT2`;
+($file, $pc11, $pc12, $pc21, $pc22, $cd1, $cd2) = split (" ", $answer);
+
+open (FILE, "$input");
+open (OUT, ">$output");
+
+# copy header lines:
+for ($i = 0; $i < 16; $i++)  { $line = <FILE>; print OUT "$line"; }
+
+while ($line = <FILE>) {
+
+    @words = split (" ", $line);
+    xy2rd ($words[12], $words[13]);
+
+    if ($words[17] eq $chip) {
+	printf OUT "%4d %7.4f %7.4f %8.4f  %9.1f %6.3f %5.2f %2d  %9.1f %6.3f %5.2f %2d  %8.3f %8.3f  %15.11f %11.8f  %1s %2s\n",
+	    $words[0], $words[1], $words[2], $words[3], 
+	    $words[4], $words[5], $words[6], $words[7], 
+	    $words[8], $words[9], $words[10], $words[11], 
+	    $words[12], $words[13], $ra, $dec,
+	    $words[16], $words[17];
+    }
+}
+
+close (OUT);
+close (FILE);
+
+sub xy2rd {
+ $x = $_[0];
+ $y = $_[1];
+
+ $X = $cd1*($x - $crpix1);
+ $Y = $cd2*($y - $crpix2);
+
+ $L = $X*$pc11 + $Y*$pc12;
+ $M = $X*$pc21 + $Y*$pc22;
+
+ $chi = $RAD_DEG*$L;
+ $eta = $RAD_DEG*$M;
+
+ $sdp = sin ($RAD_DEG*$crval2);
+ $cdp = cos ($RAD_DEG*$crval2);
+
+ $talp = $chi / ($cdp - $eta*$sdp);
+ $alpha = atan ($talp);
+ $calp = cos ($alpha);
+ $tdel = $calp*($sdp + $eta*$cdp) / ($cdp - $eta*$sdp);
+ $delta = atan ($tdel);
+    
+ $ra  = $DEG_RAD*$alpha + $crval1;
+ $dec = $DEG_RAD*$delta;
+
+}
Index: /trunk/Ohana/src/perl/src/fixscat.mef
===================================================================
--- /trunk/Ohana/src/perl/src/fixscat.mef	(revision 2443)
+++ /trunk/Ohana/src/perl/src/fixscat.mef	(revision 2443)
@@ -0,0 +1,75 @@
+#!/usr/bin/env perl
+
+# warning: this function currently uses a fixed temporary name 'fix.NN.fits' 
+# for the intermediate product.  If we add this to elixir, convert to mktemp
+
+# check the usage
+if ($ARGV[0] eq "-h") { &usage (); }
+if ($ARGV[0] eq "-help") { &usage (); }
+if (@ARGV != 3) { &usage (); }
+
+# assign the command line arguments
+$inlist   = $ARGV[0];
+$version  = $ARGV[1];
+$ID       = $ARGV[2];
+
+# find the appropriate script file
+$confdir = `gconfig -q CONFDIR`; chop ($confdir);
+$script  = "$confdir/mana/scatter.pro";
+
+# run mana script:
+open (MANA, "|mana --norc");
+print MANA "input $script\n";
+print MANA "applyscat-mef $inlist $version $ID\n";
+print MANA "exit 1\n";
+close (MANA);
+print STDERR "exit statue: $?\n";
+if ($? == 2 * 256) { 
+    print STDERR "no scattered light term available\n"; 
+    exit 2;
+}
+if ($?) { die "ERROR problem with fixscat\n"; }
+
+print STDOUT "SUCCESS: finished with fixscat\n";
+exit 0;
+
+sub vsystem {
+    print STDERR "@_\n";
+    $status = system ("@_");
+    $status;
+}
+
+sub goodbye {
+    die "@_\n";
+}
+
+sub usage {
+    print "USAGE: fixscat (inlist) (version) (ID)\n";
+    exit 1;
+}
+
+# mana within perl:  we embed the mana functions within a macro to trap the 
+# exit status.  If mana has an error with one of the steps, it will exit the macros and 
+# the second exit will be called. Otherwise, the "go" macro will perform the exit 0
+# and mana will exit with status 0
+
+# there are two possible flat-field photometric corrections: additive
+# and multiplicative:  
+# The correction images constructed by examining
+# the *difference* between dome-flats with and without the petals
+# covered is additive:  FLAT_new = (FLAT_old - SCAT) * A
+# (A is set to maintain the original normalization of chip 04)
+# 
+# The correction images constructed by examining stellar magnitude
+# difference is multiplicative: FLAT_new = (FLAT_old * SCAT) * A
+# (A is set to maintain the original normalization of chip 04)
+
+# there is a different scattered light image for each filter.
+# (these images are the same file for the additive version)
+
+# there should be no arbitrary normalization in the scattered frames
+# in the database. (we used to multiply the scattered light image by a
+# value of 10.0).  
+
+# images of the first class will be identified with the label scatter-A.0
+# images of the second class will be identified with the label scatter-B.0
Index: /trunk/Ohana/src/perl/src/fr.medbin.interp
===================================================================
--- /trunk/Ohana/src/perl/src/fr.medbin.interp	(revision 2443)
+++ /trunk/Ohana/src/perl/src/fr.medbin.interp	(revision 2443)
@@ -0,0 +1,130 @@
+#!/usr/bin/env perl
+
+# check the usage
+if ($ARGV[0] eq "-h") { usage (); }
+if ($ARGV[0] eq "-help") { usage (); }
+if (@ARGV != 5) { die "USAGE: fr.medbin (path) (root) (factor) (meddir) (mapdir)\n" }
+
+# assign the command line arguments
+$path   = $ARGV[0];
+$root   = $ARGV[1];
+$factor = $ARGV[2];
+$meddir = $ARGV[3];
+$mapdir = $ARGV[4];
+
+$Nccd = `cameraconfig -Nccd`; chop ($Nccd);
+@ccds = split (" ", `cameraconfig -ccdn`);
+if ($?) { die "ERROR: cameraconfig error\n"; }
+
+($Xmap, $Ymap) = split (" ", `gconfig FRINGE_MAP_SCALE`);
+if ($?) { die "ERROR: missing FRINGE_MAP_SCALE in config system\n"; }
+
+if (! -d $meddir) { vsystem ("mkdir -p $meddir"); }
+if (! -d $mapdir) { vsystem ("mkdir -p $mapdir"); }
+
+open (MANA, "|mana --norc");
+
+# convert BIASSEC string to x1, x2, y1, y2 vars
+print MANA "macro parsesec\n";
+print MANA "  \$f = \$1\n";
+print MANA "  getchr \$f : n\n";
+print MANA "  substr \$f 1 {\$n-1} x1\n";
+print MANA "  strlen \$f N\n";
+print MANA "  substr \$f \$n {\$N-\$n} f\n";
+  
+print MANA "  getchr \$f , n\n";
+print MANA "  substr \$f 1 {\$n-1} x2\n";
+print MANA "  strlen \$f N\n";
+print MANA "  substr \$f \$n {\$N-\$n} f\n";
+  
+print MANA "  getchr \$f : n\n";
+print MANA "  substr \$f 1 {\$n-1} y1\n";
+print MANA "  strlen \$f N\n";
+print MANA "  substr \$f \$n {\$N-\$n} f\n";
+  
+print MANA "  getchr \$f ] n\n";
+print MANA "  substr \$f 1 {\$n-1} y2\n";
+print MANA "  strlen \$f N\n";
+print MANA "  substr \$f \$n {\$N-\$n} f\n";
+print MANA "end\n";
+
+print MANA "macro mkmap\n";
+# load detrended image
+print MANA " rd a \$1\n";
+print MANA " keyword a NAXIS1 nx\n";
+print MANA " keyword a NAXIS2 ny\n";
+
+# generate binned image 
+print MANA " medianmap a b {\$nx/$factor} {\$ny/$factor} -range 0.25 0.75\n";
+print MANA " keyword a DATASEC line\n";
+print MANA " parsesec \$line\n";
+print MANA " sprint newline \"[%d:%d,%d:%d]\" {int(\$x1/2 + 1)} {int(\$x2/2 + 1)} {int(\$y1/2 + 1)} {int(\$y2/2 + 1)}\n";
+print MANA " keyword b DATASEC -w \$newline\n";
+print MANA " keyword b NAXIS1 nx\n";
+print MANA " keyword b NAXIS2 ny\n";
+
+# sky from first ccd saved for reference
+print MANA " if (\$setsky)\n";
+print MANA "  stats -q b - - - -\n";
+print MANA "  \$sky = \$MEDIAN\n";
+print MANA "  \$setsky = 0\n";
+print MANA " end\n";
+# we use the sky value of the first chip to remove the DC level for map, add it to med
+
+# create Xmap x Ymap sky map, interpolate to medbin scale
+print MANA " medianmap b m $Xmap $Ymap -ignore 0.0 -range 0.25 0.75\n";
+print MANA " set m = m - \$sky\n";
+print MANA " \$fm = \$nx / $Xmap\n";
+print MANA " \$fy = \$ny / $Ymap\n";
+print MANA " if (\$fy > \$fm)\n";
+print MANA "  \$fm = \$fy\n";
+print MANA " end\n";
+print MANA " minterp m M \$fm\n";
+print MANA " extract M sky 0 0 \$nx \$ny 0 0 \$nx \$ny\n";
+
+# multiplying by (abs(b) > 0.001) maintains the mask
+print MANA " set c = (b - sky) * (abs(b) > 0.001)\n";
+print MANA " wd c \$2\n";
+print MANA " wd m \$3 -bitpix -32 -bzero 0.0 -bscale 1.0\n";
+print MANA "end\n";
+
+print MANA "macro go\n";
+print MANA " \$setsky = 1\n";
+for ($ccd = 0; $ccd < $Nccd; $ccd++) {
+    $infile = sprintf "%s/%s%s.fits", $path,   $root, $ccds[$ccd];
+    $outmed = sprintf "%s/%s%s.fits", $meddir, $root, $ccds[$ccd];
+    $outmap = sprintf "%s/%s%s.fits", $mapdir, $root, $ccds[$ccd];
+    print MANA " mkmap $infile $outmed $outmap\n";
+}
+print MANA " exit 0\n";
+print MANA "end\n";
+print MANA "go\n";
+print MANA "exit 1\n";
+close (MANA);
+if ($?) {
+    print STDERR "ERROR running mana\n";
+    exit 1;
+}
+
+print STDOUT "SUCCESS: finished with fr.medbin.spline\n";
+exit 0;
+
+sub vsystem {
+    print STDERR "@_\n";
+    $status = system ("@_");
+    $status;
+}
+
+sub goodbye {
+    die "@_\n";
+}
+
+sub usage {
+    print "\n";
+    print "USAGE: fr.medbin.spline (path) (root) (factor) (outpath)\n";
+    print " path:   path to MEF image or SPLIT dir\n";
+    print " root:   root name of image (MEF = root.fits, SPLIT = root/rootNN.fits)\n";
+    print " mode:   MEF or SPLIT\n";
+    print " outdir: directory for output results (all split)\n";
+    exit 1;
+}
Index: /trunk/Ohana/src/perl/src/megacoords
===================================================================
--- /trunk/Ohana/src/perl/src/megacoords	(revision 2443)
+++ /trunk/Ohana/src/perl/src/megacoords	(revision 2443)
@@ -0,0 +1,58 @@
+#!/usr/bin/env perl
+
+if (@ARGV != 2) { die "USAGE: megacoords (mode) (filename)\n"; }
+$ENV{'PATH'} = "$ENV{'PATH'}:/apps/elixir/bin";
+
+# currently we keep things hardwired:
+
+$mode = $ARGV[0];
+$input = $ARGV[1];
+
+if ($mode eq "chip") { $ccd   = "ccd22"; }
+if ($mode eq "amp")  { $ccd   = "amp44"; }
+$Xref  = 973;
+$Yref  = 4560;
+
+if ($ccd eq "") { die "ERROR: camera $camera not found\n"; }
+
+$temp = `mktemp /tmp/center.XXXXXX`; chop ($temp);
+
+# mana processing of image
+open (MANA, "|mana --norc >& /dev/null");
+
+print MANA "\$CCDKEYWORD = EXTNAME\n";
+print MANA "macro go\n";
+print MANA " rd a $input -n $ccd\n";
+print MANA " wd a $temp.fits\n";
+print MANA " exec gosexphot $temp.fits $temp.sx >& /dev/null\n";
+print MANA " exec imclean -sex $temp.fits $temp.sx $temp.smp >& /dev/null\n";
+print MANA " exec gastro $temp.smp >& /dev/null\n";
+print MANA " header a -w $temp.smp\n";
+print MANA " coords a -p $Xref $Yref\n";
+print MANA " exec echo \$RA \$DEC > $temp.coords\n";
+print MANA " exit 0\n";
+print MANA "end\n";
+
+print MANA "go\n";
+print MANA "exit 1\n";
+close (MANA);
+
+($Robs, $Dobs) = split (" ", `cat $temp.coords`);
+($tmp, $Rreq, $Dreq) = split (" ", `echo $input | fields RA_DEG DEC_DEG`);
+
+($tmp, $obsid, $Nastro, $Cerror) = split (" ", `echo $temp.smp | fields OBSID NASTRO CERROR`);
+
+if ($Robs < 0.0)   { $Robs += 360.0 }
+if ($Robs > 360.0) { $Robs -= 360.0 }
+
+if ($Rreq < 0.0)   { $Rreq += 360.0 }
+if ($Rreq > 360.0) { $Rreq -= 360.0 }
+
+$dR = 3600.0 * ($Rreq - $Robs) * cos ($Dobs*3.141592643589/180.0);
+$dD = 3600.0 * ($Dreq - $Dobs);
+
+printf "$obsid %10.6f %10.6f  %10.6f %10.6f  %6.1f %6.1f  %3d %4.2f\n", $Rreq, $Dreq, $Robs, $Dobs, $dR, $dD, $Nastro, $Cerror;
+
+escape:
+system ("rm -f $temp $temp.fits $temp.sx $temp.smp $temp.coords");
+exit 0;
Index: /trunk/Ohana/src/perl/src/rerun.complete
===================================================================
--- /trunk/Ohana/src/perl/src/rerun.complete	(revision 2443)
+++ /trunk/Ohana/src/perl/src/rerun.complete	(revision 2443)
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+$fifo = `gconfig FIFOS`; chop $fifo;
+$failure = "$fifo/complete.failure"; 
+
+$Nflatten = `grep flatten $failure | wc -l`; chop $Nflatten;
+$Ngophot  = `grep gophot  $failure | wc -l`; chop $Ngophot;
+$Nimclean = `grep imclean $failure | wc -l`; chop $Nimclean;
+$Ngastro  = `grep gastro  $failure | wc -l`; chop $Ngastro;
+$Naddstar = `grep addstar $failure | wc -l`; chop $Naddstar;
+
+print "flatten: $Nflatten\n";
+print "gophot:  $Ngophot\n";
+print "imclean: $Nimclean\n";
+print "gastro:  $Ngastro\n";
+print "addstar: $Naddstar\n";
+
+# get the list of things to re-run:
+$runid  = `gconfig RUNID.POSTRUN`; chop $runid;
+$camera = `gconfig CAMERA.POSTRUN`; chop $camera;
+$catdir = `gconfig DB_STDS -D RUNID $runid -D CAMERA $camera`; chop $catdir;
+$datdir = `gconfig DATDIR`; chop $datdir;
+$ptlist = "$datdir/$runid/$runid.rerun.dat";
+$ptlist = "$datdir/$runid/$runid.rerun.log";
+
+#system ("grep addstar $failure | awk '{print \$1, \$2, \$3, \$4}' > $ptlist");
+#system ("elixir -D global.pending addstar -D RUNID $runid -D CAMERA $camera -D mode sexcomplete $ptlist >& $ptlog &");
+
+system ("cat $failure | awk '{print \$1, \$2, \$3, \$4}' > $ptlist");
+system ("elixir -D RUNID $runid -D CAMERA $camera -D mode sexcomplete $ptlist >& $ptlog &");
+
Index: /trunk/Ohana/src/shell/src/getfocus.org
===================================================================
--- /trunk/Ohana/src/shell/src/getfocus.org	(revision 2443)
+++ /trunk/Ohana/src/shell/src/getfocus.org	(revision 2443)
@@ -0,0 +1,192 @@
+#!/bin/csh -f
+# load the file, determine bias and sky, then extract a subraster
+# write out the subraster 
+
+setenv PATH /bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/apps/elixir/bin
+
+set tmpout=""
+set args=""
+while ("$1" != "") 
+ switch ($1)
+  case -output: 
+   shift
+   set tmpout=$1
+   breaksw;
+  case -*: 
+   goto usage
+   breaksw;
+  default:
+   set args=($args $1);
+   breaksw;
+ endsw
+ shift
+end
+
+if ($#args != 3) goto usage
+
+# kill off other processes with this name, and their children
+set procname=getfocus
+set list=`/bin/ps -eo pid,user,comm | awk -v n=$procname -v m=$$ '($3==n)&&($1!=m){print $1}'`
+foreach pid ($list)
+ echo "kill $pid"
+ set children=`/bin/ps -eo pid,ppid | awk -v p=$pid '($2==p){print $1}'`
+ kill $pid
+ foreach child ($children)
+   echo "kill $child"
+   kill $child
+ end
+end
+
+set fdir=$args[1]
+set name=$args[2]
+set mode=$args[3]
+
+# set script=/apps/elixir/config/mana/focus.pro
+set datdir  = `gconfig DATDIR`
+set confdir = `gconfig CONFDIR`
+set ccds    = `gconfig FOCUS-CCDS-LIST`
+set ccdn    = `gconfig FOCUS-CCDN-LIST`
+
+# sextractor needs full paths to:
+set sexconf = "$confdir/sextract/focus.sex"
+set sexpars = "$confdir/sextract/focus.param"
+set sexfilt = "$confdir/sextract/default.conv"
+set sexnnw  = "$confdir/sextract/default.nnw"
+
+set script  = "$confdir/mana/focus.pro"
+set output1 = "$datdir/plots/focus.unit.gif"
+set output2 = "$datdir/plots/$name.focus.gif"
+if ("$tmpout" != "") then 
+ set output1=$tmpout.ppm
+ set output2=$tmpout.gif
+endif
+
+# test named Xserver, or start vnc on specified machine
+set xhost = `gconfig XHOST.SUMMIT`
+set xdisp = `gconfig XDISP.SUMMIT`
+xdpyinfo -display $xdisp >& /dev/null
+if ($status) then
+  # X server is not running. start it now
+  echo "X server is not running. start it now"
+  exit 1;
+endif
+setenv DISPLAY $xdisp
+
+set temp=`mktemp /tmp/focus.XXXXXX`
+rm -f $temp
+
+if ("$mode" == "on") goto mef
+if ("$mode" == "off") goto split
+goto usage
+
+### SPLIT mode
+split:
+
+# make sure all four files exist
+foreach ccd ($ccdn)
+ block $fdir/$name/$name$ccd.fits -t 60 || goto failure;
+end
+
+# run sextractor on each chip
+foreach ccd ($ccdn)
+ sex $fdir/$name/$name$ccd.fits \
+    -c $sexconf \
+    -PARAMETERS_NAME $sexpars \
+    -FILTER_NAME     $sexfilt \
+    -STARNNW_NAME    $sexnnw \
+    -CATALOG_NAME    $temp.$ccd; \
+    mv $temp.$ccd $temp.sdat.$ccd &
+end
+
+# wait for results, extract stellar objects
+foreach ccd ($ccdn)
+ block $temp.sdat.$ccd -t 60 || goto failure;
+ awk '($6 > -14) && ($6 < -8){print $0}' $temp.sdat.$ccd | sort -k 6n | head -300 | sort -k 2n > $temp.$ccd.sdat
+ rm -f $temp.sdat.$ccd
+end
+# result i in $temp.$ccd.sdat ($ccd from $ccdn)
+
+# create mana script & run it
+rm -f $temp.pro
+set ccd = $ccdn[1]
+echo "plotfocus $temp $temp.ppm $name $fdir/$name/$name$ccd.fits" >> $temp.pro
+mana --norc --only $script $temp.pro
+if ($status) goto failure
+
+# save resulting image for posterity
+ppmtogif < $temp.ppm > $output1
+cp $output1 $output2
+
+# cleanup temp files
+rm -f $temp $temp.sdat $temp.pro $temp.ppm
+foreach ccd ($ccdn)
+ rm -f $temp.$ccd.sdat $temp.$ccd.fits
+end
+exit 0;
+
+### MEF mode
+mef:
+ 
+# wait for file to appear
+block $fdir/$name.fits -t 60 || goto failure;
+
+# extract section of each image to $temp.$ccd.fits ($ccd in $ccdn)
+rm -f $temp.pro
+set i = 1
+while ($i <= $#ccds)
+ echo $i $ccds
+ set ccdnum = $ccdn[$i]
+ set ccdnam = $ccds[$i]
+ echo "split $fdir/$name.fits $ccdnam $temp.$ccdnum.fits" >> $temp.pro
+ @ i++
+end
+mana --norc --only $script $temp.pro
+
+# run sextractor on each chip
+foreach ccd ($ccdn)
+ sex $temp.$ccd.fits \
+    -c $sexconf \
+    -PARAMETERS_NAME $sexpars \
+    -FILTER_NAME     $sexfilt \
+    -STARNNW_NAME    $sexnnw \
+    -CATALOG_NAME    $temp.$ccd; \
+    mv $temp.$ccd $temp.sdat.$ccd &
+end
+
+# wait for results, extract stellar objects
+foreach ccd ($ccdn)
+ block $temp.sdat.$ccd -t 60 || goto failure;
+ awk '($6 > -14) && ($6 < -8){print $0}' $temp.sdat.$ccd | sort -k 6n | head -300 | sort -k 2n > $temp.$ccd.sdat
+ rm -f $temp.sdat.$ccd
+end
+
+# create mana script & run it
+rm -f $temp.pro
+set ccd = $ccdn[1]
+echo "plotfocus $temp $temp.ppm $name $temp.$ccd.fits" >> $temp.pro
+mana --norc --only $script $temp.pro
+if ($status) goto failure
+
+# save resulting image for posterity
+ppmtogif < $temp.ppm > $output1
+cp $output1 $output2
+
+# cleanup temp files
+rm -f $temp $temp.sdat $temp.pro $temp.ppm
+foreach ccd ($ccdn)
+ rm -f $temp.$ccd.sdat $temp.$ccd.fits
+end
+exit 0;
+
+failure: 
+ echo "****** error with focus ******"
+ rm -f $temp $temp.sdat $temp.pro
+ foreach ccd ($ccdn)
+  rm -f $temp.$ccd.sdat $temp.$ccd.fits
+ end
+ exit 1;
+
+usage:
+ echo "USAGE: getfocus (fdir) (file) (mode)"
+ echo "(mode) may be 'on' for mef, 'off' for split"
+ exit 2;
Index: /trunk/Ohana/src/shell/src/scattercorrection
===================================================================
--- /trunk/Ohana/src/shell/src/scattercorrection	(revision 2443)
+++ /trunk/Ohana/src/shell/src/scattercorrection	(revision 2443)
@@ -0,0 +1,53 @@
+#!/bin/csh -f
+
+# USAGE: scattercorrection (input) (output) (ccd) (xcol) (ycol) (mcol) (nhead)
+if ($#argv != 6) then
+  echo "USAGE: scattercorrection (input) (output) (ccd) (xcol) (ycol) (mcol)"
+  exit 2
+endif
+
+set INPUT  = $1
+set OUTPUT = $2
+set CCD    = `echo $3 | awk '{printf "%02d", $1}'`
+set XCOL   = $4
+set YCOL   = $5
+set MCOL   = $6
+
+rm -f $OUTPUT
+rm -f tmp.cat
+
+mana << END
+
+macro fixcat
+ data $INPUT
+ read x $XCOL y $YCOL m $MCOL
+ set x = x * (x > 5)       + 5 * (x <= 5)
+ set x = x * (x < 2050) + 2050 * (x >= 2050)
+ set y = y * (y > 20)     + 20 * (y <= 20)
+ set y = y * (y < 4096) + 4096 * (y >= 4096)
+ rd a 2002B.scatter.Z.$CCD.00.fits 
+ for i 0 x[]
+  stats -q a {x[\$i]-5} {y[\$i]-5} 11 11
+  \$dmag = -2.5*log(\$MEDIAN)
+  m[\$i] = m[\$i] - \$dmag
+  sprintf line "%7.4f" m[\$i]
+  output tmp.cat
+  echo "\$line" 
+  output stdout
+ end
+ exit 0
+end
+
+fixcat
+exit 1
+
+END
+
+if ($status) then
+ echo "problem running mana on $INPUT"
+ exit 1
+endif
+
+grep '#' $INPUT > tmp.head
+grep -v '#' $INPUT | paste - tmp.cat > tmp.body
+cat tmp.head tmp.body > $OUTPUT
Index: /trunk/Ohana/src/shell/src/vnccheck
===================================================================
--- /trunk/Ohana/src/shell/src/vnccheck	(revision 2443)
+++ /trunk/Ohana/src/shell/src/vnccheck	(revision 2443)
@@ -0,0 +1,15 @@
+#!/bin/csh -f 
+
+# test if the vnc is alive.  if not, restart it.
+
+if ($#argv != 0) then
+ echo "USAGE: vnccheck" 
+ exit 2
+endif
+
+set disp = `hostname`:1
+
+xdpyinfo -display $disp >& /dev/null
+if ($status) then
+  vncstart
+endif
Index: /trunk/Ohana/src/shell/src/vncstart
===================================================================
--- /trunk/Ohana/src/shell/src/vncstart	(revision 2443)
+++ /trunk/Ohana/src/shell/src/vncstart	(revision 2443)
@@ -0,0 +1,12 @@
+#!/bin/csh -f
+
+setenv PATH {$PATH}:/apps/elixir/bin
+
+vncserver -kill :1
+
+# remove lock files from Xvnc 
+rm -f /tmp/.X1-lock
+rm -f /tmp/.X11-unix/X1
+
+# start Xvnc as user 'cfh12k' (so users can restart as needed)
+vncserver -depth 16 :1
