#!/bin/sh
# RemoteInstantAppScript:makeMatlabPCTTemplate
# SubmissionScripts/Distributor/Instant/APP/matlabpct
#
trap cleanup HUP INT QUIT ABRT TERM

cleanup()
{
   pkill -TERM --parent $$
}

@@{USEENVIRONMENT}
@@{ENVIRONMENT}

# Change to directory where job was submitted.
cd @@{WORKINGDIRECTORY}
PATH=@@{WORKINGDIRECTORY}:${PATH}
export PATH

TIMEPATH=
for timePath in /bin/time /usr/bin/time /usr/local/bin/time ; do
   if [ -x ${timePath} ] ; then
      TIMEPATH=${timePath}
      break
   fi
done

${TIMEPATH} --format "Command exited with status %x\nreal %e\nuser %U\nsys %S" -o @@{TIME_RESULTS}-0 \
   @@{EXECUTABLE} @@{ARGUMENTS} < @@{STDIN} &
