#!/bin/sh


counter=0

run_mcf() {
# $1: program 
# $2: options 
# $3: net
# $4: time counter

  printf "%-12s" $1
  cat $3 | $1 $2 | grep time > tmp
  if [ $status ]; then 
     break;
  fi
  cat tmp 
  t=`cat tmp | sed -e "s/.*time://" -e "s/cost:.*//"`
  if [ "$t" != "" ]; then
#   counter=`echo "$4 + $t" | bc`
    counter=$(awk "BEGIN{print $4 + $t}")
  else
    counter=$4
  fi
}


if [ "$1" = "" ] 
then
  get="wget -q -O - " 
  wdir=www.informatik.uni-trier.de/~naeher/download/net/mcf
  wlst=`wget -q -O - $wdir/lst`
else
  get=cat
  wlst=$*
fi


sum1=0.0
sum2=0.0
sum3=0.0
sum4=0.0
sum5=0.0
sum6=0.0
sum7=0.0
sum8=0.0
sum9=0.0
sum10=0.0


for net in  $wlst; do 

if [ "$1" = "" ]; then
  net=$wdir/$net
else
 if [ ! -f $net ]; then
    continue;
 fi
fi


  echo " "
  echo $net 
  echo " "

  $get $net > tmp.net


#  printf "cs2-4.3     ";
#  cat tmp.net | cs2-4.3 | grep time | sed s/"c time: *"/"time:  "/ | sed s/" *cost:    "/" cost:"/ > tmp
#  cat tmp 
#  t=`cat tmp | sed -e "s/.*time: *//" -e "s/ *cost:.*//"`
#  if [ "$t" != "" ]; then
#    sum1=`echo "$sum1 + $t" | bc`
#  fi


  printf "cs2-4.5     ";
  cat tmp.net | cs2-4.5 | grep time | sed s/"c time: *"/"time:  "/ | sed s/" *cost:    "/" cost:"/ > tmp
  cat tmp 
  t=`cat tmp | sed -e "s/.*time: *//" -e "s/ *cost:.*//"`
  if [ "$t" != "" ]; then
#   sum2=`echo "$sum2 + $t" | bc`
    sum2=$(awk "BEGIN{print $sum2 + $t}")
  fi



#  printf "bidirected    ";
#  cat tmp.net | mcf_cs_bidirected > tmp
#  t=`cat tmp | grep "total" | sed -e "s/ *total *//"`
#  f=`cat tmp | grep "flow cost" | sed -e "s/ *flow cost *//"`
#  if [ "$t" = "" ]; then
#    printf "time: ????? cost: %12d\n" $f
#  else
#    printf "time: %5.2f cost: %12d\n" $t $f
#    sum2=`echo "$sum2 + $t" | bc`
#  fi

#  printf "bidirectional ";
#  cat tmp.net | mcf_cs_bidirectional > tmp
#  t=`cat tmp | grep "total" | sed -e "s/ *total *//"`
#  f=`cat tmp | grep "flow cost" | sed -e "s/ *flow cost *//"`
#  if [ "$t" = "" ]; then
#    printf "time: ????? cost: %12d\n" $f
#  else
#    printf "time: %5.2f cost: %12d\n" $t $f
#    sum3=`echo "$sum3 + $t" | bc`
#  fi

  # alpha= 1.2 *(log(n^2/m)-1)  af= 0.25 ... 4.0   af_up=2.0  eps_f=2.0

# run_mcf mcfs_csdg "" tmp.net $sum3
# sum3=$counter

  run_mcf mcfs_csd8  "" tmp.net $sum4
  sum4=$counter

# run_mcf mcfs_csd9a "" tmp.net $sum5
# sum5=$counter

  run_mcf mcfs_csd9  "" tmp.net $sum6
  sum6=$counter

# run_mcf mcfs_csd10 "" tmp.net $sum6
# sum6=$counter

# run_mcf mcfg "" tmp.net $sum7
# sum7=$counter

# run_mcf mcfs4 "16"   tmp.net $sum8
# sum8=$counter

# run_mcf mcf_bf3 < tmp.net $sum8
# sum8=$counter

# run_mcf mcfs5 "64 512 2" tmp.net $sum9
# sum9=$counter

# run_mcf mcfs5 "64 256 4" tmp.net $sum9
# sum9=$counter

# run_mcf mcfs6 "16 256 4" tmp.net $sum10
# sum10=$counter

 
 total=0
 line=""

 for x in $sum1 $sum2 $sum3 $sum4 $sum5 $sum6 $sum7 $sum8 $sum9 $sum10; do

 if [ $x = 0.0 ]; then
   continue;
 fi

#total=`echo "$total + $x" | bc`
 total=$(awk "BEGIN{print $total + $x}")

 str=`printf " %.2f" $x`

 if [ "$line" = "" ]
 then
    line="$str"
 else
    line="$line + $str"
 fi

 done

 str=`printf " %.2f" $total`
#echo -n \]2\;$str = $line;
 printf "]2;$str = $line"

done

echo
echo $line
echo

