#!/bin/sh
# last modified 30 Aug 99 th

# This is a script to convert the f77 code files made by NumPrep to
# quadruple-precision f90 code in another directory. At the present
# moment it is useful (for one-loop amplitudes) only on DEC Alpha
# systems in connection with the quad prec libffx library of LoopTools.

# The actual conversion is done by a program called f77290 that comes with
# LoopTools. This script assumes that f77290 is reachable from $PATH.

# Run this script from the directory containing the f77 source files. It
# will make a new subdirectory called xprec where the results are put.
# Also, be sure to adjust the following paths:

looptoolsdir=$HOME/LoopTools/include
renconstdir=$HOME/FormCalc/numerics/rconst/fortran

if [ -d xprec ] ; then
  echo "subdirectory xprec exists already"
  echo "overwrite? y/n \c"
  read answer
  if [ "$answer" != "y" ] ; then
    exit
  fi
  rm -fr xprec
fi

mkdir xprec

MAXLINELENGTH=110
export MAXLINELENGTH

for file in *.[Fh] \
            $looptoolsdir/tools.[Fh] $looptoolsdir/ff.h \
            $renconstdir/*
do
  echo $file
  case $file in
  *.F) outname="`basename $file .F`.f90" ;;
  *)   outname="`basename $file`90"
  esac
  f77290 $file xprec/$outname
done

cp *.f90 $looptoolsdir/qcomplex.f90 xprec/
ln -s $looptoolsdir/defs.h xprec/defs.h90

sed    's/-I$([^ ]*//g
	/=/!s/$([^)]*DIR)//g
	s:include/::g
	s/-warn truncated_source//g
	s/-extend_source//g
	s/-lff/-lffx/g
	s/f77/f90 -r16/g
	s/-O/-O0/g
	s/\.F/.f90/g
	s/\.h/.h90/g
	s/-g/-cpp/g
	s/ renconst.o/& pdflibcoupler.o/g
	s/OBJS =/& qcomplex.o/g' GNUmakefile > xprec/GNUmakefile

cat << _EOF_ >> xprec/GNUmakefile
qcomplex.o pdflibcoupler.o: %.o: %.f90
	f90 -c $<
_EOF_

