if test $# -eq 0
then echo ""
echo "    /******************************************************************/"
echo "    /**                       D L I N K                              **/"
echo "    /**                                                              **/"
echo "    /** DLINK links Fortran 77 programs using DISLIN routines.       **/"
echo "    /**                                                              **/"
echo "    /** Command:    dlink    [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:    dlink  -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}.f ; then
     echo " >>>> Cannot find file ${name}.f" 
     exit 0
  fi
  bname=`basename ${name}`
fi

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

: Linken und evtl. Compilieren
if test $option = -C ; then
  fort ${name}.f -o $bname $cmd1
elif test $option = -A ; then
  fort ${name}.f -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
