3 Automatic Format Conversion with the NDF Library

 3.1 The Default Conversion Commands

SSN/20 describes a system incorporated into the NDF library routines which enables applications written to read or write NDFs to handle any arbitrary ‘foreign’ format for which a conversion utility can be defined. The system operates via environment variables which define the set of permitted conversions and the commands required to do them.

3.1 The Default Conversion Commands

Convert startup will define defaults for the NDF-conversion environment variables which permit automatic conversion of files in the formats handled by Convert (except for AST, IRCAM, PGM. SPECX and FITS tapes). It also allows data compression.

The list of format names and associated filename extensions defined by Convert is set out in Table 1—the filename extensions tell the system which format the file is in. For the unformatted and ASCII conversions the format names and extensions are somewhat arbitrary. This list will nullify any existing list so private conversions must be added after Convert startup.

For the unformatted and ASCII conversions the format names and extensions are somewhat arbitrary. The FITS and STREAM formats have synonym file extensions for the conversion to NDF. The standard file extension is required for the conversion to the foreign format.

Format Extension




FITS .fit

.fits .fts .FITS .FIT .lilo .lihi .silo .sihi .mxlo .mxhi .rilo .rihi .vdlo .vdhi


Figaro (Version 2) DST
IRAF .imh



Unformatted direct-access or stream

Unformatted with FITS header
UNF0 .dat

Unformatted without FITS header
ASCII .asc

ASCII with FITS header
TEXT .txt

ASCII without FITS header
GIF .gif

Graphics Interchange Format
TIFF .tif

Tag Image File Format
GASP .hdr


Compressed NDF
GZIP .sdf.gz

gzip compressed NDF

Table 1: Defined Formats and Extensions

Table 2 lists the utilities used to perform the conversions. In general the default parameter values are used—non-default parameters (other than the input and output filenames) are listed in the table.

FORMAT In/out Utility Non-default parameters Variable

out NDF2FITS bitpix=-1 proexts=t
out NDF2DST ×
IRAF in ??
STREAM in DA2NDF noperec=!
out NDF2DA
UNFORMATTED in UNF2NDF fits=t noperec=!
out NDF2UNF fits=t
UNF0 in UNF2NDF fits=f noperec=!
out NDF2UNF fits=f
out NDF2ASCII fits=t reclen=80
TEXT in ASCII2NDF fits=f
out NDF2ASCII fits=f reclen=80
out NDF2GIF ×
out NDF2TIFF ×
out NDF2GASP fillbad=0
COMPRESSED in uncompress ×
out compress ×
GZIP in gzip ×
out gunzip ×

Table 2: Conversion Commands.

Table 2 also contains a column headed ‘Variable’. Most of the command lines issued to do the automatic conversion will include the translation of an environment variable named NDF_FROM_fmt_PARS or NDF_TO_fmt_PARS as appropriate (where fmt is the format name). This may be used to give additional parameters to the command if you do not want to define a completely new command for yourself.

Where the ‘Variable’ column contains a tick, the variable must be used to supply the SHAPE parameter; where it contains a cross, additional parameters cannot be specified.

For example, suppose application rdndf uses the NDF library to read one NDF (named by the first parameter) and write another (named by the second parameter). This application could be made to read a TEXT file (data.txt) containing the required values for a 50 × 10 data array, and write its results as a FITS file (output.fit) as follows:

  % convert
  CONVERT commands are now available -- (Version 1.4, 2001 November)
  Defaults for automatic NDF conversion are set.
  Type conhelp for help on CONVERT commands.
  Type "showme sun55" to browse the hypertext documentation.
  % setenv NDF_FROM_TEXT_PARS ’SHAPE=[50,10]’
  % rdndf data.txt output.fit

The order of the formats in the tables also defines a search path. If you omit the file extension, the system will search for an NDF of that name. If that is absent, it will try a .fit FITS file. If neither are present it tries an IRAF file, and so on. The recognised formats and their order is defined through the environment variable NDF_FORMATS_IN. The shell convert startup defines NDF_FORMATS_IN as given below.


but from ICL the CONVERT command does not define the synonyms due to a limitation of ICL. Thus NDF_FORMATS_IN is defined to be the following.


When creating an output file, there is a similar list of recognised formats. The Convert startup procedures define NDF_FORMATS_OUT as follows.


The leading dot indicates that if you omit the file extension, the output file will be an NDF.

There are some examples of the automatic system in action and use of NDF_FORMATS_IN and NDF_FORMATS_OUT in SUN/95, Section 15.1.