#! /bin/csh -f
#I output, rather stupidly, all the SED based continuum values for all 
#counterparts. This code looks up the index for the big file and 
#puts down two EWs.
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 all_index = `cat shuf_index.out | awk '{print $1}'`
set n_cnt = 0
set n_accm = 0
rm -f comp_EW_SED.out
while ($n_cnt < $n_em)
   @ n_cnt = $n_cnt + 1
   if ($all_ID[$n_cnt] == "2" && $all_uni[$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 tot_cntr = `echo "$mini_cntr + $all_index[$n_cnt]" | bc -l`
      set SED_cont = `cat SED_cont.out | awk 'NR==var1{print $1}' var1=$tot_cntr`
      set new_EW = `echo "1." | awk '{print var1/var2/(var3/3727.)}' var1=$all_flux[$n_cnt] var2=$SED_cont var3=$all_wave[$n_cnt]`
      set kick_EW = `echo "$all_EW[$n_cnt]*(3727./1216.)" | bc -l`
      echo "$kick_EW $new_EW" >> comp_EW_SED.out
   endif
end
exit(0)
