Processing math: 100%

3 ACCESSING HEADER INFORMATION

 3.1 Reading header items
 3.2 Writing header items

Most astronomical images have collections of numeric, character or logical values associated with them. Typically these consist of important calibration values, but they are also often used to describe the history or status of the data. Collections of such data, which are not actually part of the image array, are known as “header” information (this name derives from the fact that FITS1 stores these values at the beginning – head – of a file). IMG refers to a single piece of such information as a “header item” and a separate set of subroutines exists to read, write, copy and make enquiries about them.

3.1 Reading header items

This example (taken from a complete program called hdrread.f – see §2) shows how to read the value of a header item from an image associated with the parameter ’IN’:

  *  Read the header item.
        CALL HDR_IN( ’IN’, ’ ’, ’OBSERVER’, 1, VALUE, ISTAT )

The call to ??HDR_IN specifies the image by using its parameter name – ’IN’ (argument 1). If you have not previously accessed this image you will probably be prompted for its file name at this point.

The 2nd, blank argument, indicates that an “ordinary” FITS header item is required (there are other possible “sources” of header information which are described later – §4.2.2).

The 3rd argument ’OBSERVER’ specifies the name of the header item required and the 4th argument 1 indicates that you want the first occurrence of that item (just in case it occurs several times, which some items are allowed to do).

The 5th argument VALUE returns the header item value as a character string. If the header item you requested doesn’t exist, then VALUE is returned unchanged, so you may want to set it to a sensible value (say <unknown>) beforehand.

3.2 Writing header items

This example (taken from a complete program hdrwrite.f – see §2) shows how to write the value of a header item to an image associated with the parameter ’OUT’:

  *  Write the new header item.
        CALL HDR_OUT( ’OUT’, ’ ’, ’OBSERVER’, ’The observer’,   [1]
       :              ’Fred Bloggs’, ISTAT )
  
  *  Free the image.
        CALL IMG_FREE( ’OUT’, ISTAT )                           [2]

The following notes refer to the numbered statements:
(1)
The call to ??HDR_OUT specifies the image by using its parameter name – ’OUT’ (argument 1). If you have not previously accessed this image you will probably be prompted for its file name at this point. If you have already accessed the image then it should be either an output image or one accessed for modification, as you cannot write items to images accessed by ??x]]IMG_IN.

The 2nd, blank argument, indicates that an “ordinary” FITS header item is to be written.

The 3rd argument (’OBSERVER’) specifies the name of the header item and the 4th argument ’The observer’ is a comment to store with the item.

The 5th argument (’Fred Bloggs’) is the header item value.

(2)
The image is freed. If this wasn’t done, the new header item would be lost.

1FITS, the “Flexible Image Transport System” is the de facto standard for the interchange of astronomical data.