#! /bin/csh
#++++++++++++++++
#.IDENTIFICATION lc_get
#.LANGUAGE       C-shell
#.AUTHOR         
#.ENVIRONMENT    
#.KEYWORDS       
#.VERSION  1.0   06-Apr-2006
#.PURPOSE        Get all photometric data from a QUEST1 number
#.COMMENTS       Use the indexes of the compressed files.
#		Arguments: $1 = Quest
#----------------

if ($#argv < 1) then
    echo "****lc_get: Missing QUEST number"
    exit 1
endif

set qno = $1			# QUEST1 number (between 1 and 198213)

foreach f (*.gzi)
    set r = $f:r		# Radix (without .gzi)
    set t = `gawk '{if(($1+0)>'$qno') exit; o=$2}END{print o+1}' $f`
    #echo "#From: $r"
    echo "#...tail +${t}c $r.gz "
    tail +${t}c $r.gz | gzip -cd | gawk -v qno=$qno '{dq = $1-qno; \
      if (dq>0) exit; if (dq < 0) next; \
      for(i=2; i<=NF; i += 3) printf "%9s %6s %5s\n", $i, $(i+1), $(i+2)}'
end
