#!/bin/sh
DATE="03/10/1997"
MYCOMMAND=/usr/local/share/vecfem3/vempfade
#**************************************************************************
#**                                                                     ***
#**        Copyrights University of Karlsruhe, 1996                     ***
#**        Program by L. Grosz                                          ***
#**                                                                     ***
#**************************************************************************
#**                                                                     ***
if [ $# -lt 1 ]
 then
   echo "illegal number of arguments:" >&2
   echo "call:  vemcompile <workpiece> [<target_file>]" >&2
   exit 1
fi
echo "VECFEM: start FORTRAN compiler"
echo "Version: $DATE"
echo "Copyrights by University of Karlsruhe 1996"
#
#** finde the vecfem variables
#
if [ "$MYCOMMAND" = "" ] ; then
  . vempfade
  echo vempfade from `dirname $(which vempfade)`
else
  VEMPATH=`dirname $MYCOMMAND`
  SC=`basename $MYCOMMAND`
  if test -r $VEMPATH/vempfade ; then
     . $VEMPATH/vempfade
     echo vempfade from $VEMPATH
  else
    HELP=`which $SC`
    VEMPATH=`dirname $HELP`
    if test -r $VEMPATH/vempfade ; then
      . $VEMPATH/vempfade
      echo vempfade from $VEMPATH
    else
      . vempfade
      echo vempfade from `dirname $(which vempfade)`
    fi
  fi
fi
#
#---------------------------------
WORKPIECE=$1
test -r $WORKPIECE.f
if [ $? -eq 1 ]
  then
  echo ">> input file "$WORKPIECE".f was not found !" >&2
  echo ">> abend !" >&2
  exit 1
fi

if [ $# -gt 1 ]
 then
   VEMTARGET_FILE=$2
 else
   VEMTARGET_FILE="a.out"
fi
#
#***************************************************************************
#
echo "target file : "$VEMTARGET_FILE
#
#***************************************************************************
#
$VECFEM_ROOT/bin/vemfc $WORKPIECE $VEMTARGET_FILE

if [ $? -eq 0 ]; then
   echo  "$WORKPIECE.f was compiled and linked!"
else
   exit 1
fi
