Subject: shell tools for FITS files, part II

From: sla at umbra.UCSC.EDU (Steve Allen)
Date: 6 Aug 1993 05:39:52 GMT

A while back I posted a little shell script that could be used to
print the contents of FITS file headers.  Here, with thanks to
Alberto Accomazzi, is an improved version.

#!/bin/sh
#       A little Cshell script which acts like cat.
#       Author: Steve Allen (sla at lick.ucsc.edu) 1992,1993
#       It takes as input a FITS file, and cats out the headers of
#       the primary HDU and any FITS extensions which may be present.
#       04/27/93        Modified to be a Bourne shell script and redirect
#                       the statistics generated by dd to /dev/null
#                       Alberto Accomazzi (alberto at cfa.harvard.edu).
#       06/22/93        Modified to print only primary header and quit
#                       unless flag -x is specified
#                       Alberto Accomazzi (alberto at cfa.harvard.edu).
#
#   Some recent Lick FITS headers have a "comment" as a part of the
#   END card.  This is actually illegal, but by giving the -L switch
#   as the first argument this script will tolerate them.

sed1='/^SIMPLE  = /,/^END *$/p'
sed2='/^END *$/q'
files=""

if [ $# -gt 0 ] ; then
    for arg in $* ; do
	case "$arg" in
	-l|-L)  # be compatible with the illegal Lick FITS headers
		sed1='/^SIMPLE  = /,/^END */p' ;;
	-x|-X)  # print extension header
		sed2='/^XTENSION= /,/^END *$/p' ;;
	-*)     # illegal option
		echo "Usage: $0 [-x] [-l] [fitsfile]" >&2
		exit 1 ;;
	*)      # filename
		files="$files $arg" ;;
	esac
    done
fi

#
if [ -z "$files" ] ; then
    # act like a pipeline element
    ( dd conv=unblock cbs=80  | sed -n -e "$sed1" -e "$sed2" ) 2>/dev/null
else
    set $files
    for file in $* ; do
	if [ $# -gt 1 ] ; then
	    echo "===> "$file" <==="
	fi
	( dd conv=unblock cbs=80 if=$file 2>/dev/null | sed -n -e "$sed1" -e "$sed2" ) 2>/dev/null
    done
fi

_______________________________________________________________________________
Steve Allen          | That was the equation!         |   sla at lick.ucsc.edu
UCO/Lick Observatory | Existence!...Survival must     | If the UC were opining,
Santa Cruz, CA 95064 | cancel out programming! -- Ruk | it wouldn't use me.

---

From: sla at umbra.UCSC.EDU (Steve Allen)
Date: 6 Aug 1993 17:24:21 GMT

In article <23sqr8INN5jf at darkstar.UCSC.EDU> sla at umbra.UCSC.EDU
(that was me) forgot that one of Alberto Accomazzi's best additions to
the original shell script was to create a man page.  Kindly
associate it with the shell script if you are keeping these.

.TH fitshead l "22 June 1993"
.IX fitshead
.SH NAME
fitshead - display the header of a FITS file
.SH SYNOPSIS
.B fitshead
[
.B -l
] [
.B -x
] [
.IR fitsfile \ ...
]
.SH DESCRIPTION
Displays the header of a FITS file.
If flag
.B \-x
is specified, any extensions that may be present in the
input file are displayed as well.
.SH OPTIONS
.PP
.TP
.B \-l
forces
.I fitshead
to tolerate illegal END cards in the header (these cases have been found in
files generated at Lick Observatory).
.PP
.TP
.B \-x
scans the file for any FITS extensions and, if found, displays the extension
header(s).
.SH "SEE ALSO"
dd(1), sed(1)
.SH AUTHOR
Steve Allen (sla at lick.ucsc.edu) 1992,1993
.br
Modified by Alberto Accomazzi (alberto at cfa.harvard.edu) 1993.
.\" Permission to use, copy, modify, and distribute this software and its
.\" documentation for any purpose and without fee is hereby granted, provided
.\" that the above copyright notice appear in all copies and that both that
.\" copyright notice and this permission notice appear in supporting
.\" documentation.  This software is provided "as is" without express or
.\" implied warranty.
_______________________________________________________________________________
Steve Allen          | That was the equation!         |   sla at lick.ucsc.edu
UCO/Lick Observatory | Existence!...Survival must     | If the UC were opining,
Santa Cruz, CA 95064 | cancel out programming! -- Ruk | it wouldn't use me.