#!/usr/bin/env sh
#
# To do: maybe using `tee`

# Checks for argument. If there are less than 2, show error message.
if [ $# -lt 2 ]
then
    echo "Usage: $0 arg1=alfy_option_flags arg2=sequence_files"
    exit
fi

spawn=3
# Spawn 3+1 (+1 is for remainders) processes to write files
# Requires 3 or more files
start=1
((spawnWork=$2/$spawn))
((spawnWorkRemainder=$2%$spawn))

# Instead of test.sh, final version will be `alfy64` executable
sh module_dependency.sh 1 $spawnWork &
sh module_dependency.sh 2 $spawnWork &
sh module_dependency.sh 3 $spawnWork &

if [ $spawnWorkRemainder -gt 0 ]
then
    sh module_dependency.sh d $spawnWorkRemainder
fi

# Put all the spawned files to final file.
cat temp_11.txt > test_output.txt
cat temp_22.txt > test_output.txt
cat temp_33.txt > test_output.txt

rm temp*
