#!/bin/bash
INPUT_FILE_HEADER="Small"
PRIMARY_INPUT="$INPUT_FILE_HEADER"_Post


NUM_ITERATIONS_FOR_GEMINI="100000"
NUM_ITERATIONS_FOR_TURBOENCABULATOR="100000"
NUM_ITERATIONS_FOR_NBOS="20000000"
NUM_ITERATIONS_FOR_ODM="20000000"

MAX_SIM_TIME_FOR_TURBOENCABULATOR="100000"

CHEMICAL_TO_OUTPUT="197"

clear

echo "--------------------------------------------------------------------------------"
echo "-------------------------------- MAKE PROCESS ----------------------------------"
echo "--------------------------------------------------------------------------------"
cd PreSource
make all
cd ..

######## MERCURY ########
PRIMARY_INPUT_DATA_FILENAME="$PRIMARY_INPUT".xml
INTERM_FILE_REACTIONS="$PRIMARY_INPUT"_Reactions_Interm_File.dat
INTERM_FILE_SPECIES="$PRIMARY_INPUT"_Species_Interm_File.dat
echo
echo
echo "--------------------------------------------------------------------------------"
echo "------------------------------- MERCURY LAUNCH! --------------------------------"
echo "--------------------------------------------------------------------------------"
./PreSource/MERCURY $PRIMARY_INPUT_DATA_FILENAME $INTERM_FILE_REACTIONS $INTERM_FILE_SPECIES

######## GEMINI #########
SUM_PROP_DATA_FROM_GEMINI="$PRIMARY_INPUT"_SumProp_GEMINI.dat
SORTED_OUTPUT_FROM_GEMINI="$PRIMARY_INPUT"_Sorted_GEMINI.dat
END_CHEM_CONC_FROM_GEMINI="$PRIMARY_INPUT"_ChemConc_After_"$NUM_ITERATIONS_FOR_GEMINI"_Iterations_GEMINI.dat
SECONDARY_INTERM_FILE_SPECIES="$INPUT_FILE_HEADER"_Pre_Species_Interm_File_FROM_TE.dat
echo
echo
echo "--------------------------------------------------------------------------------"
echo "------------------------------- GEMINI LAUNCH! ---------------------------------"
echo "--------------------------------------------------------------------------------"
./PreSource/GEMINI $INTERM_FILE_REACTIONS $SECONDARY_INTERM_FILE_SPECIES $NUM_ITERATIONS_FOR_GEMINI $SORTED_OUTPUT_FROM_GEMINI $SUM_PROP_DATA_FROM_GEMINI $END_CHEM_CONC_FROM_GEMINI


#### TURBO-ENCABULATOR ####
TE_SINGLET_DEPENDENCY_GRAPH_FILE_NAME="$PRIMARY_INPUT"_FOR_TURBOENCABULATOR_SDG.dat
TE_DOUBLET_DEPENDENCY_GRAPH_FILE_NAME="$PRIMARY_INPUT"_FOR_TURBOENCABULATOR_DDG.dat
SUM_PROP_DATA_FROM_TE="$PRIMARY_INPUT"_SumProp_TE.dat
SORTED_OUTPUT_FROM_TE="$PRIMARY_INPUT"_Sorted_TE.dat
END_CHEM_CONC_FROM_TE="$PRIMARY_INPUT"_ChemConc_After_"$NUM_ITERATIONS_FOR_GEMINI"_Iterations_TE.dat
INTERM_FILE_SPECIES_FROM_TE="$PRIMARY_INPUT"_Species_Interm_File_FROM_TE.dat
CHEMICAL_OUTPUT_FILE_NAME_FROM_TE="$PRIMARY_INPUT"_Chemical_Output_FROM_TE.dat
cd ODM
make clean
make all
cd ..
echo
echo
echo "--------------------------------------------------------------------------------"
echo "------------------------------ TURBOENCABULATOR --------------------------------"
echo "--------------------------------------------------------------------------------"
echo
echo "*** Parsing... ***"
./ODM/PARSER $SORTED_OUTPUT_FROM_GEMINI $TE_SINGLET_DEPENDENCY_GRAPH_FILE_NAME $TE_DOUBLET_DEPENDENCY_GRAPH_FILE_NAME
./ODM/TURBOENCABULATOR $NUM_ITERATIONS_FOR_TURBOENCABULATOR $CHEMICAL_TO_OUTPUT $SORTED_OUTPUT_FROM_GEMINI $SECONDARY_INTERM_FILE_SPECIES $TE_SINGLET_DEPENDENCY_GRAPH_FILE_NAME $TE_DOUBLET_DEPENDENCY_GRAPH_FILE_NAME $SORTED_OUTPUT_FROM_TE $SUM_PROP_DATA_FROM_TE $END_CHEM_CONC_FROM_TE $CHEMICAL_OUTPUT_FILE_NAME_FROM_TE $MAX_SIM_TIME_FOR_TURBOENCABULATOR


