#!/bin/bash
if [ $# -eq 0 ] ; then 
   echo "provide project name"
   exit
fi    
dire=$1
for i in {0..5}; do
         cp bound/BATTERY$i/scaled0/pullx.xvg ./pullx$i.xvg
         grep -v "@\|#" pullx$i.xvg >> pull.xvg 
done
rm pullx?.xvg 
echo "..computing volume correction" 
awk '{x+=10*$2; x2+=100*$2^2; print $1,$2 }END{com=x/NR; sig=sqrt(x2/NR-(x/NR)^2); vol= 4*3.14*(2*sig)^3/3;  dv=0.595*log(vol/1661); print "#  <R_com>="com"+/-"sig"  VOL="vol"  VOL_cor="dv}' pull.xvg > tmp
if [ ! -d Results ]; then
    mkdir Results 
fi
tail -1 tmp > Results/$dire.VOL_cor
echo "..making COM-COM histogram"   
awk '{if($1!="#") print $2*10}' tmp | histog +i0.01 > Results/${dire}_com.hst
rm tmp pull.xvg
echo "Done"
exit