if [ $DEBUGSCRIPTS = YES -o $DEBUGSCRIPTS = ON ] ; then
  set -x
fi
table=$1
gzipfile=$2
dsname=${2%%.gz}
cd $DATA
gunzip $gzipfile
file=$DATA/$dsname
if [ ! -s $file ] ; then
   outstring="$dsname does not exist or has zero length"
   len=${#outstring}
   if [ $len -gt $lenerror ] ; then
      lenerror=$len
   fi
   echo $outstring >> $tmperr
else
   export XLFRTEOPTS="unit_vars=yes"
   export XLFUNIT_11="$file"
fi
if [ ! -s $table ] ; then
   outstring="$table does not exist or has zero length"
   len=${#outstring}
   if [ $len -gt $lenerror ] ; then
      lenerror=$len
   fi
   echo $outstring  >> $tmperr
else
   export XLFUNIT_20="$table"
fi
typsubdir=$(dirname $TANKFILE)
if [ $typsubdir != "." ] ; then
   subtypfil=$(basename $TANKFILE)
else
   echo "    <tankfile> must be given as : subdirectory/tankfile>" 
   echo "    Last 3 digits of subdirectory are BUFR type." 
   echo "    Last 3 digits of tankfile are BUFR sub-type." 
   echo "    BUFR type and sub-type may be coded as three" 
   echo "    question marks if translation code provides" 
   echo "    BUFR type and sub-type." 
   exit 191
fi

ymdh=$(date -u '+%Y%m%d%H')
if [ $TANKPROTECT = YES ] ; then
   apndstring=_A_P_N_$dsname
else
   apndstring="' '"
fi

pgm=bufr_tranamsreswath
export pgm; $DATA/prep_step

export XLFUNIT_51="$DATA/$typsubdir.$subtypfil.$dsname.tmpout$$"

msg="$pgm has BEGUN"
$DATA/postmsg "$jlogfile" "$msg"

echo "$typsubdir $subtypfil $apndstring $ymdh" | $EXECbufr/bufr_tranamsreswath
retcode=$?

if [ $retcode -eq 0 ] ; then
   give_rc="YES"
   cword="NO"
   export give_rc cword
   EXECbufr=/nwprod/exec FIXbufr=/nwprod/fix \
   sh /nwprod/ush/tranjb $TANKDIR $DATA/$typsubdir.$subtypfil.$dsname.tmpout$$ 
   retcode=$?
   if [ $retcode -eq 0 ] ; then
      rm $DATA/$typsubdir.$subtypfil.$dsname.tmpout$$
   fi
fi
exit $retcode
