#!/bin/bash

# This script starts up a single MPI process.
# It is used in parallel environments where it
# is difficult to set up environment variables
# or command line arguments that contain special
# shell characters.

mpqc=$1 && shift
messagegrp=$1 && shift
threadgrp=$1 && shift
memorygrp=$1 && shift
integral=$1 && shift

function isodecode() {
  str=$1 && shift
  echo $str | sed -e 's/%20/ /g' \
                  -e 's/%3c/</g' -e 's/%3e/>/g' \
                  -e 's/%5b/[/g' -e 's/%5d/]/g' \
                  -e 's/%24/$/g' \
                  -e 's/%38/:/g' \
                  -e 's/%28/(/g' -e 's/%29/)/g' \
                  -e 's/%25/%/g'
}

if [ "$messagegrp" != none ]; then
  export MESSAGEGRP=`isodecode $messagegrp`
fi

if [ "$threadgrp" != none ]; then
  export THREADGRP=`isodecode $threadgrp`
fi

if [ "$memorygrp" != none ]; then
  export MEMORYGRP=`isodecode $memorygrp`
fi

if [ "$integral" != none ]; then
  export INTEGRAL=`isodecode $integral`
fi


$mpqc $*

