#! /bin/sh -
#script to format EMPIRE II output
file=$1
work=`pwd`
if [ "$1" = "" ]
   then
echo 'Inputs ready to run'
echo ' '
ls *out
echo ' '
echo -n 'Choose one of the above (without .out extention!): '
read file
fi                          

#run EMPEND to format EMPIRE output into ENDF

cp $file.out OUTPUT.DAT
../util/empend/empend <../util/empend/EMPEND.INP && mv OUTPUT.ENDF $file-e.endf
mv empend.log $file-log.empend
rm OUTPUT.DAT


# RECONSTRUCT (N,N), (N,P), AND (N,A) REACTIONS WITH FIXUP

rm $file-f.endf 2>/dev/null
cd ../util/fixup/
rm OUTPUT.ENDF 2>/dev/null
ln -sf $work/$file-e.endf OUTPUT.ENDF
cp FIXUP1.INP FIXUP.INP
./fixup
rm OUTPUT.ENDF
mv FIXUP.ENDF $work/$file-f.endf
mv FIXUP.LST $work/$file-log.fixup
cd $work


# RUN ENDRES TO INCLUDE RESONANCE PARAMETRS (FILE 2)

#rm $file.endf 2>/dev/null
#cd ../util/endres/
#rm empire.end endf.dat 2>/dev/null
#ln -sf $work/$file-f.endf empire.end
#./endres <ENDRES.INP
#rm empire.end 
#mv endf.dat $work/$file.endf
#mv endres.lst $work/$file-log.endres
#cd $work
# $work/$file.endf is the final ENDF output file
mv $file-f.endf $file.endf

# RUN STANEF

rm -f INPUT
cat >INPUT <<EOF
$file.endf
$file-stan.endf
0

DONE
EOF
../util/stanef/stanef <INPUT
mv $file-stan.endf $file.endf

# remove left-over files
rm INPUT 2>/dev/null
rm angdis.cur 2>/dev/null
rm angdis.pnt 2>/dev/null

exit
