#!/bin/sh
#
# rip out comments
#
#
if test $# -ne 1
then
   echo "Usage: ml_install input_file"
   exit
fi
if test -f $1
then
   echo
else
   echo "ml_install: file $1 not found?"
   exit
fi

cat $1 | sed "s/#.*//" > .input_nocomments

arch=`./get_field "ARCHITECTURE" .input_nocomments`
\rm -f .installer_input
echo $arch >> .installer_input
./get_field "USE LAPACK" .input_nocomments  >> .installer_input
./get_field "USE BLAS" .input_nocomments >> .installer_input
#JJH
./get_field "BINARY INPUT DATA" .input_nocomments >> .installer_input
./get_field "USE EPETRA" .input_nocomments >> .installer_input
use_mpi=`./get_field "USE MPI" .input_nocomments`
echo $use_mpi >> .installer_input
if test `expr ${use_mpi}` = 'yes'
then
   ins_mpi=`./get_field "LOCATION OF MPICC" .input_nocomments`
   tins_mpi=`echo ${ins_mpi} xxx | sed "s/ *//g" `
   if test `expr ${tins_mpi}` = 'xxx'
   then
      echo  no >> .installer_input
   else 
      if test `expr ${ins_mpi}` = 'default'
      then
         echo  >> .installer_input
      else
         echo ${ins_mpi} >> .installer_input
      fi
   fi
fi

echo yes >> .installer_input
lib=`./get_field "LIBRARY INCLUDE PATH" .input_nocomments`
for i in $lib
do
  echo ${i} >> .installer_input
done
echo x >> .installer_input
lib=`./get_field "LIBRARY DIRECTORY LOCATION" .input_nocomments`
for i in $lib
do
  echo ${i} >> .installer_input
done
echo x >> .installer_input
lib=`./get_field "LIBRARY NAME" .input_nocomments`
for i in $lib
do
  echo ${i} >> .installer_input
done
echo x >> .installer_input

aztec=`./get_field "AZTEC INCLUDE DIRECTORY" .input_nocomments`
taztec=`echo ${aztec} xxx | sed "s/ *//g" `
if test `expr ${taztec}` = 'xxx'
then
   echo no >> .installer_input
else 
   echo yes >> .installer_input
   if test `expr ${aztec}` = 'default'
   then
     echo  >> .installer_input
   else
     echo ${aztec} >> .installer_input
   fi
   develop=`./get_field "AZTEC INTERNAL DEVELOPER" .input_nocomments`
   echo $develop >> .installer_input
   build=`./get_field "NEED TO BUILD AZTEC" .input_nocomments`
   echo ${build} >> .installer_input
fi
super=`./get_field "SERIAL SUPERLU DIRECTORY" .input_nocomments`
tsuper=`echo ${super} xxx | sed "s/ *//g" `
if test `expr ${tsuper}` = 'xxx'
then
   echo no >> .installer_input
   super=`./get_field "DISTRIBUTED SUPERLU DIRECTORY" .input_nocomments`
   tsuper=`echo ${super} xxx | sed "s/ *//g" `
   if test `expr ${tsuper}` = 'xxx'
   then
      echo no >> .installer_input
   else
      echo yes >> .installer_input
      if test `expr ${use_mpi}` = 'yes'
      then
         if test `expr ${super}` = 'default'
         then
           echo  >> .installer_input
         else
           echo ${super} >> .installer_input
         fi
         ./get_field "NEED TO BUILD SUPERLU" .input_nocomments  >> .installer_input
      fi
   fi
else 
   echo yes >> .installer_input
   if test `expr ${super}` = 'default'
   then
     echo  >> .installer_input
   else
     echo ${super} >> .installer_input
   fi
   build=`./get_field "NEED TO BUILD SUPERLU" .input_nocomments`
   echo ${build} >> .installer_input
fi
psail=`./get_field "PARASAILS DIRECTORY" .input_nocomments`
tpsail=`echo ${psail} xxx | sed "s/ *//g" `
if test `expr ${tpsail}` = 'xxx'
then
   echo no >> .installer_input
else
   echo yes >> .installer_input
   if test `expr ${use_mpi}` = 'yes'
   then
      echo  >> .installer_input
      echo yes >> .installer_input
   fi
fi
metis=`./get_field "METIS DIRECTORY" .input_nocomments`
tmetis=`echo ${metis} xxx | sed "s/ *//g" `
if test `expr ${tmetis}` = 'xxx'
then
   echo no >> .installer_input
else
   echo yes >> .installer_input
   echo  >> .installer_input
   echo yes >> .installer_input
fi
\rm -f .input_nocomments
cd ..
./installer CALLED_BY_ML_INSTALL < etc/.installer_input
\rm -f etc/.installer_input
