next up previous
Next: How to make a simple GUI
Up: Writing csh scripts
Previous: My file has been converted to NDF. How do I access FITS header keywords?

How do I create an NDF file from an ASCII file?

If it possible to build an NDF file from a flat ASCII text file using the CONVERT application ascii2ndf and then use KAPPA and DATACUBE applications to modify the structure and contents of the NDF extensions until it has the correct specifications.

   # Create a basic NDF from an ASCII file.
   ascii2ndf in=${datfile} out=${tmpfile} shape=[${dims[1]},${dims[2]}] \
             maxlen=1024 type='_double'

   # Set bad pixels to the magic value VAL__BADD.
   setmagic in=${tmpfile} out=${outfile} repval=-9999.99
   rm -f "${tmpfile}.sdf"

   # Set the origin of the output file.
   setorigin ndf=${outfile} origin=[${lbnd[1]},${lbnd[2]}]

   # Attach the variance array.
   ascii2ndf in=${varfile} comp="Variance" out=${outfile} \
                shape=[${dims[1]},${dims[2]}] maxlen=1024 type='_double'

   # We have a similar shaped NDF from which we want to clone the WCS
   # and AXIS information and attach to our newly created ${outfile}.

   # Clone the AXIS information from an similar shaped NDF.
   setaxis ndf=${outfile} like=${likefile}

   # Clone the WCS information.  This will be done incorrectly if the
   # AXIS structures does not exits before the WCS extension is cloned
   wcscopy ndf=${outfile} like=${likefile}

Here we take a flat ASCII data file $datfile and create an NDF of dimensions $dims[1] $\times$ $dims[2], with data type _DOUBLE, using ascii2ndf. We then cal upon setmagic to flag all pixels that have the value $-9999.99$ in the NDF with the standard bad `magic' value, in this case VAL__BADD. setorigin sets the pixel origin to ($lbnd[1],$lbnd[2]). We then use ascii2ndf again to attach a variance array, from the ASCII flat file $varfile, to our newly created NDF.

For both invocations of ascii2ndf we make use of the MAXLEN parameter. This is the maximum record length (in bytes) of the records within the input text file, the default value being 512. If you attempt to generate an NDF from a file where many of the entries are double-precision numbers, it might be necessary to set this value higher than the default value otherwise some records (lines) may become truncated leading to `stepping' effects within your output NDF.

After including our variance array, we attach AXIS information using the setaxis application, and incorporate WCS information with wcscopy application, both from KAPPA. We clone this information from an NDF whose world co-ordinate information is the same as our newly created NDF. If we wanted to avoid copying the AXIS information (or if the NDF from where we were cloning had no WCS information) we could make use of the wcscopy command's TR parameter to provide a transformation matrix.

Alternatively, we could make use of the KAPPA setaxis command to create an AXIS structure within the NDF being cloned obtained from its existing WCS extension via the $likefile parameter. setaxis should be invoked for each axis. Then we copying the AXIS and WCS structures to our new NDF.

   # Create an AXIS structure from a WCS extension
   setaxis ndf=${likefile} mode=wcs comp=Centre dim=1
   setaxis ndf=${likefile} mode=wcs comp=Centre dim=2

   # Copy the AXIS structure to our new NDF.
   setaxis ndf=${outfile} like=${likefile}

   # Copy the WCS extension to our new NDF
   wcscopy ndf=${outfile} like=${likefile}

The above usage of setaxis is sometimes needed when including non-WCS compliant legacy applications, such as fitgauss, in scripts, as these legacy tasks do recognise the AXIS structure.

next up previous
Next: How to make a simple GUI
Up: Writing csh scripts
Previous: My file has been converted to NDF. How do I access FITS header keywords?

The IFU Data-Product Cookbook
Starlink Cookbook 16
A. Allan & Malcolm J. Currie
2008 July 4

Copyright © 2014 Science and Technology Facilities Council