##
Finding and Changing Cards in a FitsChan

You can search for, and retrieve, particular cards in a FitsChanFitsChan by keyword, using the function astFindFitsastFindFits. This performs a search, starting at the current card, until it finds a card whose keyword matches the template you supply, or the end-of-file is reached.

If a suitable card is found, astFindFits optionally returns the card's contents and then sets the FitsChan's CardCard attribute either to identify the card found, or the one following it. The way you want the Card attribute to be set is indicated by the final boolean (int) argument to astFindFits. A value of one is returned to indicate success. If a suitable card cannot be found, astFindFits returns a value of zero to indicate failure and sets the FitsChan's Card attribute to the end-of-file.

Requesting that the Card attribute be set to indicate the card that astFindFits finds is useful if you want to replace that card with a new one, as in this example:

263#263

Here, astFindFits is used to search for a card with the keyword AIRMASS, with a NULL pointer being given to indicate that we do not want the card's contents returned. If the card is found, astPutFitsastPutFits then overwrites it with a new card. Otherwise, the Card attribute ends up pointing at the end-of-file and the new card is simply appended to the end of the FitsChan.

A similar approach can be used to delete selected cards from a FitsChan using astDelFitsastDelFits, which deletes the current card:

264#264

This deletes the first card, if any, with the BSCALE keyword.

Requesting that astFindFits increments the Card attribute to identify the card following the one found is more useful when writing loops. For example, the following loop extracts each card whose keyword matches the template “CD%6d” (that is, “CD” followed by six decimal digits):

265#265

For further details of keyword templates, see the description of astFindFits in Appendix B.