#!/bin/sh

HLIMIT=14	# limiting magnitude [mag]

# cutoffs
eos_min=11.5
eos_max=13.5

for FILE in eos ; do
#  ./H.awk < $FILE.astorb > $FILE.dat_H
  awk '{ print $10; }' $FILE"_family.list" > $FILE.dat_H
  sort -n < $FILE.dat_H > $FILE.srt
  ./hist_cumulative.awk 25 < $FILE.srt > $FILE.dat_Hhc

  eval MIN=\$"$FILE"_min
  eval MAX=\$"$FILE"_max
  awk 'BEGIN{d1=ARGV[1]; d2=ARGV[2]; ARGV[1]=ARGV[2]="";}($1>d1) && ($1<d2) && ($2>1){print;}' $MIN $MAX < $FILE.dat_Hhc > $FILE.dat_fit
  echo -e "$MIN 0\n$MIN 1\n\n$MAX 0\n$MAX 1" > $FILE.dat_rng
  ./linlog.awk < $FILE.dat_fit > $FILE.dat_log
  ./linreg.awk < $FILE.dat_log > $FILE.lsm
  awk 'BEGIN{f=ARGV[1]; ARGV[1]=""}{print "f_" f "(x) = (10**(" $2 "*x + " $1 "))";}' $FILE < $FILE.lsm > $FILE.plt
  awk 'BEGIN{f=ARGV[1]; ARGV[1]=""}{print "set label \"  {/=12 " sprintf("%.3f", $2) "\" at 12, f_" f "(12)";}' $FILE < $FILE.lsm >> $FILE.plt
  awk 'BEGIN{f=ARGV[1]; ARGV[1]=""}{print f " " $2}' $FILE < $FILE.lsm

  awk 'BEGIN{H=ARGV[1]; ARGV[1]="";}($1<=H){print;}' $HLIMIT < $FILE.dat_H > $FILE.dat_Hlt$HLIMIT
done

#wc -l *.dat_Hlt$HLIMIT > wc.out

./eos-absmag_distribution_bw.plt
epstopdf_embed eos-absmag_distribution_bw.eps

exit


