next up previous
Next: Accessing Sub-structures Within Foreign Data Files
Up: SETTING UP FOR FORMAT CONVERSION
Previous: Rules and Regulations

Defining Conversion Commands   

For each foreign format which appears in the NDF_FORMATS_IN list, you should also provide commands to perform the necessary format conversions to and/or from the native NDF format. These commands are also defined by means of environment variables.

Taking the FITS format (above) as an example, this means defining up to two commands - one for converting from FITS format to NDF format and the other for converting back again, such as the following:

setenv NDF_FROM_FITS 'fitsin in=^dir^name^type out=^ndf'
setenv NDF_TO_FITS   'fitsout in=^ndf out=^dir^name^type'

Here, the names of two environment variables have been formed by prefixing `NDF_FROM_' and `NDF_TO_' to the foreign format name (in upper case) and each of these variables has been set to contain a command which performs the appropriate format conversion (in this case by invoking two conversion utilities called ``fitsin'' and ``fitsout'', which we assume to exist).

Ideally, you would define both of these commands. However, if you only want to support conversion in one direction, then it is quite acceptable to omit either of them. The commands are only accessed when the occasion to use them arises, so no error will result if they are omitted but never used.

When needed, the conversion commands you define will be interpreted (in a separate process) by a command interpreter appropriate to the host operating system.[*] The commands are actually invoked by passing them to the C run time library ``system'' function, and they may therefore use any components of the environment which are inherited through that interface. Typically this means that such things as the default directory and environment variables are available to these commands.

Before the commands are invoked, the NDF library will perform token substitution on them, in order to insert the names of the actual datasets to be processed. The tokens used to represent these datasets are, in fact, message tokens - identical to those used by the MERS and EMS libraries (SUN/104 and SSN/4) and commonly used when reporting errors and other messages from within applications. They are used in conversion commands in exactly the same way (they appear in the example commands above prefixed with the `^' substitution character), and the NDF library defines a set of them for this purpose, as follows:

Token Value
dir Directory in which the foreign file resides
name Foreign file name (without directory or extension)
type Foreign file extension (with leading `.')
vers Foreign file version number (blank if not supported)
fxs Foreign extension specifier (see §[*] )
fxscl Clean version of fxs (all non-alphanumeric characters replaced by underscores)
fmt Foreign format name (upper case)
ndf Full name of the native NDF format copy of the dataset

Note that the EMS library, which performs substitution of these tokens, imposes a limit of 200 characters on the resulting command. If long file names are in use this may present a problem unless the conversion command itself is short. Fortunately, this can always be arranged by wrapping it up in a simple script if necessary.



next up previous
Next: Accessing Sub-structures Within Foreign Data Files
Up: SETTING UP FOR FORMAT CONVERSION
Previous: Rules and Regulations


Starlink System Note 20
R.F.Warren-Smith & D.S.Berry
17th July 2000
E-mail:ussc@star.rl.ac.uk

Copyright © 2000 Council for the Central Laboratory of the Research Councils