If you have modified the WCS calibration associated with a dataset,
such as in the example above (), then you
will need to write the modified version out along with any new data.
In the same way as when reading a WCS calibration
(), how you do this will depend on your data
system, but we will assume that you wish to generate a set of FITS
header cards that can be stored with the data. You should usually make
preparations for doing this when you first read the WCS calibration
from your input dataset by modifying the example given in
as follows:
AstFitsChan *fitschan1; AstFrameSet *wcsinfo1; const char *encode; ... /* Create an input FitsChan and fill it with FITS header cards. */ fitschan1 = astFitsChan( NULL, NULL, "" ); for ( icard = 0; icard < ncard; icard++ ) astPutFits( fitschan1, cards[ icard ], 0 ); /* Note which encoding has been used for the WCS information. */ encode = astGetC( fitschan1, "Encoding" ); /* Rewind the input FitsChan and read the WCS information from it. */ astClear( fitschan1, "Card" ); wcsinfo1 = astRead( fitschan1 );
Note how we have added an enquiry to determine how the WCS information is encoded in the input FITS cards, storing a pointer to the resulting string in the ``encode'' variable. This must be done before actually reading the WCS calibration.
(N.B. If you will be making extensive use of astGetC in your program, then you should allocate a buffer and make a copy of this string, because the pointer returned by astGetC will only remain valid for 50 invocations of the function, and you will need to use the Encoding value again later on.)
Once you have produced a modified WCS calibration for the output
dataset (e.g. ), in the form of a
FrameSet identified by the pointer ``wcsinfo2'', you can produce a new
FitsChan containing the output FITS header cards as follows:
AstFitsChan *fitschan2; AstFrameSet *wcsinfo2; ... /* Make a copy of the input FitsChan, AFTER the WCS information has been read from it. This will propagate all the input FITS header cards, apart from those describing the input WCS calibration. */ fitschan2 = astCopy( fitschan1 ); /* If necessary, make modifications to the cards in "fitschan2" (e.g. you might need to change NAXIS1, NAXIS2, etc., to account for a change in image size). You probably only need to do this if your data system does not provide these facilities itself. */ <details not shown - see below> /* Alternatively, if your data system handles the propagation of FITS header cards to the output dataset for you, then simply create an empty FitsChan to contain the output WCS information alone. fitschan2 = astFitsChan( NULL, NULL, "" ); */ /* Rewind the new FitsChan (if necessary) and attempt to write the output WCS information to it using the same encoding method as the input dataset. */ astSet( fitschan2, "Card=1, Encoding=%s", encode ); if ( !astWrite( fitschan2, wcsinfo2 ) ) { /* If this didn't work (the WCS FrameSet has become too complex), then use the native AST encoding instead. */ astSet( fitschan2, "Encoding=NATIVE" ); (void) astWrite( fitschan2, wcsinfo2 ); }
For details of how to modify the contents of the output FitsChan in
other ways, such as by adding, over-writing or deleting header cards,
see ,
and
.
Once you have assembled the output FITS cards, you may retrieve them from the FitsChan that contains them as follows:
#include <stdio.h> char card[ 81 ]; ... astClear( fitschan2, "Card" ); while ( astFindFits( fitschan2, "%f", card, 1 ) ) (void) printf( "%s\n", card );
Here, we have simply written each card to the standard output stream, but you would obviously replace this with a function invocation to store the cards in your output dataset.
For data systems that do not use FITS header cards, a different
approach may be needed, possibly involving use of a Channel
() rather than a FitsChan. In the case of the
Starlink NDF data format, for example, all of the above may be
replaced by a single call to the function
ndfPtwcs--see SUN/33. The
whole process can probably be encapsulated in a similar way for most
data systems, whether they use FITS header cards or not.
For an overview of how to propagate WCS information through data
processing steps, see . For more
information about writing WCS information to FitsChans, see
and
. For
information about the options for encoding WCS information in FITS
header cards, see
,
, and the description of the Encoding
attribute in
. For a complete
understanding of FitsChans and their use with FITS header cards, you
should read
and
.
AST A Library for Handling World Coordinate Systems in Astronomy