#!/bin/tcsh

#  This script builds executables make2dspline and use2dspline,
#  which are needed to generate the knots and coefficients of the
#  2d spline used by the splinemap tester (testsplinemap.f). It
#  also runs these executables, leaving the spline information in
#  text file "2dspline.dat" (which is read by testsplinemap.f) and
#  displaying on stdout the results of transforming a set of standard
#  input positions using the 2dspline. These positions should be
#  copied into testsplinemap.f. The parameter values defined in
#  make2dspline.f, use2dspline.f and testsplinemap.f must all be the
#  same. The test positions are defined within use2dspline.f and must
#  match those used by testsplinemap.f.
#
#  All this information is generated using the spline routines in the
#  public domain library CMLIB. The required CMLIB source files are
#  included in directories dbsplin and dtensbs.

rm -f `find . -name "*.o"`
rm -f libcmlib.a

#  Compile the CMLIB source files
foreach n (dbsplin/*.f  dtensbs/*.f)
   gfortran -c -g -fallow-argument-mismatch $n
end
ar rcs libcmlib.a `find . -name "*.o"`
rm `find . -name "*.o"`

#  Compile make2dspline
gfortran -o make2dspline make2dspline.f -L. -lcmlib

#  Run make2dspline to put the spline info in 2dspline.dat
./make2dspline > 2dspline.dat

#  The following starlink commands can be used to visualise the two spline
#  surfaces. To do this, make2dspline.f must be changed to set "dump1"
#  to .true. and "dump2" to .false. This causes the file 2dspline.dat to
#  contain the interpolatred 2d surface values rather than the spline
#  knots and coefficients.
#$KAPPA_DIR/trandat valcol=3 freename=2dspline.dat ndf=u quiet
#$KAPPA_DIR/trandat valcol=4 freename=2dspline.dat ndf=v quiet
#$KAPPA_DIR/gdclear
#$KAPPA_DIR/picdef mode=a xpic=2 ypic=2 prefix=a
#$KAPPA_DIR/picsel a1
#$KAPPA_DIR/display u.sdf mode=scale accept
#$KAPPA_DIR/picsel a2
#$KAPPA_DIR/display v.sdf mode=scale accept
#$KAPPA_DIR/picsel a3
#$KAPPA_DIR/linplot u'(,50)'
#$KAPPA_DIR/picsel a4
#$KAPPA_DIR/linplot v'(50,)'

#  Compile and run use2dspline to display the transformed standard test
#  positions on the screen.
gfortran -g -o use2dspline use2dspline.f -L. -lcmlib
./use2dspline < 2dspline.dat | sed -e 's/ 0.0000000000000000 / AST__BAD           /g'
