#!/bin/bash

readonly VRR="$1/vrr"
echo "VRR is at $VRR"
echo "cli args $@"


main () {
    # Run inpmod
    "$VRR" i sa3_restart0 || exit 255

    for i in 0 1 2 3
    do
        let j="i + 1"
        # Run restart $i
        "$VRR" so sa3_restart$i
        if ! [[ $? == 0 ]]
        then
            echo "Error: Test '$(pwd)' failed on restart step $i"
            exit $j
        fi
        # Copy results file from restart i to input to restart i + 1
        cp sa3_restart${i}_ifninp.sam sa3_restart${j}_ifninp.sam
        cp sa3_restart${i}_ifnsys.sam sa3_restart${j}_ifnsys.sam
        cp sa3_restart${i}_ifndmp.sam sa3_restart${j}_ifndmp.sam
        cp sa3_restart${i}_ifnsta.ffi sa3_restart${j}_ifnsta.ffi
    done
}


# The only global command is to start the main() function
main

exit 0
