Appendix B
Converting File Formats

 B.1 Converting a FITS file to NDF
 B.2 Converting an NDF file to FITS

B.1 Converting a FITS file to NDF

A FITS file can be converted to NDF using the Starlink package Convert. The convert instruction sets up the definitions for this package and only needs to be entered once,

  % convert

the relevant one here being fits2ndf.

  % fits2ndf file.fits file.sdf

Note that the .sdf file extension NDF may be omitted to save typing.

Unless your FITS file is from a recognised source, fits2ndf puts the various FITS extensions into NDF extensions called FITS_EXT_ < n >, where n counts from one for the first FITS extension. These are located in the top-level MORE component of the NDF. If one of these is the array you want—it should be an NDF too—it will be easier to handle if you copy out of the NDF extension to its own NDF.

  % ndfcopy in=file.more.fits_ext_1 out=file_data

If there is a variance array stored in another extension that you want to attach to your new NDF, a command like the following will do that.

  % setvar ndf=file_data from=file.more.fits_ext_2

fits2ndf does offer a way of mapping FITS extensions to familiar NDF array components DATA, VARIANCE, and QUALITY through the EXTABLE file, avoiding the ndfcopy and possible setvar steps.

B.2 Converting an NDF file to FITS

The Convert package can also be used to convert an NDF file to FITS format.

  % convert
  % ndf2fits file file.fits

There are options to control whether or not to export all of the NDF extensions (PROEXTS) and history records (PROHIS), and whether or not to merge the contents of the FITS airlock (PROFITS).

For historical reasons the specific set of headers encoding the world co-ordinate system varies from package to package. There is a parameter to select the appropriate encoding for the destination of the FITS file. A common one in the submillimetre world is the Class package used for spectroscopic reductions.

  % ndf2fits ga20091011_37_1_reduced \* encoding=fits-class

This will create a ga20091011_37_1_reduced.fit file with the Class-style of WCS headers.