Overview of Procedures and Functions

Procedures and functions are self-contained modules that break large tasks into smaller, more manageable ones. Modular programs simplify debugging and maintenance and, because they are reusable, minimize the amount of new code required for each application.

New procedures and functions can be written in IDL and called in the same manner as the system-defined procedures or functions from the command prompt or from other programs. When a procedure or function is finished, it executes a RETURN statement that returns control to its caller. Functions always return an explicit result.

A procedure is called by a procedure call statement, while a function is called by a function reference. For example, if myproABC is a procedure and myfuncXYZ is a function, the calling syntax is:

; Call procedure with two parameters. 
myproABC, A, 12 
 
; Call function with one parameter. The result is stored  
; in variable A. 
A = myfuncXYZ(C/D) 
 

Note
See Library Authoring for information on naming procedures to avoid conflicts with IDL routine names. It is important to implement and consistently use a naming scheme from the earliest stages of code development.

Procedures and functions are collectively referred to as routines. An IDL program file may contain one or many routines, which can be a mix of procedures and functions.