#! /bin/sh
# file: hrlomb		G. Moody	14 June 1995
#
# Derive a heart rate time series (using ihr) and plot it

while [ $# -gt 1 ]
do
  case $1 in
    -a) ANNOTATOR=$2 ;;
    -f) START=$2 ;;
    -p) PLOT=$2 ;;
    -r) RECORD=$2 ;;
    -t) END=$2 ;; 
    -T) DEVICE=$2 ;;
  esac
  shift
  shift
done

if [ x$PLOT = x ]; then
  if [ -x /usr/local/bin/plt ]; then
    PLOT=/usr/local/bin/plt
  elif [ -x /usr/local/bin/plot2d ]; then
    PLOT=/usr/local/bin/plot2d
  else
    echo "No plot utility found -- exiting"
    exit 1
  fi
fi

if [ x$RECORD = x ]; then
  echo -n "Enter the record name: "
  read RECORD
fi

if [ x$ANNOTATOR = x ]; then
  echo -n "Enter the annotator name: "
  read ANNOTATOR
fi

if [ x$START = x ]; then
  START=0
fi

if [ x$END = x ]; then
  END=e
fi

if [ x$DEVICE = x ]; then
  PLOTOUT=""
else
  PLOTOUT="-T $DEVICE"
fi

ihr -r $RECORD -a $ANNOTATOR -f $START -t $END -x | \
 $PLOT 0 1 -x "Time (sec)" -y "Heart Rate (bpm)" \
  -t "Record $RECORD ($START - $END): Heart rate time series" \
  $PLOTOUT
