The ASSOC function associates an array structure with a file. It provides a basic method of random access input/output in IDL. An associated variable , which stores this association, is created by assigning the result of ASSOC to a variable. This variable provides a means of mapping a file into vectors or arrays of a specified type and size.

Calling Sequence

Result = ASSOC( Unit, Array_Structure [, Offset] )



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. For stream files, and RMS (VMS) block mode files, this offset is given in bytes. For RMS record-oriented files, the offset is specified in records. Offset is useful for dealing with data files that contain a descriptive header block followed by the actual data.



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]

See Also