%N hsortd %F $MIR/src/subs/hsort.for
%D Perform an indexed heapsort on a double precision array.
%P jm
%: sorting
%B
      subroutine hsortd(n, array, indx)

      implicit none
      integer n, indx(n)
      double precision array(n)

  HSORTD performs an index based heapsort on a double precision array.
  The number of elements in the array and the array are left unchanged.
  The size of the indx array should be at least as large as the size of
  the double precision array.

     Input:
       n        The number of elements in the array.
       array    The double precision array on which to base the sort.

     Output:
       indx     Sorted integer index array such that array(indx(1)) is
                the smallest and array(indx(n)) is the largest element.
