#!/bin/sh
#####################################################
#  Get the light curve of an existing OGLE variable
#####################################################


if test $# -lt 0; then
    echo "Usage: $0 [-v] OGLEhhmmss.ss+ddmmss.s ..."
    exit 1
fi

dir=`dirname $0`	# Directory with data/scripts
verbop=0
while [ $# -gt 0 ]; do
    case "$1" in
    -v)
    	verbop=1;
	;;
   OGLE[012][0-9][0-5][0-9][0-5][0-9].*)
   	test $verbop -gt 0 && echo -n "# $1 = "
	oo=`fgrep $1 $dir/*.gzi`
	if [ $verbop -gt 0 ]; then
	    echo $oo | wc -w 
	    fgrep $1 $dir/*.gzi | acut -i\# -c1-
	fi
	if [ -z "$oo" ]; then
	    echo "#***No matching OGLE: $1"
	else for fo in $oo; do
	    test $verbop -gt 0 && echo "#fo=" $fo
	    if [ -z $f ]; then
	        f=`echo $fo | cut -d: -f1 | sed s'/i$//'`; 
	    else
	        o=$fo;
		test $verbop -gt 0 && echo "#...tail -c $o $f"
	        tail -c $o $f | gzip -cd | awk '{print; if(length==0) exit}'
	        f=""; o=""; 
	    fi
	    done
	fi
	;;
    *)
	echo "#***Invalid argument in $0: $1"
	;;
    esac
    shift
done
