#!/bin/sh
#$ -o /exports/csce/eddie/geos/groups/LURG/models/PLUM/output/qlogs
#$ -e /exports/csce/eddie/geos/groups/LURG/models/PLUM/output/qlogs
#$ -l h_vmem=8G 
#$ -R y

if [ $# -lt 1 ]; then
	echo need 1 argument to specify config/output directory
	exit 0
fi

. /etc/profile.d/modules.sh
module load java

PATH=$PATH:/exports/csce/eddie/geos/groups/LURG/models/gams/gams24.7_linux_x64_64_sfx
export PATH

buildver="$(cat /exports/csce/eddie/geos/groups/LURG/models/PLUM/classes/buildver)"

echo "starting"
java -Xmx1G -XX:+PrintGC -classpath /exports/csce/eddie/geos/groups/LURG/models/gams/gams24.7_linux_x64_64_sfx/apifiles/Java/api/GAMSJavaAPI.jar:/exports/csce/eddie/geos/groups/LURG/models/PLUM/classes -DBUILDVER=$buildver -DCONFIG_FILE=/exports/csce/eddie/geos/groups/LURG/models/PLUM/output/$1/config.properties ac.ed.lurg.ModelMain
echo "finished"

module load R
R < /exports/csce/eddie/geos/groups/LURG/models/PLUM/plumv2/scripts/summariseLandUseOneSim.R  --no-save --args $1

if [[ $* == *-NoP* ]]; then
	echo "Not pruning outputs"
else
	echo "Pruning outputs, to save disk space"
	/exports/csce/eddie/geos/groups/LURG/models/PLUM/plumv2/scripts/pruneOutputs.sh /exports/csce/eddie/geos/groups/LURG/models/PLUM/output/$1
fi

