Index: /trunk/Ohana/src/shell/src/block
===================================================================
--- /trunk/Ohana/src/shell/src/block	(revision 16)
+++ /trunk/Ohana/src/shell/src/block	(revision 16)
@@ -0,0 +1,40 @@
+#!/bin/csh -f
+# wait for the file to exist
+
+set file=""
+set timeout=10;
+while ("$1" != "") 
+ switch ($1)
+  case -t: 
+   shift;
+   if ("$1" == "") goto escape
+   set timeout=$1;
+   breaksw;
+  case -*: 
+   goto escape
+   breaksw;
+  default:
+   if ("$file" != "") goto escape
+   set file=$1;
+   breaksw;
+ endsw
+ shift
+end
+
+if ("$file" == "") goto escape
+
+set i=0
+while ($i < $timeout)
+ if (-r $file) then
+  echo "block success: $i seconds $file"
+  exit 0;
+ endif
+ sleep 1
+ @ i++
+end
+echo "block failure: $i seconds $file";
+exit 1;
+
+escape:
+ echo "USAGE: block file [-t timeout]";
+ exit 2;
Index: /trunk/Ohana/src/shell/src/checkdisks
===================================================================
--- /trunk/Ohana/src/shell/src/checkdisks	(revision 16)
+++ /trunk/Ohana/src/shell/src/checkdisks	(revision 16)
@@ -0,0 +1,7 @@
+#!/bin/csh -f
+
+set disks="/data/elixir /data/elixir3 /data/koa /data/milo /data/elixir2 /data/kiawe /data/noni"
+
+df $disks
+
+
Index: /trunk/Ohana/src/shell/src/dads.cleanup
===================================================================
--- /trunk/Ohana/src/shell/src/dads.cleanup	(revision 16)
+++ /trunk/Ohana/src/shell/src/dads.cleanup	(revision 16)
@@ -0,0 +1,14 @@
+#!/bin/csh -f
+
+if ($#argv != 1) then
+ echo "USAGE: dads.remef (outbase)"
+ exit;
+endif
+
+set outdir=$1
+
+rm -f $outdir/*.raw
+rm -f $outdir/*.det
+rm -f $outdir/*.dem
+
+echo "SUCCESS"
Index: /trunk/Ohana/src/shell/src/detstats
===================================================================
--- /trunk/Ohana/src/shell/src/detstats	(revision 16)
+++ /trunk/Ohana/src/shell/src/detstats	(revision 16)
@@ -0,0 +1,86 @@
+#!/bin/csh
+
+if ($#argv != 7) then
+ echo "USAGE: detstats (list) (detimage) (type) (medbin) (tenbin) (stats) (imbin)"
+ exit;
+endif
+
+set nline = `wc -l $1 | awk '{print $1}'`
+
+if ($nline == 0) then
+ echo "no files in source list, skipping"
+ echo "ERROR"
+ exit;
+endif
+
+# find the appropriate script file
+set confdir=`gconfig -q CONFDIR`
+set script="$confdir/mana/flips.pro"
+
+# set up temp files
+set temp=`mktemp /tmp/detstats.XXXXXX`
+rm -f $temp
+rm -f $4
+rm -f $5
+rm -f $6
+rm -f $7
+
+# choose appropriate operation
+switch ($3) 
+  case flat:
+  case FLAT:
+    goto doflat;
+    breaksw;
+  case dark:
+  case DARK:
+  case bias:
+  case BIAS:
+    goto dodark;
+    breaksw;
+  default:
+    echo "unknown type $3";
+    echo ERROR;
+    exit;
+endsw
+
+doflat:
+    
+# flatstats (list) (detimage) (medlist) (tenlist) (statlist) 
+cat > $temp << END
+input $script
+flatstats $1 $2 $4 $5 $6 $7
+END
+
+mana --only $temp
+
+rm -f $temp
+
+echo "SUCCESS"
+exit; 
+
+dodark:
+    
+# darkstats (list) (detimage) (medlist) (tenlist) (statlist) 
+cat > $temp << END
+input $script
+darkstats $1 $2 $4 $5 $6 $7
+END
+
+mana --only $temp
+
+rm -f $temp
+
+echo "SUCCESS"
+exit; 
+
+
+# we are performing statistics on the detrended images:
+# input is a list of images for a given ccd, along with the
+# appropriate detrend image
+# 
+# for each image in the list, detrend the image, measure statistics,
+# create a binned-by-10 image, create a median-binned image, write
+# them out.  to be used by the mosaicing step
+#
+# need to create many output files: 1 medbin & 1 jpeg for each entry in list.
+# these need to be merged by a later program...       
Index: /trunk/Ohana/src/shell/src/dumptape
===================================================================
--- /trunk/Ohana/src/shell/src/dumptape	(revision 16)
+++ /trunk/Ohana/src/shell/src/dumptape	(revision 16)
@@ -0,0 +1,81 @@
+#!/bin/csh
+
+# possible machines:
+# druid /dev/dlt
+
+# set dumpdir=/data/elixir2/eugene/archive/raw
+set dumpdir=.
+set host=`hostname | awk -F. '{print $1}'`
+set tape=""
+
+if ("$host" == "druid") then
+ set tape=/dev/dlt
+endif
+if ("$host" == "hoku") then
+ set tape=/dev/rmt/0mn
+endif
+if ("$host" == "kapu") then
+ set tape=/dev/rmt/0mn
+endif
+
+if ("$tape" == "") then
+ echo "ERROR: must use dumptape on druid, hoku, or kapu"
+ exit 1
+endif
+
+mt -f $tape stat
+
+echo "type 'y' to continue"
+
+set n=$<
+
+if ("$n" == "y") then
+ echo "continuing"
+else
+ echo "stopping"
+ exit 
+endif
+
+cd $dumpdir
+set dname=`date +%m%d%H`
+echo $dname
+
+set temp1=/tmp/dumptape.1.$$
+set temp2=extracted.$host.$dname.list
+set temp3=deleted.$host.$dname.list
+
+rm -f temp1
+
+set i=1
+
+while ($i < 32)
+ echo $i
+ tar xvf $tape >>& $temp1
+ if ($status) goto finish
+ mt -f $tape fsf
+ if ($status) goto finish
+ @ i++
+end
+
+finish:
+
+mt -f $tape rewind
+mt -f $tape offline
+
+mail eugene << END
+ done with tape on $host
+END
+ 
+grep fits $temp1 | awk '{s=index($0,"fits")}{n=substr($0,s-8,7)}{printf "%s.fits\n", n}' | fields INSTRUME | awk '($2=="CFH12K"){print $0}' > $temp2
+grep fits $temp1 | awk '{s=index($0,"fits")}{n=substr($0,s-8,7)}{printf "%s.fits\n", n}' | fields INSTRUME | awk '($2!="CFH12K"){print $0}' > $temp3
+
+foreach f (`awk '{print $1}' $temp3`) 
+ rm -f $f
+end
+
+# foreach f (`awk '{print $1}' $temp2`) 
+#  imsort $f -C config info here on this line
+# end
+
+rm -f $temp1
+
Index: /trunk/Ohana/src/shell/src/el_plots
===================================================================
--- /trunk/Ohana/src/shell/src/el_plots	(revision 16)
+++ /trunk/Ohana/src/shell/src/el_plots	(revision 16)
@@ -0,0 +1,60 @@
+#!/bin/csh -f
+
+if (($#argv != 1) && ($#argv != 2)) goto usage
+
+setenv PATH /bin:/usr/bin:/usr/bin/X11:/apps/elixir/bin:/usr/local/bin
+
+# check that camera is ok:
+set camera=`gconfig CAMERA.CURRENT`
+if ($camera == "cfh12k") goto valid;
+if ($camera == "cfhtir") goto valid;
+
+if ("$1" == "init") then
+  echo "current camera $camera, not supported by el_plots"
+endif
+exit 0;
+
+valid:
+# find the appropriate script file
+set confdir=`gconfig CONFDIR`
+set script="$confdir/mana/$camera.plots"
+set xhost=`gconfig XHOST`
+set xdisp=`gconfig XDISP`
+setenv DISPLAY $xdisp
+
+if ("$1" == "init") goto init;
+if ("$1" == "plot") goto plot;
+if ("$1" == "done") goto done;
+goto usage;
+
+init:
+ # test named Xserver, or start vnc on specified machine
+ 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
+ echo "X server $xdisp is running"
+ exit 0;
+
+plot: 
+ echo $script
+ echo "doplots; exit 0" | status -D CAMERA $camera --norc $script
+ exit 0;
+
+
+done:
+ if ("$2" == "") then
+  echo "USAGE: el_plots done (date)"
+  exit 2;
+ endif 
+
+ cp /data/milo/elixir/plots/seeing_night.png /apps/www/www.cfht.hawaii.edu/Instruments/Elixir/seeing/archive/seeing_$2.png
+ exit 0;
+
+usage:
+ echo "USAGE: el_plots init"
+ echo "USAGE: el_plots plot"
+ echo "USAGE: el_plots done (date)"
+ exit 2;
Index: /trunk/Ohana/src/shell/src/elixir.fork
===================================================================
--- /trunk/Ohana/src/shell/src/elixir.fork	(revision 16)
+++ /trunk/Ohana/src/shell/src/elixir.fork	(revision 16)
@@ -0,0 +1,103 @@
+#!/bin/csh -f
+
+# this script is called by the CFH12K 'go' command and is run on the
+# acquisition machine.  It is run as user cfh12k, or who ever else
+# might be running the camera.  It assumes the user does not have any
+# the elixir path (/apps/elixir/bin at CFHT) define.
+
+# all needed elixir functions should be in the path of cfh12k (and megacam)
+setenv PATH /bin:/usr/bin:/apps/elixir/bin
+umask 0
+
+# file must exist when elixir.fork is called
+if ($#argv != 1) then
+ echo "USAGE: elixir.fork (filename)"
+ echo "(filename) must be the file for MEF, the top directory for SPLIT"
+ exit;
+endif
+
+# convert filename to (dir) (base) (mode):
+set answer=`/apps/elixir/bin/cfht.names $1`
+if ($status) exit 1
+
+set list=($answer)
+set fdir=$list[1]
+set name=$list[2]
+set mode=$list[3]
+
+# set logdir for various logging
+set logdir=`gconfig LOGDIR`
+if ($status) then 
+ echo "error with elixir configurations: missing LOGDIR, using /tmp"
+endif
+
+# get name for a specific image, get image type
+# the definition of the name is system dependent
+if ("$mode" == "on") then
+ set file=$fdir/$name.fits
+else 
+ set file=$fdir/$name/$name\00.fits
+endif
+
+# abstract the OBSTYPE keyword? 
+set type=`echo $file | fields OBSTYPE | awk '{print $2}' | tr '[:lower:]' '[:upper:]'`
+
+# name for summit processing machine
+set remote=wekiu
+
+# realtime functions to perform
+set focus=0
+set seeing=0
+set jpeg=0
+switch ($type)
+    case FOCUS:
+	set focus=1
+	breaksw;
+    case DARK:
+    case BIAS:
+    case FLAT:
+	breaksw;
+    case OBJECT:
+	set jpeg=1
+	set seeing=1
+	# send to the seeing stats
+	breaksw;
+    default:
+	breaksw;
+endsw
+
+if (-r ~/.elixir.override) then
+ echo "NOTE: using values from .elixir.override" >> $logdir/fork.log
+ source ~/.elixir.override
+endif
+
+set comp = ""
+if ($focus) set comp = "getfocus $comp"
+if ($seeing) set comp = "getseeing $comp"
+if ($jpeg) set comp = "mkjpeg $comp"
+if ("$comp" == "") set comp = "nothing" 
+
+echo "$fdir $name $mode : type $type : running $comp" >> $logdir/fork.log
+# echo "$fdir $name $mode : type $type : running $comp"
+
+if ($seeing) then 
+    # getseeing - measure seeing stats for image
+    rsh -n $remote /apps/elixir/bin/getseeing $fdir $name $mode >>& $logdir/getseeing.log &
+endif
+
+if ($focus) then 
+    # getfocus - measure focus frame
+    rsh -n $remote /apps/elixir/bin/getfocus $fdir $name $mode >>& $logdir/getfocus.log &
+endif
+
+if ($jpeg) then 
+    # mkjpeg - create binned images
+    rsh -n $remote /apps/elixir/bin/mkjpeg $fdir $name $mode >>& $logdir/mkjpeg.log &
+endif
+
+exit 0;
+
+# note on script launches:
+# script >>& logfile.log &
+# launches the script immediately, ignores the exit status,
+# saves all output into logfile.log
Index: /trunk/Ohana/src/shell/src/elixir.launch
===================================================================
--- /trunk/Ohana/src/shell/src/elixir.launch	(revision 16)
+++ /trunk/Ohana/src/shell/src/elixir.launch	(revision 16)
@@ -0,0 +1,66 @@
+#!/bin/csh -f
+
+if ($#argv != 1) then
+ echo "USAGE: elixir.launch (system)"
+ exit 2
+endif
+
+set run    = `gconfig RUNID.CURRENT`;
+set camera = `gconfig CAMERA.CURRENT`;
+
+if ($1 == "mkdetrend") then
+    switch ($camera)
+     case cfh12k:
+#     case megacam:
+      echo "starting mkdetrend"
+      mkdetrend auto run -run $run -camera $camera >>& /data/milo/elixir/log/mkdetrend.log &
+      breaksw;
+
+     default:
+      breaksw;
+    endsw
+
+    exit 0;
+endif
+
+if ($1 == "imstats") then
+    switch ($camera)
+     case cfh12k:
+#     case megacam:
+      echo "starting elixir imstats"
+      elixir -restart -D mode imstats -D CAMERA $camera -D RUNID $run >>& /data/milo/elixir/log/imstats.log &
+      breaksw;
+
+     case cfhtir:
+      echo "starting elixir irstats"
+      elixir -restart -D mode irstats -D CAMERA $camera -D RUNID $run >>& /data/milo/elixir/log/imstats.log &
+      breaksw;
+
+     default:
+      echo "stopping elixir imstats"
+      elixir -stop -D mode imstats
+      breaksw;
+    endsw
+    exit 0;
+endif
+
+if ($1 == "sextract") then
+    exit 0;
+
+    switch ($camera)
+     case cfh12k:
+#     case megacam:
+      echo "starting elixir sextract"
+      elixir -restart -D mode sextract -D CAMERA $camera -D RUNID $run >>& /data/milo/elixir/log/sextract.log &
+      breaksw;
+
+     default:
+      echo "stopping elixir sextract"
+      elixir -stop -D mode sextract
+      breaksw;
+    endsw
+    exit 0;
+endif
+
+echo "command $1 not found"
+exit 1
Index: /trunk/Ohana/src/shell/src/fits2jpeg
===================================================================
--- /trunk/Ohana/src/shell/src/fits2jpeg	(revision 16)
+++ /trunk/Ohana/src/shell/src/fits2jpeg	(revision 16)
@@ -0,0 +1,68 @@
+#!/bin/csh -f
+# convert a FITS image to jpeg, scaling based on data
+
+set sys=`uname -s` 
+switch ($sys)
+ case IRIX64:
+   setenv ARCH irix;
+   breaksw;
+ case SunOS:
+   set ver=`uname -r | awk '{print substr($1,1,1)}'`;
+   if ($ver == 5) then
+     setenv ARCH sol
+   else 
+     setenv ARCH sun4
+   endif
+   breaksw;
+ case Linux:
+   setenv ARCH linux;
+   breaksw;
+ case HP-UX:
+    setenv ARCH hp;
+    breaksw;
+ default:
+   echo "unknown architecture";
+   setenv ARCH unknown;
+   breaksw;
+endsw
+
+setenv PATH /bin:/usr/bin:/usr/bin/X11:/data/milo/eugene/elixir/ohana/bin/{$ARCH}
+
+if ($#argv != 2) then
+ echo "USAGE: fits2jpeg (fits) (jpeg)"
+ exit;
+endif
+
+set temp=`mktemp /tmp/fitsjpg.XXXXXX`
+rm -f $temp
+
+xset q >& /dev/null
+if ($status) then
+ echo "can't access X server"
+ exit 1
+endif
+
+cat > $temp << END
+ \$KII = kii -nomap -private
+ rd a $1
+ keyword a NAXIS1 nx
+ keyword a NAXIS2 ny
+ rotate a flipy
+ stats a - - - -
+ tv a {\$MEDIAN-0.5*\$SIGMA} {2.5*\$SIGMA} 
+ resize \$nx \$ny
+ center {0.5*\$nx} {0.5*\$ny} 
+ jpeg -name $2
+ exit 0
+END
+
+(mana --only $temp) >& /dev/null
+if ($status) then
+ echo "problem running mana
+ rm -f $temp
+ exit 1
+endif
+
+rm -f $temp
+exit 0
+
Index: /trunk/Ohana/src/shell/src/flatten.subaru
===================================================================
--- /trunk/Ohana/src/shell/src/flatten.subaru	(revision 16)
+++ /trunk/Ohana/src/shell/src/flatten.subaru	(revision 16)
@@ -0,0 +1,43 @@
+#!/bin/csh -f
+
+# this script performs the detrending operation using mana
+# for image arithmetic.  detrending images are stored in the
+# detrend database.  flats are defined so that the science image
+# is divided by the flatfield image, and the normalization is such 
+# that the entire mosaic is normalized by this process
+
+if ($#argv < 2) then
+ echo "USAGE: flatten (in) (out)"
+ exit 2
+endif
+
+set temp=`mktemp /tmp/flatten.XXXXXX`
+
+# create mana script
+echo "fixing the astrometry keywords"
+
+echo "macro go"                    > $temp
+echo "rd a $1"                    >> $temp
+echo "keyword a PC001001 -wf 1.0" >> $temp
+echo "keyword a PC001002 -wf 0.0" >> $temp
+echo "keyword a PC002001 -wf 0.0" >> $temp
+echo "keyword a PC002002 -wf 1.0" >> $temp
+echo "wd a $2"                    >> $temp
+echo "exit 0"                     >> $temp
+echo "end"                        >> $temp
+
+echo "go"                         >> $temp
+echo "exit 1"                     >> $temp
+
+mana --only $temp
+set mana=$status
+rm -f $temp
+
+if ($mana) then
+ echo "ERROR: flatten failed"
+else
+ echo "SUCCESS: flatten succeeded"
+endif
+
+exit $mana
+
Index: /trunk/Ohana/src/shell/src/getfocus
===================================================================
--- /trunk/Ohana/src/shell/src/getfocus	(revision 16)
+++ /trunk/Ohana/src/shell/src/getfocus	(revision 16)
@@ -0,0 +1,191 @@
+#!/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 escape
+   breaksw;
+  default:
+   set args=($args $1);
+   breaksw;
+ endsw
+ shift
+end
+
+if ($#args != 3) goto escape
+
+# 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`
+
+# 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
+echo "invalid mode $mode in getfocus"
+exit 1;
+
+### SPLIT mode
+split:
+
+# make sure all four files exist
+foreach ccd (01 04 07 10)
+ block $fdir/$name/$name$ccd.fits -t 60 || goto failure;
+end
+
+foreach ccd (01 04 07 10)
+ 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
+# sextract writes output to catalog while processing;
+# mv to real file *after* sextract is done
+
+foreach ccd (01 04 07 10)
+ 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
+
+rm -f $temp.pro
+set ccd=00
+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
+
+rm -f $temp $temp.sdat $temp.pro $temp.ppm
+foreach ccd (01 04 07 10)
+ rm -f $temp.$ccd.sdat 
+end
+exit 0;
+
+### MEF mode
+mef:
+ 
+block $fdir/$name.fits -t 60 || goto failure;
+
+rm -f $temp.pro
+foreach ccd (01 04 07 10)
+ echo "split $fdir/$name.fits $ccd $temp.$ccd.fits" >> $temp.pro
+end
+
+mana --norc --only $script $temp.pro
+
+foreach ccd (01 04 07 10)
+ 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
+# sextract writes output to catalog while processing;
+# mv to real file *after* sextract is done
+
+foreach ccd (01 04 07 10)
+ block $temp.sdat.$ccd -t 30 || 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
+
+rm -f $temp.pro
+set ccd=01
+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
+
+rm -f $temp $temp.sdat $temp.pro $temp.ppm
+foreach ccd (01 04 07 10)
+ 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 (01 04 07 10)
+  rm -f $temp.$ccd.sdat $temp.$ccd.fits
+ end
+ exit 1;
+
+escape:
+ echo "USAGE: getfocus (fdir) (file) (mode)"
+ echo "(mode) may be 'on' for mef, 'off' for split"
+ exit 2;
+
+
+ sex $temp.$ccd.fits -c $config -CATALOG_NAME $temp.sdat
+ sort -k 2n $temp.sdat | head -300 > $temp.$ccd.sdat
+
+rm -f $temp.pro
+rm -f $temp.ppm
+echo "plotfocus $temp $temp.ppm $name $fdir/$name.fits" >> $temp.pro
+mana --norc --only $script $temp.pro
+if ($status) goto failure
+
Index: /trunk/Ohana/src/shell/src/getseeing
===================================================================
--- /trunk/Ohana/src/shell/src/getseeing	(revision 16)
+++ /trunk/Ohana/src/shell/src/getseeing	(revision 16)
@@ -0,0 +1,110 @@
+#!/bin/csh -f
+# measure the seeing on a subraster of a specific CCD
+# write the results to a file for the TCL display
+
+setenv PATH /bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/apps/elixir/bin
+
+set screen=0
+if (($#argv == 4) && ("$4" == "-screen")) then
+ set screen=1
+ set argv=($1 $2 $3)
+endif
+
+if ($#argv != 3) then
+ echo "USAGE: getseeing (fdir) (file) (mode) [-screen]"
+ echo "(mode) may be 'on' for mef, 'off' for split"
+ exit;
+endif
+
+# kill off other processes with this name, and their children
+set procname=getseeing
+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 up references & defaults
+set fdir=$1
+set name=$2
+set mode=$3
+
+set ccd=03
+
+set datdir  = `gconfig DATDIR`
+set confdir = `gconfig CONFDIR`
+
+# sextractor needs full paths to:
+set sexconf = "$confdir/sextract/seeing.sex"
+set sexpars = "$confdir/sextract/seeing.param"
+set sexfilt = "$confdir/sextract/default.conv"
+set sexnnw  = "$confdir/sextract/default.nnw"
+
+set script  = "$confdir/mana/seeing.pro"
+set output  = "$datdir/plots/seeing.dat"
+
+# MEF / SPLIT mode
+if ("$mode" == "on") then
+ set mef=1
+ set file=$fdir/$name.fits
+else
+ set mef=0
+ set file=$fdir/$name/$name$ccd.fits
+endif
+
+# wait for file to exist
+block $file -t 60 || exit 1;
+
+# create mana script 
+set temp=`mktemp /tmp/seeing.XXXXXX`
+rm -f $temp $temp.fits $temp.stats $temp.pro $temp.cat
+if ($mef) then
+ echo "subraster.mef   $file $ccd $temp.fits $temp.stats" > $temp.pro
+else
+ echo "subraster.split $file $ccd $temp.fits $temp.stats" > $temp.pro
+endif
+
+# run mana
+mana --only $script $temp.pro || goto failure;
+
+# run sextractor
+sex $temp.fits \
+    -c $sexconf \
+    -PARAMETERS_NAME $sexpars \
+    -FILTER_NAME     $sexfilt \
+    -STARNNW_NAME    $sexnnw \
+    -CATALOG_NAME    $temp.cat
+set fwhm=`seeingstats $temp.cat | awk '{print $1*0.2}'`
+set filter=`echo $temp.fits | fields FILTER`
+
+# send output (screen || $output & QSO)
+if ($screen) then
+ echo $name $fwhm $filter
+else
+ echo $name $fwhm $filter > $output
+ imstatqso $temp.fits $temp.stats $temp.cat
+endif 
+
+# cleanup 
+rm -f $temp $temp.fits $temp.stats $temp.pro $temp.cat
+exit 0;
+
+# failure:
+failure:
+ rm -f $temp $temp.fits $temp.stats $temp.pro $temp.cat
+ echo $name died X.XX 0.0 0.0 X > $output
+ exit 1;
+ 
+
+
+# old method of sending data to QSO db:
+#set obs=`echo $name | awk '{n=substr($1,1,6)}{print n}'`
+#/cfht/bin/update_xexpe.sh -U qso_elixir -P op1eliw --obsid $obs --iq $fwhm
+
+
+
Index: /trunk/Ohana/src/shell/src/gettemps
===================================================================
--- /trunk/Ohana/src/shell/src/gettemps	(revision 16)
+++ /trunk/Ohana/src/shell/src/gettemps	(revision 16)
@@ -0,0 +1,44 @@
+#!/bin/csh -f
+
+# check command-line arguments
+while ("$1" != "") 
+ switch ($1)
+  case -h:
+  case -help:
+  default:  
+   echo "USAGE: gettemps"
+   exit 1
+   breaksw;
+ endsw
+ shift
+end
+
+# find the appropriate script file
+set file=`gconfig TEMPERATURE_LOG`
+if ($status) then 
+ echo "configuration error: TEMPERATURE_LOG"
+ exit 1;
+endif
+
+set temp=`mktemp /tmp/teltemps.XXXXXX`
+set date=`date +%Y/%m/%d`
+cfhtlog -f $date -t "$date 23:59" -p 2,36,43,45 > $temp
+
+# mv is atomic - other processes won't miss the file
+mv -f $temp $file
+
+exit 0;
+
+# using dl_query gives a consistent output format regardless of 
+# whether it is recent or old DataLogger data
+
+# dl_now -p 4  | awk '(NR==2){print $0}' >  /tmp/teltemps.$$
+
+# data logger probe choices:
+#  2 surface temp, primary mirror west (silver)           deg celsius
+# 36 air temp, dome top ws side                           deg celsius
+# 43 air temp, 6' above 5th floor                         deg celsius
+# 45 air temp, 2" above 5th floor                         deg celsius
+
+# the complete list of data logger probes is found in:
+# /data/logger/www/probe.list
Index: /trunk/Ohana/src/shell/src/gopsfphot
===================================================================
--- /trunk/Ohana/src/shell/src/gopsfphot	(revision 16)
+++ /trunk/Ohana/src/shell/src/gopsfphot	(revision 16)
@@ -0,0 +1,46 @@
+#!/bin/csh -f
+# load the file, determine bias and sky, then extract a subraster
+# write out the subraster 
+
+set sexconf=/data/milo/eugene/elixir/config/sextract
+
+if ($#argv != 4) then
+ echo "USAGE: gopsfphot file.fits file.px file.st file.psf"
+ exit;
+endif
+
+set infile = $1
+set pxfile = $2
+set stfile = $3
+set psfile = $4
+
+# find the appropriate script file
+set confdir=`gconfig -q CONFDIR`
+
+# sextractor needs full paths to:
+set sexconf = "$confdir/sextract/gosexphot.sex"
+set sexpars = "$confdir/sextract/gosexphot.param"
+set sexfilt = "$confdir/sextract/default.conv"
+set sexnnw  = "$confdir/sextract/default.nnw"
+
+set psfconf = "$confdir/sextract/gopsfphot.psf"
+set psfpars = "$confdir/sextract/psf.param"
+
+set pexconf = "$confdir/sextract/gopsfphot.psfex"
+
+sex $infile \
+    -c $psfconf \
+    -PARAMETERS_NAME $psfpars \
+    -FILTER_NAME     $sexfilt \
+    -STARNNW_NAME    $sexnnw \
+    -CATALOG_NAME    $stfile
+
+psfex $stfile -c $pexconf -PSF_NAME $psfile
+
+sex $infile \
+    -c $sexconf \
+    -PARAMETERS_NAME $sexpars \
+    -FILTER_NAME     $sexfilt \
+    -STARNNW_NAME    $sexnnw \
+    -PSF_NAME        $psfile \
+    -CATALOG_NAME    $pxfile
Index: /trunk/Ohana/src/shell/src/gosexphot
===================================================================
--- /trunk/Ohana/src/shell/src/gosexphot	(revision 16)
+++ /trunk/Ohana/src/shell/src/gosexphot	(revision 16)
@@ -0,0 +1,40 @@
+#!/bin/csh -f
+# load the file, determine bias and sky, then extract a subraster
+# write out the subraster 
+
+if (($#argv != 2) && ($#argv != 3)) then
+ echo "USAGE: gosexphot file.fits file.sx [-shallow]"
+ exit;
+endif
+
+set infile = $1
+set outfile = $2
+
+set name="gosexphot.sex"
+if ($#argv == 3) then
+    if ("$3" == "-shallow") then
+        set name="gosexshallow.sex"
+    endif
+endif
+
+# find the appropriate script file
+set confdir=`gconfig CONFDIR`
+
+# sextractor needs full paths to:
+set sexconf = "$confdir/sextract/$name"
+set sexpars = "$confdir/sextract/gosexphot.param"
+set sexfilt = "$confdir/sextract/default.conv"
+set sexnnw  = "$confdir/sextract/default.nnw"
+
+sex $infile \
+    -c $sexconf \
+    -PARAMETERS_NAME $sexpars \
+    -FILTER_NAME     $sexfilt \
+    -STARNNW_NAME    $sexnnw \
+    -CATALOG_NAME    $outfile
+
+if ($status) then 
+  echo "ERROR: problem with sextractor"
+else
+  echo "SUCCESS"
+endif
Index: /trunk/Ohana/src/shell/src/irsex
===================================================================
--- /trunk/Ohana/src/shell/src/irsex	(revision 16)
+++ /trunk/Ohana/src/shell/src/irsex	(revision 16)
@@ -0,0 +1,55 @@
+#!/bin/csh -f
+# measure stars (fluxes, fwhm, etc) 
+
+if ($#argv != 2) then
+ echo "USAGE: irsex infile file.sdat"
+ exit;
+endif
+
+set infile = $1
+set outfile = $2
+
+if (! -e $infile) then
+ echo "ERROR: file $infile is missing"
+ exit 1
+endif
+
+# determine image type
+set imageword = `gconfig IMAGETYPE-KEYWORD`
+set type = `echo $1 | fields $imageword | awk '{print $2}'`
+
+# find the sextractor param files (can tune for cfhtir if needed)
+set confdir = `gconfig CONFDIR`
+set sexconf = "$confdir/sextract/cfhtir.sex"
+set sexpars = "$confdir/sextract/cfhtir.param"
+set sexfilt = "$confdir/sextract/default.conv"
+set sexnnw  = "$confdir/sextract/default.nnw"
+
+switch ($type)
+  case object:
+  case Object:
+  case OBJECT:
+     sex $infile \
+	-c $sexconf \
+	-PARAMETERS_NAME $sexpars \
+	-FILTER_NAME     $sexfilt \
+	-STARNNW_NAME    $sexnnw \
+	-CATALOG_NAME    $outfile
+     set stat=$status
+     breaksw;
+
+   default:
+      echo '0' > $2;
+      echo "image type $type, skipping FWHM";
+      set stat = 0
+      breaksw;
+endsw
+
+if ($stat) then
+  echo "ERROR ($stat): problem with sextractor"
+else
+  echo SUCCESS;
+endif
+
+exit $stat
+
Index: /trunk/Ohana/src/shell/src/mkjpeg
===================================================================
--- /trunk/Ohana/src/shell/src/mkjpeg	(revision 16)
+++ /trunk/Ohana/src/shell/src/mkjpeg	(revision 16)
@@ -0,0 +1,89 @@
+#!/bin/csh -f
+# create a binned-by-10 mosaic in jpeg format
+# write the results to a file for the TCL display
+
+setenv PATH /bin:/usr/bin:/usr/bin/X11:/apps/elixir/bin:/usr/local/bin
+
+if ($#argv != 3) then
+ echo "USAGE: mkjpeg (fdir) (file) (mode)"
+ echo "(mode) may be 'on' for mef, 'off' for split"
+ exit;
+endif
+
+# this is stupid, but simple: wait a few seconds to let 'getseeing' win
+sleep 5
+
+# kill off other processes with this name, and their children
+set procname=mkjpeg
+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=$1
+set name=$2
+set mode=$3
+
+# find the appropriate script file
+set confdir = `gconfig CONFDIR`
+set datdir  = `gconfig DATDIR`
+
+set confdir  = "/data/elixir2/elixir/config"
+set script   = "$confdir/mana/mkjpeg.pro"
+set output   = "$datdir/plots/current.b10.gif"
+set outzoom  = "$datdir/plots/current.zoom.gif"
+set outshort = "$datdir/plots/lastshort.zoom.gif"
+
+# 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 on $xhost"
+  exit 1;
+endif
+setenv DISPLAY $xdisp
+
+set temp=`mktemp /tmp/mkjpeg.XXXXXX`
+rm -f $temp $temp.jpg
+
+if ("$mode" == "on") then
+ set mef=1
+else 
+ set mef=0
+endif
+
+echo "init.mosaic" > $temp
+foreach ccd (00 01 02 03 04 05 06 07 08 09 10 11)
+ if ($mef) then
+  set file=$fdir/$name.fits
+  block $file -t 60 || exit 1;
+  echo "load.mosaic $file $ccd MEF" >> $temp
+ else
+  set file=$fdir/$name/$name$ccd.fits
+  block $file -t 60 || exit 1;
+  echo "load.mosaic $fdir/$name/$name$ccd.fits $ccd SPLIT" >> $temp
+ endif
+end
+echo "jpeg.mosaic $temp.jpg $temp.zoom.jpg" >> $temp
+
+mana --norc --only $script $temp
+# ppmquant 256 $temp.jpg | ppmtogif > $output
+djpeg -gif < $temp.jpg > $output
+djpeg -gif < $temp.zoom.jpg > $outzoom
+
+set short = `echo $file | fields EXPTIME | awk '{s = 0}($2 < 30){s = 1}{print s}'`
+echo "short: $short"
+if ($short) then
+ cp -f $outzoom $outshort
+endif
+
+rm -f $temp $temp.jpg $temp.zoom.jpg
+exit 0
Index: /trunk/Ohana/src/shell/src/rm.elixir
===================================================================
--- /trunk/Ohana/src/shell/src/rm.elixir	(revision 16)
+++ /trunk/Ohana/src/shell/src/rm.elixir	(revision 16)
@@ -0,0 +1,12 @@
+#!/bin/csh -f 
+
+# USAGE: rm.elixir *
+# deletes files in arg list
+# echo "SUCCESS" at end (or ERROR if failure)
+
+while ("$1" != "") 
+ /bin/rm $1
+ shift
+end
+
+echo SUCCESS
Index: /trunk/Ohana/src/shell/src/setpath
===================================================================
--- /trunk/Ohana/src/shell/src/setpath	(revision 16)
+++ /trunk/Ohana/src/shell/src/setpath	(revision 16)
@@ -0,0 +1,30 @@
+#!/bin/csh -f
+
+set sys=`uname -s` 
+switch ($sys)
+ case IRIX64:
+   setenv ARCH irix;
+   breaksw;
+ case SunOS:
+   set ver=`uname -r | awk '{print substr($1,1,1)}'`;
+   if ($ver == 5) then
+     setenv ARCH sol
+   else 
+     setenv ARCH sun4
+   endif
+   breaksw;
+ case Linux:
+   setenv ARCH linux;
+   breaksw;
+ case HP-UX:
+    setenv ARCH hp;
+    breaksw;
+ default:
+   echo "unknown architecture";
+   setenv ARCH unknown;
+   breaksw;
+endsw
+
+setenv PATH /bin:/usr/bin:/data/milo/eugene/elixir/ohana/bin/{$ARCH}
+
+echo $PATH
Index: /trunk/Ohana/src/shell/src/sexstats
===================================================================
--- /trunk/Ohana/src/shell/src/sexstats	(revision 16)
+++ /trunk/Ohana/src/shell/src/sexstats	(revision 16)
@@ -0,0 +1,55 @@
+#!/bin/csh -f
+# measure stars (fluxes, fwhm, etc) 
+
+if ($#argv != 2) then
+ echo "USAGE: sexstats infile file.sdat"
+ exit;
+endif
+
+set infile = $1
+set outfile = $2
+
+if (! -e $infile) then
+ echo "ERROR: file $infile is missing"
+ exit 1
+endif
+
+# determine image type
+set imageword = `gconfig IMAGETYPE-KEYWORD`
+set type = `echo $1 | fields $imageword | awk '{print $2}'`
+
+# find the sextractor param files (can tune for cfhtir if needed)
+set confdir = `gconfig CONFDIR`
+set sexconf = "$confdir/sextract/shallow.sex"
+set sexpars = "$confdir/sextract/shallow.param"
+set sexfilt = "$confdir/sextract/default.conv"
+set sexnnw  = "$confdir/sextract/default.nnw"
+
+switch ($type)
+  case object:
+  case Object:
+  case OBJECT:
+     sex $infile \
+	-c $sexconf \
+	-PARAMETERS_NAME $sexpars \
+	-FILTER_NAME     $sexfilt \
+	-STARNNW_NAME    $sexnnw \
+	-CATALOG_NAME    $outfile
+     set stat=$status
+     breaksw;
+
+   default:
+      echo '0' > $2;
+      echo "image type $type, skipping FWHM";
+      set stat = 0
+      breaksw;
+endsw
+
+if ($stat) then
+  echo "ERROR ($stat): problem with sextractor"
+else
+  echo SUCCESS;
+endif
+
+exit $stat
+
Index: /trunk/Ohana/src/shell/src/sp_command
===================================================================
--- /trunk/Ohana/src/shell/src/sp_command	(revision 16)
+++ /trunk/Ohana/src/shell/src/sp_command	(revision 16)
@@ -0,0 +1,267 @@
+#!/bin/csh -f
+
+set IOPENER   = "root@128.171.83.9"
+set template  = "/h/skyprobe/data/Refs/template.fits"
+set dummyfits = "/h/skyprobe/data/Refs/dummy.fits"
+set dlogfile  = "/h/skyprobe/sp_expose.log"
+set photlog   = "/h/skyprobe/sp_phot.log"
+set process   = 1
+
+set args=""
+while ($#argv) 
+ switch ($1)
+  case -iopener: 
+   shift
+   set IOPENER=$1
+   breaksw;
+  case -noprocess: 
+   set process = 0
+   breaksw;
+  case -h: 
+  case --help: 
+   goto usage;
+   breaksw;
+  default:
+   set args=($args $1);
+   breaksw;
+ endsw
+ shift
+end
+
+if ($#args == 0) goto usage;
+if ($args[1] == "init")   goto init;
+if ($args[1] == "cool")   goto cool;
+if ($args[1] == "warm")   goto warm;
+if ($args[1] == "dark")   goto dark;
+if ($args[1] == "test")   goto test;
+if ($args[1] == "expose") goto expose;
+goto usage;
+
+######
+
+init:
+ if ($#args != 2) goto usage
+ if (! -d $args[2]) then
+  mkdir -p $args[2]
+ endif
+ exit 0;
+
+cool: 
+ if ($#args != 2) goto usage
+ ssh -n $IOPENER sp_ccdcontrol cool 1 $args[2]
+ exit 0;
+
+warm: 
+ if ($#args != 1) goto usage
+ ssh -n $IOPENER sp_ccdcontrol cool 2 0
+ exit 0;
+
+dark:
+ if ($#args != 3) goto usage
+ set exptime = $args[2]
+ set output  = $args[3]
+ ssh -n $IOPENER sp_ccdcontrol expose -etime $exptime -shuttermode 2 > $output
+ exit 0;
+
+test:
+ echo ""
+ echo "starting skyprobe test suite"
+ echo "this will take about 2 minutes"
+ echo ""
+
+ # is computer user & name valid?
+ set machine = `echo $IOPENER | tr '@' ' '`
+ if ($#machine != 2) then
+   echo "invalid name for iopener $IOPENER"
+   exit 1;
+ endif
+
+ # is computer alive?
+ ping -c 2 -w 4 $machine[2] >& /dev/null
+ if ($status) then    
+   echo "can't contact iopener $machine[2]"
+   exit 1;
+ endif
+ echo "iopener is OK"
+ echo ""
+
+ # cool camera & wait for 60 seconds
+ echo "cooling camera & waiting for 1 minute"
+ ssh -n $IOPENER sp_ccdcontrol cool 1 -20
+ sleep 60
+ echo ""
+
+ # take a dark frame
+ echo "taking 1 sec dark frame test.dark.fits"
+ set exptime = 1.0
+ set output  = test.dark.fits
+ ssh -n $IOPENER sp_ccdcontrol expose -etime $exptime -shuttermode 2 > $output
+ echo ""
+
+ # is DETTEMP in range?
+ set temps = `echo test.dark.fits | fields DETTEM CAMTEM`
+ if ($status) then
+   echo "header information incorrect for test.dark.fits"
+   exit 1
+ endif
+ echo "temperatures: camera: $temps[2], outside: $temps[3]"
+ set t = `echo $temps[2] | awk '($1 > 10){print 1}'`
+ if ($t) then
+  echo "WARNING: camera temperature is high!"
+ else
+  echo "camera temperature OK"
+ endif
+ echo ""
+
+ # measure dark frame stats
+ mana --norc << EOF >& /dev/null
+  macro go
+   rd a test.dark.fits
+   stats a - - - -
+   exec echo \$MEAN \$MEDIAN \$SIGMA > test.dark.dat
+   exit 0
+  end
+  go
+  exit 1
+EOF
+ if ($status) then 
+  echo "error measuring dark flux"
+  exit 1
+ endif
+
+ # check dark frame stats
+ set flux = `cat test.dark.dat`
+ echo "dark flux: $flux[2]"
+ set t = `echo $flux[2] | awk '($1 > 10000){print 1}'`
+ if ($t) then
+  echo "WARNING: dark frame is bright!"
+ endif
+ echo ""
+ 
+ # take a light frame
+ echo "taking 0.1 sec light frame test.light.fits"
+ set exptime = 0.1
+ set output  = test.light.fits
+ ssh -n $IOPENER sp_ccdcontrol expose -etime $exptime -shuttermode 1 > $output
+ echo ""
+
+printout:
+
+ # 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 on $xdisp. start it now"
+   exit 1;
+ endif
+ setenv DISPLAY $xdisp
+
+ # delete old PS file
+ date +%Y.%m.%d | awk '{printf "TEXT 10 20 date:%s\n", $1}' > date.reg
+
+ # measure light frame stats
+ mana --norc << EOF >& /dev/null
+  macro go
+   rd a test.light.fits
+   stats a - - - -
+   exec echo \$MEAN \$MEDIAN \$SIGMA > test.light.dat
+   keyword a NAXIS1 nx
+   keyword a NAXIS2 ny
+   echo "nx, ny: \$nx, \$ny"
+   resize \$nx \$ny
+   tv a {\$MEDIAN*1.1} {-0.2*\$MEDIAN}
+   load red date.reg
+   ps -name skyprobe.ps
+   exit 0
+  end
+  go
+  exit 1
+EOF
+ if ($status) then 
+  echo "error measuring light flux"
+  exit 1
+ endif
+
+ # check light frame stats
+ set flux = `cat test.light.dat`
+ echo "light flux: $flux[2]"
+ echo "approx. expected counts: "
+ echo "     100 for dark dome"
+ echo "   15000 for dome lights on"
+ echo "   30000 for dome open daytime"
+ echo ""
+
+ if (! -e skyprobe.ps) then 
+   echo "skyprobe.ps not created, cannot print out image"
+ else
+   lpr -Psps skyprobe.ps
+   echo "image is being printed on SPS"
+ endif
+
+ # test tcsh & loggerh
+# cp -f $template $dummyfits
+# setenv FFTEMPLATE $dummyfits
+# /cfht/bin/tcsh -B >>& $logfile
+# /cfht/bin/loggerh -E >>& $logfile
+
+ exit 0; 
+
+expose:
+ if ($#args != 3) goto usage
+ set exptime  = $args[2]
+ set output = $args[3]
+
+ # setup logfile (default or /dev/null)
+ if ((-e $dlogfile) && (! -w $dlogfile)) then
+  set logfile = /dev/null
+ else
+  set logfile = $dlogfile
+ endif
+
+ # pre-exposure:
+ # get current RA & DEC, etc
+ # cp -f $template $dummyfits
+ # setenv FFTEMPLATE $dummyfits
+ # /cfht/bin/tcsh -B >>& $logfile
+ # at this point, we could check the TCS status and wait until dome & tel
+ # are not moving.  a future addition
+    
+ # take exposure:
+ if ($process) then
+  (ssh -n $IOPENER sp_ccdcontrol expose -etime $exptime -shuttermode 1 > $output) >>& $logfile
+ else
+   ssh -n $IOPENER sp_ccdcontrol expose -etime $exptime -shuttermode 1 > $output
+ endif
+
+ # post-exposure 
+ if ($process) then 
+  # set target for tcsh & loggerh
+  setenv FFTEMPLATE $output
+
+  # update RA & DEC in image header
+  /cfht/bin/tcsh -B >>& $logfile
+  /cfht/bin/loggerh -E >>& $logfile
+
+  # todo:
+  # read RA & DEC from $dummyfits, check for offset, set flag
+  # check exit status for functions above. if they fail, exit 1
+
+  # currently skipping the animation jpegs
+  # makejpegs $output &
+  sp_phot $output >>& $photlog & 
+ endif
+  
+ exit 0;
+
+######
+
+usage:
+  echo "USAGE: sp_command init (path)"
+  echo "USAGE: sp_command cool (temp)"
+  echo "USAGE: sp_command warm"
+  echo "USAGE: sp_command test"
+  echo "USAGE: sp_command dark (exptime) (filename)"
+  echo "USAGE: sp_command expose (exptime) (filename)"
+exit 2;
Index: /trunk/Ohana/src/shell/src/sp_phot
===================================================================
--- /trunk/Ohana/src/shell/src/sp_phot	(revision 16)
+++ /trunk/Ohana/src/shell/src/sp_phot	(revision 16)
@@ -0,0 +1,119 @@
+#!/bin/csh -f
+
+# USAGE: sp_phot (filename.fits) 
+
+# this script has a few goals:
+# 1) make a copy of the unreduced image in RAWDIR
+# 2) run skyproberedccd, produce a reduced image
+# 3) run skyprobephot (sextractor) on image
+# 4) run imclean on result, place smp file in SMPDIR
+# 5) run gastro on smp file 
+# 6) run addstar on smp to add to CATDIR
+
+# run this process on 'druid' instead of 'ohia'?
+
+set PROCNAME=sp_phot
+set MAXTIME=300
+
+set args=""
+set setdate=1
+while ("$1" != "") 
+ switch ($1)
+  case -date: 
+   set setdate=0;
+   shift;
+   set DATE=$1;
+   breaksw;
+  default:
+   set args=($args $1);
+   breaksw;
+ endsw
+ shift
+end
+
+if ($#args != 1) then
+  echo "USAGE: sp_phot (filename.fits) [-date YYYYMMDD]";
+  exit 2;
+endif
+
+# kill off other processes with this name, and their children
+# but only if they've run for more than $MAXTIME
+set list=`/bin/ps -eo pid,user,comm | awk -v n=$PROCNAME -v m=$$ '($3==n)&&($1!=m){print $1}'`
+foreach pid ($list)
+  set etime=`/bin/ps -eo pid,etime | awk -v n=$pid '($1==n){{m=substr($2,1,2)}{s=substr($2,4,2)}{print m*60+s}}'`
+  if ($etime < $MAXTIME) continue
+  echo "kill $pid ($etime)"
+  set children=`/bin/ps -eo pid,ppid | awk -v p=$pid '($2==p){print $1}'`
+  kill $pid
+  foreach child ($children)
+    echo "kill $child (child)"
+    kill $child
+  end
+end
+
+# setenv PATH {$PATH}:/apps/elixir/bin
+
+if ($setdate) then
+  set DATE=`date -u +%Y%m%d`
+endif
+set spdir = `gconfig SKYPROBE_DIR`
+if ($?) then 
+  echo "problem with config system"
+  exit 1;
+endif
+set RAWDIR = "$spdir/rawdir/$DATE"
+set SMPDIR = "$spdir/smpdir/$DATE"
+set TYCHO  = "$spdir/tycho" 
+
+# check that directories exist
+if (! -d $RAWDIR) then
+  mkdir -p $RAWDIR
+  if ($status) then
+    echo "can't create save directory $RAWDIR";
+    exit 1;
+  endif
+endif
+if (! -d $SMPDIR) then
+  mkdir -p $SMPDIR
+  if ($status) then
+    echo "can't create save directory $SMPDIR";
+    exit 1;
+  endif
+endif
+
+set raw=$args[1]
+set root=`echo $raw | awk -F/ '{print $NF}' | sed s/.fits//`
+
+cp $raw $RAWDIR/
+if ($status) then
+  echo "warning: can't make copy of image $raw"
+endif
+
+skyproberedccd $raw $SMPDIR/$root.flt
+if ($status) goto cleanup;
+
+# skyprobephot $SMPDIR/$root.flt $SMPDIR/$root.sx
+sp_sexphot $SMPDIR/$root.flt $SMPDIR/$root.sx
+if ($status) goto cleanup;
+
+# need to have a generic method of introducing the correct photcode
+# based on both camera and filter
+imclean -sex -p SKYPROBE.V $SMPDIR/$root.flt $SMPDIR/$root.sx $SMPDIR/$root.smp 
+if ($status) goto cleanup;
+
+# use the tycho data only to do astrometry
+rsh -n milo gastro -D CATDIR $TYCHO $SMPDIR/$root.smp
+# if ($status) goto cleanup;
+
+rsh -n milo addspphot -cal TYCHO_V TYCHO_B $SMPDIR/$root.smp 
+# rsh -n milo addstar -cal TYCHO_V TYCHO_B $SMPDIR/$root.smp 
+# if ($status) goto cleanup;
+
+rm -f $SMPDIR/$root.flt 
+rm -f $SMPDIR/$root.sx
+exit 0;
+
+cleanup:
+rm -f $SMPDIR/$root.flt 
+rm -f $SMPDIR/$root.sx
+exit 1;
Index: /trunk/Ohana/src/shell/src/sp_plots
===================================================================
--- /trunk/Ohana/src/shell/src/sp_plots	(revision 16)
+++ /trunk/Ohana/src/shell/src/sp_plots	(revision 16)
@@ -0,0 +1,49 @@
+#!/bin/csh -f
+
+if (($#argv != 1) && ($#argv != 2)) goto usage
+
+setenv PATH /bin:/usr/bin:/usr/bin/X11:/apps/elixir/bin:/usr/local/bin
+
+# find the appropriate script file
+set confdir=`gconfig CONFDIR`
+set script="$confdir/mana/skyprobe"
+set xhost=`gconfig XHOST`
+set xdisp=`gconfig XDISP`
+setenv DISPLAY $xdisp
+
+if ("$1" == "init") goto init;
+if ("$1" == "plot") goto plot;
+if ("$1" == "done") goto done;
+goto usage;
+
+init:
+ # test named Xserver, or start vnc on specified machine
+ 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
+ echo "X server $xdisp is running"
+ exit 0;
+
+plot: 
+# status -c $elixir -C skyprobe --norc --only $script >& /dev/null
+ echo "init; doplots; exit 0" | status -C skyprobe --norc $script
+ exit 0;
+
+
+done:
+ if ("$2" == "") then
+  echo "USAGE: sp_plots done (date)"
+  exit 2;
+ endif 
+
+ cp /data/milo/elixir/plots/skyprobe_night.png /apps/www/www.cfht.hawaii.edu/Instruments/Skyprobe/archive/mcal_$2.png
+ exit 0;
+
+usage:
+ echo "USAGE: sp_plots init"
+ echo "USAGE: sp_plots plot"
+ echo "USAGE: sp_plots done (date)"
+ exit 2;
Index: /trunk/Ohana/src/shell/src/sp_sexphot
===================================================================
--- /trunk/Ohana/src/shell/src/sp_sexphot	(revision 16)
+++ /trunk/Ohana/src/shell/src/sp_sexphot	(revision 16)
@@ -0,0 +1,32 @@
+#!/bin/csh -f
+# load the file, determine bias and sky, then extract a subraster
+# write out the subraster 
+
+if ($#argv != 2) then
+ echo "USAGE: skyprobephot file.fits file.sx"
+ exit 2;
+endif
+
+set infile = $1
+set outfile = $2
+
+# sex $1 -c $script -CATALOG_NAME $2
+# exit $status
+
+# find the appropriate script file
+set confdir=`gconfig CONFDIR`
+
+# sextractor needs full paths to:
+set sexconf = "$confdir/sextract/skyprobe.sex"
+set sexpars = "$confdir/sextract/skyprobe.param"
+set sexfilt = "$confdir/sextract/default.conv"
+set sexnnw  = "$confdir/sextract/default.nnw"
+
+sex $infile \
+    -c $sexconf \
+    -PARAMETERS_NAME $sexpars \
+    -FILTER_NAME     $sexfilt \
+    -STARNNW_NAME    $sexnnw \
+    -CATALOG_NAME    $outfile
+
+exit $status
