KEYWORD_SET Function
Tests if an input expression has a nonzero value.
 
note
For keywords where 0 is a valid and meaningful value, do not use KEYWORD_SET to test the validity of the keyword. To test these keywords, use the N_ELEMENTS Function instead.
Usage
result = KEYWORD_SET(expr)
Input Parameters
expr—The expression to be tested. Usually a named variable.
Returned Value
result—A nonzero value, if expr is defined and nonzero.
Keywords
None.
Discussion
KEYWORD_SET is especially useful in user-written procedures and functions when you want to process keywords that can be interpreted as being either true (keyword is present and nonzero) or false (keyword was not used, or was set false).
It can also be used to test whether an expression evaluates to zero, or whether a variable has been set.
Example 1
Assume you type the following commands:
IF KEYWORD_SET(x) THEN PRINT, 'It is set' ELSE PRINT, 'Not set'
You will see:
Not set
because the value of x has not been initialized. On the other hand, if you set x to a specific value, say 2, you will see:
x = 2
IF KEYWORD_SET(x) THEN PRINT, 'It is set' ELSE PRINT, 'Not set'
; PV-WAVE prints: It is set
Example 2
The following user-defined routine uses KEYWORD_SET to make a call to print the results of a squaring operation:
FUNCTION square_it, Value, Print_Flag=print_flag
   Squared_Val = Value * Value
   IF (KEYWORD_SET(Print_Flag)) THEN PRINT, Squared_Val
   RETURN, Squared_Val
END
To run this routine, enter the following commands at the WAVE> prompt:
.RUN SQUARE_IT.PRO
y = SQUARE_IT(5) 
PRINT, y      ; PV-WAVE prints: 25
y = SQUARE_IT(10, /Print_Flag)      ; 100
See Also