8.5.16   Miscellaneous Functions

Operation Meaning HALCON operator

sort(t) sorting in increasing order tuple_sort
sort_index(t) return index instead of values tuple_sort_index
inverse(t) reverse the order of the values tuple_inverse
number(v) convert string to a number tuple_number
environment(s) value of an environment variable tuple_environment
ord(a) convert strings of length 1 into character codes (Unicode or ANSI) tuple_ord
chr(a) Inverse of ord(a) tuple_chr
ords(s) convert strings into character codes (Unicode or ANSI) tuple_ords
chrt(i) Inverse of ords(s) tuple_chrt
rand(a) create random numbers tuple_rand

Table 8.23: Miscellaneous functions.

sort sorts the tuple values in ascending order, that means, that the first value of the resulting tuple is the smallest one. But again: strings must not be mixed up with numbers. sort_index sorts the tuple values in ascending order, but in contrast to sort it returns the index positions (0..) of the sorted values.

The function inverse reverses the order of the tuple values. Both sort and inverse are identical, if the input is empty, if the tuple is of length 1, or if the tuple contains only one value in all positions, e.g., [1,1,...,1].

is_number returns true for variables of the type integer or real and for variables of the type string that represent a number.

The function number converts a string representing a number to an integer or a real depending on the type of the number. Note that strings starting with 0x are interpreted as hexadecimal numbers, and strings starting with 0 (zero) as octal numbers; for example, the string '20' is converted to the integer 20, '020' to 16, and '0x20' to 32. If called with a string that does not represent a number or with a variable of the type integer or real, number returns a copy of the input.

environment returns the value of an environment variable. Input is the name of the environment variable as a string.

ord converts a tuple of strings of length 1 into a tuple of integers (Unicode character codes or ANSI codes). chr converts the Unicode character codes or the ANSI codes into a tuple of strings, each of length 1.

ords converts a tuple of strings into a tuple of integers (Unicode character codes or ANSI codes). chrt converts the Unicode character codes or the ANSI codes into a tuple with strings that are separated by the number 0.