#!/bin/csh -f

# Run synthetic test cases

set sources = (lev1N_node.f lev1S_node.f lev1R_node.f lev1B_node.f \
	       lev2N_node.f lev2S_node.f lev2R_node.f lev2B_node.f)

set nprocs  = (4 2 2 4 \
               4 8 4 8 )

set buildSamples = 0

set adlibHome = @top_srcdir@

set MPI       = @MPI@

if ($MPI == mpich) then
  set machineFile = machines
else if ($MPI == sp2) then
  set machineFile = host.list
else
  echo Not supported yet. ; exit 1
endif

(hostname; hostname; hostname; hostname; hostname ; hostname ; hostname ; hostname ) > $machineFile

if($buildSamples) then
  cat > diffs.sample <<.
.
else
  cat > diffs <<.
.
endif


foreach source ($sources)
  set executable=${source:r}
  echo $adlibHome/src/pcrcFortran/pcrcf -o $executable $source
  $adlibHome/src/pcrcFortran/pcrcf -o $executable $source
  if($buildSamples) then
    echo $adlibHome/src/script/prun ${nprocs[1]} $executable \| tee ${executable}.out.sample
    $adlibHome/src/script/prun ${nprocs[1]} $executable | tee ${executable}.out.sample
    shift nprocs
    cat >> diffs.sample <<.
diff ${executable}.out ${executable}.out.sample
.
  else
    echo $adlibHome/src/script/prun ${nprocs[1]} $executable \| tee ${executable}.out
    $adlibHome/src/script/prun ${nprocs[1]} $executable | tee ${executable}.out
    shift nprocs
    echo diff ${executable}.out ${executable}.out.sample \| tee -a diffs
    cat >> diffs <<.
diff ${executable}.out ${executable}.out.sample
.
    diff ${executable}.out ${executable}.out.sample | tee -a diffs
  endif
  echo rm -f $executable ${executable}.o
  rm -f $executable ${executable}.o
end

if($buildSamples) then
else
  diff diffs diffs.sample > /dev/null
  if($status) then
    echo Warning: see file \"diffs\" for differences to sample output
  endif
endif

#rm -f $machineFile
