#!/bin/bash
#
# GPSReport <filename> {<max-lines> {<min-time> {<max-time>}}}
#
# <filename> is the name of the file to parse
#
# <max-lines> is the maximum number of lines to return (default: 400,000)
#
# <min-time> is the minimum Excel time number to return (default: 0; "-" = default)
#
# <max-time> is the maxmimum Excel time number to return (default: 999999; "-"=default)
# 
# The file is filtered and lines starting with "GPS," that match the criteria above
# are returned as a compressed bzip2 stream.
#
FILENAME="$1"
shift
GPSDIR=/home/smc/roots/200_GPSListener

if [ ! -d "$GPSDIR" ]
then
	echo "Missing GPS home directory ($GPSDIR)!"
	exit 1
fi

cd "$GPSDIR"
RETCODE=$?

if [ $RETCODE -ne 0 ]
then
	exit $RETCODE
fi

if [ ! -f "$FILENAME" ]
then
	echo "No such file: $FILENAME"
	exit 1
fi

lua GPSReport.lua $* < "$FILENAME" | bzip2

