#!/bin/sh
#
#	wrap
#
#	Wrap up PARKBENCH result files for database
#
#	Format is "wrap"
#
#	Location of "pvmgetarch"
#	Change this if necessary...
#
NAMER=../conf/pvmgetarch
#
#
echo '                  ============='
echo '                  ============='
echo 'Thank you for testing some of the routines within'
echo '                  PARKBENCH 2.0'
echo '                  ============='
echo '                  ============='
echo
sleep 2
echo 'Some things you should be aware of in advance:'
echo
echo 'All of the following information (which may help'
echo 'if troubleshooting is necessary) is explained in'
echo 'in detail in the README.wrap file.'
sleep 4
echo
echo 'PSTSWM output files are not modified by this script.'
echo 'They should be sent in as is with all the other files.'
echo
sleep 3
echo 'AND'
echo
sleep 2
echo 'This script will only recognize NPB output files'
echo 'if they are created in the following format:'
echo
echo 'sp.A.25 > sp.A.25.out'
echo
sleep 2
echo 'That is, the NPB executable name followed by a .out suffix.'
echo
sleep 2
echo 'Please exit and move the NPB files if you have used'
echo 'another format.'
echo
sleep 4
#
echo 'Prepare to begin...'
echo
sleep 3
echo 'This routine will put your result file in'
echo 'a format for the PARKBENCH database.'
echo 'Please answer the following questions.'
echo 'If you cannot answer a question, hit <RETURN>.'
echo 'If you make a mistake, continue through'
echo 'the program.  You will be asked at the end'
echo 'if all the information is correct.  If not,'
echo 'you may try again.  Do not worry--this is short.'
echo
#
FINISHED=UNKNOWN
while [ "$FINISHED" = UNKNOWN ]
do
	rm -f header
	rm -f SEQheader
	echo 'PARKBENCH 2.0' >> header

	echo 'What is your name?'
	read NAME
	echo "Benchmarker: $NAME" > header
	echo
	echo $NAME', what is your e-mail address?'
	read EMAIL
	echo "E-mail address: $EMAIL" >> header
	echo
	echo $NAME', what is your URL?'
	echo 'Example:  http://www.netlib.org/parkbench/'
	read URL
	echo "URL:  $URL" >> header
	echo
	echo $NAME', what organization are you with?'
	read WITHWHOM
	echo "Organization:  $WITHWHOM" >> header
	echo
	echo "Date:  "`date` >> header
	MMYY=`date | cut -c5-7,27-28`

	CHECK=UNKNOWN
	while [ "$CHECK" = UNKNOWN ]
	do
		echo 'Select the communication package that you'
		echo 'have used.  Choose SEQ only if you have not'
		echo 'used any of the other communication libraries.'
		echo 'PVM'
		echo 'MPI'
		echo 'SEQ--sequential runs only'
		read MPL
		echo
		case "$MPL" in
		PVM | MPI) echo 'What '${MPL}' version are you using?'
		echo 'Examples:  PVM 3.3.10, MPICH 1.0.12, etc.'
		cp header SEQheader
		read VERSION
		echo "$MPL Version:  $VERSION" >> header
		echo "Version:  Sequential" >> SEQheader
		echo
		CHECK=KNOWN;;
		SEQ ) CHECK=KNOWN ;;
		esac
	done

	if [ $PVM_ARCH ]; then
		echo 'PVM_ARCH was given as '$PVM_ARCH
	else
		PVM_ARCH=`$NAMER`
		echo 'PVM_ARCH was selected as '$PVM_ARCH
	fi
	echo

	CHECK=UNKNOWN
	while [ "$CHECK" = UNKNOWN ]
	do
		echo 'Is PVM_ARCH = '$PVM_ARCH' correct? (y or n)'
		read ANSWER
		case "$ANSWER" in
		Y | y | Yes | YES | yes ) CHECK=KNOWN;;
		N | n | No | NO | no ) echo 'Please enter a PVM_ARCH.';
		read PVM_ARCH;;
		esac
		echo
	done

	echo "PVM_ARCH: $PVM_ARCH" >> header
	echo "PVM_ARCH: $PVM_ARCH" >> SEQheader
 
	echo 'Here is some machine info that will be included:'
	uname -a
	echo
	echo "Platform info:  "`uname -a` >> header
	echo "Platform info:  "`uname -a` >> SEQheader

	echo 'How many processors were used on the '${PVM_ARCH}'?'
	read NP
	echo
	echo "Number of processors:  $NP" >> header
	echo "Number of processors:  1" >> SEQheader
	echo ' ' >> header
	echo ' ' >> SEQheader

	CHECK=UNKNOWN
	while [ "$CHECK" = UNKNOWN ]
	do
		echo 'That is all the info we need for the header file.'
		echo 'Is the information that you gave correct? (y or n)'
		read ANSWER
		case "$ANSWER" in
		Y | y | Yes | YES | yes ) FINISHED=KNOWN;
		CHECK=KNOWN;;
		N | n | No | NO | no ) CHECK=KNOWN;;
		esac
		echo
	done
