#!/bin/bash
# script to submit interactive job to mcc05 or mcc06 with 64 cores
[[ -z "$1" ]] && { echo "You have to supply mcc05 or mcc06" ; exit 1; }
# make sure the tag for the generated files is correct 
# by checking that all changes have been commited to GIT
# (this does not include newly created files)
if ( ! git diff-index --quiet --cached HEAD -- ) || ( ! git diff-files --quiet )
  then
    echo "Uncommitted changes in the GIT repository:"
    git status --untracked-files=no

    read -p "Add changes and commit, amend last commit or exit [c/a/e]: " res
    case $res in
        [Cc]* ) git commit -a;;
        [Aa]* ) git commit -a --amend;;
        * ) exit 1;;
    esac
fi

CURRENT_VERSION=`git describe --tags --long`
NCORES=${2:-64}

echo "Starting at `date`"
echo "Running on hosts: $1"
echo "Running on $NCORES processors."
echo "Current working directory is `pwd`"
echo "Estia GIT revision is $CURRENT_VERSION"

mpirun -np $NCORES --host $1 mcnp6.mpi \
      inp=e2-estia.i outp=results/e2-estia_$CURRENT_VERSION.out \
      runtpe=runs/e2-estia_$CURRENT_VERSION.run \
      mctal=results/e2-estia_$CURRENT_VERSION.mct \
      mdata=results/e2-estia_$CURRENT_VERSION.mdt \
      wwout=weight_windows/e2-estia_$CURRENT_VERSION.wwg \
      wwone=weight_windows/e2-estia_$CURRENT_VERSION.wwo \
      wwinp=weight_windows/current.wwg

echo "Program finished with exit code $? at: `date`"
