PARAM_PRESENT Function
Tests if a parameter was actually present in the call to a procedure or function.
Usage
result = PARAM_PRESENT(parameter)
Input Parameters
parameter — One of the formal parameters as given in the function or procedure definition.
Returned Value
result — A nonzero value (true) if the parameter was present in the call to the current procedure or function. Returns a zero value (false) if the parameter was not present.
Keywords
None.
Discussion
PARAM_PRESENT compliments the KEYWORD_SET and N_ELEMENTS functions. PARAM_PRESENT lets you distinguish between the two cases in which KEYWORD_SET returns FALSE, and the two cases when N_ELEMENTS returns zero (0).
With KEYWORD_SET
The KEYWORD_SET function returns FALSE when:
1. the keyword is set to zero or an undefined variable.
2. the keyword is not used in the call.
PARAM_PRESENT distinguishes between these cases by returning TRUE in case 1 and FALSE in case 2.
With N_ELEMENTS
The N_ELEMENTS function returns zero (0) in two cases when:
1. the keyword or parameter is present but is an undefined variable
2. the keyword or parameter is not present in the call
PARAM_PRESENT distinguishes between these two cases by returning TRUE in case 1 and FALSE in case 2.
Example
The following example demonstrates the expected results when the functions PARAM_PRESENT, KEYWORD_SET, and N_ELEMENTS are used in a procedure.
PRO param_present_ex1, var1, Key=k
   ; Use PARAM_PRESENT to check the parameter
   IF (PARAM_PRESENT(var1)) THEN PRINT, 'Parameter var1 is present.' $
   ELSE PRINT, 'Parameter param1 is not present.'
 
   ; Use N_ELEMENTS to check the parameter
   PRINT, 'Number of elements in var1 = ', STRTRIM(N_ELEMENTS(var1), 2)
   IF (N_ELEMENTS(var1) GT 0) THEN PRINT, 'Parameter var1 is present.' $
   ELSE PRINT, 'Parameter var1 is not present.'
 
   ; Use PARAM_PRESENT to check the keyword
   IF (PARAM_PRESENT(k)) THEN PRINT, 'Keyword Key is present' $
   ELSE PRINT, 'Keyword Key is not present'
 
   ; Use KEYWORD_SET to check the keyword
   IF (KEYWORD_SET(k)) THEN PRINT, 'Keyword Key is set' $
   ELSE PRINT, 'Keyword Key is NOT set'
END
 
WAVE> param_present_ex1
; PV-WAVE prints:
;   Parameter param1 is not present.
;   Number of elements in var1 = 0
;   Parameter var1 is not present.
;   Keyword Key is not present
;   Keyword Key is NOT set
 
WAVE> param_present_ex1, p
; PV-WAVE prints:
;   Parameter var1 is present.
;   Number of elements in var1 = 0
;   Parameter var1 is not present.
;   Keyword Key is not present
;   Keyword Key is NOT set
 
WAVE> p = INDGEN(4)
WAVE> param_present_ex1, p
; PV-WAVE prints:
;   Parameter var1 is present.
;   Number of elements in var1 = 4
;   Parameter var1 is present.
;   Keyword Key is not present
;   Keyword Key is NOT set
 
WAVE> param_present_ex1, p, Key=0
; PV-WAVE prints:
;   Parameter var1 is present.
;   Number of elements in var1 = 4
;   Parameter var1 is present.
;   Keyword Key is present
;   Keyword Key is NOT set
 
WAVE> param_present_ex1, Key=a
; PV-WAVE prints:
;   Parameter param1 is not present.
;   Number of elements in var1 = 0
;   Parameter var1 is not present.
;   Keyword Key is present
;   Keyword Key is NOT set
 
WAVE> a = 10
WAVE> param_present_ex1, Key=a
; PV-WAVE prints:
;   Parameter param1 is not present.
;   Number of elements in var1 = 0
;   Parameter var1 is not present.
;   Keyword Key is present
;   Keyword Key is set
See Also
For more information, see the PV‑WAVE Programmer’s Guide.