#!/bin/csh -f
# Create skys from images

if ( $#argv < 3 ) then
caterr <<'EOF'
Create skys from images
  usage: skys1 threshold area image1 [image2 ...]
  Arguments: threshold - detection threshold in sky sigma
	     area - minimum detection area in pixels
	     image1 [image2 ...] - images to extract skys for

  For each image the specified detection threshold and minimum area is
  used with a 5 x 5 filter to detect objects in the image.  The detected
  objects are then cleaned from the raw images with a growing parameter
  of 1 and files image1.sky, image2.sky, etc. are created.  A temporary
  working directory skys1.tmp is created and removed.
'EOF'
exit
endif

set th=$1
set ar=$2
shift
shift

# Make working directory
mkdir skys1.tmp
cd skys1.tmp

foreach i ($*)
cp ../$i skys1
setcat skys1.cat >&/dev/null <<EOF
y
skys1











$th
$th

$ar



y
y
EOF
detect skys1.cat
clean 1 G D <skys1.cat
mv skys1 ../${i}.sky
end
cd ..
rm -r skys1.tmp
endif
