FITSIO Home
Next: 2.7 READIMAGE - read
Up: 2. Example FITSIO Programs
Previous: 2.5 SELECTROWS - copy
  Contents
This subroutine will read and print out all the header keywords in every
extension of a FITS file.
- The STATUS parameter must always be initialized. See the WRITEIMAGE
program for a more detailed discussion.
- FTGIOU allocates a logical unit number for use when opening a file.
See the WRITEIMAGE program for a more detailed discussion.
- The FITS file is opened with the READWRITE parameter set
= 0 to just give read access to the file. Set it equal to 1 if one
needs read and write access to the FITS file. The returned BLOCKSIZE
parameter gives the size of each logical record, but
this is only relevant on machines such as VAX/VMS which have a record
oriented file system.
- The FTGHSP subroutine returns the number of existing keywords in the
current header data unit (CHDU), not counting the required END keyword,
and also returns the number of blank records currently available for
writing more keywords. FITSIO will automatically add more space for
keywords if necessary so programmers generally do not have to be
concerned about the amount of free space in the header.
- The FTGREC routine returns the contents of the particular header
keyword specified by the second parameter. This do-loop prints out
every keyword record in the current HDU.
- The FTMRHD subroutine attempts to move to the next HDU, as specified by
the second parameter. This subroutine moves by a relative number of
HDUs from the current HDU. The related FTMAHD routine may be used to
move to an absolute HDU number in the FITS file. If the end-of-file is
encountered when trying to move to the specified extension, then a
status = 107 is returned.
- If the program reachs this branch of the IF...ELSEIF block,
then the previous attempt to move to the next FITS extension was
successful.
- This branch of the IF...ELSEIF block is reached whenever the end-of-file
is detected.
- The FITS file must always be closed before exiting the program.
Any unit numbers allocated with FTGIOU must be freed with FTFIOU.
- PRINTERROR is a general routine to print out error messages and is
described later in the Utilities section of this cookbook.
subroutine readheader
C Print out all the header keywords in all extensions of a FITS file
integer status,unit,readwrite,blocksize,nkeys,nspace,hdutype,i
character filename*80,record*80
1 status=0
C Get an unused Logical Unit Number to use to open the FITS file
2 call ftgiou(unit,status)
C name of FITS file
filename='ATESTFILEZ.FITS'
C open the FITS file, with read-only access
readwrite=0
3 call ftopen(unit,filename,readwrite,blocksize,status)
100 continue
C Determine the number of keywords in the header
4 call ftghsp(unit,nkeys,nspace,status)
C Read each 80-character keyword record, and print it out
do i = 1, nkeys
5 call ftgrec(unit,i,record,status)
print *,record
end do
C Print out and END record, and a blank line to mark the end of the header
if (status .eq. 0)then
print *,'END'
print *,' '
end if
C try moving to the next extension in the FITS file, if it exists
6 call ftmrhd(unit,1,hdutype,status)
if (status .eq. 0)then
C success, so loop back and print out keywords in this extension
7 go to 100
else if (status .eq. 107)then
C hit end of file, so quit
8 print *,'***** END OF FILE *****'
status=0
call ftcmsg
end if
C close the file, free the unit number, and exit
9 call ftclos(unit, status)
call ftfiou(unit, status)
C check for any error, and if so print out error messages
10 if (status .gt. 0)call printerror(status)
end
FITSIO Home
Next: 2.7 READIMAGE - read
Up: 2. Example FITSIO Programs
Previous: 2.5 SELECTROWS - copy
  Contents