IDL 8.4: Boolean variables
posted Tue 4 Nov 2014 by Michael Galloy under IDLIDL 8.4 also introduces a new boolean “type”, which is actually not a real type, but just a metadata flag on byte variables[1]. This boolean flag allows for better understanding of the purpose of the variable. For example, JSON_SERIALIZE
can convert boolean IDL variables to boolean JSON declarations.
Create boolean variables by converting existing variables with the BOOLEAN
function or by creating arrays with BOOLARR
. The rules used to convert variables to boolean are not the normal truth values in IDL[2]; they are the rules used with the logical_predicate
compile option is set, i.e., null, empty, or 0 values are false, everything else is true:
IDL> print, boolean(indgen(5))
0 1 1 1 1
IDL> print, boolean(['', 'yes', 'no'])
0 1 1
There are also convenient new !true
and !false
boolean system variables:
IDL> help, !true<
BOOLEAN = true (1)
IDL> help, !false
BOOLEAN = false (0)
IDL> if 1 then print, 'true' else print, 'false'
true
IDL> if 2 then print, 'true' else print, 'false'
false
IDL> if 3 then print, 'true' else print, 'false'
true
For those familiar with IDL’s internal API, IDL 8.4 introduces a
IDL_V_BOOLEAN
flag that is used to mark theflags
field of anIDL_VARIABLE
structure. There is also anIDL_BOOLEAN
macro to determine if a variable is a boolean. The macro requires that theIDL_V_BOOLEAN
flag is set and that the variable is of type byte. ??Thank goodness. The “normal” IDL rules for the truth value of integers depend on the lowest order bit of the integer, i.e., whether the integer is even or odd: ??