#!/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;
