#!/bin/bash
# Check I have two arguments supplied
if [ "x$1" == "x" ]; then
  echo "I take two arguments, the name of the dax file and the logpath. None supplied."
  exit 1
fi

if [ "x$2" == "x" ]; then
  echo "I take two arguments, the name of the dax file and the logpath. Only got one: $1"
  exit 1
fi

# find the site-local template directory
PEG_DIR=`python -c 'from pycbc.workflow import PEGASUS_FILE_DIRECTORY;print PEGASUS_FILE_DIRECTORY'`
SITE_TEMPLATE=$PEG_DIR/basic_site_template.xml

# Set up the site-local with the correct paths
echo 'cat <<END_OF_TEXT' >  temp.sh
cat $SITE_TEMPLATE       >> temp.sh
echo 'END_OF_TEXT'       >> temp.sh
bash temp.sh > site-local-parsed.xml

# Plan the workflow
echo "Generating concrete workflow"
touch _reuse.cache

if [ "x$3" == "x--cache" ]; then
  cp $4 _reuse.cache
  pegasus-plan --conf $PEG_DIR/basic_pegasus.conf -d $1 --sites local -o local --dir $2 --cleanup inplace --cache $4 --cluster label,horizontal
else
  pegasus-plan --conf $PEG_DIR/basic_pegasus.conf -d $1 --sites local -o local --dir $2 --cleanup inplace --cluster label,horizontal
fi
