#!/bin/sh

echo "Content-type: text/html"
echo
read input junk
echo "<HTML>"
echo "<BODY>"
echo "<FORM>"
echo "<A HREF=\"http://www.sdsc.edu/~jpg/qmview.cgi\"> QMVIEW </A>"
echo "</FORM>"
echo "<PRE>"
input=`echo $input |sed 's/&/ /g'`
rm inputfiles/runfile.inp
for i in $input; do
j=`echo $i|sed 's/=.*//'`
if [ $j = "scftyp" ];then
SCFTYP=`echo $i|sed 's/......=//'`
elif [ $j = "runtyp" ];then
RUNTYP=`echo $i|sed 's/......=//'`
elif [ $j = "timlim" ];then
TIMLIM=`echo $i|sed 's/......=//'`
elif [ $j = "gbasis" ];then
GBASIS=`echo $i|sed 's/......=//'`
elif [ $j = "ngauss" ];then
NGAUSS=`echo $i|sed 's/......=//'`
elif [ $j = "ndfunc" ];then
NDFUNC=`echo $i|sed 's/......=//'`
elif [ $j = "npfunc" ];then
NPFUNC=`echo $i|sed 's/......=//'`
elif [ $j = "nffunc" ];then
NFFUNC=`echo $i|sed 's/......=//'`
elif [ $j = "diffsp" ];then
DIFFSP=`echo $i|sed 's/......=//'`
elif [ $j = "diffs" ];then
DIFFS=`echo $i|sed 's/.....=//'`
elif [ $j = "memory" ];then
MEMORY=`echo $i|sed 's/......=//'`
elif [ $j = "symmetry" ];then
SYMMETRY=`echo $i|sed 's/........=//'`
elif [ $j = "naxis" ];then
NAXIS=`echo $i|sed 's/.....=//'`
elif [ $j = "title" ];then
TITLE=`echo $i|sed 's/.....=//'`
elif [ $j = "coord_data" ];then
datalines=`echo $i|sed 's/..........=//'`
datalines=`echo $datalines|sed 's/\%0D\%0A/ /g'`
#echo DATALINES $datalines
fi
done
cat - > inputfiles/runfile.inp << EOF 
 \$CONTRL SCFTYP=$SCFTYP RUNTYP=$RUNTYP \$END
EOF
#echo
cat inputfiles/runfile.inp inputfiles/ctrlopts > inputfiles/tmp
mv inputfiles/tmp inputfiles/runfile.inp
cat - >> inputfiles/runfile.inp << EOF 
 \$SYSTEM TIMLIM=$TIMLIM MEMORY=$MEMORY \$END
 \$BASIS GBASIS=$GBASIS NGAUSS=$NGAUSS NDFUNC=$NDFUNC NPFUNC=$NPFUNC \$END
 \$BASIS NFFUNC=$NFFUNC DIFFSP=$DIFFSP DIFFS=$DIFFS \$END
EOF
cat inputfiles/runfile.inp inputfiles/basisopts > inputfiles/tmp
mv inputfiles/tmp inputfiles/runfile.inp
chmod 0666 inputfiles/runfile.inp
if [ $SYMMETRY = "C1" ]; then
cat - >> inputfiles/runfile.inp << EOF 
 \$DATA
$TITLE
$SYMMETRY
EOF
else
cat - >> inputfiles/runfile.inp << EOF 
 \$DATA
$TITLE
$SYMMETRY $NAXIS

EOF
fi
for i in $datalines;do
j=`echo $i|sed 's/+/ /g'`
cat - >> inputfiles/runfile.inp << EOF 
$j
EOF
done
cat - >> inputfiles/runfile.inp << EOF 
 \$END
EOF
chmod 0666 inputfiles/runfile.inp
echo `hostname`
echo `uname -a`
rm -f inputfiles/ctrlopts
rm -f inputfiles/basisopts
echo
./gamessh
cat inputfiles/runfile.out
echo "</PRE>"
echo "<A HREF=\"http://www.sdsc.edu/~jpg/qmview.cgi\"> QMVIEW </A>"
echo "</BODY>"
echo "</HTML>"
