Index: /tags/shell-1-3-0/Ohana/src/shell/Makefile
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/Makefile	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/Makefile	(revision 11924)
@@ -0,0 +1,42 @@
+include ../../Configure
+HOME 	=	$(ROOT)/src/shell
+
+shell:
+
+default: install
+
+DADS = \
+dads.cleanup
+
+GENERAL = \
+block checkdisks dumptape \
+fits2jpeg gopsfphot gosexphot \
+setpath scattercorrection \
+vncstart vnccheck
+
+IMSTATS = \
+irsex sexstats
+
+MKDETREND = \
+detstats rm.elixir
+
+REALTIME = \
+el_plots elixir.fork elixir.launch \
+getfocus getseeing gettemps mkjpeg
+
+SKYPROBE = \
+sp_command sp_phot \
+sp_plots sp_sexphot
+
+CODE = $(DADS) $(GENERAL) $(IMSTATS) $(MKDETREND) $(POSTRUN) $(PTOLEMY) $(REALTIME) $(SKYPROBE)
+
+install:
+	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN); fi
+	for file in $(CODE); do \
+	(chmod +x src/$$file && cd $(DESTBIN) && rm -f $$file && ln -s $(HOME)/src/$$file .); \
+	done
+
+# utilities #################################################
+clean:	
+	rm -f `find . -name "*~"`
+	rm -f `find . -name "#*"`
Index: /tags/shell-1-3-0/Ohana/src/shell/doc/ChangeLog.txt
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/doc/ChangeLog.txt	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/doc/ChangeLog.txt	(revision 11924)
@@ -0,0 +1,10 @@
+
+- shell 1.2
+  * fixed to work with mana 1.0 changes (only one cmd line input file)
+  * replace addspphot with addstar -skyprobe
+
+shell-1-1:
+  - changed sp_phot to use unified addstar, not addspphot
+
+shell-1-0:
+  - initial release
Index: /tags/shell-1-3-0/Ohana/src/shell/doc/flips.notes
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/doc/flips.notes	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/doc/flips.notes	(revision 11924)
@@ -0,0 +1,51 @@
+
+Some of the Elixir scripts call Flips programs.  Here is a list of the
+programs in Flips being used by Elixir:
+
+fr.defringe   : flipsrun (imcombred)
+fr.gtfringe   : flipsrun (imstat)
+defringe      : flipsrun (imcombred)
+doflips       : flatccd
+doflips       : darkccd
+flatten.flips : redccd 
+fr.mkrough    : flipsrun (imcombred)
+fr.smooth     : flipsrun (imfilter)
+gtfringe      : flipsrun (imstat)
+
+noni: file *
+RCS:            directory
+block:          C shell script text
+checkdisks:     C shell script text
+dads.cleanup:   C shell script text
+dads.remef:     C shell script text  - to be deprecated?
+dads.split:     C shell script text  - to be deprecated
+defringe:       C shell script text  - perl
+detstats:       C shell script text  - (mkdetrend)
+doflips:        C shell script text  - perl/detflips
+dumptape:       C shell script text
+el_plots:       C shell script text
+elixir.fork:    C shell script text
+elixir.launch:  C shell script text
+fits2jpeg:      C shell script text
+flatten.flips:  C shell script text  - perl
+flatten.subaru: C shell script text  - old
+fr.defringe:    C shell script text  - perl
+fr.mkrough:     C shell script text  - perl/detflips
+fr.smooth:      C shell script text  - perl TBD
+getfocus:       C shell script text
+getfringe:      bash shell script    - perl
+getseeing:      C shell script text
+gettemps:       C shell script text
+gopsfphot:      C shell script text
+gosexphot:      C shell script text
+irsex:          C shell script text
+mk.ptlist:      C shell script text
+mkjpeg:         C shell script text
+pt.export:      C shell script text
+rm.elixir:      C shell script text
+setpath:        C shell script text
+sexstats:       C shell script text
+sp_command:     C shell script text
+sp_phot:        C shell script text
+sp_plots:       C shell script text
+sp_sexphot:     C shell script text
Index: /tags/shell-1-3-0/Ohana/src/shell/doc/notes.txt
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/doc/notes.txt	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/doc/notes.txt	(revision 11924)
@@ -0,0 +1,113 @@
+block			general
+checkdisks		CFHT specific
+dads.cleanup		
+dads.remef		
+dads.split		
+defringe		N CCDs, CFH12K Coord file
+detrend			Not Used?
+detstats		OK (check mana scripts)
+doflips			OK
+dumptape		
+elixir.fork		
+elixir.grab		
+elixir.report		
+fits2jpeg		
+fixdetrend		
+flatten.flips		OK
+flatten.mana		OK	
+focusstats		
+fr.ckfile		Not Used
+fr.defringe		N CCDs (check mana scripts)
+fr.mkimage		OK
+fr.mkrough		OK
+fr.mkstats		(check scripts)
+fr.smooth		Scale is CCD dependent
+fr.stats		OK
+getfocus		
+getseeing		
+gettemps		
+gopsfphot		
+gosexphot		
+gtfringe		(sh) OK
+imstats			CCD size specific -- should use DETSEC
+merge.lists		OK
+mk2d			Not Used
+mkjpeg			(realtime) N CCD specific
+normalize		OK
+normalize.invert	-
+phot.by.night		
+pt.export		(ptolemy export process)
+rm.elixir		(drop & convert to the exit status method)
+setpath			unused?
+sexstats		OK
+skyprobephot		
+split.mef		OK
+spphot			
+
+-
+
+cfht.names		a
+checkconfig		CFHT specific
+ckastrom		
+ckdetrend		
+ckphotom		
+ckrunid			
+ckvalid			
+clear.rawdir		
+create.imlists		nut used
+create.subset		OK
+dads.detrend		
+dads.jpeg		
+dads.keywords		
+darktime.cfht		CFH12K specific -- these curves must be measured for a new device!
+fixlists		
+fl.split2mef		not used?
+fr.detrend		Nccds from gt_names -- more general encapsulation
+fr.gtstats		Nccds
+fr.medbin		Nccds
+fr.medbin.spline	Nccds
+fr.mklists		OK
+fr.select		
+fr.subset		
+get.standards		
+grab.keywords		
+images.names		
+imclean.cfht		
+imselect		
+imstatqso		
+merge.lists		
+mkdetrend		
+mkfringe		
+mkptolemy.names		
+mktrans			
+mktreport		
+mosaic.merge		
+mosaic.stats		
+pt.run			
+seeingstats		
+validate		
+
+shell scripts that use awk -v (convert to perl):
+defringe
+fr.defringe
+fr.smooth
+gtfringe   (convert from sh anyway)
+
+shell scripts which use CFH12K dependent things:
+
+defringe		N CCDs, CFH12K Coord file
+detstats		(check mana scripts)
+fr.ckfile		Nccds
+fr.defringe		N CCDs (check mana scripts)
+fr.mkimage		(check scripts)
+fr.mkstats		(check scripts)
+fr.smooth		Scale is CCD dependent
+fr.stats		(check scripts)
+imstats			CCD size specific -- should use DETSEC
+normalize		OK
+split.mef		CCD size specific
+
+(watch out for header keywords -- make a complete dictionary)
+
+shell -> perl
+split.mef
Index: /tags/shell-1-3-0/Ohana/src/shell/doc/programs.txt
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/doc/programs.txt	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/doc/programs.txt	(revision 11924)
@@ -0,0 +1,61 @@
+block			: x
+checkdisks		: x
+ckastro			: x
+dads.cleanup		: x
+dads.remef		: x
+dads.split		: +
+doflips			: x
+dumptape		: x
+elixir.fork		: x
+fits2jpeg		: x
+flatten.flips		: +
+flatten.subaru		: x (fake)
+gettemps		: x
+gopsfphot		: x
+gosexphot		: +
+imstats			: +
+merge.lists		: x
+mk2d			: x
+normalize		: x
+normalize.invert	: x
+phot.by.night		: x
+pt.export		: x
+rm.elixir		: x
+setpath			: x
+sexstats		: x
+detstats		: x
+
+getfocus		: [which chips should be camera-dependent]
+getseeing		: [which chip should be camera-dependent]
+mkjpeg			: [scale and ccd list should be camera-dependend]
+
+mk.ptlist		: - [ccds in list need to be ID, not N - add option to imsearch?]
+el_plots		: - (in script mana/elixir)
+
+skyprobe should have its own minimal config file
+
+skyprobephot		: [cleanup up config reference]
+sp_expose		: x
+split.mef		: x
+spphot			: [abstract RAWDIR, etc?]
+sp_plots		: [abstract plot directory?]
+
+mkfringe stuff:
+
+fr.fitstats		: +
+fr.imstats		: +
+fr.mkimage		: 
+fr.mkrough		: 
+fr.mkstats		: 
+fr.smooth		: 
+fr.stats		: 
+getfringe		: 
+defringe		: - (not very clean; might work)
+fr.defringe		: - (some major issues..)
+
+
+already checked:
+
+mode.imstats
+mode.sextract
+mode.flips
Index: /tags/shell-1-3-0/Ohana/src/shell/src/block
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/block	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/block	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/checkdisks
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/checkdisks	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/checkdisks	(revision 11924)
@@ -0,0 +1,9 @@
+#!/bin/csh -f
+
+set disks="/data/elixir /data/elixir1 /data/elixir2 /data/elixir3 /h/skyprobe /data/ulu /data/hau /data/naupaka /data/mamane /data/naio /data/koa /data/kiawe /data/noni"
+
+foreach f ($disks)
+    set uspace = `sdf -a $f -M`
+    set aspace = `sdf -c $f -M`
+    echo $f $uspace $aspace | awk '{printf "%-20s %8.3f of %8.3f GB\n", $1, $2/1000, $3/1000}'
+end
Index: /tags/shell-1-3-0/Ohana/src/shell/src/dads.cleanup
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/dads.cleanup	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/dads.cleanup	(revision 11924)
@@ -0,0 +1,17 @@
+#!/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/*.def
+
+# generate binned-by-12 image
+mosmc $outdir/*.fits $outdir.B12.fits 12
+
+echo "SUCCESS"
Index: /tags/shell-1-3-0/Ohana/src/shell/src/detstats
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/detstats	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/detstats	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/dumptape
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/dumptape	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/dumptape	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/el_plots
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/el_plots	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/el_plots	(revision 11924)
@@ -0,0 +1,63 @@
+#!/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`
+set datdir=`gconfig DATDIR`
+if ($camera == "cfh12k") goto valid;
+if ($camera == "cfhtir") goto valid;
+if ($camera == "megacam") goto valid;
+if ($camera == "meganorth") 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" | dvo -D CAMERA $camera --norc $script
+ exit 0;
+
+
+done:
+ if ("$2" == "") then
+  echo "USAGE: el_plots done (date)"
+  exit 2;
+ endif 
+
+ cp $datdir/plot/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: /tags/shell-1-3-0/Ohana/src/shell/src/elixir.fork
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/elixir.fork	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/elixir.fork	(revision 11924)
@@ -0,0 +1,112 @@
+#!/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
+
+set logdir = "$HOME/elixir"
+if (! -e $logdir) then 
+  mkdir $logdir
+  if ($status) then 
+    echo "error with elixir configurations: missing LOGDIR, using /tmp" 
+    set logdir = "/tmp"
+  endif
+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: /tags/shell-1-3-0/Ohana/src/shell/src/elixir.launch
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/elixir.launch	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/elixir.launch	(revision 11924)
@@ -0,0 +1,124 @@
+#!/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`;
+set logdir = `gconfig LOGDIR`;
+set datdir = `gconfig DATDIR`;
+
+if ($1 == "mkdetrend") then
+    switch ($camera)
+     case cfh12k:
+     case megacam:
+     case meganorth:
+      echo "starting mkdetrend"
+      mkdetrend auto run -run $run -camera $camera >>& $logdir/mkdetrend.log &
+      breaksw;
+
+     default:
+      breaksw;
+    endsw
+
+    exit 0;
+endif
+
+if ($1 == "imstats") then
+    switch ($camera)
+     case cfh12k:
+     case megacam:
+     case meganorth:
+      echo "starting elixir imstats"
+      elixir -restart -D mode imstats -D CAMERA $camera -D RUNID $run >>& $logdir/imstats.log &
+      breaksw;
+
+     case cfhtir:
+      echo "starting elixir irstats"
+      elixir -restart -D mode irstats -D CAMERA $camera -D RUNID $run >>& $logdir/imstats.log &
+      breaksw;
+
+     default:
+      echo "stopping elixir imstats"
+      elixir -stop -D mode imstats
+      breaksw;
+    endsw
+    exit 0;
+endif
+
+if ($1 == "imstatreg") then
+    switch ($camera)
+     case cfhtir:
+     case cfh12k:
+     case megacam:
+     case meganorth:
+      echo "checking for existing imstatreg -daemon"
+      imstatreg -D CAMERA $camera -D RUNID $run -daemon -status
+      if ($status) then
+	echo "no imstatreg -daemon, starting..."
+	imstatreg -D CAMERA $camera -D RUNID $run -daemon -v
+	if ($status) then
+	    echo "error starting imstatreg -daemon"
+	endif
+      endif
+      breaksw;
+
+     default:
+      echo "no imstatreg -daemon needed for $camera"
+      breaksw;
+    endsw
+    exit 0;
+endif
+
+if ($1 == "cadc") then
+    switch ($camera)
+     case cfh12k:
+     case megacam:
+     case meganorth:
+      set date = `date -u +%Y%m%d+%H:%M:%S`
+
+      # extract CADC table, using all undistributed, object images from the past few days
+      imsearch -D CAMERA $camera -D RUNID $run -type object -dist f -trange now -4d -cadctable $datdir/cadc/mcmd.raw.$date.fits
+      if ($status) then
+	echo "error extracting cadc table"
+	exit 1;
+      endif
+      # mark the images above distributed
+      imsearch -D CAMERA $camera -D RUNID $run -type object -dist f -trange now -4d -modify dist t
+
+      # send the file to the CADC ftp location
+      cp $datdir/cadc/mcmd.raw.$date.fits /h/ftp/pub/fits_hdrs/
+
+      # update the values to the QSO database
+      cadc2qso $datdir/cadc/mcmd.raw.$date.fits
+
+      breaksw;
+
+     default:
+      echo "no CADC table needed for $camera"
+      breaksw;
+    endsw
+    exit 0;
+endif
+
+if ($1 == "sextract") then
+    switch ($camera)
+     case cfh12k:
+     case megacam:
+     case meganorth:
+      echo "starting elixir sextract"
+      elixir -restart -D mode sextract -D CAMERA $camera -D RUNID $run >>& $logdir/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: /tags/shell-1-3-0/Ohana/src/shell/src/fits2jpeg
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/fits2jpeg	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/fits2jpeg	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/flatten.subaru
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/flatten.subaru	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/flatten.subaru	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/getfocus
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/getfocus	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/getfocus	(revision 11924)
@@ -0,0 +1,195 @@
+#!/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) && ($4== 0){print $0}' $temp.sdat.$ccd | sort -k 6n | head -500 | 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 "input $script" >> $temp.pro
+echo "plotfocus $temp $temp.ppm $name $fdir/$name/$name$ccd.fits" >> $temp.pro
+mana --norc --only $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 "input $script" >> $temp.pro
+ echo "split $fdir/$name.fits $ccdnam $temp.$ccdnum.fits" >> $temp.pro
+ @ i++
+end
+mana --norc --only $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) && ($4 == 0){print $0}' $temp.sdat.$ccd | sort -k 6n | head -500 | 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 "input $script" >> $temp.pro
+echo "plotfocus $temp $temp.ppm $name $temp.$ccd.fits" >> $temp.pro
+mana --norc --only $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: /tags/shell-1-3-0/Ohana/src/shell/src/getfocus.org
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/getfocus.org	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/getfocus.org	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/getseeing
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/getseeing	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/getseeing	(revision 11924)
@@ -0,0 +1,119 @@
+#!/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 pixscale = `gconfig ASEC_PIX`
+set ccd      = `gconfig SEEING_REF_CCD`
+set amp      = `gconfig SEEING_REF_AMP`
+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
+ set Nextend = `echo $file | fields NEXTEND | awk '{print $2}'` 
+ set Nccds   = `echo $file | fields NCCDS | awk '{print $2}'` 
+ set tccd = $ccd
+ if ($Nextend != $Nccds) set tccd = $amp
+ # use amp for un-spliced data, ccd for spliced
+ echo "input $script" > $temp.pro
+ echo "subraster.mef   $file $tccd $temp.fits $temp.stats" >> $temp.pro
+else
+ echo "input $script" > $temp.pro
+ echo "subraster.split $file $ccd $temp.fits $temp.stats" >> $temp.pro
+endif
+
+# run mana
+mana --only $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 -v scale=$pixscale '{print $1*scale}'`
+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: /tags/shell-1-3-0/Ohana/src/shell/src/gettemps
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/gettemps	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/gettemps	(revision 11924)
@@ -0,0 +1,45 @@
+#!/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
+chmod 666 $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: /tags/shell-1-3-0/Ohana/src/shell/src/gopsfphot
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/gopsfphot	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/gopsfphot	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/gosexphot
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/gosexphot	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/gosexphot	(revision 11924)
@@ -0,0 +1,49 @@
+#!/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
+
+# find the appropriate script file
+set confdir=`gconfig CONFDIR`
+
+set name = "gosexphot.sex"
+set param = "gosexphot.param"
+
+if ($#argv == 3) then
+    if ("$3" == "-shallow") then
+        set name  = "gosexshallow.sex"
+    endif
+    if ("$3" == "-stds") then
+        set name  = "gosexstds.sex"
+	set param = "gosexstds.param"
+    endif
+    if ("$3" == "-deep") then
+        set name  = "gosexdeep.sex"
+    endif
+endif
+
+# 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: /tags/shell-1-3-0/Ohana/src/shell/src/irsex
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/irsex	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/irsex	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/mkjpeg
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/mkjpeg	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/mkjpeg	(revision 11924)
@@ -0,0 +1,90 @@
+#!/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 "input $script" > $temp
+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 $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: /tags/shell-1-3-0/Ohana/src/shell/src/rm.elixir
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/rm.elixir	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/rm.elixir	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/scattercorrection
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/scattercorrection	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/scattercorrection	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/setpath
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/setpath	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/setpath	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/sexstats
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/sexstats	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/sexstats	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/sp_command
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/sp_command	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/sp_command	(revision 11924)
@@ -0,0 +1,274 @@
+#!/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/log/sp_expose.log"
+set photlog   = "/h/skyprobe/log/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[1] == "") 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
+ echo "" > $dlogfile
+ echo "" > $photlog
+ 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 sample.dark.fits"
+ set exptime = 1.0
+ set output  = sample.dark.fits
+ ssh -n $IOPENER sp_ccdcontrol expose -etime $exptime -shuttermode 2 > $output
+ echo ""
+
+ # is DETTEMP in range?
+ set temps = `echo sample.dark.fits | fields DETTEM CAMTEM`
+ if ($status) then
+   echo "header information incorrect for sample.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 sample.dark.fits
+   stats a - - - -
+   exec echo \$MEAN \$MEDIAN \$SIGMA > sample.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 sample.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 sample.light.fits"
+ set exptime = 0.1
+ set output  = sample.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
+ echo $xdisp
+
+ # delete old PS file
+ date +%Y.%m.%d | awk '{printf "TEXT 10 20 date:%s\n", $1}' > date.reg
+
+ mana --norc << EOF >& /dev/null
+  macro go
+   rd a sample.light.fits
+   stats a - - - -
+   exec echo \$MEAN \$MEDIAN \$SIGMA > sample.light.dat
+   keyword a NAXIS1 nx
+   keyword a NAXIS2 ny
+   tv a {\$MEDIAN*1.1} {-0.2*\$MEDIAN}
+   resize \$nx \$ny
+   load red date.reg
+   exec sleep 2
+   ps -name sample.light.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 sample.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 sample.light.ps) then 
+   echo "sample.light.ps not created, cannot print out image"
+ else
+   lpr -Psps sample.light.ps
+   echo "image is being printed on SPS"
+ endif
+
+ rm -f date.reg
+ rm -r sample.dark.dat
+ rm -r sample.light.dat
+
+ # 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: /tags/shell-1-3-0/Ohana/src/shell/src/sp_phot
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/sp_phot	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/sp_phot	(revision 11924)
@@ -0,0 +1,148 @@
+#!/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 DBMACHINE = `gconfig DBMACHINE`
+set PROCNAME  = sp_phot
+set MAXTIME   = 300
+
+set args=""
+set setdate=1
+set testrun=0
+while ($#argv)
+ 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]";
+  echo "USAGE: sp_phot (test)";
+  exit 2;
+endif
+
+if ($args[1] == "test") set testrun = 1
+
+# 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
+
+if ($setdate) then
+  set DATE=`date -u +%Y%m%d`
+endif
+
+set spdir = `gconfig SKYPROBE_DIR`
+if ($?) then 
+  echo "problem with config system: missing SKYPROBE_DIR"
+  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]
+if ($testrun) then
+ set raw = /h/skyprobe/data/Refs/sample.fits
+endif
+
+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 $DBMACHINE gastro -D CATDIR $TYCHO $SMPDIR/$root.smp
+echo gastro -D CATDIR $TYCHO $SMPDIR/$root.smp
+gastro -D CATDIR $TYCHO $SMPDIR/$root.smp
+# if ($status) goto cleanup;
+
+# rsh -n $DBMACHINE addstar -skyprobe -image -cal TYCHO_V TYCHO_B $SMPDIR/$root.smp 
+addstar -skyprobe -image -cal $SMPDIR/$root.smp 
+# if ($status) goto cleanup;
+
+if ($testrun) then
+ set N = `imphotsearch -name sample | wc -l`
+ imphotsearch -name sample
+ if ($status) then
+   echo "failure to find image in db"
+   exit 2;
+ endif
+ if ($N == 0) then
+   echo "failure to write image to db"
+   exit 1;
+ endif
+ echo delstar $SMPDIR/$root.smp 
+ delstar $SMPDIR/$root.smp 
+ if ($status) then
+   echo "failure to remove test image from db"
+   exit 2;
+ endif
+endif
+
+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: /tags/shell-1-3-0/Ohana/src/shell/src/sp_plots
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/sp_plots	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/sp_plots	(revision 11924)
@@ -0,0 +1,57 @@
+#!/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 datdir=`gconfig DATDIR`
+set script="$confdir/mana/skyprobe"
+set xhost=`gconfig XHOST.SUMMIT`
+set xdisp=`gconfig XDISP.SUMMIT`
+setenv DISPLAY $xdisp
+
+if ("$1" == "init")   goto init;
+if ("$1" == "plot")   goto plot;
+if ("$1" == "mkplot") goto mkplot;
+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 "init; doplots; exit 0" | dvo -C skyprobe --norc $script
+ exit 0;
+
+
+mkplot: 
+ if ($#argv != 2) goto usage
+ echo "init; ntplot $2; exit 0" | status -C skyprobe --norc $script
+ exit 0;
+
+
+done:
+ if ("$2" == "") then
+  echo "USAGE: sp_plots done (date)"
+  exit 2;
+ endif 
+
+ cp $datdir/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 mkplot (yyyy/mm/dd)"
+ echo "USAGE: sp_plots done (yyyymmdd))"
+ exit 2;
Index: /tags/shell-1-3-0/Ohana/src/shell/src/sp_sexphot
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/sp_sexphot	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/sp_sexphot	(revision 11924)
@@ -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
Index: /tags/shell-1-3-0/Ohana/src/shell/src/vnccheck
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/vnccheck	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/vnccheck	(revision 11924)
@@ -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: /tags/shell-1-3-0/Ohana/src/shell/src/vncstart
===================================================================
--- /tags/shell-1-3-0/Ohana/src/shell/src/vncstart	(revision 11924)
+++ /tags/shell-1-3-0/Ohana/src/shell/src/vncstart	(revision 11924)
@@ -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