#########  ODM  #########
ODM_SINGLET_DEPENDENCY_GRAPH_FILE_NAME="$PRIMARY_INPUT"_FOR_ODM_SDG.dat
ODM_DOUBLET_DEPENDENCY_GRAPH_FILE_NAME="$PRIMARY_INPUT"_FOR_ODM_DDG.dat
cd ODM
make clean
make all
cd ..
echo
echo
echo "--------------------------------------------------------------------------------"
echo "--------------------------- OPTIMIZED DIRECT METHOD ----------------------------"
echo "--------------------------------------------------------------------------------"
echo
echo "*** Parsing... ***"
./ODM/PARSER $SORTED_OUTPUT_FROM_TE $ODM_SINGLET_DEPENDENCY_GRAPH_FILE_NAME $ODM_DOUBLET_DEPENDENCY_GRAPH_FILE_NAME
./ODM/ODM $NUM_ITERATIONS_FOR_ODM $PRIMARY_INPUT $SORTED_OUTPUT_FROM_TE $SECONDARY_INTERM_FILE_SPECIES $ODM_SINGLET_DEPENDENCY_GRAPH_FILE_NAME $ODM_DOUBLET_DEPENDENCY_GRAPH_FILE_NAME

######### SOYUZ #########
GNUPLOT_SCRIPT_FILE_NAME="$PRIMARY_INPUT"_Gnuplot_Script.dat
NUM_RESERVED_REACTIONS_FILE="$PRIMARY_INPUT_RESERVED_REACTIONS".dat
echo
echo
echo "--------------------------------------------------------------------------------"
echo "-------------------------------- SOYUZ LAUNCH! ---------------------------------"
echo "--------------------------------------------------------------------------------"
echo "Making first pass through Soyuz..."
./PreSource/SOYUZ FIRSTPASS $GNUPLOT_SCRIPT_FILE_NAME $SUM_PROP_DATA_FROM_TE
echo "Opening up Gnuplot for Human Input"
gnuplot $GNUPLOT_SCRIPT_FILE_NAME
echo "Making second pass through Soyuz..."
./PreSource/SOYUZ SECONDPASS $NUM_RESERVED_REACTIONS_FILE

######### ARESV #########
HEADER_TITLE="$INPUT_FILE_HEADER"_ARESV
MAIN_TREE_DEPTH_FILE="$INPUT_FILE_HEADER"_ARESV_MTDF.dat
cd src
make clean
make ARESV
cd ..
echo
echo
echo "--------------------------------------------------------------------------------"
echo "-------------------------------- ARESV LAUNCH! ---------------------------------"
echo "--------------------------------------------------------------------------------"
./src/ARESV $SORTED_OUTPUT_FROM_TE $SECONDARY_INTERM_FILE_SPECIES_FROM_TE $SUM_PROP_DATA_FROM_TE $NUM_RESERVED_REACTIONS_FILE $HEADER_TITLE $MAIN_TREE_DEPTH_FILE

######### NBOS #########
BASIC_INPUT_FILE_NAME="$HEADER_TITLE"_BASIC_OUTPUT.dat
SPECIES_INPUT_FILE_NAME="$HEADER_TITLE"_SPECIES_OUTPUT.dat
RXN_INPUT_FILE_NAME="$HEADER_TITLE"_RXN_OUTPUT.dat

echo
echo
echo "--------------------------------------------------------------------------------"
echo "--------------------------------- NBOS LAUNCH! ---------------------------------"
echo "--------------------------------------------------------------------------------"

OUTPUT_FROM_ARES_MTDF="cat $MAIN_TREE_DEPTH_FILE"
if [ OUTPUT_FROM_ARES_MTDF == "PLAIN" ]; then
	echo "OUTPUT FROM ARES MTDF = PLAIN"
	cd src
	make NBOS_D_PLAIN
	./src/NBOS_D_PLAIN $NUM_ITERATIONS_FOR_NBOS $BASIC_INPUT_FILE_NAME $SPECIES_INPUT_FILE_NAME $RXN_INPUT_FILE_NAME
elif [ OUTPUT_FROM_ARES_MTDF == "ONE" ]; then
	echo "OUTPUT FROM ARES MTDF = ONE"
	cd src
	make NBOS_D_ONE
	./src/NBOS_D_ONE $NUM_ITERATIONS_FOR_NBOS $BASIC_INPUT_FILE_NAME $SPECIES_INPUT_FILE_NAME $RXN_INPUT_FILE_NAME
elif [ OUTPUT_FROM_ARES_MTDF == "TWO" ]; then
	echo "OUTPUT FROM ARES MTDF = TWO"
	cd src
	make NBOS_D_TWO
	./src/NBOS_D_TWO $NUM_ITERATIONS_FOR_NBOS $BASIC_INPUT_FILE_NAME $SPECIES_INPUT_FILE_NAME $RXN_INPUT_FILE_NAME
elif [ OUTPUT_FROM_ARES_MTDF == "THREE" ]; then
	echo "OUTPUT FROM ARES MTDF = THREE"
	cd src
	make NBOS_D_THREE
	./src/NBOS_D_THREE $NUM_ITERATIONS_FOR_NBOS $BASIC_INPUT_FILE_NAME $SPECIES_INPUT_FILE_NAME $RXN_INPUT_FILE_NAME
elif [ OUTPUT_FROM_ARES_MTDF == "FOUR" ]; then
	echo "OUTPUT FROM ARES MTDF = FOUR"
	cd src
	make NBOS_D_FOUR
	./src/NBOS_D_FOUR $NUM_ITERATIONS_FOR_NBOS $BASIC_INPUT_FILE_NAME $SPECIES_INPUT_FILE_NAME $RXN_INPUT_FILE_NAME
fi
