Skip to content
Fabian Kindermann edited this page May 6, 2024 · 5 revisions
subroutine sort(x, iorder)

Description:

This subroutine sorts an array x in ascending order. The array can either be of type integer or real*8. The subroutine can also return the ordering permutation.

Input arguments:

  • integer :: x(:)    or    real*8 :: x(:)
    An array of arbitrary length that should be sorted in ascending order.

Output arguments:

  • integer :: x(:)    or    real*8 :: x(:)
    After the sorting process is finished, the subroutine stores the sorted array in the variable x.

Optional arguments:

  • integer :: iorder(:)
    In this one-dimensional array that must have exactly the same length as the array x, the subroutine stores the ordering permutation, meaning that for any element of the original input array x, the subroutine stores where this element went after the sorting process. If, hence, iorder(1) = 3, then the first element of the sorted array will be the third element of the original array x. Recording the permutation ordering is useful, if you have other arrays that should be rearranged in the same way as x.

References

  • Parts of this routine were copied and adapted from:
  • For further reading refer to:
    • Cormen, T.H., Leiserson, C.E., Rivest, R.L. & Stein, C. (2009). Introduction to Algorithms, 3rd edition. Cambridge: MIT Press.
  • This routine is used in the following programs:
    • prog04_08.f90
    • prog04_09.f90
    • prog10_04.f90

HOME
» Toolbox Documentation
» Other useful routines

Clone this wiki locally