The routine NDF_OPEN is a general-purpose routine for accessing NDF data structures. It will perform the same tasks as NDF_FIND and NDF_PLACE but, although it is a little more complicated, it also offers some additional features. In particular, using NDF_OPEN to access an NDF is similar to using a Fortran OPEN statement to access a file, in that it allows you to specify whether you think the NDF already exists or not. It also allows you to specify an access mode.
If the fourth (STAT) argument to NDF_OPEN is set to 'OLD', the routine behaves like NDF_FIND, allowing you to access an existing NDF. For example:
CALL NDF_OPEN( DAT__ROOT, 'any_ndf', 'UPDATE', 'OLD', INDF, PLACE, STATUS )
would obtain `UPDATE' access to the specified NDF and return an identifier for it via the INDF argument (in this case the PLACE argument is not used and returns the value NDF__NOPL). An error would result if the NDF did not exist.
If the fourth argument is set to 'NEW', NDF_OPEN instead behaves like NDF_PLACE. A placeholder for the specified NDF is returned via the PLACE argument, and the INDF argument (which is not used in this case) returns the value NDF__NOID.
Finally, if its fourth argument is set to 'UNKNOWN', then NDF_OPEN first attempts to access an existing NDF data structure using the locator and name supplied. If it succeeds, an identifier for the NDF is returned via the INDF argument. However, if it fails because the NDF does not exist, it instead creates a new placeholder for it and returns this via the PLACE argument. You can tell which of these two possibilities occurred by examining the INDF and PLACE arguments on return - only one of these will differ from its ``null'' value (NDF__NOID or NDF__NOPL respectively).
A typical use of NDF_OPEN might be to access an existing NDF if it exists, or to create a new one if it does not, as follows:
CALL NDF_OPEN( LOC, 'CALIB.BAND_B', 'UPDATE', 'UNKNOWN',
: INDF, PLACE, STATUS )
IF ( PLACE .NE. NDF__NOPL ) THEN
CALL NDF_NEWP( '_INTEGER', 1, UBND, PLACE, INDF, STATUS )
END IF