#! /bin/sh
#
# Make a tar file of the tutorial examples, but without the alog files
#
set -x
cd /home/MPI/class/mpiexmpl
leave_alog=0
for arg in "$@" ; do
    case "$arg" in 
	-alog) leave_alog=1 ;;
        *) echo "Unrecognized argument $arg"; exit 1 ;;
    esac
done
#
# Use tar to copy to /tmp
if [ ! -d /tmp/tutcopy ] ; then
    mkdir /tmp/tutcopy
fi
cd /tmp/tutcopy
tar cf - -C /home/MPI/class mpiexmpl | tar xf -
#
# Remove the .alog files, old executables, and debris
cd /tmp/tutcopy/mpiexmpl
make clean
if [ $leave_alog = 1 ] ; then
    find . \( -name '*~' -o -name 'PI*' -o -name '.nfs*' \) -exec rm \{\} \;
else 
    find . \( -name '*.alog' -o -name '*~' -o -name 'PI*' -o -name '.nfs*' \) \
		-exec rm \{\} \;
fi
#
# rebuild the tar file
cd /tmp/tutcopy
tar cf - mpiexmpl | gzip > /tmp/mpiexmpl.tar.gz
/bin/rm -rf /tmp/tutcopy &
echo "tar file in /tmp/mpiexmpl.tar.gz"
