#! /bin/sh
#
# Compiles a collection of Fortran programs and links them to gplot as a single executable.
# Written by Avygdor Moise - October 19, 2009
# Update  by Avygdor Moise - April 16, 2013
#         -- Supports .f and .for extensions
#
F77=g77
F77_FLAGS="-Wall -g -fno-second-underscore -fno-automatic -malign-double"
F77_LIBS="/usr/local/triumf//gplot/libgplot.a -lX11 -lpthread"
EXEC='a.out'
F77_FILES=''
while [ $# -gt 0 ]; do
	case $1 in
	*.[Ff])
		F77_FILES="$F77_FILES $1"
		;;
	*.[fF][oO][rR])
		F77_FILES="$F77_FILES $1"
		;;
	-o)
		EXEC="$2"
		shift
		;;
	*)
		echo "*** Warning *** : Argument '$1' ignored"
		;;
	esac
	shift
done

if [ "$F77_FILES" == "" ]; then
	echo "Usage: $0 [-o outfile] <file-1.f> [<file-2.f> ... <file-n.f>]"
else
	echo $F77 $F77_FLAGS -o $EXEC $F77_FILES $F77_LIBS
	$F77 $F77_FLAGS -o $EXEC $F77_FILES $F77_LIBS
fi
