#! /bin/sh
. /usr/local/etc/fermi.shrc
echo ---------------------------------------------------------------
date
echo Begin setup of products needed
setup -r /usrdevel/dp2/bgreen/dp dp
setup astrotools
setup ssc
setup ocs
DERVISH_USER=$DP_DIR/etc/dpStartup.tcl
export DERVISH_USER
cd /data/dp3.b/data/727/ssc
echo Done setup of products needed
echo ---------------------------------------------------------------
date
echo Begin mounting tape drive for spooling
TAPEDRIVE=`ocs_allocate | cut -d" " -f2`
if [ $TAPEDRIVE = 'No' ] 
then
  echo Error: not able to allocate a tape drive
  exit 1
fi
echo TAPEDRIVE is $TAPEDRIVE
ocs_request -t $TAPEDRIVE -v JL0913 -r
if [ $? -ne 0 ] 
then
  ocs_deallocate -t $TAPEDRIVE
  echo Error: Failure requesting tape mount
  exit 1
fi
DEVFILE=`ocs_devfile -t $TAPEDRIVE`
echo DEVFILE is $DEVFILE
count=0
dstat=2
until [ $count -ge 5 -o $dstat -eq 0 ] 
do
 count=`expr $count + 1` 
 ocs_check_tape -t $TAPEDRIVE -v JL0913 -r | grep Success
 if [ $? -eq 0 ] 
 then
  dstat=0
 fi
 echo $count $dstat - checked drive
done
if [ $count -ge 5 ]
then
  ocs_dismount -t $TAPEDRIVE
  ocs_deallocate -t $TAPEDRIVE
  echo Error: Failure properly mounting tape. Possibly wrong tape.
  exit 1
fi
mt -f $DEVFILE rewind
echo Done mounting tape drive for spooling
echo ---------------------------------------------------------------
date
echo Begin setupDPssc
astrotools -command "setupDPssc /data/dp3.b/data 727 0 6 6 10 92 51251 51251 51162 51008 51075 $DEVFILE JL0913 1 \"\"" 
echo End setupDPssc
echo ---------------------------------------------------------------
date
echo Begin run_ssc_pipeline
ssc -command "run_ssc_pipeline scPlan-6.par" 
astrotools -command "driveSpaceRemove ssc 727 6" 
echo Done run_ssc_pipeline
echo ---------------------------------------------------------------
date
echo Dismount and deallocate tapedrive
ocs_dismount -t $TAPEDRIVE
ocs_deallocate -t $TAPEDRIVE
echo ---------------------------------------------------------------
date
echo ALL DONE
exit

