#!/bin/sh
#
# A simple script to compare a serial version of a restricted
# range N body problem with the parallel version (midpoint method)
# 
# Written by:
# -- 
# John L. Weatherwax                2006-10-12
# 
# email: wax@alum.mit.edu
# 
# Please send comments and especially bug reports to the
# above email address.
# 
#-----

#TS=1

NTS="`ls ParSimResults/force_calc_proc_0_ts_*.dat | wc -l`"

# Compare the results of each timestep ...
tsi=1
while [ $tsi -le $NTS ] ; do
  echo "comparing timestep = $tsi..."
  # Get all data to compare into two files: 
  # 
  rm -f /tmp/pAlgo_results.dat /tmp/pAlgo_results_unsorted.dat /tmp/sAlgo_results.dat
  for x in ParSimResults/sim_proc_rnk_*_ts_$tsi.dat ; do 
    sed '1d' $x >> /tmp/pAlgo_results_unsorted.dat 
  done
  sort -n /tmp/pAlgo_results_unsorted.dat > /tmp/pAlgo_results.dat

  sort -n SerialVersion/SerSimResults/seq_sim_ts_$tsi.dat > /tmp/sAlgo_results.dat

  if diff -b /tmp/pAlgo_results.dat /tmp/sAlgo_results.dat > /dev/null ; then 
    echo "...SAME"
  else
    echo "...DIFFERENT"
    emacs /tmp/pAlgo_results.dat /tmp/sAlgo_results.dat & 
    break
  fi

  tsi=`expr $tsi + 1`
done

