#! /bin/csh -f
#A simple script to run through all unique objects and grab a single 
#band's photometry with the help of grab_ind_photo.csh and selected over 
#the input classification value
set scname=$0
if($#argv != 2) then
   echo Usage: $scname:t 'band_number class_number'
   exit(1)
endif
set n_search = `wc -l < classify_j1.out`
set all_indx = `cat classify_j1.out | awk '{print $1}'`
set all_photo = `cat classify_j1.out | awk '{print $11}'`
set all_class = `cat classify_j1.out | awk '{print $8}'`
set all_unique = `cat classify_j1.out | awk '{print $18}'`
set all_z = `cat classify_j1.out | awk '{print $4/1216.-1.}'`
set n_cnt = 0
if ($n_search == 0) then
   echo "Error in grab_photo.csh"
   exit(1)
endif
set n_undet = 0
rm -f grab_photo.out
while ($n_cnt < $n_search)
   @ n_cnt = $n_cnt + 1
#   set tru_test = 0
#   set tru_test = `echo "$all_z[$n_cnt]<=3.||$all_z[$n_cnt]>=3.4" | bc -l`
   set tru_test = `echo "$all_z[$n_cnt]>3.&&$all_z[$n_cnt]<3.4" | bc -l`
   if ($all_unique[$n_cnt] == 0 && $all_class[$n_cnt] == $2 && $tru_test == 0) then
      if ($all_photo[$n_cnt] > 0) then
         ./grab_ind_photo.csh $all_indx[$n_cnt] $all_photo[$n_cnt] $1 >> grab_photo.out
      else
         @ n_undet = $n_undet + 1
      endif
   endif
end
echo "Uncounterparted objects "$n_undet
exit(0)
