The FIX function converts a given expression to an integer type. Optionally, the conversion type can be specified at runtime, allowing flexible runtime type-conversion to arbitrary types.
Result = FIX( Expression [, Offset [, D1 [, ..., D8]]] [, /PRINT]
[, TYPE=type code{0 to 15}] )
Returns a result equal to Expression converted to integer type.
The expression to be converted.
Offset from beginning of the Expression data area. Specifying this argument allows fields of data extracted from Expression to be treated as integer data. See the description in Constants and Variables for details.
The Offset and Dimi arguments are not allowed when converting to or from the string type.
When extracting fields of data, the Di arguments specify the dimensions of the result. If no dimension arguments are given, the result is taken to be scalar.
The Di arguments can be either an array or a series of scalar expressions specifying the dimensions of the result. If a single argument is specified, it can be either a scalar expression or an array of up to eight elements. If multiple arguments are specified, they must all be scalar expressions. Up to eight dimensions can be specified.
The Offset and Di arguments are not allowed when converting to or from the string type.
Set this keyword to specify that any special-case processing when converting between string and byte data, or the reverse, should be suppressed. The PRINT keyword is ignored unless the TYPE keyword is used to convert to these types.
FIX normally converts Expression to the integer type. If TYPE is specified, it is the type code to set the type of the conversion. This feature allows dynamic type conversion, where the desired type is not known until runtime, to be carried out without the use of large CASE or IF...THEN logic. When TYPE is specified, FIX behaves as if the appropriate type conversion routine for the desired type had been called. See the "See Also" list below for the complete list of such routines.
When using the TYPE keyword to convert BYTE data to STRING or the reverse, you should be aware of the special-case processing that the BYTE and STRING functions do in this case. To prevent this, and get a simple type conversion in these cases, you must specify the PRINT keyword.
This routine is written to make use of IDL's thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the
Convert the floating-point array [2.2, 3.0, 4.5] to integer type and store the new array in the variable I by entering:
I = FIX([2.2, 3.0, 4.5])
Introduced: Original
BYTE, COMPLEX, DCOMPLEX, DOUBLE, FLOAT, LONG, LONG64, STRING, UINT, ULONG, ULONG64