Reading Foreign WCS Information from a FITS Header

Having stored a set of FITS header cards in a FitsChanFitsChan and determined how the WCS information is encoded (§17.3), the next step is to read an AST ObjectObject from the FitsChan using astReadastRead. We must also remember to rewind the FitsChan first, if necessary, such as by clearing its CardCard attribute, which defaults to 1:


\begin{terminalv}
AstObject *wcsinfo;
\par
...
\par
astClear( fitschan, ''Card'' );
wcsinfo = astRead( fitschan );
\end{terminalv}

If the pointer returned by astRead is not equal to AST__NULL, then an Object has been read successfully. Otherwise, there was either no information to read or the choice of FITS encoding (§17.3) was inappropriate.

At this point you might like to indulge in a little data validation along the lines described in §15.6, for example:


\begin{terminalv}
if ( !strcmp( astGetC( wcsinfo, ''Class'' ), ''FrameSet'' ) ) ...
...FrameSet, so use it>
} else {
<something unexpected was read>
}
\end{terminalv}

If a foreign encoding has definitely been used, then the Object will automatically be a FrameSetFrameSet (§17.2), so this stage can be omitted. However, if the native encoding (§16.1) might have been employed, which is a possibility if you accept the FitsChan's default EncodingEncoding value, then any class of Object might have been read and a quick check would be worthwhile.

If you used astShowastShow (§4.4) to examine the FrameSet which results from reading our example FITS header (§17.3), you would find that its base FrameFrame describes the image's pixel coordinate system and that its current Frame is a SkyFrameSkyFrame representing galactic coordinates. These two Frames are inter-related by a MappingMapping (actually a CmpMapCmpMap) which incorporates the effects of various rotations, scalings and a “zenithal equal area” sky projection, so that each pixel of the FITS image is mapped on to a corresponding sky position in galactic coordinates.

Because this FrameSet may be used both as a Mapping (§13.6) and as a Frame (§13.8), it may be employed directly to perform many useful operations without any need to decompose it into its component parts. These include:

If the FrameSet contains other Frames (apart from the base and current Frames), then you would also have access to information about other coordinate systems associated with the image.