#!/bin/bash

SCRIPTDIR="`dirname $0`"
TMPDIR="/tmp"
STARTUP="$TMPDIR/para.$$.$RANDOM.tmp"
I1401="i1401"

if [ x"$2" = x ]
then
  echo "usage: "`basename $0`" [-r] <source file> [Autocoder tape]"
  exit 1
fi

source="$1"

if [ -d "$source" ]
then
  echo `basename $0`": $source: is a directory"
  exit 1
fi

if [ ! -s "$source" ]
then
  echo `basename $0`": $source: no such file (or it is empty)"
  exit 1
fi

if [ ! -r "$source" ]
then
  echo `basename $0`": $source is unreadable"
  exit 1
fi

tape="$2"
if [ x"$tape" = x ]
then
  tape="Fortran_v3m0.tap"
fi

source_stem="`echo $source | sed 's/\..*$//g'`"

rm -f print.out


cat > $STARTUP << EOF
a mt1 $tape
at cdr $source
at cdp $source_stem.obj
at lpt $source_stem.lst
b mt1
! rm -f print.txt
at lpt print.txt
c
! cat print.txt
EOF

rm -f scratch.mt*

"$I1401" $STARTUP
rm -f $STARTUP
