# the only thing you should pass to make_pbs_script is the parallel program you
# want to run and its arguments.  
# Example:
#	make_pbs_script cpi
#	make_pbs_scirpt mpi-io-test -f pvfs2:/mnt/pvfs2/testfile
#
# i'm terribly sorry for how confusing this function is... I want to generate a
# pbs script that itself uses some environment variables.  Thus we escape some
# dollar signs before things like $PATH, but not others like $PAV_CONFIG.  

make_pbs_script() {

	echo "#!/bin/sh
#PBS -l walltime=0:10:0
#PBS -l nodes=8
#PBS -j oe
#PBS -q shared

nprocs=4

$CLUSTER_DIR/pav/pav_start -c $PAV_CONFIG -n \$nprocs >/dev/null

eval \$( $CLUSTER_DIR/pav/pav_info -c $PAV_CONFIG)
export PVFS2TAB_FILE

PATH=${CLUSTER_DIR}/mpich2/bin:\${PATH}
mpdboot --file=\${WORKINGDIR}/compnodes --totalnum=\$nprocs

mpiexec -np \$nprocs $@
mpdallexit
$CLUSTER_DIR/pav/pav_stop -c $PAV_CONFIG >/dev/null" 
}

# takes one argument: the PBS job id on which to block

block_until_done() {
	while true ; do 
		qstat -i $1 >/dev/null 2>&1 
		if [ $? -eq 0 ] ; then
			sleep 60
			continue
		else
			break
		fi	
	done
}


