#!/bin/sh

if [ $# -lt 1 ];then
	echo "syntax $0 arbfile [treename] (no .arb ending)"
	exit -1;
fi

mkdir test.$1

echo optimizing database
arb_2_bin -c$2 $1.arb test.$1/$1_o1.arb

echo generate mapfile
arb_2_bin -m test.$1/$1_o1.arb test.$1/$1_o1m.arb

echo optimizing optimized
arb_2_bin -c$2 test.$1/$1_o1.arb test.$1/$1_o2.arb

echo optimizing optimized mapfile
arb_2_bin -c$2 -t test.$1/$1_o1m.arb test.$1/$1_o2m.arb

echo '    generate original ascii file'
arb_2_ascii $1.arb test.$1/$1_a.arb

echo  '    generate optimized ascii file'
arb_2_ascii test.$1/$1_o1.arb test.$1/$1_o1_a.arb

echo '    generate optimized map ascii file'
arb_2_ascii test.$1/$1_o1m.arb test.$1/$1_o1m_a.arb

echo '    generate optimized2 ascii file'
arb_2_ascii test.$1/$1_o2.arb test.$1/$1_o2_a.arb

echo '    generate optimized2 map ascii file'
arb_2_ascii test.$1/$1_o2m.arb test.$1/$1_o2m_a.arb

echo '    regenerate binary ascii'
arb_2_bin test.$1/$1_a.arb test.$1/$1_ab.arb
arb_2_ascii test.$1/$1_ab.arb test.$1/$1_aba.arb

echo 'check original and optimized'
cmp test.$1/$1_a.arb test.$1/$1_o1_a.arb || echo '***'

echo check optimized and optimized map
cmp test.$1/$1_o1_a.arb test.$1/$1_o1m_a.arb

echo check opti and opti2
cmp test.$1/$1_o1_a.arb test.$1/$1_o2_a.arb

echo check opti and opti2 map
cmp test.$1/$1_o1_a.arb test.$1/$1_o2m_a.arb

echo check source and regenerated
cmp test.$1/$1_a.arb test.$1/$1_aba.arb 
