#!/bin/rc
###
#calculate Ma from proportions
###
#add base ID
sort -t* +5 -6 bnd |uniq > tmp1
sort -t* +0 -1 unt |uniq > tmp2
join -t* -a1 -1 6 -2 1 -o 1.1 1.2 1.3 1.4 1.5 1.6 1.7 2.2 tmp1 tmp2 > tmpb
wc -l bnd
wc -l tmp1
#add top ID
sort -t* +5 -6 tmpb |uniq > tmp3
join -t* -a1 -1 6 -2 1 -o 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.3 tmp3 tmp2 > tmpb
#change base ID to base age
sort -t* +7 -8 tmpb |uniq > tmp3
sort -t* +0 -1 bnd |uniq > tmp1
join -t* -a1 -1 8 -2 1 -o 1.1 1.2 1.3 1.4 1.5 1.6 1.7 2.2 1.9 tmp3 tmp1 > tmpb
#change top ID to top age
sort -t* +8 -9 tmpb |uniq > tmp3
sort -t* +0 -1 bnd |uniq > tmp1
join -t* -a1 -1 9 -2 1 -o 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 2.2 tmp3 tmp1 > tmpb
#calculate boundary age
awk -F* ' {prop=$7; base=$8; top=$9; x=base-top; z=base-x*prop; print $1 "*" $2"*" $3"*" $4"*" $5"*" $6"*" $7"*" z} ' tmpb |sort > bnd7
wc -l bnd
wc -l bnd7
echo cp bnd7 bnd
echo rm bnd7
|