#!/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-09-26
# 
# email: wax@alum.mit.edu
# 
# Please send comments and especially bug reports to the
# above email address.
# 
#-----

#TS=1

NTS="`ls SimResults/sim_proc_rnk_0_ts_?.dat | wc -l`"
NTS=$(( $NTS - 1 ))

# Compare the results of the LAST timestep ...

# Get all data to compare into two files: 
# 
rm -f /tmp/pAlgoResults.dat /tmp/pAlgoResults_unsorted.dat /tmp/sAlgoResults.dat
for x in SimResults/sim_proc_rnk_?_ts_$NTS.dat ; do 
  sed '1d' $x >> /tmp/pAlgoResults_unsorted.dat 
done
sort -n /tmp/pAlgoResults_unsorted.dat > /tmp/pAlgoResults.dat

sort -n Testing/SimResults/seq_sim_ts_$NTS.dat > /tmp/sAlgoResults.dat

if which ndiff > /dev/null ; then 
  echo "using ndiff..."
  #ndiff -abserr 1d-5 /tmp/pAlgoResults.dat /tmp/sAlgoResults.dat
  ndiff -relerr 1d-4 /tmp/pAlgoResults.dat /tmp/sAlgoResults.dat
else
  echo "no ndiff ... using diff..."
  if diff -b /tmp/pAlgoResults.dat /tmp/sAlgoResults.dat > /dev/null ; then 
    echo "no difference between the files"
  else
    emacs /tmp/pAlgoResults.dat /tmp/sAlgoResults.dat & 
  fi
fi
