#!/bin/csh -f
# script to check metafiles (.plt*, .gif* and .ps) created after a run of the 
# benchmark routine against master metafiles. 
# Use ImageMagick to actually compare the contents of ps and gif files when they differ

# Clean up anything left from a previous check_metafiles_ImageMagick

rm -f *.plt.ps
rm -f *.meta.ps
rm -f *.diff.ps*
rm -f *.diff_ps*
rm -f *.diff_gif*
rm -f *bat.ps
rm -f diff*.ps
rm -f master*.ps
rm -f bat*.plt*.ps

set plt_files = ( bn*.plt dots.plt flowlines.plt graticules.plt \
linecolors.plt multi_line_labels.plt pattern*.plt polygon*.plt \
vec_curv*.plt timetics*.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
if ($num_plt_files < $total_plt_files ) set err_plt = 1
foreach plt_file ($plt_files)
    set size = `ls -l $plt_file | awk '{print $5}'`
    set size2 = `ls -l metafile_masters_64bit_rh6/$plt_file | awk '{print $5}'`
    if ("$size" != "$size2") then
       echo "plt files differ $plt_file size $size metafile_masters_64bit_rh6/ size $size2" 

       Fprint -R -p portrait -o $plt_file.ps $plt_file
       Fprint -R -p portrait -o $plt_file.meta.ps metafile_masters_64bit_rh6/$plt_file
       compare $plt_file.ps $plt_file.meta.ps $plt_file.diff.ps
       display -title new_$plt_file.ps $plt_file.ps &
       display -title stored_$plt_file.meta.ps $plt_file.meta.ps & 
       display $plt_file.diff.ps

       set err_plt = 1
    endif
end
   
set err_gif = 0
foreach gif_file ($gif_files)
    set size = `ls -l $gif_file | awk '{print $5}'`
    set size2 = `ls -l metafile_masters_64bit_rh6/$gif_file | awk '{print $5}'`
    if ("$size" != "$size2") then
       echo "gif files differ $gif_file size $size metafile_masters_64bit_rh6/ size $size2" 
       rm -f $gif_file.diff_gif.gif
       compare $gif_file metafile_masters_64bit_rh6/$gif_file $gif_file.diff_gif.gif
       display  -title new_$gif_file $gif_file &
       display  -title stored_$gif_file metafile_masters_64bit_rh6/$gif_file &
       display $gif_file.diff_gif.gif

       set err_gif = 1
    endif
end

set err_ps = 0
foreach ps_file ($ps_files)
    set size = `ls -l $ps_file | awk '{print $5}'`
    set size2 = `ls -l metafile_masters_64bit_rh6/$ps_file | awk '{print $5}'`
    if ("$size" != "$size2") then
       echo "plt files differ $ps_file size $size metafile_masters_64bit_rh6/ size $size2" 
       rm -f $ps_file.diff_ps.ps
       compare $ps_file metafile_masters_64bit_rh6/$ps_file $ps_file.diff_ps.ps
       display -title new_$ps_file $ps_file &
       display -title stored_$ps_file metafile_masters_64bit_rh6/$ps_file &
       display $ps_file.diff_ps.ps

       set err_ps = 1
    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_rh6/$mb_file | cut -b 21-27`
   set size = `ls -l $mb_file | awk '{print $5}'`
   set size2 = `ls -l metafile_masters_64bit_rh6/$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_rh6/ size $size2" 
       rm -f $mb_file.ps master_$mb_file.ps diff_$mb_file.ps 
       Fprint -R -p portrait -o $mb_file.ps $mb_file
       Fprint -R -p portrait -o master_$mb_file.ps metafile_masters_64bit_rh6/$mb_file
       compare $mb_file.ps master_$mb_file.ps diff_$mb_file.ps
       display $mb_file.ps &
       display master_$mb_file.ps &
       display diff_$mb_file.ps
    endif
end

if ($err_plt) then
	echo "CHECK PLT FILES - THERE HAS BEEN AN ERROR"
else
	echo "    PLT files look good....."
endif 
if ($err_gif) then
	echo "CHECK GIF FILES - THERE HAS BEEN AN ERROR"
else
	echo "    GIF files look good....."
endif
if ($err_ps) then
	echo "CHECK PS FILES - THERE HAS BEEN AN ERROR"
else
	echo "    PS files look good......"
endif


# clean up
rm -f *.plt.ps
rm -f *.meta.ps
rm -f *.diff.ps*
rm -f *.diff_ps*
rm -f *.diff_gif*
rm -f *bat.ps
rm -f diff*.ps
rm -f master*.ps
rm -f bat*.plt*.ps
