#!/bin/bash


if [ $1 == "clean" ]
then
	for i in *.inp
	do
		if [ -e ${i%.inp}.dat ];   then rm ${i%.inp}.dat   ;fi
		if [ -e ${i%.inp}.gamess ];then rm ${i%.inp}.gamess;fi
		if [ -e ${i%.inp}.trj ];   then rm ${i%.inp}.trj   ;fi
		if [ -e ${i%.inp}.ccrest ];then rm ${i%.inp}.ccrest;fi
		if [ -e ${i%.inp}.*vec* ]; then rm ${i%.inp}.*vec* ;fi
		if [ -e ${i%.inp}.rst ];   then rm ${i%.inp}.rst   ;fi
	done
	exit
fi

if [ -z $2 ]
then
	echo "Usage: runtest /path/to/rungms version [ncpu] [ppn]"
	echo "   Caution: some of these examples are serial only!"
	exit
fi

RUNGMS=$1
version=$2

if [ -z $3 ]
then
	cpu=1
else
	cpu=$3
	if [ -z $4 ]
	then
		ppn=$3
	else
		ppn=$4
	fi
fi

for i in *.inp
do
	if [ -e ${i%.inp}.dat ];   then rm ${i%.inp}.dat   ;fi
	if [ -e ${i%.inp}.gamess ];then rm ${i%.inp}.gamess;fi
	if [ -e ${i%.inp}.trj ];   then rm ${i%.inp}.trj   ;fi
	if [ -e ${i%.inp}.ccrest ];then rm ${i%.inp}.ccrest;fi
	if [ -e ${i%.inp}.*vec* ]; then rm ${i%.inp}.*vec* ;fi
	if [ -e ${i%.inp}.rst ];   then rm ${i%.inp}.rst   ;fi
	echo "--- $i ---"
	$RUNGMS ${i%.inp} $version $cpu $ppn > ${i%.inp}.gamess 2>&1
done
