#! /bin/csh
#++++++++++++++++
#.IDENTIFICATION tycepo
#.LANGUAGE       C-shell
#.AUTHOR         Francois Ochsenbein [CDS]
#.ENVIRONMENT    
#.KEYWORDS       
#.VERSION  1.0   19-Apr-2002
#.PURPOSE        Get the Tycho Epoch Photometry
#.COMMENTS       We assume as input = Tycho Number(s)
#----------------

if ($#argv < 1) then
    echo "Usage: tycepo tyc1-tyc2-tyc3 [tyc1-tyc2-tyc3]..."
    exit 0
endif

set dir = `dirname $0`	# Data share same root directory

while ($#argv > 0)
    set tyc = `echo $1 | tr - ' ' | gawk '{printf("%04d %d %s",$1,$2,$3)}'`
    if ($#tyc == 2) set tyc = ($tyc 1)
    if (($#tyc != 3 ) || ($tyc[2] == 0)) then
	echo "++++Bad Tycho number (must be tyc1-tyc2-tyc3): $1"
	exit 1
    endif
    shift
    set fgz = $dir/tep`echo $tyc[1] | cut -c1-2`/$tyc[1].gz
    #ls -l $fgz
    set o   = `look $tyc[2]-$tyc[3]= $fgz.idx | cut -d= -f2`
    echo "#....In file $fgz, at offset: $o"
    tail +${o}c $fgz | gzip -cd | gawk '/^$/{p++}\
       NR==2{ printf("JD-2440000| BTmag| s.e.| BTbg | VTmag| s.e.| VTbg |"); \
       print "    z |  PAz | Dmas|s.e.| Fit |Flags"}\
       {print; if (p>0) exit}'
end
