#!/bin/sh
#
# From sla@umbra.UCSC.EDU Fri Aug  6 22:41:08 1993
# From: sla@umbra.UCSC.EDU (Steve Allen)
# Newsgroups: sci.astro.fits
# Subject: shell tools for FITS files, part II
# Date: 6 Aug 1993 05:39:52 GMT
# Organization: UCO/Lick Observatory
# NNTP-Posting-Host: umbra.ucsc.edu
# Summary: prints contents of FITS header cards
# Keywords: Bourne shell, Un*x,
# 
# 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.
# 
#       A little Cshell script which acts like cat.
#       Author: Steve Allen (sla@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@cfa.harvard.edu).
#       06/22/93        Modified to print only primary header and quit
#                       unless flag -x is specified
#                       Alberto Accomazzi (alberto@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@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.

