# version for UNIX / LINUX (using the bash shell)
#
# Use: runphr filename [list of filenames]
#
#       filename     name of a file containing the .SIF
#                    definition for the problem of interest.
#

export CUTEDIR=/home/egbirgin/private/cute

export METHDIR=$CUTEDIR/phr
export OBJEDIR=$CUTEDIR/tools/objects/double
export CURRDIR=$CUTEDIR/mastsif/output_auglag

if ! [[ -e $CURRDIR/phrtable.txt  ]] ; then touch $CURRDIR/phrtable.txt  ; fi
if ! [[ -e $CURRDIR/phrtable2.txt ]] ; then touch $CURRDIR/phrtable2.txt ; fi

if (( $# == 0 )) ; then

    echo 'Syntax: runphr filename [list of filenames],'
    echo 'where filename is the name of a file containing '
    echo 'the SIF definition for the problem of interest. '
    exit

else

    for i in $*

        do

        if ! [[ -e $CURRDIR/$i.SIF ]] ; then

            echo "file $i.SIF does not exist in the current directory" 

        else

            echo $i  >  $CURRDIR/phr.input
            echo "3" >> $CURRDIR/phr.input
            echo "0" >> $CURRDIR/phr.input

            $CUTEDIR/sifdec_d < $CURRDIR/phr.input

            f77 -O4 -c ELFUNS.f GROUPS.f RANGES.f SETTYP.f EXTERN.f
            
            f77 $METHDIR/phrma.o $METHDIR/phr.o $CURRDIR/ELFUNS.o \
                $CURRDIR/GROUPS.o $CURRDIR/RANGES.o $CURRDIR/SETTYP.o \
                $CURRDIR/EXTERN.o $OBJEDIR/csetup.o $OBJEDIR/cnames.o \
                $OBJEDIR/cfn.o $OBJEDIR/csgr.o $OBJEDIR/others.o \
                $OBJEDIR/elgrd.o $OBJEDIR/asmbl.o $OBJEDIR/initw.o \
                $OBJEDIR/hsprd.o $OBJEDIR/local.o $OBJEDIR/linpac.o \
                -o $CURRDIR/phrmin 
            
            $CURRDIR/phrmin

            cat $CURRDIR/phrline.txt  >> $CURRDIR/phrtable.txt
            cat $CURRDIR/phrline2.txt >> $CURRDIR/phrtable2.txt

            rm $CURRDIR/phr.input $CURRDIR/phrmin $CURRDIR/ELFUNS.f \
               $CURRDIR/GROUPS.f $CURRDIR/RANGES.f $CURRDIR/SETTYP.f \
               $CURRDIR/EXTERN.f $CURRDIR/OUTSDIF.d $CURRDIR/ELFUNS.o \
               $CURRDIR/GROUPS.o $CURRDIR/RANGES.o $CURRDIR/SETTYP.o \
               $CURRDIR/EXTERN.o $CURRDIR/phrline.txt \
               $CURRDIR/phrline2.txt

        fi

        done

fi