done

#
# Single process output files created by Low_Level routines
#
echo 'Processing Low_Level single process (SEQ) files.'
echo
for file in poly1.res poly2.res rinf1.res tick1.res tick2.res
do
#
# Check if file exists
#
	if [ ! -f "$file" ]
	then
		echo "$file not found!"
		continue
	fi
# 
# Process the file by prepending the SEQheader to it, and
# renaming it.
#
	SHORT=`echo $file | cut -d. -f1`
	cat SEQheader $file > SEQ.LowLevel.$SHORT.$PVM_ARCH.1.$MMYY
done
echo
sleep 2
#
# Multi process output files created by Low_Level routines
#
echo 'Processing Low_Level multi process files.'
echo
for file in comms1.res comms2.res comms3.res poly3.res synch1.res
do
#
# Check if file exists
#
	if [ ! -f "$file" ]
	then
		echo "$file not found!"
		continue
	fi
# 
# Process the file by prepending header to it, and
# renaming it.
#
	SHORT=`echo $file | cut -d. -f1`
	cat header $file > $MPL.LowLevel.$SHORT.$PVM_ARCH.$NP.$MMYY
done
echo
sleep 2
#
# Output files created by routines in Linear Algebra Kernels
#
echo 'Processing Linear Algebra Kernel files.'
echo
for file in LU.out MATMUL.out QR.out TRANS.out TRD.out
do
#
# Check if file exists
#
	if [ ! -f "$file" ]
	then
		echo "$file not found!"
		continue
	fi
# 
# Process the file by prepending header to it, and
# renaming it.
#
	SHORT=`echo $file | cut -d. -f1`
	cat header $file > $MPL.LinAlg.$SHORT.$PVM_ARCH.$NP.$MMYY
done
echo
sleep 2
#
# Output files created by routines in NAS Parallel Benchmarks
#
echo 'Processing NAS Parallel Benchmark files.'
echo
for file in bt.*.out cg.*.out ep.*.out ft.*.out is.*.out lu.*.out mg.*.out sp.*.out
do
#
# Check if file exists
#
	if [ ! -f "$file" ]
	then
		echo "$file not found!"
		continue
	fi
# 
# Process the file by prepending header to it, and
# renaming it.
#
	SHORT=`echo $file | cut -d. -f1`
	SIZE=`echo $file | cut -d. -f2`
	NP=`echo $file | cut -d. -f3`
	cat header $file > $MPL.NPB.$SHORT$SIZE.$PVM_ARCH.$NP.$MMYY
done
echo
sleep 2
rm -f header
rm -f SEQheader
#
echo
echo 'Great!  That should be all the information'
echo 'that we need for the PARKBENCH database.'
echo 'Please send the newly wrapped files to us'
echo 'as well as a copy of the make.def file that'
echo 'was used for compilation.'
echo
#
echo 'Email all files to'
echo 'parkbench_comments@cs.utk.edu'
echo
echo 'If this is difficult, please let us'
echo 'know how to obtain them (ftp, etc.).'
echo
echo 'Thanks again--the ParkBench Committee.'
