#!/bin/bash
exe=../../shi/src/shi.exe

##prepare in file
sed -e 's/_RNG_SEED_/1902/g' \
    -e 's/_NUM_FULL_MATRICES_/20/g' \
	asep_template.in > testAsep.in

##clean the restart file from last time
rm -f asepSpresTest.log.restart

startTime=$(date | awk '{print $4}')

echo "Running test.  Output is directed to testAsep.out, log to testAsep.elog."

####run the test
$exe -n -ptestAsep.in -ctestAsep.shi > testAsep.out 2>testAsep.elog

##log the performance if anyone is interested.
endTime=$(date | awk '{print $4}')
echo "elapsed time for test was from $startTime to $endTime"



##find probability of a logjam
awk 'BEGIN{t=0}NF==2&&$1==500{print t,$2}NF==0{t+=250}' asepSpresTest.log.dat > spresLogjam.dat

##find the density versus time
awk 'BEGIN{t=0}NF==2{rho+=$1*$2;p=1}NF==0&&p==1{print t,rho/500.0;t+=250;rho=0;p=0}' asepSpresTest.log.dat > spresDensity.dat

##collect state vectors
awk 'p==1&&NF==2{print t,$1,$2}NF!=2{p=0}/state vector is/{p=1;t++;printf "\n"}' testAsep.elog > spresN.dat


##compare elogs
echo comparing error logs
echo diff of testAsep.elog and testAsep.elog.ref:
diff testAsep.elog testAsep.elog.ref | head
echo









