-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathread-fits-tape
More file actions
executable file
·80 lines (71 loc) · 1.86 KB
/
Copy pathread-fits-tape
File metadata and controls
executable file
·80 lines (71 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Use the TAPE envar by default
tapedev="${TAPE:-/dev/nst0}"
# Default base name of 'fitstape'
basename='fitstape'
# Tape block size for FITS files
blocksize=28800
function helpme {
echo "read-fits-tape"
echo "Extracts all FITS files from a FITS tape into current directory"
echo ""
echo "Usage: $0 [-f <tapedev>] [-b <basename>]"
echo ""
echo " -f Path to tape device (Def: /dev/nst0)"
echo " -b Base filename for extracted files (Def: fitstape)"
echo ""
}
while getopts "hf:b:" opt ; do
case "$opt" in
f) tapedev="$OPTARG"
;;
b) basename="$OPTARG"
;;
h) helpme
exit
;;
*) echo "Unknown option: $opt" >&2
helpme
exit 1
;;
esac
done
if [ -z "$1" ]; then
read -n 1 -p "Will read FITS tape from $tape. Proceed (y/n)? " yorn
case "$yorn" in
n|N) echo -e "\nAborting!"
exit 1
;;
*) echo -e "\nContinuing with default settings..."
;;
esac
fi
# Error out if we don't have perms on the tape device
if ! [ -r "$tapedev" ]; then
echo "Error: cannot read from tape device $tapedev" >&2
exit 1
fi
# Set variable blocksize
if ! mt -f "${tapedev}" setblk 0 ; then
echo -e "WARNING: Unable to set tape blocksize. Read errors may occur.\n"
fi
file=0
seqnum=$(printf "%05d" $file)
outfile="${basename}-${seqnum}.fits"
if [ -f "${outfile}" ]; then
echo "Error: Cowardly refusing to overwrite exiting file $outfile" >&2
exit 1
fi
echo "Reading file $file from $tapedev..."
while dd if="${tapedev}" of="${outfile}" bs=$blocksize >/dev/null; do
file=$(( $file +1 ))
seqnum=$(printf "%05d" $file)
outfile="${basename}-${seqnum}.fits"
if [ -f "${outfile}" ]; then
echo "Error: Cowardly refusing to overwrite exiting file $outfile" >&2
exit 1
fi
echo "Reading file $file from $tapedev..."
done
echo "Done reading files from $tapedev"
echo "$file files read from tape"