The SORT function returns a vector of subscripts that allow access to the elements of Array in ascending order.
Result = SORT(Array [, /L64] )
The result is always a vector of integer type with the same number of elements as Array.
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.
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
When sorting data including Not A Number (NaN) values, the NaN entries are moved to the end of the resulting array. For example:
values = [ 500,
!VALUES.F_NAN,-500 ] PRINT, SORT(values)
2 0 1
REVERSE, UNIQ, WHERE