The ASSOC function associates an array structure with a file. It provides a basic method of random access input/output in IDL.
| Note |
| Note |
Result = ASSOC( Unit, Array_Structure [, Offset] [, /PACKED] )
Returns a value that when assigned to a variable, stores the association between an array structure and a file in an associated variable. This variable provides a means of mapping a file into vectors or arrays of a specified type and size.
The IDL file unit to associate with Array_Structure.
An expression of the data type and structure to be associated with Unit are taken from Array_Structure. The actual value of Array_Structure is not used.
The offset in the file to the start of the data in the file, in bytes.
When ASSOC is applied to structures, the default action is to map the actual definition of the structure for the current machine, including any holes required to properly align the fields. (IDL uses the same rules for laying out structures as the C language). If the PACKED keyword is specified, I/O using the resulting variable instead works in the same manner as READU and WRITEU, and data is moved one field at a time and there are no alignment gaps between the fields.
Suppose that the file images.dat holds 5 images as 256-element by 256-element arrays of bytes. Open the file for reading and create an associated variable by entering:
OPENR, 1, 'images.dat' ;Open the file as file unit 1. A = ASSOC(1, BYTARR(256, 256)) ;Make an associated variable.
Now A[0] corresponds to the first image in the file, A[1] is the second element, etc. To display the first image in the file, you could enter:
TV, A[0]
The data for the first image is read and then displayed. Note that the data associated with A[0] is not held in memory. It is read in every time there is a reference to A[0]. To store the image in the memory-resident array B, you could enter:
B = A[0]
| Note |
Introduced: Original
OPEN, READU, Associated Input/Output.