next up previous
Next: Using Foreign FITS Encodings
Up: Storing AST Objects in FITS Headers (FitsChans)
Previous: Finding and Changing Cards in a FitsChan

Source and Sink Routines for FitsChans  

The use of source and sink routines with a FitsChan is optional. This is because you can always arrange to explicitly fill a FitsChan with FITS cards ([*]) and you can also extract any cards that remain and write them out yourself ([*]) before you delete the FitsChan.

If you choose to use these routines, however, they behave in a very similar manner to those used by a Channel ([*] and [*]). You supply these routines, as arguments to the constructor function AST_FITSCHAN when you create the FitsChan ([*]). The source routine is invoked implicitly at this point to fill the FitsChan with FITS cards and the FitsChan is then rewound, so that the first card becomes current. The sink routine is automatically invoked later, when the FitsChan is deleted, in order to write out any cards that remain in it.

The only real difference between the source and sink routines for a FitsChan and a basic Channel is that FITS cards are limited in length to 80 characters, so the choice of buffer size is simplified. This affects the way the card contents are passed, so the routines themselves are slightly different. The following is therefore the FitsChan equivalent of the Channel SOURCE routine given in [*]:

      INTEGER FUNCTION FITSSOURCE( CARD, STATUS )
      CHARACTER * ( 80 ) CARD
      INTEGER STATUS

      READ( 1, '(A)', END = 99 ) CARD
      FITSSOURCE = 1
      RETURN

 99   FITSSOURCE = 0
      END

Here, the FITS card contents are returned via the CARD argument (the AST_PUTLINE routine should not be used) and the function returns 1 to indicate that a card has been read. A value of zero is returned if there are no more cards to read.

The sink routine for a FitsChan is also a little different (c.f. the SINK routine in [*]), as follows:

      SUBROUTINE FITSSINK( CARD, STATUS )
      CHARACTER * ( 80 ) CARD
      INTEGER STATUS

      WRITE( 2, '(A)' ) CARD

      END

The contents of the FITS card being written are passed via the CARD argument (the AST_GETLINE routine should not be used).

Of course, both of these examples assume that you are accessing text files. If this is not the case, then appropriate changes to the I/O statements would be needed. The details obviously depend on the format of the file you are handling, which need not necessarily be a true FITS file.



next up previous
Next: Using Foreign FITS Encodings
Up: Storing AST Objects in FITS Headers (FitsChans)
Previous: Finding and Changing Cards in a FitsChan

AST A Library for Handling World Coordinate Systems in Astronomy
Starlink User Note 210
R.F. Warren-Smith & D.S. Berry
30th April 2003
E-mail:ussc@star.rl.ac.uk

Copyright (C) 2003 Central Laboratory of the Research Councils