#!/bin/sh

MACH=`uname -s`
Sysx="`echo $MACH | cut -b -6`"
if [ $Sysx = "CYGWIN" ]; then
   MACH=`uname -o`
elif [ $Sysx = "AIX" ]; then
   MACH=`uname -s`
else
   MACH=`uname -sm | sed 's/[ ]/_/'`
fi

isph=4
while [ $isph -le 4 ]
  do 

if [ $isph -eq 1 ]; then
  sel="STD"
elif  [ $isph -eq 2 ]; then
  sel="SELE_FD"
elif  [ $isph -eq 3 ]; then
#  sel="SELE_GAP"
  sel="SELE_MWG"
elif  [ $isph -eq 4 ]; then
#  sel="EDF"
  sel="SELE_EDF"
fi

intp=""
#intp="_nointp"
#intp="_112"
#intp="_123"

rm ${MACH}/ACPOenrich_UOX_0123
rm ${MACH}/ACPOenrich_MOX_0123
# phi_d_inf_p with ${sel} normalized cross-section
tst=""
#cp ${MACH}/ACPOenrich_${sel}_UOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenrich_${sel}_MOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_MOX_0123
#cp ${MACH}/ACPOenrsph_${sel}_UOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenrsph_${sel}_MOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_MOX_0123
cp ${MACH}/ACPOenrsphA_${sel}_UOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_UOX_0123
cp ${MACH}/ACPOenrsphA_${sel}_MOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_MOX_0123
# test phi_d_inf_p with STD normalized cross-section
#tst="2"
#cp ${MACH}/ACPOenrich2_${sel}_UOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenrich2_${sel}_MOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_MOX_0123
#cp ${MACH}/ACPOenr2sph_${sel}_UOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenr2sph_${sel}_MOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_MOX_0123
#cp ${MACH}/ACPOenr2sphU0_${sel}_UOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenr2sphU0_${sel}_UOX_0_1x2-12_13_22_23${intp} ${MACH}/ACPOenrich_MOX_0123
# very old:
#cp ${MACH}/ACPOenrichU0_${sel}_UOX_0_112_113_122_123 ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenrichU0_${sel}_MOX_0_112_113_122_123 ${MACH}/ACPOenrich_MOX_0123
#cp ${MACH}/ACPOenrichU0_${sel}_UOX_0_112_113_122_123_212_213_222_223 ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenrichU0_${sel}_MOX_0_112_113_122_123_212_213_222_223 ${MACH}/ACPOenrich_MOX_0123
#cp ${MACH}/ACPOenrichU0_${sel}_UOX_0_112_113_122_123_nointp ${MACH}/ACPOenrich_UOX_0123
#cp ${MACH}/ACPOenrichU0_${sel}_MOX_0_112_113_122_123_nointp ${MACH}/ACPOenrich_MOX_0123

SPHSPH="SPHSPH"
#sph="noSPH"
#sph="SPH"
#sph="SPH_D"
sph=${sel}
SUBSUB="SUBSUB"
#sub=rep900cluster_data_new${tst}_${sel}${intp}
#sub=rep900clusph_data_nw${tst}_${sel}${intp}
sub=rep900clusphA_data_nw${tst}_${sel}${intp}
mkdir ${MACH}/${sub}

#case number 
inum=1
ilast=12
CASECASE="CASECASE"
#heterogeneous model
ihetm=0
ihetl=2
HETHET="HETHET"
#split model
ispm=1
ispl=2
SPISPI="SPISPI"
#Tracking model
rtm=2
rtl=3
RTRT="RTRT"

while [ $inum -le $ilast ]
  do 
  ihet=$ihetm
while [ $ihet -le $ihetl ]
  do 
  isp=$ispm
while [ $isp -le $ispl ]
  do 
  rt=$rtm
while [ $rt -le $rtl ]
  do 
  cp mydata/rep900cluster_template.x2m mydata/rep900cluster.x2m 
  perl -pi -e "s/$CASECASE/$inum/g" mydata/rep900cluster.x2m
  perl -pi -e "s/$HETHET/$ihet/g" mydata/rep900cluster.x2m
  perl -pi -e "s/$SPISPI/$isp/g" mydata/rep900cluster.x2m
  perl -pi -e "s/$RTRT/$rt/g" mydata/rep900cluster.x2m
  cp mydata/rep900cluster_template.save mydata/rep900cluster.save 
  perl -pi -e "s/$CASECASE/$inum/g" mydata/rep900cluster.save
  perl -pi -e "s/$HETHET/$ihet/g" mydata/rep900cluster.save
  perl -pi -e "s/$SPISPI/$isp/g" mydata/rep900cluster.save
  perl -pi -e "s/$RTRT/$rt/g" mydata/rep900cluster.save
  perl -pi -e "s/$SPHSPH/$sph/g" mydata/rep900cluster.save
  perl -pi -e "s/$SUBSUB/$sub/g" mydata/rep900cluster.save
  cp mydata/rep900cluster.x2m mydata/rep900cluster.x2m_${inum}_h${ihet}_s${isp}_t${rt}_${sph}
  ./rdonjon -p rep900cluster.x2m
  mv ${MACH}/rep900cluster.result ${MACH}/${sub}/rep900cluster.result_${inum}_h${ihet}_s${isp}_t${rt}_${sph}
  rt=`expr $rt + 1 `
done
  isp=`expr $isp + 1 `
done
  ihet=`expr $ihet + 1 `
done
  inum=`expr $inum + 1 `
done


  isph=`expr $isph + 1 `
done
