#!/bin/csh -f ############################################################################# # Copyright: J.Brewer/ESO 1999.############################################## ############################################################################# # # Name: tape2disk # Description: This script reads files from a tape that were written with the # wfits shell script, using the `dd' option. # # Note: if using Sun Unix, change `mt -t' to `mt -f'... # # # Author: James Brewer, jbrewer@eso.org # Version: 1.0, 5 May99: First release # ############################################################################# # # Check script arguments... # if($#argv != 3 || $1 == "-help") then goto error endif # # Set variables... # set mt = "mt -t" # -t: SunOS, -f: HP set bl = 28800 # blocksize to read from tape... set root = TAPE # Root name for files... set ext = fits # extension to be used... # # Define action on interrupt (^c)... # onintr cleanup # # Check that the tape drive can be read from... # if !(-r $1) then echo $0": Couldn't find drive "$1" on this machine..." exit(-1) endif # # Check that file names to be used are `vacant'... # @ n=1 while ($n <= $2) set op = $root`printf "%03d" $n`.$ext if (-e $op) then echo $0": a file named "$op" already exists. No action taken..." exit (-1) endif @ n+=1 end # # Start loop to extract the files... # @ n=1 while ($n <= $2) # # Set the output name, and read the file... # set op = $root`printf "%03d" $n`.$ext echo " " echo "Reading file "$op dd if=$1 of=$op bs=$bl # # Check status to see if dd executed successfully... # if($status != 0) then echo "Problem with the dd command. (End of tape, incorrect bs?)" goto cleanup endif # # Check the size of the new file... # set size = `ls -l $op | tr -s ' ' | cut -f5 -d ' '` if ($size == 0) then echo $0": "$op" is an empty file -- end of tape reached?" goto cleanup endif # # If option specified, attempt to restore original filename... # if ($3 == 'y' || $3 == 'Y') then RestoreID $op endif @ n+=1 end cleanup: # # Tape handling options... # echo " " echo "Choose:" echo " r -- Rewind " echo " o -- Rewind, take drive offline" echo " x -- Do nothing (default)" echo " " echo -n "Enter your choice... " set reply = $< if ($reply == 'r') then echo "Rewinding tape..." $mt $1 rew endif if ($reply == 'o') then echo "Taking tape offline..." $mt $1 offline endif exit(0) error: echo "Usage: "$0" drive number rename" echo " drive: Name of tape drive, e.g. /dev/rmt/0bn" echo " number: Number of files to read" echo " rename: Restore original names (y/n)" echo " " echo "[Further information --> "$0" -help]" echo "[See this script --> more `which "$0"`]" if($1 == "-help") then more `echo $0 | sed -e s/tape2disk/ObsLog.man/` endif exit(-1)