#!/bin/tcsh
#+
#  Purpose:
#     Plot one FITS header, leaving the PostScript behind for comparison.

#  Usage:
#     makeplot <case>
#
#     <case> is either the name of a case registered in
#     fixtures/plot/cases.txt, in which case that case's attributes and box
#     are used, or the name of any header below fixtures/wcsconv/inputs
#     (without the ".head" suffix), or a path to a header, either of which
#     is plotted with default settings.
#
#     The plot is written to <case>-new.ps in the current directory, to be
#     looked at.  The references in fixtures/plot/expected are SVG, written by
#     the grid_ tests' logging GRF module and compared automatically by them, so
#     there is no PostScript reference to diff this against; open both if you
#     want to compare by eye.
#-

if( "$1" == "" ) then
   echo "Usage: makeplot <case>"
   echo "   (e.g. makeplot serpens)"
   exit 1
endif

gfortran -fno-second-underscore -w -g -fno-range-check -o plotter plotter.f \
         -I$GITSTAR/include -L$GITSTAR/lib `ast_link -pgp -ems` `pgplot_link`

set bn = $1
eval `awk -f plotcase.awk -v name=$bn fixtures/plot/cases.txt`

#  Not a registered case, so plot the named header with default settings.
if( "$head" == "" ) then
   set head = fixtures/wcsconv/inputs/${bn}.head
   if( ! -e $head ) set head = $bn
   set attr1 = ' '
   set attr2 = ' '
   set box = ( )
endif

if( ! -e $head ) then
   echo "No such plot case or header: $bn"
   exit 1
endif

set psfile = "${bn}-new.ps"
echo "plotter $head '$attr1' '$attr2' a.ps $box"
./plotter $head "$attr1" "$attr2" a.ps $box

if( -e $GITSTAR/bin/psmerge ) then
   $GITSTAR/bin/psmerge -t300x300 -r90 a.ps > $psfile
else
   cp a.ps $psfile
endif

gv $psfile -orientation=landscape
