Reference Guide > A Routines > ASSOC Function
  

ASSOC Function
Associates an array definition with a file, allowing random access input and output.
 
note
ASSOC should only be used for homogenous arrays of simple data types. No structures, lists, and so forth. Not only is padding between the structure elements, but an array of structures may also contain padding between each array element. The machine specific issues require this restriction.
Usage
result = ASSOC(unit, array_definition [, offset])
Input Parameters
unit—The file unit to associate with array_definition.
array_definition—An expression that defines the data type and dimensions of the associated data.
offset—The offset in the file to the start of the data in the file. For stream files and RMS block mode files, this offset is given in bytes. For RMS record-oriented files, this offset is specified in records.
 
note
The offset parameter is useful for skipping past descriptive header blocks in files.
Returned Value
result—A variable that associates the array definition with the file.
Keywords
None.
Discussion
ASSOC provides a basic method of random access input/output. The associated variable (the one storing the association) is created by assigning the result of ASSOC to a variable. This variable provides a means for mapping a file into vectors or arrays of a specified type and size.
 
note
ASSOC does not work with UNIX FORTRAN binary files.
Example
Assume you have a binary file, image_file.img, with five 512-by-512 byte images and a 1024-byte header:
; Open the file.
OPENR, 1, 'image_file.img'
aimage = ASSOC(1, BYTARR(512, 512), 1024)
; Read the first image.
image1 = aimage(0)
; Read the fifth image.
image5 = aimage(4)
; Display the third image.
TVSCL, aimage(2)
; Do an FFT function on the second image.
fft_image = FFT(aimage (1), -1)
arow = ASSOC(1, BYTARR(512), 1024)
; Read the 100th row.
row100 = arow(99)
; Plot the first row in the second image.
PLOT, arow(512)

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.