#!/bin/csh -f
#
# GSTEST - test PGS
#

set System = `../manager/system-id`
set BinDir = ../dev/$System/bin
set ERROR  = "FALSE"
set FAIL   = "NO"
set status = 0

source ../manager/env-$System

set FrontEnd = ""
set DPE = `which pact-dpe`
if ("$DPE" != "")then
   if (-e "$DPE[1]") then
      source $DPE
   endif
endif

if (-e ../dev/$System/include/pgs.h) then

   touch test.error

   rm -f gstest.debug
   echo `../manager/pwhich pact` >& gstest.debug
   echo `../manager/pwhich cc` >>& gstest.debug
   echo "BinDir = $BinDir" >>& gstest.debug

   echo ""
   echo "PGS TEST..."

#--------------------------------------------------------------------------
#--------------------------------------------------------------------------

   echo ""
   echo -n "                    PGS Basic Test ........"

   pact Cstd >>& test.error

   if ($status != 0) then
      echo ""
      cat test.error
      echo "                         Can't build PGS Basic Test Program"
      echo "                    PGS Line Plot Test ..... FAILED"
      set ERROR = "TRUE"
   else
      $FrontEnd $BinDir/gsatst -A -3 -8 -r 500
      ps-diff gspsts.ps gspsts.ps.ref >>& test.error
      set DiffStat = $status

      echo ""

      if ($DiffStat != 0) then
         cat test.error
         echo "                    PGS Basic Test ......... FAILED"
         set ERROR = "TRUE"
      else
         echo "                    PGS Basic Test ......... PASSED"
         touch gsjpgt.jpeg.foo
         rm gspsts.ps gscgmt.cgm gsjpgt.jpeg.*
      endif

   endif

   set FAIL = "NO"

#--------------------------------------------------------------------------
#--------------------------------------------------------------------------

   echo ""
   echo -n "                    PGS Log Axis Test ....."

   pact logaxis >>& test.error

   if ($status != 0) then
      echo ""
      cat test.error
      echo "                         Can't build PGS Log Axis Test Program"
      echo "                    PGS Log Axis Test .....  FAILED"
      set ERROR = "TRUE"
   else
      rm -f gslaxt.res gslaxt.ps
      $FrontEnd $BinDir/gslaxt -s gslaxt.dat > gslaxt.res

      diff gslaxt.res gslaxt.res.ref > gslaxt.res.diff
      set ResFile = `find . -name "gslaxt.res.diff" -size 0c -print`

      ps-diff gslaxt.ps gslaxt.ps.ref > /dev/null
      set DiffStat = $status

      if ($#ResFile != 1) then
         echo ""
         echo "                             Results Differ"
         set FAIL = "YES"
      else if ($DiffStat != 0) then
         echo ""
         echo "                             Plots Differ"
         set FAIL = "YES"
      endif

      if ($FAIL == "YES") then
         echo "                    PGS Log Axis Test ...... FAILED"
         set ERROR = "TRUE"
      else
         echo "  PASSED"
      endif
   endif

#--------------------------------------------------------------------------
#--------------------------------------------------------------------------

   rm test.error

   echo ""
   if ($ERROR == "TRUE") then
      echo ""
      echo "Debug:"
      cat gstest.debug
      echo ""
      echo "PGS TEST...FAILED"
   else
      echo "PGS TEST...PASSED"
   endif

   echo ""
   echo " --------------------------------------------------------"

endif

set xstatus = 0
if ($ERROR == "TRUE") then
   set xstatus = 1
endif

exit($xstatus)

