#!/bin/sh

# geometric albedo
eos_A=0.13

# lower log(diameter) cutoff
eos_min=7

# upper diameter cutoff
eos_max=20

D_min=1
D_max=200
dD=1
N=`awk -vmin=$D_min -vmax=$D_max -vd=$dD 'BEGIN{ print int((max-min)/d+0.5); }'`

echo "dD=$dD" > dD.plt

for FILE in eos ; do
#  ./H.awk < $FILE.astorb > $FILE.dat_H
  awk '{ print $10; }' < $FILE"_family.list" > $FILE.dat_H
  eval A=\$"$FILE"_A
  awk -v A=$A '{ print $1, A; }' < $FILE.dat_H > maga2r.in
  maga2r < maga2r.in > maga2r.out
  awk '{ print $1*2; }' < maga2r.out > $FILE.dat_D

  echo -e "$N\n$D_min $D_max\n$FILE.dat_D\n" > hist.in
  hist4 < hist.in > hist.out
  awk '{ print $1, $3; }' < hist.out > $FILE.dat_Dh

  eval MIN=\$"$FILE"_min
  eval MAX=\$"$FILE"_max
  awk -vdD=$dD 'BEGIN{d1=ARGV[1]; d2=ARGV[2]; ARGV[1]=ARGV[2]="";}($1>=d1) && ($1<=d2) && ($2>1){ print $1+0.5*dD, $2; }' $MIN $MAX < $FILE.dat_Dh > $FILE.dat_fit
  echo -e "$MIN 0\n$MIN 1\n\n$MAX 0\n$MAX 1" > $FILE.dat_rng
  ./loglog.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**" $1 ") * x**(" $2 ")";}' $FILE < $FILE.lsm > $FILE.plt
  awk 'BEGIN{f=ARGV[1]; ARGV[1]=""}{print "set label \" {/=12{/Symbol -}" sprintf("%.2f", -$2) "\" at 10, f_" f "(10)*1.5";}' $FILE < $FILE.lsm >> $FILE.plt
  awk 'BEGIN{f=ARGV[1]; ARGV[1]=""}{print f " " $2}' $FILE < $FILE.lsm
done

./eos-size_distribution_DIFFERENTIAL_bw.plt
epstopdf_embed eos-size_distribution_DIFFERENTIAL_bw.eps


