Identifying Foreign Encodings on Input

Let us now examine the practicalities of extracting WCS information from a set of FITS header cards which have been written by some other software system. We will pretend that our program does not know which encoding has been used for the WCS information and must discover this for itself. In order to have a concrete example, however, we will use the following set of cards. These use the FITS-AIPS encoding and contain a typical mix of other FITS cards which are irrelevant to the WCS information in which we are interested:


\begin{terminalv}
SIMPLE = T / Written by IDL: 30-Jul-1997 05:35:42.00
BITPIX = ...
...DATE-END= '25/09/90' / date of final data represented (dd/mm/yy)
\end{terminalv}

The first step is to create a FitsChanFitsChan and insert these cards into it. If “cards” is an array of pointers to character strings holding the header cards and “ncards” is the number of cards, this could be done as follows:


\begin{terminalv}
...

Note that we have not initialised the EncodingEncoding attribute of the FitsChan as we did in §16.3 when we wanted to use the native encoding. This is because we are pretending not to know which encoding to use and want AST to determine this for us. By leaving the Encoding attribute un-set, its default value will adjust to whichever encoding AST considers to be most appropriate, according to the FITS header cards present. For details of how this choice is made, see the description of the Encoding attribute in Appendix C.

This approach has the obvious advantages of making our program simpler and more flexible and of freeing us from having to know about the different encodings available. As a bonus, it also means that the program will be able to read any new encodings that AST may support in future, without needing to be changed.

At this point, we could enquire the default value of the Encoding attribute, which indicates which encoding AST intends to use, as follows:


\begin{terminalv}
const char *encode;
\par
...
\par
encode = astGetC( fitschan, ''Encoding'' );
\end{terminalv}

The result of this enquiry would be the string “FITS-AIPS”. Note that we could also have set the FitsChan's Encoding attribute explicitly, such as when creating it:


\begin{terminalv}
fitschan = astFitsChan( NULL, NULL, ''Encoding=FITS-AIPS'' );
\end{terminalv}

If we tried to read information using this encoding (§17.4), but failed, we could then change the encoding and try again. This would allow our program to take control of how the optimum choice of encoding is arrived at. However, it would also involve using explicit knowledge of the encodings available and this is best avoided if possible.