#!/bin/csh

# this script is used to form the input file eqlistper??.
# the last line "echo /home/yingjie/progs/TWO_PLANE/sensprog/sens${per}s65km.dat >>  $outfn" needed to 
# be changed to the location of files of sensitivity kernels. 


set  freq =   (  0.040  0.025  0.020  0.010  0.007  )
set  avgvel = (  3.65   3.79   3.81   3.97   4.18  )

@ iper = 0

foreach per (  25 40 50 100 143 )

\rm eqlistper${per}.tp eqlistper${per}

set outfn = eqlistper${per}.tp

@ iper +=1

@ nevt = 0
@ evt0 = 0 
@ nray = 0

foreach evt ( `ls -d 200*`  )
@ evt0 += 1




ls  ${evt}/Z/data/YS_PL*.SAC${per} > tempper
  if ( -z tempper ) then
  else
    @ nevt += 1
    wc tempper > tempwc
    set nnray = `wc -l tempper | awk '{print $1}'`
    @ nray += ${nnray}
    echo $evt0 > temp1
    sdiff temp1 tempwc > temp2
    awk '{print "   ", $3,$1 }' temp2 >> eqlistper${per}
    cat tempper >>  eqlistper${per}
  endif 

end

echo $nevt > tempeq
cat eqlistper${per} >>  tempeq
cp tempeq $outfn

set freqtp = ${freq[$iper]}

echo 1                         >> $outfn
echo $freqtp                   >> $outfn
echo detail.${per}.1.65.2   >> $outfn
echo summar.${per}.1.65.2   >> $outfn
echo invrsnodes2               >> $outfn
echo phampcor.${per}        >> $outfn
echo covar.${per}.1.65.2    >> $outfn
echo mavamp.${per}.1.65.2   >> $outfn
echo resmax${per}.dat          >> $outfn 
echo velarea.${per}.1.65.2  >> $outfn
echo 5  65  0.2 0.2           >> $outfn
echo $avgvel[$iper]            >> $outfn
echo ./kern_cal/sens${per}s65km.dat >>  $outfn
echo ${per} ${nevt} ${nray} >> ray_number

end
