To simplify the exchange of data between different applications packages, Starlink have released a set of standards for representing data within HDS. This is the Extensible N-Dimensional Data Format (NDF) - it is described in SGP/38. A library of subroutines (the NDF library, described in SUN/33) is provided for accessing these standard structures and will generally be used when writing applications.
Below is a simple example that calculates the mean value of the data in an NDF. For such data files the data will be found in a component of the file, called .DATA.
SUBROUTINE MEAN(STATUS)
IMPLICIT NONE
INTEGER STATUS
INCLUDE 'SAE_PAR'
INTEGER NELM ! Number of Data elements
CHARACTER*(DAT__SZLOC) LOC ! HDS locator
INTEGER PNTR ! Pointer to Data
REAL MN ! Mean value of data
* Start an NDF context
CALL NDF_BEGIN
* Get locator to parameter
CALL NDF_ASSOC('INPUT','READ',LOC,STATUS)
* Map the data array
CALL NDF_MAP(LOC,'DATA','_REAL','READ',PNTR,NELM,STATUS)
* If everything OK calculate mean value of data array and output it
IF (STATUS .EQ. SAI__OK) THEN
CALL MEAN_SUB(NELM,%VAL(PNTR),MN)
CALL MSG_SETR('MEAN',MN)
CALL MSG_OUT(' ','Mean Value of Array is ^MEAN',STATUS)
ENDIF
* End the NDF context
CALL NDF_END(STATUS)
END
SUBROUTINE MEAN_SUB(NELM,ARRAY,MEAN)
* Subroutine to calculate the mean value of the array
IMPLICIT NONE
INTEGER NELM
REAL ARRAY(NELM)
REAL MEAN
INTEGER I
MEAN = 0.0
DO I=1,NELM
MEAN = MEAN + ARRAY(I)
ENDDO
MEAN = MEAN / NELM
END
There are a number of points to note about this example:
INTERFACE MEAN
PARAMETER INPUT
TYPE NDF
POSITION 1
VPATH PROMPT
PPATH CURRENT
PROMPT 'NDF to calculate Mean Value from'
ENDPARAMETER
ENDINTERFACE
The above example shows how to handle the case where an NDF file is used for input. Where output to an NDF file is involved it is usually necessary to create a new HDS file when the application runs. This can be achieved using routine NDF_CREAT or NDF_CREP. For details of their usage, see SUN/33.
ICL The Interactive Command Language for ADAM