#! /bin/csh
# Procedure to copy a FITS tape onto an exabyte tape.
# This procedure presumes that there is enough space on the disk to receive
# the entire contents of the tape.
if ($#argv == 0) then
    setenv TAPNAM dd
else if ($#argv == 1) then
    setenv TAPNAM $1
else
    echo "Usage:  $0 [tapename]"
    exit 1
endif
if ( ! $?TAPE ) then
    echo 'The environment variable TAPE was not set.'
    echo 'It has been set to /dev/nrmt8 '
    echo 'Be aware of this.'
    setenv TAPE /dev/nrmt8
endif
echo "The name of each file will begin with $TAPNAM"
cd /public/scratch/jesus/exa
unalias rm
echo 'Rewinding to BOT'
mt rew
set i = -1
set keepgoing = 1
while ( $keepgoing )
	@ i = $i + 1
	echo "Reading file # $i"
	dd if=$TAPE ibs=2880 of=$TAPNAM.$i >& /tmp/\#ascript.$$
	fgrep '0+0 records in' /tmp/\#ascript.$$
	set keepgoing = $status
	rm /tmp/\#ascript.$$
end
# Remove the last file, which is empty
unalias rm
rm -f $TAPNAM.$i
echo 'Rewinding tape to beginning'
mt rew &
# copy the the files to exabyte tape and remove the files from disk
rsh eos "cd /public/scratch/jesus/exa; tar -cvf /dev/nrst8 $TAPNAM.*"
rm -f $TAPNAM.*
