Format of Program Files
A self-contained code unit with a unique name that is called by other code units to perform a desired function. The calling code unit and the procedure communicate via passed arguments.
- Purpose: Specify a procedure name and parameters.
name is the name of the procedure.
pro test, a, b, c
if a eq b and b eq c then print,'All equals'
pro compute, x, y, z, help=help
if keyword_set(help) then begin
print,'x and y : inputs, z: output'
va_tmp = (x^2 - y^2)
if va_tmp ge 0 then z = sqrt(va_tmp) else z = 0
- Notes: A procedure must end with an end statement and may have one or more return statements inside. If program flow reaches the final end statement a return is implied.
Example calls to the above procedures:
test, 2, 3, 2
compute, x, y, z, /help
Rem: The recursivity of procedure and function is allowed.
A self-contained code unit similar to a procedure. The only difference is that a function returns a value and can therefore be used in expressions.
- Purpose: Specify a function name and parameters.
name is the name of the function. It will be saved in a file called name.pro
function test2,a, b, c
if a eq b and b eq c then return,1 else return,0
function compute2, x, y, z, flag=flag
if keyword_set(flag) then print,' In the function compute2'
va_tmp = x^2 - y^2 - z^2
if va_tmp ge 0 then return,sqrt(va_tmp) $
- Notes: A function must end with an end statement and must have one or more return
statements inside. A return statement in a
function must include the return value: return,
Example calls to the above functions:
IDL> a =
test2(2, 3, 5)
IDL> t =
compute2(x, y, z, /flag)
That's why the best way to read a vector or an array is to define well a variable before (most of the time an array or a structure will be welcome) , and to read all the data in one rush. Or you have to use a temporary variable if you really want to use a loop:
for i=1,N do begin
tata(i) = temp
A series of statements that are not preceded by a procedure or function
heading. They do, however, require an END statement. Since there is no heading,
it cannot be called from other routines and cannot be passed in arguments. When
IDL encounters a main program as the result of a .RUN executive command, it
compiles it into the special program named $MAIN$ and immediately executes it.
Afterwards, it can be executed again by using the .GO executive command.
A file to be included in other files. The statements contained in an include file are textually inserted into the including file. A file can contain any combination of functions, procedures, and/or include files. For example, a file might contain three procedures and two functions and also might be included in another file.
IDL courses C. Morisset © 2004 IA/UNAM V 2.2