#!/bin/bash

if [[ $# < 1 ]]
then
  echo ""
  echo "FACT.sub_star_mc.sh <input dir> <output dir>"
  echo ""
  exit
fi

cd $MARSSYS

INDIR=$1
OUTDIR=$2

TEMPFILE="temp.star.file"

## Need to edit this TODO
ls $INDIR/cer* | head -n 1 > $TEMPFILE

while read LINE
do

  INFILE=$LINE

## Need to edit this TODO
  NUMBER=`echo $LINE | sed s/cer/" "/g | gawk '{print $2}'`

  QSUB=$MARSSYS"/batch/queue/FACT.qsub_star_mc_"$NUMBER".sh"
  QSUBERR=$MARSSYS"/batch/queue/FACT.qsub_star_mc_"$NUMBER".err"
  QSUBOUT=$MARSSYS"/batch/queue/FACT.qsub_star_mc_"$NUMBER".out"

  sed -e "s|FFFFF|$INFILE|"  \
      -e "s|DDDDD|$OUTDIR|"   $MARSSYS"/batch/FACT.qsub_star_mc.sh" > $QSUB

  chmod +x $QSUB

  ##qsub -q fact_medium -b yes -o $QSUBOUT -e $QSUBERR $QSUB
  qsub -q test -b yes -o $QSUBOUT -e $QSUBERR $QSUB
  ##qsub -b yes -o $QSUBOUT -e $QSUBERR $QSUB

done <$TEMPFILE

rm $TEMPFILE
