#!/bin/csh

module purge
module load comp/intel-12.0.4
#module load comp/gcc-5.3
module load comp/gcc-8.2

set logfile=npb-run.log
touch $logfile
set tmpf=npb.tmp.$$

echo "Date: `date`" >> $logfile
echo "Host: `hostname`" >> $logfile
module list >>& $logfile
echo "" >> $logfile

set cnt=0
set cntf=0
set cntp=0

set aps=(bt sp lu lu ua ua)
set spv=(blk blk hp doac au rd)
set c="A"
setenv NPB_TIMER_FLAG 1

foreach nt (4)
foreach cf (gcc itc_p pgi)

set bindir=bin_$cf
set outdir=out_$cf
if ( ! -d $outdir) mkdir -p $outdir

foreach ap (bt cg ep ft is lu mg sp ua)
   set pgm=${ap}.${c}.x
   set pgmx=$bindir/$pgm
   set case="run $cf/$pgm nt=$nt"
   @ cnt++
   if ( -e $pgmx ) then
      set outf=$outdir/${ap}.${c}.out.$nt
      touch $outf
      mbind.x -t$nt -cs-1 $pgmx >&! $tmpf
      grep -i ' successful' $tmpf >& /dev/null
      if ( $status == 0 ) then
         echo ">>> $case - successful" | tee -a $logfile
      else
         echo "*** $case - FAILED" | tee -a $logfile
         @ cntf++
      endif
      cat $tmpf >> $outf
      \rm $tmpf
   else
      echo "... $case - not present" | tee -a $logfile
      @ cntp++
   endif
end

set n=1
while ( $n <= $#aps )
   set ap=$aps[$n]
   set ver=$spv[$n]
   set pgm=${ap}-${ver}.${c}.x
   set pgmx=$bindir/$pgm
   set case="run $cf/$pgm nt=$nt"
   @ cnt++
   if ( -e $pgmx ) then
      set outf=$outdir/${ap}-${ver}.${c}.out.$nt
      touch $outf
      mbind.x -t$nt -cs-1 $pgmx >&! $tmpf
      grep -i ' successful' $tmpf >& /dev/null
      if ( $status == 0 ) then
         echo ">>> $case - successful" | tee -a $logfile
      else
         echo "*** $case - FAILED" | tee -a $logfile
         @ cntf++
      endif
      cat $tmpf >> $outf
      \rm $tmpf
   else
      echo "... $case - not present" | tee -a $logfile
      @ cntp++
   endif
   @ n++
end

end
end

echo "" >> $logfile
echo "Date: `date`" >> $logfile
echo "Total number of cases: $cnt" | tee -a $logfile
echo "Total number of FAILED cases: $cntf" | tee -a $logfile
echo "Total number of not present cases: $cntp" | tee -a $logfile
echo "" >> $logfile


