C Library Functions  - sort (3)

NAME

sort(3f) - [M_datapac:SORT] sort a vector of sample observations, also return the positions in the original vector

CONTENTS

Synopsis
Description
Options
Input
Output
Examples
Author
Maintainer
References
License

SYNOPSIS

SUBROUTINE SORT(X,N,Y)

     real,intent(in)    :: x(:)
     integer,intent(in) :: n
     real,intent(out)   :: y(:)

DESCRIPTION

This subroutine sorts (in ascending order) the N elements of the REAL vector X using the binary sort algorithm and puts the resulting N sorted values into the REAL vector Y.

OPTIONS

INPUT

X The REAL vector of observations to be sorted. The input vector X remains unaltered.
N The integer number of observations in the vector X.

OUTPUT

Y The REAL vector into which the sorted data values from X will be placed in ascending order.

EXAMPLES

Sample program:

   program demo_sort
   use M_datapac, only : sort
   implicit none
   integer,parameter            :: isz=20
   real                         :: aa(isz)
   real                         :: bb(isz)
   integer                      :: i
      write(*,*)’initializing array with ’,isz,’ random numbers’
      call random_seed()
      CALL RANDOM_NUMBER(aa)
      aa=aa*450000.0
      bb=real([(i,i=1,isz)])

call sort(aa,isz,bb) ! sort data

write(*,*)’checking if real values are sorted(3f)’ do i=1,isz-1 if(bb(i).gt.bb(i+1))then write(*,*)’Error in sorting reals small to large ’,i,bb(i),bb(i+1) endif enddo write(*,’(2(g0,1x))’)’ORIGINAL’,’SORTED’,(aa(i),bb(i),i=1,isz)

end program demo_sort

Results:

AUTHOR

The original DATAPAC library was written by James Filliben of the Statistical Engineering Division, National Institute of Standards and Technology.

MAINTAINER

John Urban, 2022.05.31

REFERENCES

1. CACM MARCH 1969, page 186 (BINARY SORT ALGORITHM BY RICHARD C. SINGLETON).
2. CACM JANUARY 1970, page 54.
3. CACM OCTOBER 1970, page 624.
1. JACM JANUARY 1961, page 41.

LICENSE

CC0-1.0


Nemo Release 3.1 sort (3) July 22, 2023
Generated by manServer 1.08 from 8d19eaf6-ec2f-4c37-a7cc-1e2fb77f74ca using man macros.