{I,S,D}SORTQX ( order, n, x, incx, index )
order character*1 On entry, order specifies the operation to be performed as follows: If order = 'A' or 'a', x is sorted in ascending sequence If order = 'D' or 'd', x is sorted in descending sequence On exit, order is unchanged. n integer*4 On entry, the length of vector x. On exit, n is unchanged. x integer*4 | real*4 | real*8 On entry, a length n vector of data to be sorted. On exit, x is unchanged. incx integer*4 On entry, incx specifies the distance between elements of vector x. incx must be positive. On exit, incx is unchanged. index integer*4 On entry, the content of index is ignored. On exit, index contains a permuted vector of indices which may be used to access data vector x in the sorted order specified by order.
The _SORTQX routines sort an indexed vector of data using the quicksort algorithm. Data is sorted in ascending order if order is 'A' or 'a' and in descending order if order is 'D' or 'd'. The quicksort algorithm is implemented by recursinq until the partition size is less than sixteen. At that point a modified insertion sort is used to sort the elements of the partition.
REAL*4 DATA( 100 ),INDEX( 100 ) N = 100 CALL SSORTQX( 'A',N,DATA,1,INDEX ) DO I=1,N PRINT *,DATA( INDEX(I) ) ENDDO This FORTRAN code sorts a 100 element single real vector and prints its contents in sorted order.