#!/bin/sh

Dytest=.
CmV=/virgoApp/Cm/v8r4
FdV=/virgoApp/Fd/v5r1p6
#UNAME=`uname`

DYDIR=`dirname ${0}`
DyServer=$DYDIR/../$UNAME/dataDisplay.exe
echo "Using $DyServer"

if [ ${#} -eq 0 ] ; then
  echo " "
  echo "Provide please a test number:"
  echo "    0=do all tests"
  echo "    1=data from one raw data file    (ddfileraw.car)"
  echo "    2=data from one 50Hz data file   (ddfile50Hz.car)"
  echo "    3=data from one trend data file  (ddfiletrend.car)"
  echo "    4=data from raw data dir         (ddfiledir.car)"
  echo "    5=data from ffl file             (ddfileffl.car)"
  echo "    6=all types of plot              (ddplotall.car)"
  echo "    7=superposed plots               (ddplotsuperpose.car)"
  echo "    8=plots with special features    (ddplotspecial.car)"
  echo "    9=plots with missing channels and corrupted data (ddfilebaddata.car)"
  echo "   10=cm connection to dataSender (ddsender.car)"
  echo " "
  echo "   11=dynamic cm connection                                    (ddcm.car)"
  echo "   12=static cm connection with Cm name displaytest            (ddcmstatic.car)"
  echo "   13=cm connection with time plot at online limit             (ddcmlimit.car)"
  echo "   14=cm connection with superposed time plots at online limit (ddcmlimit_same.car)"
  echo " "
  exit 0 
fi

cd $Dytest


# Reading files tests
#####################

if [ ${1} -eq "1" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfileraw.car ; echo "running ddfileraw.car"; fi
if [ ${1} -eq "2" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfile50Hz.car ; echo "running ddfile50Hz.car"; fi
if [ ${1} -eq "3" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfiletrend.car ; echo "running ddfiletrend.car"; fi
if [ ${1} -eq "4" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfiledir.car ; echo "running ddfiledir.car"; fi
if [ ${1} -eq "5" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfileffl.car ; echo "running ddfileffl.car"; fi
if [ ${1} -eq "6" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddplotall.car ; echo "running ddplotall.car"; fi
if [ ${1} -eq "7" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddplotsuperpose.car ; echo "running ddplotsuperpose.car"; fi
if [ ${1} -eq "8" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddplotspecial.car ; echo "running ddplotspecial.car"; fi
if [ ${1} -eq "9" ] || [ ${1} -eq "0" ];  then $DyServer $DYDIR/ddfilebaddata.car ; echo "running ddfilebaddata.car"; fi


# Cm Online connections tests
#############################

if [ ${1} -gt "14" ]; then
  echo "No test defined for this number. Type ${0} to see possible numbers."
  echo " "
  exit 0
fi

if [ ${1} -gt "10" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
fi

if [ ${1} -eq "11" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcm.car ; echo "running ddcm.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
  sleep 2
fi

if [ ${1} -eq "12" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcmstatic.car ; echo "running ddcmstatic.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
  sleep 2
fi

if [ ${1} -eq "13" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcmlimit.car ; echo "running ddcmlimit.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
  sleep 2
fi

if [ ${1} -eq "14" ] || [ ${1} -eq "0" ]; then
  xterm -sb -sl 1024 -geometry 168x10+10+0 -T "fbsimtest - `date +\"%d %b %Y-%T\"`" -e $FdV/$UNAME/FdSim.exe displaytest 0 1 -adc 20000 4 -proc 20000 1 -cmname fbsimtest &
  sleep 2
  $DyServer $DYDIR/ddcmlimit_same.car ; echo "running ddcmlimit_same.car";
  $CmV/$UNAME/cm.exe send -to fbsimtest -type CfgKill
  echo "Removing fbsimtest"
fi

if [ ${1} -eq "10" ] || [ ${1} -eq "0" ]; then
  OLDDOMAIN=$CMDOMAIN
  export CMDOMAIN=Cascina
  sleep 2
  $DyServer $DYDIR/ddsender.car ; echo "running ddsender.car";
# export CMDOMAIN=$OLDDOMAIN
fi


if [ ${1} -eq "0" ]; then
  echo "All tests done"
else
  echo "Test ${1} done."
fi
echo " "


