    PROGRAM nag_sort_ex07

      ! Example Program Text for nag_sort
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_sort, ONLY : nag_rank_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, m, n
      ! .. Local Arrays ..
      INTEGER, ALLOCATABLE :: rank(:)
      REAL (wp), ALLOCATABLE :: a(:,:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_sort_ex07'
      WRITE (nag_std_out,*)

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) m, n

      ALLOCATE (rank(n),a(m,n))    ! Allocate storage

      READ (nag_std_in,*) (a(i,:),i=1,m)

      ! Rank the kth column of matrix in ascending order

      CALL nag_rank_mat(a,rank,row=.FALSE.)

      WRITE (nag_std_out,*) 'Ranks'
      WRITE (nag_std_out,'(12(1X,I4))') rank

      DEALLOCATE (a,rank)          ! Deallocate storage

    END PROGRAM nag_sort_ex07
