#! /bin/csh -f
#Simple script to grab some magnitudes for each object.
set n_mv1 = 0
set n_em = `wc -l < classify_j1.out`
set all_ID = `cat classify_j1.out | awk '{print $8}'`
set all_uni = `cat classify_j1.out | awk '{print $18}'`
#set all_wave = `cat classify_j1.out | awk '{print $4}'`
set all_flux = `cat classify_j1.out | awk '{print $6}'`
#set all_EW = `cat classify_j1.out | awk '{print $9}'`
set all_cntr = `cat classify_j1.out | awk '{print $11}'`
set n_cnt = 0
set n_accm = 0
rm -f obj_2_mags.out
while ($n_cnt < $n_em)
   @ n_cnt = $n_cnt + 1
   if ($all_ID[$n_cnt] == "1" && $all_uni[$n_cnt] == "0" && $all_cntr[$n_cnt] > 0) then
      if ($n_cnt < 10) then
         set form_tag = "000"$n_cnt
      else if ($n_cnt < 100) then
         set form_tag = "00"$n_cnt
      else if ($n_cnt < 1000) then
         set form_tag = "0"$n_cnt
      else
         set form_tag = $n_cnt
      endif
      set mini_cntr = `cat "SEDs/nspawn_${form_tag}.cat" | awk '$1==var1{print NR}' var1=$all_cntr[$n_cnt]`
      set band1 = `cat "SEDs/spawn_${form_tag}.cat" | awk 'NR==var1{print -2.5*log($5)/log(10.)-48.6}' var1=$mini_cntr`
      set band2 = `cat "SEDs/spawn_${form_tag}.cat" | awk 'NR==var1{print -2.5*log($7)/log(10.)-48.6}' var1=$mini_cntr`
      echo "$band1 $band2 $all_flux[$n_cnt]" >> obj_2_mags.out
   endif
end
exit(0)
