#!/bin/bash

# Name of the program's source file (no extension)
main="make_user_spectral_grid"

# Various files
main_source=$main'.for'
main_object=$main'.o'
exec=$main'.exe'

# Controls
if [ ! -e $main_source ]
then
    echo "Main source file does not exist:"
    echo $main_source
    exit 1
else
    rm -f $exec
fi

if [ "$F77" = "" ]
then
    echo "No fortran77 compiler is defined"
    echo "please enter compiler's name"
    read F77
    exit 2
else
    echo "Fortran77 compiler is: "$F77
fi

# Compilation
$F77 -c $main_source error.for strlen.for
$F77 -o $exec $main_object error.o strlen.o

# Control
if [ -e $exec ]
then
    echo "Executable file was produced:"
    echo $exec
else
    echo "compilation failed"
    exit 3
fi

exit 0
