#!/bin/csh -f
if ( ($#argv < 1 ) || ($argv[1] == ^) ) then
caterr <<'EOF'
Average together a set of images using transformation matrices.
  Usage: addimages image1 image2 ...
  Arguments: image1 image2 ... - the images to be averaged
  Input:  The program prompts for a set of four scan and reference points
          for each image, then an output image filename for the averaged image,
          and the image size and pixel size of the final image in the reference
          coordinate system.
  A temporary working directory addimages.tmp is created and removed.
'EOF'
exit
endif

mkdir addimages.tmp
cd addimages.tmp
set cat=($argv)
set j=1
foreach i ($*)
ln ../$i
set cat[$j]=${i}.cat
echo Set reference points for $i
echo -n Scan coordinates of point     1 :
set pnt1=$<
echo -n Reference coordinate of point 1 :
set ref1=$<
echo -n Scan coordinates of point     2 :
set pnt2=$<
echo -n Reference coordinate of point 2 :
set ref2=$<
echo -n Scan coordinates of point     3 :
set pnt3=$<
echo -n Reference coordinate of point 3 :
set ref3=$<
echo -n Scan coordinates of point     4 :
set pnt4=$<
echo -n Reference coordinate of point 4 :
set ref4=$<
setcat $cat[$j] >&/dev/null <<EOF
y
$i
EOF
setcat $cat[$j] >&/dev/null <<EOF
n
n
y
n
n
y
$pnt1
$ref1
$pnt2
$ref2
$pnt3
$ref3
$pnt4
$ref4
EOF
@ j++
end
addfields $cat
rm $cat $argv
mv * ..
cd ..
rm -r addimages.tmp
