This section presents a format conversion routine – an NDF is created from data in a text file. Only portions of the program are reproduced below; the full source code and interface file are contained in ADAM_EXAMPLES:OUTNDF.FOR and OUTNDF.IFL. (The part of the program which reads the input text file is very similar to the code used to illustrate the use of the FIO package in Section 9.)
A new NDF is created with the call:
where, PARAM is the ADAM parameter used to get the name of the NDF; TYPE is the data type required for the main data array, NDIM is the number of dimensions for the main data array, LBND and UBND are integer arrays containing the lower and upper pixel bounds respectively as described below, NDF contains the NDF identifier allocated, and STATUS is the global status.
The arrays LBND and UBND require a little explanation. Just like a Fortran array, an NDF may have dimensions in which the array index begins with a number other than one. The shape of an NDF is completely specified by the number of dimensions and the lower and upper pixel bound of each dimension. For example (2:6, 0:100) describes a 2-D array with pixel indices ranging from to 6 in the first dimension and 0 to 100 in the second. An NDF with this shape could be created by calling NDF_CREAT with NDIM, LBND, LBND, UBND and UBND. In the example below, the lower pixel index bound is simply set to one.
The program OUTNDF reads a text file with the format shown below:
That is, a title on the first line, the number of data elements on the second, followed by successive pairs of axis and data values.
In OUTNDF.FOR the title of the NDF and the number of data elements are read into TITLE and NELM respectively. The program only deals with 1-d data so the number of dimensions, NDIM, is set to one. The lower bound of the main data array is set to one, and the upper bound is set to NELM. An NDF is then created with the call to NDF_CREAT as shown below.
The title read from the text file is used to set the NDF title. Note that the main data and axis arrays are not read in the main subroutine OUTNDF – this is to avoid the necessity of declaring arrays to accommodate them. Instead the arrays are mapped for ’WRITE’ in the output NDF and the dynamically allocated space is used in the subroutine GTDATA to read in the arrays from the text file.
The code which creates the output NDF is reproduced below:
And the subroutine which reads the data…
The program OUTNDF can be tested with the data file SATURN.DAT in ADAM_EXAMPLES and can easily be adapted to deal with other data formats as required.