if test $# -eq 0
then echo ""
echo "    /******************************************************************/"
echo "    /**                    F 9 0 L I N K                             **/"
echo "    /**                                                              **/"
echo "    /** F90LINK links Fortran 90 programs using DISLIN routines.     **/"
echo "    /**                                                              **/"
echo "    /** Command:    f90link    [option]   main                       **/"
echo "    /**                                                              **/"
echo "    /** option      is an optional  parameter  that can  have one of **/"
echo "    /**             the following values:                            **/"
echo "    /**        -c   for compiling programs before linking            **/"
echo "    /**        -r   for running programs after linking               **/"
echo "    /**        -a   for compiling, linking and running programs.     **/"
echo "    /**                                                              **/"
echo "    /** main        is the name of the main program or may be in the **/"
echo "    /**             form   'main obj lib'   where obj is  a field of **/"
echo "    /**             object files and lib a  field of library  files. **/"
echo "    /**             Several files must be separated by blanks.       **/"
echo "    /**             A file  'main'  will be created after linking.   **/"
echo "    /**                                                              **/"
echo "    /** Example:    f90link  -a  test mylib.a                        **/"
echo "    /** Version:    Compaq Fortran, Linux Alpha                      **/"
echo "    /******************************************************************/"
  exit 0
fi

if test ! $DISLIN; then
 DISLIN=/usr/local/dislin
fi
:
option=-X
if test $1 = -c ; then
  option=-C
elif test $1 = -C ; then
  option=-C
elif test $1 = -a ; then
  option=-A
elif test $1 = -A ; then
  option=-A
elif test $1 = -r ; then
  option=-R 
elif test $1 = -R ; then
  option=-R
fi

if test $option = -X ; then
  name=$1
elif test $# -eq 1 ; then
  echo "<<<< File is missing!"
  exit 0
else 
  name=$2
fi

if test $option = -X || test $option = -R ; then
  if test ! -f ${name}.o ; then
     echo " >>>> Cannot find file ${name}.o" 
     exit 0
  fi
  bname=`basename ${name}`
fi

if test $option = -C || test $option = -A ; then
  if test ! -f ${name}.f90 ; then
     echo " >>>> Cannot find file ${name}.f90" 
     exit 0
  fi
  bname=`basename ${name}`
fi

if test $option = -X; then
  cmd1="$2 $3 $4 $5 $6 $7 $8 $9 $DISLIN/libdiscf90.so"
else 
  cmd1="$3 $4 $5 $6 $7 $8 $9    $DISLIN/libdiscf90.so"
fi

: Linken und evtl. Compilieren
if test $option = -C ; then
  fort -I$DISLIN/cf90 ${name}.f90 -o $bname $cmd1
elif test $option = -A ; then
  fort -I$DISLIN/cf90 ${name}.f90 -o $bname $cmd1
else 
  fort  ${name}.o -o $bname $cmd1
fi

: Starten
if test $option = -A ; then
  ./$bname
elif test $option = -R ; then
  ./$bname
fi
