When a user-written procedure or function is called, the following actions occur:
Recursion (i.e., a program calling itself) is supported for both procedures and functions.
Here is an example of an IDL procedure that reads and plots the next vector from a file. This example illustrates using common variables to store values between calls, as local parameters are destroyed on exit. It assumes that the file containing the data is open on logical unit 1 and that the file contains a number of 512-element, floating-point vectors.
;Read and plot the next record from file 1. If RECNO is specified, ;set the current record to its value and plot it. PRO NXT, recno ;Save previous record number. COMMON NXT_COM, lastrec ;Set record number if parameter is present. IF N_PARAMS(0) GE 1 THEN lastrec = recno ;Define LASTREC if this is first call. IF N_ELEMENTS(lastrec) LE 0 THEN lastrec = 0 ;Define file structure. AA = ASSOC(1, FLTARR(512)) ;Read and plot record. PLOT, AA[lastrec] ;Increment record for next time. lastrec = lastrec + 1 END
Once the user has opened the file, typing NXT will read and plot the next record. Typing NXT, N will read and plot record number N.