#!/bin/tcsh

rm -f end
echo 0 > count

while(1)
  echo `cat count` 1 + p | dc > count.tmp
  rm -f count
  mv count.tmp count
  echo Round `cat count`
  foreach i (`ls *.net`)
    echo Running NETSIM with $i
    rm -f rawout.txt
    netsim $i > rawout.txt
#    fgrep "route requirement" rawout.txt >> $i.time_to_route_satisfaction.out
#    fgrep "route requirement" rawout.txt | tail --lines=1 >> $i.time_to_route_satisfaction.max.out
    fgrep "converged" rawout.txt | head --lines=1 >> $i.convergence.out
    fgrep "STATS proto" rawout.txt >> $i.STATS_proto.out
    fgrep "STATS medium" rawout.txt >> $i.STATS_medium.out
  end
  if (-e end) then
    echo Exiting on "end" request.
    exit
  endif
  if (-e endcount) then
    if ( `cat endcount` <= `cat count` ) then
      echo Exiting on "endcount" request.
      exit
    endif
  endif
end
