#!/bin/bash
# This script pre-processes the Fortran source code for g95 and Absoft af95. They do not recognize
# the `back` keyword in `min/maxloc`, which is available since F2008.

DIR="$(realpath "$1")"
GETACTF90="getact.f90"
GETACT="$DIR/lincoa/$GETACTF90"

if ! basename "$DIR" | grep -q ".test\|test." || ! [[ -d "$DIR" ]] ; then
    printf "\n%s is not a testing directory.\n\nExit.\n\n" "$DIR"
    exit 1
fi

if [[ -f "$GETACT" ]] ; then
    sed -i "s/,\s*back\s*=\s*\.true\.//" "$GETACT"
fi

exit 0
