#! /bin/sh

usage () {
    cat <<EOF
Usage: $0 [-b]

Plots data from files using grace parameters file $0.bat.

 -b  batch plot + fragmaster (using figs.fm) to $0.{eps,pdf}
 -h  this help message

kkumer 2010-11-26 
EOF
}

prefix=$0
# Parsing arguments
batch="no"
while getopts behn: opt
do  
    case "$opt" in
      h)  usage; exit 0;;
      b)  batch="yes";;
      n)  num="$OPTARG";;
      \?) usage; exit 1;;               # unknown flag
    esac 
done
shift `expr $OPTIND - 1`
name=$@

prog=xmgrace
if [ $batch = "yes" ]; then
    prog="gracebat -hdevice EPS -printfile ${name}_fm.eps"
fi

#errs=" -settype xydy -bxy 1:2:3 "

prog="$prog -noask -batch ${name}.bat"

echo $prog

$prog

if [ $batch = "yes" ]; then
   ln -s figs.fm ${name}_fm
   fragmaster
#  Correcting bounding box:
  cp ${name}.eps tosed
  sed 's/\(BoundingBox:\) 0 \(.*\) [0-9]*/\1 0 \2 795/' tosed > ${name}.eps
  rm ${name}_fm ${name}.pdf ${name}_fm.eps tosed
fi
