A = [4, 3, 7, 1, 2]
PRINT, 'SORT(A) = ', SORT(A)
; Display the elements of A in sorted order:
PRINT, 'Elements of A in sorted order: ', A[SORT(A)]
; Display the elements of A in descending order:
PRINT, 'Elements of A in descending order: ', A[REVERSE(SORT(A))]
SORT(A) = 3 4 1 0 2
Elements of A in sorted order: 1 2 3 4 7
Elements of A in descending order: 7 4 3 2 1
SORT(A) returns “3 4 1 0 2” because:
A < A < A < A < A
Sorting NaN Values
When sorting data including Not A Number (NaN) values, the NaN entries are moved to the end of the resulting array. For example:
2 0 1
Result = SORT(Array [, /L64] )
The result is always a vector of integer type with the same number of elements as Array.
Note: If Array contains any identical elements, the order in which the identical elements are sorted is arbitrary and may vary between operating systems.
The array to be sorted. Array can be any basic type of vector or array. String arrays are sorted using the ASCII collating sequence. Complex arrays are sorted by their magnitude. Array values which are Not A Number (NaN) are moved to the end of the resulting array.
By default, the result of SORT is 32-bit integer when possible, and 64-bit integer if the number of elements being sorted requires it. Set L64 to force 64-bit integers to be returned in all cases.
Note: Only 64-bit versions of IDL are capable of creating variables requiring a 64-bit sort. Check the value of !VERSION.MEMORY_BITS to see if your IDL is 64-bit or not.