9 NDF extensions

 9.1 Example 11 – Reading an extension
 9.2 Example 12 – Creating a new extension

The NDF format is an example of the HDS (Hierarchical Data Structure) format. Essentially, this means that lots of different items of information can be put into the same file. For example, we have already seen how the Data and Variance arrays come as distinct pieces of information.

All NDFs have a number of standard components, many of which (but not all) we have dealt with in this book. HDS (and therefore NDF) files may also contain extensions. These may be so commonly used they are virtually standard (e.g. a FITS header), or be specific to a particular instrument or software package (e.g. the IRAS extension).

In this section, we deal with how to access and create extensions to NDF files.

9.1 Example 11 – Reading an extension

The following example reads in an IRAS extension:

         SUBROUTINE EXTEND(STATUS)
  *
  * This application looks for an IRAS extension to an NDF.
  * If it is present, it reads and prints the OFFSET value
  *
         INTEGER STATUS               ! Global Status
         INTEGER INDF                 ! NDF identifier
         INTEGER OFFSET               ! Item from the IRAS extension
         INCLUDE ’DAT_PAR’            ! Define DAT__SZLOC
         CHARACTER * (DAT__SZLOC) LOC ! Locator for the IRAS extension
         LOGICAL EXIST                ! TRUE if the IRAS extension exists
         INCLUDE ’SAE_PAR’            ! Define the SAE constants
  *
  * Begin the NDF context
  *
         CALL NDF_BEGIN
  *
  * Get the name of the NDF
  *
         CALL NDF_ASSOC(’IN’,’READ’,INDF,STATUS)
  *
  * Find out if the IRAS extension exists or not
  *
         CALL NDF_XSTAT(INDF,’IRAS’,EXIST,STATUS)
  *
  * If it does, print it to the screen. If not, finish up.
  *
         IF (EXIST) THEN
           CALL NDF_XLOC(INDF,’IRAS’,’READ’,LOC,STATUS)
           CALL CMP_GET0I(LOC,’OFFSET’,OFFSET,STATUS)
           WRITE (*,*) ’Offset = ’, OFFSET
  *
  * Annul the locator
  *
           CALL DAT_ANNUL(LOC,STATUS)
         ELSE
           WRITE (*,*) ’No IRAS extension exists in this file’
         ENDIF
  *
  * Tidy up
  *
         CALL NDF_END(STATUS)
         END

Interface file:

  interface EXTEND
    parameter IN
    prompt ’Input NDF’
    endparameter
  endinterface

Note that the call to CMP_GET0I should be replaced by CMP_GET0R for real numbers, CMP_GET0D for double precision numbers, CMP_GET0L for logical values, CMP_GET0C for character values.

9.2 Example 12 – Creating a new extension

In the following example, a code is used to place the temperature of the CCD chip used during the observations into a new extension. In practice, many more items could also be put there such as pixel scale, size, gain etc. These items can then be read and used by later applications as part of the data reduction process.

         SUBROUTINE EXTEND2(STATUS)
  *
  * This application puts a value for the CCD temperature into
  * an extension designed to hold information about the CCD’s
  * run time properties.
  *
         INTEGER INDF                 ! NDF identifier
         INTEGER STATUS               ! Global Status
         REAL TEMP                    ! CCD Temperature
         LOGICAL EXIST                ! TRUE if the extension exists
         INCLUDE ’DAT_PAR’            ! DAT constants
         CHARACTER * (DAT__SZLOC) LOC ! Extension Locator
         INCLUDE ’SAE_PAR’            ! SAE constants
  *
  * Begin the NDF context
  *
         CALL NDF_BEGIN
  *
  * Get the name of the NDF
  *
         CALL NDF_ASSOC(’IN’,’UPDATE’,INDF,STATUS)
  *
  * Find out if the CCD extension exists or not
  *
         CALL NDF_XSTAT(INDF,’CCD’,EXIST,STATUS)
         IF (.NOT. EXIST) THEN
  *
  * Create the new extension
  *
           CALL NDF_XNEW(INDF,’CCD’,’CCD_EXTENSION’,0,0,LOC,STATUS)
  *
  * If the temperature component doesn’t exist then make it
  *
           CALL CMP_MOD(LOC,’TEMPERATURE’,’_REAL’,0,0,STATUS)
  *
  * Get the _REAL value for the temperature
  *
           CALL PAR_GET0R(’TEMP’,TEMP,STATUS)
  *
  * Put the _REAL value into the extension
  *
           CALL CMP_PUT0R(LOC,’TEMPERATURE’,TEMP,STATUS)
  *
  * Annul the locator
  *
           CALL DAT_ANNUL(LOC,STATUS)
         ELSE
           WRITE (*,*) ’CCD extension already present’
         ENDIF
  *
  * Tidy up
  *
         CALL NDF_END(STATUS)
         END

Interface file:

  interface EXTEND2
  
    parameter IN
    prompt ’Name of NDF’
    endparameter
  
    parameter TEMP
    type _REAL
    prompt ’Temperature’
    endparameter
  
  endinterface