#!/bin/sh

if [ "$1" = "LASER" ]
then

# these are the laser cameras
P_UNIT=(10 12 B100 B101 B102 B103 B104)

# set the time stamp source so pulse IDs update
for i in ${!P_UNIT[*]}; do
  caput PROF:LI20:${P_UNIT[$i]}:TSS_SETEC $2
done

# Set triggers to correct state
  caput EVR:LI20:PM20:EVENT1CTRL.ENM $2
  caput EVR:LI20:PM20:EVENT1CTRL.OUT0 1
  caput EVR:LI20:PM20:EVENT1CTRL.OUT1 1
  caput EVR:LI20:PM20:EVENT1CTRL.OUT2 1
  caput EVR:LI20:PM20:EVENT1CTRL.VME 1
  caput EVR:LI20:PM20:EVENT1CTRL.ENAB 0
  sleep 0.1
  caput EVR:LI20:PM20:EVENT1CTRL.ENAB 1
fi

if [ "$1" = "EBEAM" ]
then

# these are the e-beam cameras
P_UNIT=(2432 3075 3158 3180 3208 3202 3230)

# set the time stamp source so pulse IDs update
EVR=PM21
for i in ${!P_UNIT[*]}; do
  caput PROF:LI20:${P_UNIT[$i]}:TSS_SETEC $2
done

# Set triggers to correct state
  caput EVR:LI20:PM21:EVENT1CTRL.ENM $2
  caput EVR:LI20:PM21:EVENT1CTRL.OUT0 1
  caput EVR:LI20:PM21:EVENT1CTRL.OUT1 1
  caput EVR:LI20:PM21:EVENT1CTRL.OUT2 1
  caput EVR:LI20:PM21:EVENT1CTRL.VME 1
  caput EVR:LI20:PM21:EVENT1CTRL.ENAB 0
  sleep 0.1
  caput EVR:LI20:PM21:EVENT1CTRL.ENAB 1
fi

if [ "$1" = "EXPT1" ]
then

# these are the expt 1 cameras
P_UNIT=(3300 3301 3302 3303 3304 3305 3306)

# set the time stamp source so pulse IDs update
EVR=PM22
for i in ${!P_UNIT[*]}; do
  caput EXPT:LI20:${P_UNIT[$i]}:TSS_SETEC $2
done

# Set triggers to correct state
  caput EVR:LI20:PM22:EVENT1CTRL.ENM $2
  caput EVR:LI20:PM22:EVENT1CTRL.OUT0 1
  caput EVR:LI20:PM22:EVENT1CTRL.OUT1 1
  caput EVR:LI20:PM22:EVENT1CTRL.OUT2 1
  caput EVR:LI20:PM22:EVENT1CTRL.VME 1
  caput EVR:LI20:PM22:EVENT1CTRL.ENAB 0
  sleep 0.1
  caput EVR:LI20:PM22:EVENT1CTRL.ENAB 1
fi

if [ "$1" = "EXPT2" ]
then

# these are the expt 2 cameras
P_UNIT=(3307 3308 3309 3310 3311 3312 3313)

# set the time stamp source so pulse IDs update
EVR=PM23
for i in ${!P_UNIT[*]}; do
  caput EXPT:LI20:${P_UNIT[$i]}:TSS_SETEC $2
done

# Set triggers to correct state
  caput EVR:LI20:PM23:EVENT1CTRL.ENM $2
  caput EVR:LI20:PM23:EVENT1CTRL.OUT0 1
  caput EVR:LI20:PM23:EVENT1CTRL.OUT1 1
  caput EVR:LI20:PM23:EVENT1CTRL.OUT2 1
  caput EVR:LI20:PM23:EVENT1CTRL.VME 1
  caput EVR:LI20:PM23:EVENT1CTRL.ENAB 0
  sleep 0.1
  caput EVR:LI20:PM23:EVENT1CTRL.ENAB 1
fi

if [ "$1" = "CMOS" ]
then

# these are the cmos iocs
P_UNIT=(CS01 CS02 CS03)
C_EVR=(CS01 CS02 CS03 CS04)

# set the time stamp source so pulse IDs update
for i in ${!P_UNIT[*]}; do
  caput IOC:LI20:${P_UNIT[$i]}:TSS_SETEC $2
done
  caput CMOS:LI20:3493:TSS_SETEC $2


# Set triggers to correct state
for i in ${!C_EVR[*]}; do
  caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.ENM $2
  if [ $2 -eq 213 ] 
     then 
     caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.ENM 221 
  fi
  if [ $2 -eq 233 ] 
      then
      caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.ENM 227
  fi
  caput EVR:LI20:${C_EVR[$i]}:EVENT2CTRL.ENM $2
  caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.OUT0 1
  caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.OUT1 1
  caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.OUT2 1
  caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.VME 1
  caput EVR:LI20:${C_EVR[$i]}:EVENT2CTRL.VME 1

  caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.ENAB 0
  sleep 0.1
  caput EVR:LI20:${C_EVR[$i]}:EVENT1CTRL.ENAB 1

done

fi
