#! /bin/csh -f
#A simple script to find z's for objects and literature to compare
set n_do = 102
set cnt_i = 0
set AB_num = `cat zlit_comp.txt | awk '{print $1}'`
set cat_num1 = `cat zlit_comp.txt | awk '{print $2}'`
rm -f zlit_comp.out
set rms1 = 0
while ($cnt_i < $n_do)
   @ cnt_i = $cnt_i + 1
   set zlit = `cat AB.dat | awk 'NR==var1{print $9}' var1=$AB_num[$cnt_i]`
   set ra_deg_in = `cat classify_j1.out | awk 'NR==var1{print $2}' var1=$cat_num1[$cnt_i]`
#   set SN_in = `cat classify_j1.out | awk 'NR==var1{print $5}' var1=$cat_num1[$cnt_i]`
#   set flux_in = `cat classify_j1.out | awk 'NR==var1{print $6}' var1=$cat_num1[$cnt_i]`
   set dec_deg_in = `cat classify_j1.out | awk 'NR==var1{print $3}' var1=$cat_num1[$cnt_i]`
   set wave_in = `cat classify_j1.out | awk 'NR==var1{print $4}' var1=$cat_num1[$cnt_i]`
   set ra_in = `/data1/grad56/jjadams/finder_code_delta/scripts/deg_to_ra.csh $ra_deg_in`
   set dec_in = `/data1/grad56/jjadams/finder_code_delta/scripts/deg_to_dec.csh $dec_deg_in`
   set cat_num2 = `cat ../pap_cat1.out | awk '$2==var1&&$3==var2&&(var3-$4)^2<(5.)^2{print NR}' var1=$ra_in var2=$dec_in var3=$wave_in`
   set z_us = `cat ../pap_cat2.out | awk 'NR==var1{print $9}' var1=$cat_num2`
   set rms1 = `echo "$rms1+($zlit-$z_us)^2" | bc -l`
   echo "$zlit $z_us" >> zlit_comp.out
end
set rms1 = `echo "sqrt($rms1/($n_do-1))" | bc -l`
echo "RMS is "$rms1
exit(0)
