#! /bin/bash

function  julia_check() {
    if  [[ -e examples/julial ]]; then
        JULIAL=examples/julial
    else
        JULIAL=julial
    fi
    
    # Check if 'julial' is in the system PATH
    if ! command -v $JULIAL &> /dev/null; then
        echo "Error: program 'julial' is not available."
        echo "It is available from the examples/ subdirectory. You should either:"
        echo ""
        echo "- cp examples/julial ~/bin (any directory on your path would work)"
        echo ""
        echo "- or run the program from the root directory of the project. That is:"
        echo "   examples/scripts/run_test_<fill relevant name>"
        echo ""
        echo " Also, don't forget to run julial src/deps.jl before running this script"
        echo -n " to install needed packages."
        echo ""
        echo "Anyway, bye for now!"
        exit 1
    fi
    
    REQUIRED_VER="1.12"
    CURRENT_VER=$(julia -e 'print(VERSION)')
    # sort -V handles multi-digit version components correctly
    if [ "$(printf '%s\n%s' "$REQUIRED_VER" "$CURRENT_VER" | sort -V | head -n1)" != "$REQUIRED_VER" ]; then
        echo "Error: Julia version $CURRENT_VER is below the required $REQUIRED_VER."
        echo "Please update Julia at https://julialang.org/downloads/"
        echo ""
        echo "Important: Use juliaup to install julia, not the default package provided."
        exit 1
    fi
    echo "Julia check completed!"
}


julia_check


kill_grep emacs
kill_grep firefox
killm
kill_browser
kill_grep julia

DRES=various/results/
mkdir -p $DRES
rm $DRES/*.txt

examples/scripts/run_test_queries_characters_serial >& $DRES/chars_ser.txt

examples/scripts/run_test_queries_sigspatial_serial >& $DRES/sig_ser.txt

examples/scripts/run_test_queries_geolife_serial >& $DRES/geolife_ser.txt

