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:
INTEGER FITSCHAN1, WCSINFO1
CHARACTER * ( 20 ) ENCODE
...
* Create an input FitsChan and fill it with FITS header cards.
FITSCHAN1 = AST_FITSCHAN( AST_NULL, AST_NULL, ' ', STATUS )
DO 1 ICARD = 1, NCARD
CALL AST_PUTFITS( FITSCHAN1, CARDS( ICARD ), .FALSE., STATUS )
1 CONTINUE
* Note which encoding has been used for the WCS information.
ENCODE = AST_GETC( FITSCHAN1, 'Encoding', STATUS );
* Rewind the input FitsChan and read the WCS information from it.
CALL AST_CLEAR( FITSCHAN1, 'Card', STATUS )
WCSINFO1 = AST_READ( FITSCHAN1, STATUS )
Note how we have added an enquiry to determine how the WCS information is encoded in the input FITS cards, storing the resulting string in the ENCODE variable. This must be done before actually reading the WCS calibration.
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:
INTEGER FITSCHAN2, JUNK, 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 WCS calibration.
FITSCHAN2 = AST_COPY( FITSCHAN1, STATUS )
* 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 = AST_FITSCHAN( AST_NULL, AST_NULL, ' ', STATUS )
* 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.
CALL AST_SET( FITSCHAN2, 'Card=1, Encoding=' // ENCODE, STATUS )
IF ( AST_WRITE( FITSCHAN2, WCSINFO2, STATUS ) .EQ. 0 ) THEN
* If this didn't work (the WCS FrameSet has become too complex), then
* use the native AST encoding instead.
CALL AST_SETC( FITSCHAN2, 'Encoding', 'NATIVE', STATUS );
JUNK = AST_WRITE( FITSCHAN2, WCSINFO2, STATUS );
END IF
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:
CHARACTER * ( 80 ) CARD
...
CALL AST_CLEAR( FITSCHAN2, 'Card', STATUS )
5 CONTINUE
IF ( AST_FINDFITS( FITSCHAN2, '%f', CARD, .TRUE., STATUS ) ) THEN
WRITE ( *, '(A)' ) CARD
GO TO 5
END IF
Here, we have simply written each card to the standard output unit, but you would obviously replace this with a subroutine call 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 routine
NDF_PTWCS--see SUN/33. The
whole process can probably be encapsulated in a similar way for most
other 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