#!/bin/bash

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

# 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 write_files.for read_molparam.for num2str.for get_nlines.for exec.for error.for strlen.for
$F77 -o $exec $main_object write_files.o read_molparam.o num2str.o get_nlines.o exec.o 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
