###
#check for inconsistencies between boundaries present in unt and bnd
###
awk -F* '{print $2 } ' unt > $home/tmp/tstunt
awk -F* '{print $3 } ' unt >> $home/tmp/tstunt
cat $home/tmp/tstunt | sort |uniq > $home/tmp/tmpfile
mv $home/tmp/tmpfile $home/tmp/tstunt
echo UNT unique boundaries:
join -t* -a 1 -o 1.1 2.1 $home/tmp/tstunt bnd | awk -F* '$1 != $2'
echo BND unique boundaries:
join -t* -a 2 -o 1.1 2.1 $home/tmp/tstunt bnd | awk -F* '$1 != $2'
rm $home/tmp/tstunt
###
#generate UNITS table with absolute dates (unt.g)
###
sort -t* +1 -2 unt |uniq > tmp1
sort -t* +0 -1 bnd |uniq > tmp2
join -t* -1 2 -2 1 -o 1.1 2.8 1.3 1.4 1.5 1.6 tmp1 tmp2 |
sort -t* +2 -3 > tmp3
join -t* -1 3 -2 1 -o 1.1 1.2 2.8 1.4 1.5 1.6 tmp3 tmp2 | sort > unt.g.new
rm tmp*
#query it for NAME, print out age of lower and upper boundary
awk -F* '$1 ~ /NAME/ {print $1 " base: "$2 ", top: "$3 " Ma"}' unt.g
###
#calculate proportions from Ma
###
#add base ID
sort -t* +5 -6 bnd3 |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 2.2 tmp1 tmp2 > tmpb
#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 2.3 tmp3 tmp2 > tmpb
#change base ID to base age
sort -t* +6 -7 tmpb |uniq > tmp3
sort -t* +0 -1 bnd3 |uniq > tmp1
join -t* -a1 -1 7 -2 1 -o 1.1 1.2 1.3 1.4 1.5 1.6 2.2 1.8 tmp3 tmp1 > tmpb
#calculate boundary proportional age
sort -t* +7 -8 tmpb |uniq > tmp3
join -t* -a1 -1 8 -2 1 -o 1.1 1.2 1.3 1.4 1.5 1.6 1.7 2.2 tmp3 tmp1 | sort > tmpb
awk -F* ' {base=$7; top=$8; bnd=$2; x=base-top; y=base-bnd; if(x==0) z=0; else z=y/x; print $1 "*" $2"*" $3"*" $4"*" $5"*" $6"*" z} ' tmpb > bnd4
rm tmp*
###
#just once: remove 'ages' where they were used for calculation of 'proportions'
###
awk -F* ' {if($7==0) z=$2; else z=""; print $1 "*" z"*" $3"*" $4"*" $5"*" $6"*" $7"*" $8}' bnd5 > bnd6
sort -t* +1 -2 unt |uniq > tmp1 #sort according to base age
sort -t* +0 -1 bnd6 |uniq > tmp2
join -t* -1 2 -2 1 -o 1.1 2.8 1.3 1.4 1.5 tmp1 tmp2 |
sort -t* +2 -3 > tmp3 #sort according to top age
join -t* -1 3 -2 1 -o 1.1 1.2 2.8 1.4 1.5 tmp3 tmp2 | sort > unt.g
rm tmp*
###
#print out ICS stages which NAME overlaps with
###
name=NAME
base=`{awk -F* '$1 ~ /'$name'/ {print $2}' unt.g}
top=`{awk -F* '$1 ~ /'$name'/ {print $3}' unt.g}
echo awk -F* '''$4 ~ /ICS/ && $5 ~ /Stage/ && $2 >= '$base' && $3 < '$base' {print "from: " $1}''' unt.g | rc
echo awk -F* '''$4 ~ /ICS/ && $5 ~ /Stage/ && $2 > '$top' && $3 <= '$top' {print "to: " $1}''' unt.g | rc
###
# print stage that follows NAME in the same column
###
name=NAME
#base=`{awk -F* '$1 ~ /'$name'/ {print $2}' unt.g}
top=`{awk -F* '$1 ~ /'$name'/ {print $3}' unt.g}
where=`{awk -F* '$1 ~ /'$name'/ {print $4}' unt.g}
#echo awk -F* '''$4 ~ /'$where'/ && $5 ~ /Stage/ && $2 >= '$base' && $3 < '$base' {print "from: " $1}''' unt.g | rc
echo awk -F* '''$4 ~ /ICS/ && $5 ~ /Stage/ && $2 == '$top' {print $1}''' unt.g | rc
###
# change headers to UNIX for export
###
for(i in tst/stratbase/*)
{sed 's/\/bin/\/usr\/bin/' $i > tempfile; mv tempfile $i ; chmod 755 $i}
### UNTESTED
|