[fitsbits] unix raw fits view

Steve Allen sla at ucolick.org
Mon Oct 7 23:53:03 EDT 2002


On Tue 2002-10-08T00:23:49 +0000, mike333_n at yahoo.com hath writ:
> there is a solaris commad to cat fits files to view header information,...,bytes,..
> what is it, anyone?.

Typically I just use "cat", or "more", or "less" in an 80-character wide
terminal, but to go one step farther you might

dd cbs=80 conv=unblock if=thefile.fits

which lets you see the primary HDU just fine.
Alternatively, see the entire attached shell script for more processing.

To see HDUs beyond the primary HDU is a bit trickier because, ideally,
the unix file utility wants to skip past the subsequent data units
and see only the headers.

--
Steve Allen          UCO/Lick Observatory       Santa Cruz, CA 95064
sla at ucolick.org      Voice: +1 831 459 3046     http://www.ucolick.org/~sla
PGP: 1024/E46978C5   F6 78 D1 10 62 94 8F 2E    49 89 0E FE 26 B4 14 93
-------------- next part --------------
#! /bin/sh
#       A little bourne shell script which acts like fgrep for FITS keywords.
#       It only looks in the primary header; extensions are ignored.
#       Author: Steve Allen <sla at ucolick.org> 1993
#       It takes as input a FITS file, and prints out the FITS key
#       values associated with the given FITS keyword.
#       Could be enhanced to look at XTENSIONs, and to optionally print
#       the keyword itself and/or the comment field, but by that time
#       you should seriously be thinking of using perl, Tcl, python,
#       or some other more robust scripting language.
#
if [ $# -lt 1 ]; then
    echo "Usage: $0 FITSkeyword [FITSfile ...]" >&2
    exit 1
fi

# a legal FITS key must be 8 characters long with explicit trailing spaces
# the awk script here ensures that arrangement
# find a quoted string (but not one which contains quotes!)
seds=`echo $1 | awk '{printf("s&^%-8.8s= *%c(%c[^%c]%c%c)&%c1&p",$1,92,39,39,39,92,92)}'`
#echo seds is $seds
# find a value followed by a comment
sedc=`echo $1 | awk '{printf("s&^%-8.8s= *%c(.*%c)/.*&%c1&p",$1,92,92,92)}'`
#echo sedc is $sedc
# find a value not followed by a comment
sedv=`echo $1 | awk '{printf("s&^%-8.8s= *%c(.*%c)&%c1&p",$1,92,92,92)}'`
#echo sedv is $sedv
shift                   # throw away the FITS keyword in the first argument
sedq='/^END */q'        # detect end of primary fits header (even if from Lick)

if [ -z "$*" ] ; then
    # act like a pipeline element
    ( dd conv=unblock cbs=80  | sed -n -e "$sedq" -e "$seds" -e t -e "$sedc" -e t -e "$sedv" ) 2>/dev/null
else
    for file in $* ; do
	keyval=`dd cbs=80 conv=unblock if=$file 2>/dev/null | \
	sed -n -e "$sedq" -e "$seds" -e t -e "$sedc" -e t -e "$sedv"`
	if [ ! -z "$keyval" ]; then
	    if [ $# -gt 1 ]; then
		echo $file": "$keyval
	    else
		echo $keyval
	    fi
	fi
    done
fi


More information about the fitsbits mailing list