#!/bin/bash
#

if [ $# -ne 1 ]; then
    echo "Exactly one argument is required (e.g., \"bayer2sesjpg.sh myfile.b16\")"
    exit 1
fi

B16=$1
if [ -f "$B16" ]; then
    # Convert b16 to tiff
    bayer2tiff $B16
    # Ensure that tiff was created before continuing
    BASE=${B16%.b16}
    TIFF=$BASE.tiff
    if [ -f $TIFF ]; then
        # Continue to convert to jpg
        JPEG=$BASE.jpg
        tiff2jpeg.sh $TIFF
        exit 0
    else
        echo "There was a problem. $TIFF was not created"
        exit 1
    fi
else
    echo "$B16 does not exist"
    exit 1
fi
