KDM_ISDEFINED
Name
KDM_ISDEFINED
Purpose
This procedure checks if a variable is defined or not, and
optionally sets it to a default value, or prompts the user to
enter a value.
This is a fancy wrapper for N_ELEMENTS() EQ 0 and KEYWORD_SET()
Category
Genaral Programming
Calling Sequence
KDM_ISDEFINED, Variable
Inputs
Variable: A variable that may or may not be defined.
Keyword Parameters
DEFAULT: The value to set the variable to. This is ONLY if
the variable is not defined.
PROMPT: The prompt to use to let the user set the value. The user
is only prompted to enter a value if the variable is
undefined.
Outputs
Variable may be changed. If it was undefined, and one (or both) of
the DEFAULT and/or PROMPT keywords were set.
Restrictions
If the input variable is undefined, and no default value is
supplied, but a PROMPT value is supplied, then the returned
variable is of type STRING because that is the most general data
type.
Example
If a variable is defined, nothing happens:
x = 42
kdm_isdefined, x, default='foo', prompt='P'
Set an undefined variable to a default value:
kdm_isdefined, xx, default='bar'
kdm_isdefined, xx2, default=dist(42,24)
kdm_isdefined, ll, d=[0.,0], p="Enter lat,lon: "
Set an undefined variable to user inputs:
kdm_isdefined, xxx, prompt='Enter Something: '
Set an undefinde variable to a user input but control the type:
kdm_isdefined, xxxx, prompt='Enter Something: ', default=BYTE(42)
Modification History
Written by: Ken Mankoff, 2010-03
2010-04-18: Provide type hint. Allow empty strings to
default to default input if supplied.