#!/bin/csh -f
# script to check metafiles (.plt*, .gif* and .ps) created after a run of the 
# benchmark routine against master metafiles. 
# kob  10/97
# acm   4/05 add more .plt files for checking, new directory metafile_masters_v580
# acm  12/06 as suggested by Remik Ziemlinski, use awk rather than cut to get file sizes.
# acm  11/10 Rename metafile_masters_vxx to metafile_masters_32bit and metafile_masters_64bit


set plt_files = ( bn*.plt dots.plt flowlines.plt graticules.plt linecolors.plt multi_line_labels.plt \
pattern*.plt polygon*.plt vec_curv*.plt degC_axlab.plt axticlabel.plt)
set gif_files = ( bn*.gif )
set ps_files = (bn*.ps)
set mb_files = (bat.plt_*)
set num_plt_files = `ls -l *.plt | wc -l `

set err_plt = 0
set total_plt_files = 23
foreach plt_file ($plt_files)
#    set size = `ls -l $plt_file | cut -b 21-27`
#    set size2 = `ls -l metafile_masters_64bit/$plt_file | cut -b 21-27`
   set size = `ls -l $plt_file | awk '{print $5}'`
   set size2 = `ls -l metafile_masters_64bit/$plt_file | awk '{print $5}'`
   if ($size != $size2) then
      set err_plt = 1
      echo "plt files differ $plt_file size $size metafile_masters_64bit/ size $size2" 
   endif
   if ($num_plt_files != $total_plt_files ) set err_plt = 1
end

set err_gif = 0
foreach gif_file ($gif_files)
#    set size = `ls -l $gif_file | cut -b 21-26`
#    set size2 = `ls -l metafile_masters_64bit/$gif_file | cut -b 21-26`
   set size = `ls -l $gif_file | awk '{print $5}'`
   set size2 = `ls -l metafile_masters_64bit/$gif_file | awk '{print $5}'`
   if ($size != $size2) then
      set err_gif = 1
      echo "gif files differ $gif_file size $size metafile_masters_64bit/ size $size2" 
   endif
end
 
set err_ps = 0
foreach ps_file ($ps_files)
   set size = `ls -l $ps_file | cut -b 21-27`
   set size2 = `ls -l metafile_masters_64bit/$ps_file | cut -b 21-27`
   set size = `ls -l $ps_file | awk '{print $5}'`
   set size2 = `ls -l metafile_masters_64bit/$ps_file | awk '{print $5}'`
   if ($size != $size2) then
      set err_ps = 1
      echo "ps files differ $ps_file size $size metafile_masters_64bit/ size $size2" 
   endif
end

set err_mb = 0
foreach mb_file ($mb_files)
   set size = `ls -l $mb_file | cut -b 21-27`
   set size2 = `ls -l metafile_masters_64bit/$mb_file | cut -b 21-27`
   set size = `ls -l $mb_file | awk '{print $5}'`
   set size2 = `ls -l metafile_masters_64bit/$mb_file | awk '{print $5}'`
   if ($size != $size2) then
      set err_mb = 1
      echo "metafile batch files differ $mb_file size $size metafile_masters_64bit/ size $size2" 
   endif
end

set any_error = 0
if ($err_plt) then
	echo "CHECK PLT FILES - THERE HAS BEEN AN ERROR"
	if ($num_plt_files != $total_plt_files ) then 
	  echo "num_plt_files $num_plt_files There should be $total_plt_files"
	endif
        set any_error = 1
else
	echo "    PLT files look good....."
endif 
if ($err_gif) then
	echo "CHECK GIF FILES - THERE HAS BEEN AN ERROR"
        set any_error = 1
else
	echo "    GIF files look good....."
endif
if ($err_ps) then
	echo "CHECK PS FILES - THERE HAS BEEN AN ERROR"
        set any_error = 1
else
	echo "    PS files look good......"
endif
if ($err_mb) then
	echo "CHECK metafile batch FILES - THERE HAS BEEN AN ERROR"
        set any_error = 1
else
	echo "    metafile batch files look good......"
endif

if ($any_error) then
	echo "  "
	echo " If ImageMagick is available, run check_metafiles_ImageMagick to see plot differences. "
	echo " As the script runs, it shows the standard plot, the plot from this benchmark run, and a diff plot. "
	echo " Delete the standard and benchmark plots first, then the diff plot. "
	echo "  "
endif
