IDL Syntax
The following table lists the elements used in IDL syntax listings:
Elements of Syntax
Square Brackets ( [ ] )
- Content between square brackets is optional. Pay close attention to the grouping of square brackets. Consider the following examples:
- Do not include square brackets in your statement unless the brackets are italicized. Consider the following syntax:
- Note that when [, Value1, ... , Valuen] is listed, you can specify any number of arguments. When an explicit number is listed, as in [, Value1, ... , Value8], you can specify only as many arguments as are listed.
ROUTINE_NAME, Value1 [, Value2] [, Value3]: You must include Value1. You do not have to include Value2 or Value3. Value2 and Value3 can be specified independently.
ROUTINE_NAME, Value1 [, Value2, Value3]: You must include Value1. You do not have to include Value2 or Value3, but you must include both Value2 and Value3, or neither.
ROUTINE_NAME [, Value1 [, Value2]]: You can specify Value1 without specifying Value2, but if you specify Value2, you must also specify Value1.
Result = KRIG2D( Z [, X, Y] [, BOUNDS=[xmin, ymin, xmax, ymax]] )
An example of a valid statement is:
R = KRIG2D( Z, X, Y, BOUNDS=[0,0,1,1] )
Braces ( { } )
- For certain keywords, a list of the possible values is provided. This list is enclosed in braces, and the choices are separated by a vertical line ( | ). Do not include the braces in your statement. For example, consider the following syntax:
- Braces are used to enclose the allowable range for a keyword value. Unless otherwise noted, ranges provided are inclusive. Consider the following syntax:
- Braces are also used to provide useful information about a keyword. For example:
- Certain keywords are prefaced by X, Y, or Z. Braces are used for these keywords to indicate that you must choose one of the values it contains. For example, [{X | Y}RANGE=array] indicates that you can specify either XRANGE=array or YRANGE=array.
- Note that in IDL, braces are used to define structures. When defining a structure, you do want to include the braces in your statement.
READ_JPEG [, TRUE={1 | 2 | 3 }]
In this example, you must choose either 1, 2, or 3. An example of a valid statement is:
READ_JPEG, TRUE=1
Result = CVTTOBM( Array [, THRESHOLD=value{0 to 255}] )
An example of a valid statement is:
Result = CVTTOBM( A, THRESHOLD=150 )
[, LABEL=n{label every nth gridline}]
Do not include the braces or their content in your statement.
Italics
- Italicized words are arguments, expressions, or statements for which you must provide values. The value you provide can be a numerical value, such as 10, an expression, such as DIST(100), or a named variable. For keywords that expect a string value, the syntax is listed as KEYWORD=string. The value you provide can be a string, such as 'Hello' (enclosed in single quotation marks), or a variable that holds a string value.
- The italicized values that must be provided for keywords are listed in the most helpful terms possible. For example, [, XSIZE=pixels] indicates that the XSIZE keyword expects a value in pixels, while [, ORIENTATION=ccw_degrees_from_horiz] indicates that you must provide a value in degrees, measured counter-clockwise from horizontal.
Procedures
IDL procedures use the following general syntax:
PROCEDURE_NAME, Argument [, Optional_Argument]
where PROCEDURE_NAME is the name of the procedure, Argument is a required parameter, and Optional_Argument is an optional parameter to the procedure.
Functions
IDL functions use the following general syntax:
Result = FUNCTION_NAME( Argument [, Optional_Argument] )
where Result is the returned value of the function, FUNCTION_NAME is the name of the function, Argument is a required parameter, and Optional_Argument is an optional parameter. Note that all arguments and keyword arguments to functions should be supplied within the parentheses that follow the function's name.
Functions do not always have to be used in assignment statements (i.e., A=SIN(10.2)), they can be used just like any other IDL expression. For example, you could print the result of SIN(10.2) by entering the command:
Arguments
The "Arguments" section describes each valid argument to the routine. Note that these arguments are positional parameters that must be supplied in the order indicated by the routine's syntax.
Named Variables
Often, arguments that contain values upon return from the function or procedure ("output arguments") are described as accepting "named variables". A named variable is simply a valid IDL variable name. This variable does not need to be defined before being used as an output argument. Note, however that when an argument calls for a named variable, only a named variable can be used—sending an expression causes an error.
Keywords
The "Keywords" section describes each valid keyword argument to the routine. Note that keyword arguments are formal parameters that can be supplied in any order.
Keyword arguments are supplied to IDL routines by including the keyword name followed by an equal sign ("=") and the value to which the keyword should be set. The value can be a value, an expression, or a named variable (a named variable is simply a valid IDL variable name).
Note
If you set a keyword equal to an undefined named variable, IDL will quietly ignore the value.
For example, to produce a plot with diamond-shaped plotting symbols, the PSYM keyword should be set to 4 as follows:
Note the following when specifying keywords:
- Certain keywords are boolean, meaning they can be set to either 0 or 1. These keywords are switches used to turn an option on and off. Usually, setting such keywords equal to 1 causes the option to be turned on. Explicitly setting the keyword to 0 (or not including the keyword) turns the option off. In the syntax listings in this reference, all keywords that are preceded by a slash can be set by prefacing them by the slash. For example, SURFACE, DIST(10), /SKIRT is a shortcut for SURFACE, DIST(10), SKIRT=1. To turn the option back off, you must set the keyword equal to 0, as in SURFACE, DIST(10), SKIRT=0.
- Some keywords are used to obtain values that can be used upon return from the function or procedure. These keywords are listed as KEYWORD=variable. Any valid variable name can be used for these keywords, and the variable does not need to be defined first. Note, however, that when a keyword calls for a named variable, only a named variable can be used—sending an expression causes an error.
- Some routines have keywords that are mutually exclusive, meaning only one of the keywords can be present in a given statement. These keywords are grouped together, and separated by a vertical line. For example, consider the following syntax:
- Keywords can be abbreviated to their shortest unique length. For example, the XSTYLE keyword can be abbreviated to XST because there are no other keywords in IDL that begin with XST. You cannot shorten XSTYLE to XS, however, because there are other keywords that begin with XS, such as XSIZE.
In rare cases, a keyword's default value is 1. In these cases, the syntax is listed as KEYWORD=0, as in SLIDE_IMAGE [, Image] [, CONGRID=0]. In this example, CONGRID is set to 1 by default. If you specify CONGRID=0, you can turn it back on by specifying either /CONGRID or CONGRID=1.
For example, the WIDGET_CONTROL procedure can return the user values of widgets in a named variable using the GET_UVALUE keyword. To return the user value for a widget ID (contained in the variable mywidget) in the variable userval, you would use the command:
WIDGET_CONTROL, mywidget, GET_UVALUE = uservalUpon return from the procedure,
uservalcontains the user value. Note thatuservaldid not have to be defined before the call to WIDGET_CONTROL.
PLOT, [X,] Y [, /DATA | , /DEVICE | , /NORMAL]
In this example, you can choose either DATA, DEVICE, or NORMAL, but not more than one. An example of a valid statement is:
PLOT, SIN(A), /DEVICE